Module javafx.base

Class DoubleBinding

java.lang.Object
All Implemented Interfaces:
Binding<Number>, NumberBinding, NumberExpression, Observable, ObservableDoubleValue, ObservableNumberValue, ObservableValue<Number>

public abstract class DoubleBinding extends DoubleExpression implements NumberBinding
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 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);
     }
 };
 
 
Since:
JavaFX 2.0
See Also: