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 ;-)

About these ads

2 Responses to “Xtend, JavaFX-Properties and operator overloading”

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

Trackbacks/Pingbacks

  1. Interview with Tom Schindl // JavaFX News, Demos and Insight // FX Experience - July 14, 2012

    [...] talk about alternate programming languages to write JavaFX applications I’m an Xtend fan and have blogged already about my experiments with it. I can only advise Eclipse IDE users to take a look at it. [...]

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

Follow

Get every new post delivered to your Inbox.

Join 695 other followers

%d bloggers like this: