Java Reference
In-Depth Information
Another set of concrete classes in the JavaFX properties and bindings framework is the
ReadOnlyIntegerWrapper series of classes. These classes implement the Property interface
but also have a getReadOnlyProperty() method that returns a ReadOnlyProperty that is
synchronized with the main Property . They are very handy to use when you need a full-
blown Property for the implementation of a component but you only want to hand out a
ReadOnlyProperty to the client of the component.
The
IntegerPropertyBase series of abstract classes can be extended to provide
implementations of full Property classes, although in practice the SimpleIntegerProperty
series of classes is easier to use. The only abstract methods in the IntegerPropertyBase series
of classes are getBean() and getName() .
The
ReadOnlyIntegerPropertyBase series of abstract classes can be extended to provide
implementations of ReadOnlyProperty classes. This is rarely necessary. The only abstract
methods in the ReadOnlyIntegerPropertyBase series of classes are get() , getBean() , and
getName() .
The
WeakInvalidationListener and WeakChangeListener classes can be used to wrap
InvalidationListener and ChangeListener instances before addListener() is called. They
hold weak references of the wrapped listener instances. As long as you hold a reference to
the wrapped listener on your side, the weak references will be kept alive and you will receive
events. When you are done with the wrapped listener and have unreferenced it from your side,
the weak references will be eligible for garbage collection and later garbage collected. All the
JavaFX properties and bindings framework Observable objects know how to clean up a weak
listener after its weak reference has been garbage collected. This prevents memory leaks when
the listeners are not removed after use. The WeakInvalidationListener and WeakListener
classes implement the WeakListener interface, whose wasGarbageCollected() method will
return true if the wrapped listener instance was garbage collected.
That covers all the JavaFX properties and bindings APIs that reside in the javafx.beans , javafx.beans.
property , and javafx.beans.value packages and some but not all of the APIs in the javafx.beans.binding package.
The javafx.beans.property.adapters package provides adapters between old-style JavaBeans properties and
JavaFX properties. We will cover these adapters in the “Adapting JavaBeans Properties to JavaFX Properties” section.
The remaining classes of the javafx.beans.binding package are APIs that help you to create new bindings out of
existing properties and bindings. That is the focus of the next section.
Creating Bindings
We now turn our focus to the creation of new bindings out of existing properties and bindings. You learned in the
“Understanding Key Interfaces and Concepts” section earlier in this chapter that a binding is an observable value that
has a list of dependencies that are also observable values.
The JavaFX properties and bindings framework offers three ways of creating new bindings:
Extending the
IntegerBinding series of abstract classes.
Using the bindings-creating static methods in the utilities class
Bindings .
IntegerExpression series of abstract classes.
You saw the direct extension approach in the “Understanding the Binding Interface” section earlier in this
chapter. We explore the Bindings utility class next.
Using the fluent interface API provided by the
 
Search WWH ::




Custom Search