Base class that provides most of the functionality needed to implement a
Binding
of a double
value.
DoubleBinding
provides a simple invalidation-scheme. An extending
class can register dependencies by calling bind(Observable...)
.
If One of the registered dependencies becomes invalid, this
DoubleBinding
is marked as invalid. With
unbind(Observable...)
listening to dependencies can be stopped.
To provide a concrete implementation of this class, the method
computeValue()
has to be implemented to calculate the value of this
binding based on the current state of the dependencies. It is called when
get()
is called for an invalid binding.
Below is a simple example of a DoubleBinding
calculating the square-
root of a javafx.beans.value.ObservableNumberValue
moo
.
final ObservableDoubleValue moo = ...;
DoubleBinding foo = new DoubleBinding() {
{
super.bind(moo);
}
@Override
protected double computeValue() {
return Math.sqrt(moo.getValue());
}
};
Following is the same example with implementations for the optional methods
Binding.getDependencies()
and Binding.dispose()
.
final ObservableDoubleValue moo = ...;
DoubleBinding foo = new DoubleBinding() {
{
super.bind(moo);
}
@Override
protected double computeValue() {
return Math.sqrt(moo.getValue());
}
@Override
public ObservableList<?> getDependencies() {
return FXCollections.singletonObservableList(moo);
}
@Override
public void dispose() {
super.unbind(moo);
}
};
extends
Binding, NumberBinding, javafx.beans.binding.DoubleExpression