Xtend, JavaFX-Properties and operator overloading

JavaFX has properties you can bind to each other to keep them insync. Watch this video for a very minimal example which scales a text by dragging a slider.

Now let’s look at the Xtend code used to write this small sample

The important lines are:

// Bidirectional binding between sliders
sl_1.valueProperty .. sl_2.valueProperty;

// Unidirectional binding from slider to scaleX/Y
l.scaleXProperty -> sl_2.valueProperty;
l.scaleYProperty -> sl_2.valueProperty;

The trick here to make this code not as verbose as it’s java counterpart is that Xtend allows to overload operators (+, -, ->, .., …).

What I don’t fully understand is why I can’t define my operator overloading like this:

def static <T> operator_mappedTo(Property<T> x, ObservableValue<? extends T> y) {

which should work when looking at the inheritance hierarchy of DoubleProperty, maybe some Xtend guru can explain it to me 😉

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Xtend, JavaFX-Properties and operator overloading

  1. Pingback: Interview with Tom Schindl // JavaFX News, Demos and Insight // FX Experience

  2. heimp says:

    Looks like it’s got something to do with the mappedTo operator. Other operators work fine with your parameterized code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.