Interface Binding<T>
- Type Parameters:
T- the type of the wrapped value
- All Superinterfaces:
Observable, ObservableValue<T>
- All Known Subinterfaces:
NumberBinding
- All Known Implementing Classes:
BooleanBinding, DoubleBinding, FloatBinding, IntegerBinding, ListBinding, LongBinding, MapBinding, ObjectBinding, SetBinding, StringBinding
Binding calculates a value that depends on one or more sources. The
sources are usually called the dependency of a binding. A binding observes
its dependencies for changes and updates its value automatically.
While a dependency of a binding can be anything, it is almost always an
implementation of ObservableValue. Binding
implements ObservableValue allowing to use it in another binding.
With that one can assemble very complex bindings from simple bindings.
All bindings in the JavaFX runtime are calculated lazily. That means, if a dependency changes, the result of a binding is not immediately recalculated, but it is marked as invalid. Next time the value of an invalid binding is requested, it is recalculated.
It is recommended to use one of the base classes defined in this package
(e.g. DoubleBinding) to define a custom binding, because these
classes already provide most of the needed functionality. See
DoubleBinding for an example.
- Since:
- JavaFX 2.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Signals to theBindingthat it will not be used anymore and any references can be removed.Returns the dependencies of a binding in an unmodifiableObservableList.voidMark a binding as invalid.booleanisValid()Checks if a binding is valid.Methods declared in interface Observable
addListener, removeListener, subscribeModifier and TypeMethodDescriptionvoidaddListener(InvalidationListener listener) Adds anInvalidationListenerwhich will be notified whenever theObservablebecomes invalid.voidremoveListener(InvalidationListener listener) Removes the given listener from the list of listeners, that are notified whenever the value of theObservablebecomes invalid.default SubscriptionCreates aSubscriptionon thisObservablewhich callsinvalidationSubscriberwhenever it becomes invalid.Methods declared in interface ObservableValue
addListener, flatMap, getValue, map, orElse, removeListener, subscribe, subscribe, whenModifier and TypeMethodDescriptionvoidaddListener(ChangeListener<? super T> listener) Adds aChangeListenerwhich will be notified whenever the value of theObservableValuechanges.default <U> ObservableValue<U> flatMap(Function<? super T, ? extends ObservableValue<? extends U>> mapper) Returns anObservableValuethat holds the value of anObservableValueproduced by applying the given mapping function on this value.getValue()Returns the current value of thisObservableValuedefault <U> ObservableValue<U> Returns anObservableValuethat holds the result of applying the given mapping function on this value.default ObservableValue<T> Returns anObservableValuethat holds this value, or the given constant if it isnull.voidremoveListener(ChangeListener<? super T> listener) Removes the given listener from the list of listeners that are notified whenever the value of theObservableValuechanges.default Subscriptionsubscribe(BiConsumer<? super T, ? super T> changeSubscriber) Creates aSubscriptionon thisObservableValuewhich calls the givenchangeSubscriberwith the old and new value whenever its value changes.default SubscriptionCreates aSubscriptionon thisObservableValuewhich immediately provides the current value to the givenvalueSubscriber, followed by any subsequent values whenever its value changes.default ObservableValue<T> when(ObservableValue<Boolean> condition) Returns anObservableValuethat holds this value and is updated only whenconditionholdstrue.
-
Method Details
-
isValid
boolean isValid()Checks if a binding is valid.- Returns:
trueif theBindingis valid,falseotherwise
-
invalidate
void invalidate()Mark a binding as invalid. This forces the recalculation of the value of theBindingnext time it is request. -
getDependencies
ObservableList<?> getDependencies()Returns the dependencies of a binding in an unmodifiableObservableList. The implementation is optional. The main purpose of this method is to support developers during development. It allows to explore and monitor dependencies of a binding during runtime.Because this method should not be used in production code, it is recommended to implement this functionality as sparse as possible. For example if the dependencies do not change, each call can generate a new
ObservableList, avoiding the necessity to store the result.- Returns:
- an unmodifiable ObservableList of the dependencies
-
dispose
void dispose()Signals to theBindingthat it will not be used anymore and any references can be removed. A call of this method usually results in the binding stopping to observe its dependencies by unregistering its listener(s). The implementation is optional.All bindings in our implementation use instances of
WeakInvalidationListener, which means usually a binding does not need to be disposed. But if you plan to use your application in environments that do not supportWeakReferencesyou have to dispose unusedBindingsto avoid memory leaks.
-