Class State

Direct Known Subclasses:
PersistentState

public class State extends EventManager

A piece of state information that can be shared between objects, and might be persisted between sessions. This can be used for commands that toggle between two states and wish to pass this state information between different handlers.

This state object can either be used as a single state object shared between several commands, or one state object per command -- depending on the needs of the application.

Clients may instantiate or extend this class.

Since:
3.2
  • Constructor Details

    • State

      public State()
  • Method Details

    • addListener

      public void addListener(IStateListener listener)
      Adds a listener to changes for this state.
      Parameters:
      listener - The listener to add; must not be null.
    • dispose

      public void dispose()
      Disposes of this state. This allows the state to unregister itself with any managers or as a listener.
    • fireStateChanged

      protected final void fireStateChanged(Object oldValue)
      Notifies listeners to this state that it has changed in some way.
      Parameters:
      oldValue - The old value; may be anything.
    • getId

      public final String getId()
      Returns the identifier for this state.
      Returns:
      The id; may be null.
    • getValue

      public Object getValue()
      The current value associated with this state. This can be any type of object, but implementations will usually restrict this value to a particular type.
      Returns:
      The current value; may be anything.
    • removeListener

      public void removeListener(IStateListener listener)
      Removes a listener to changes from this state.
      Parameters:
      listener - The listener to remove; must not be null.
    • setId

      public void setId(String id)
      Sets the identifier for this object. This method should only be called by the command framework. Clients should not call this method.
      Parameters:
      id - The id; must not be null.
    • setValue

      public void setValue(Object value)
      Sets the value for this state object.
      Parameters:
      value - The value to set; may be anything.