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😉

2 thoughts on “Xtend, JavaFX-Properties and operator overloading

  1. heimp September 22, 2012 / 3:50 pm

    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 )

Google+ photo

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

Connecting to %s