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) {
  x.bind(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 comment

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