java.lang.Object
io.github.palexdev.materialfx.utils.others.observables.When<T>
io.github.palexdev.materialfx.utils.others.observables.OnChanged<T>

public class OnChanged<T> extends When<T>
Concrete implementation of When that uses ChangeListeners to listen for changes for a given ObservableValue.

You can specify the action to perform when this happens using a BiConsumer, then(BiConsumer).

To activate the construct do not forget to call listen() at the end.

An example:
 
      IntegerProperty aNumber = new SimpleIntegerProperty(69);
      When.onChanged(aNumber) // You can also use... OnChanged.forObservable(...)
              .then((oldValue, newValue) -> System.out.println("Value switched from: " + oldValue + " to " + newValue))
              .oneShot()
              .listen();
 
 
  • Method Details

    • forObservable

      public static <T> OnChanged<T> forObservable(ObservableValue<T> observableValue)
      Creates and instance of this construct for the given ObservableValue.
    • then

      public OnChanged<T> then(BiConsumer<T,T> action)
      To set the action to perform when the specified ObservableValue changes. The action is a BiConsumer that carries both the old value and the new value of the observable.
    • listen

      public OnChanged<T> listen()
      Activates the OnChanged construct with the previously specified parameters. So, builds the ChangeListener according to the When.isOneShot() parameter, then adds the listener to the specified ObservableValue and finally puts the Observable and the OnChanged construct in the map.
      Specified by:
      listen in class When<T>
    • dispose

      public void dispose()
      Disposes the OnChanged construct by removing the ChangeListener from the ObservableValue, then sets the listener to null and finally removes the observable from the map.
      Specified by:
      dispose in class When<T>