java.lang.Object
io.github.palexdev.materialfx.utils.others.observables.When<T>
Direct Known Subclasses:
OnChanged, OnInvalidated

public abstract class When<T> extends Object
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 using disposeFor(ObservableValue) to avoid memory leaks. When constructs and ObservableValues are stored in a WeakHashMap for this purpose.
  • Field Details

  • Constructor Details

  • Method Details

    • listen

      public abstract When<T> listen()
    • dispose

      public abstract void dispose()
    • isOneShot

      public boolean isOneShot()
      Returns:
      whether the construct is "one-shot"
      See Also:
    • oneShot

      public When<T> oneShot()
      Specifies that the construct is "one-shot", meaning that once the value changes the first time, the construct will automatically dispose itself.
    • onInvalidated

      public static <T> OnInvalidated<T> onInvalidated(ObservableValue<T> observableValue)
      Convenience method to create and instance of OnInvalidated.
    • onChanged

      public static <T> OnChanged<T> onChanged(ObservableValue<T> observableValue)
      Convenience method to create an instance of OnChanged.
    • disposeFor

      public static void disposeFor(ObservableValue<?> observableValue)
      If a When constructs exists for the given ObservableValue, dispose() is invoked.