Class ObservableProperty<T>

Direct Known Subclasses:
ConfigOption, SelectionProperty

public class ObservableProperty<T> extends MutableProperty<T>
A property that triggers observers whenever its value changes.
  • Field Details

    • logger

      protected Logger logger
  • Constructor Details

    • ObservableProperty

      public ObservableProperty()
      Creates an observable property without an initial value.
    • ObservableProperty

      public ObservableProperty(T initialValue)
      Creates an observable property with an initial value.
      Parameters:
      initialValue - The initial value
  • Method Details

    • read

      public void read(Observer<T> reader)
      Adds an observer that is immediately called with the current value.

      This is the equivalent of calling MutableProperty.getValue(), then doing something with that value, and then adding an observer which does the same thing each time the value changes.

      Parameters:
      reader - The observer
    • addObserver

      public void addObserver(Observer<T> observer)
    • removeObserver

      public void removeObserver(Observer<T> observer)
    • setLogger

      public void setLogger(Logger logger)
      Sets the logger of this property, which is used to log errors thrown by observers.
    • onValueChange

      protected void onValueChange(T oldValue, T newValue)
      Description copied from class: MutableProperty
      This method is called whenever the value of this property changes.

      The default implementation does nothing.

      Overrides:
      onValueChange in class MutableProperty<T>
      Parameters:
      oldValue - The previous value
      newValue - The new value