java.lang.Object
io.github.palexdev.materialfx.utils.others.observables.When<T>
- Direct Known Subclasses:
OnChanged,OnInvalidated
Useful class to listen to changes for a given
ObservableValue and perform any
specified action when it changes.
You can read this construct as "When condition changes, then do this"
This is just an abstract class that defines common properties and behavior but it has two concrete
implementation, OnChanged and OnInvalidated.
This construct also allows to define one-shot listeners, meaning that the above phrase changes like this: "When condition changes, then do this, then dispose(remove listener)"
Note:Once the construct is not needed anymore it's highly recommended to dispose it usingdisposeFor(ObservableValue) to avoid memory leaks.
When constructs and ObservableValues are stored in a WeakHashMap for this purpose.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ObservableValue<T>protected booleanprotected static final WeakHashMap<ObservableValue<?>,When<?>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voiddispose()static voiddisposeFor(ObservableValue<?> observableValue) If a When constructs exists for the givenObservableValue,dispose()is invoked.booleanlisten()static <T> OnChanged<T>onChanged(ObservableValue<T> observableValue) Convenience method to create an instance ofOnChanged.oneShot()Specifies that the construct is "one-shot", meaning that once the value changes the first time, the construct will automatically dispose itself.static <T> OnInvalidated<T>onInvalidated(ObservableValue<T> observableValue) Convenience method to create and instance ofOnInvalidated.
-
Field Details
-
whens
-
observableValue
-
oneShot
protected boolean oneShot
-
-
Constructor Details
-
When
-
-
Method Details
-
listen
-
dispose
public abstract void dispose() -
isOneShot
public boolean isOneShot()- Returns:
- whether the construct is "one-shot"
- See Also:
-
oneShot
Specifies that the construct is "one-shot", meaning that once the value changes the first time, the construct will automatically dispose itself. -
onInvalidated
Convenience method to create and instance ofOnInvalidated. -
onChanged
Convenience method to create an instance ofOnChanged. -
disposeFor
If a When constructs exists for the givenObservableValue,dispose()is invoked.
-