Reputation: 414
Given a property of a JavaFX Node declared as:
public final ReadOnlyObjectProperty<Bounds> boundsInParentProperty
...which is an ObservableValue<Bounds>. And a method implemented in corresponding ChangeListener<Bounds>:
public void changed(ObservableValue<? extends Bounds> observedValue, Bounds oldvalue, Bounds newvalue)
What is the first argument in the method for?
At first I used observedValue.getValue(), but later I was able to calculate the delta of various coordinates of Bounds from just the second and third argument (newvalue - oldvalue). The type of argument is known (Bounds), so it's not like a key-value scheme. I'm highly distrustful of what I don't understand, so what is this 'observedValue' and should I use it?
EDIT: After the comments I understand it's used for determining which ObservableValue (if multiple) is the source of the event. Let's say I want to have a Line drawn between two draggable Nodes on screen, and I want to track the Bounds of both this way. How to determine which Node is the source of change event (get its reference)?
Upvotes: 0
Views: 302
Reputation: 477
Sometimes you subscribe your listener to multiple variables change, and you may be interested which one of them had changed. It's quite popular trick in Observer implementation.
Upvotes: 0