de.caff.gimmicks.swing

## Class StateManager

- java.lang.Object
- - de.caff.gimmicks.swing.StateManager

- All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.util.EventListener

      public class StateManager
      extends java.lang.Object
      implements java.beans.PropertyChangeListener

  Handle a bunch of states and take care that only one is active.
  Author:
    Rammi

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StateManager()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addState(State state)` Add a state.
    `State` | `getActiveState()` Get the active state.
    `protected State` | `getFirstEnabledState(AbstractState ignore)` Get the first state which is enabled.
    `java.util.List<State>` | `getStates()` Get the list of known states.
    `boolean` | `isIgnoringChanges()` Is this state manager ignoring changes?
    `(package private) boolean` | `mayActivate(AbstractState state)` May a state be activated?
    `(package private) boolean` | `mayEnable(AbstractState state, boolean enable)` May the state be enabled or disabled?
    `void` | `propertyChange(java.beans.PropertyChangeEvent evt)` This method gets called when a bound property is changed.
    `(package private) void` | `setActiveState(State state)` Set the currently active state.
    `void` | `setIgnoringChanges(boolean ignoringChanges)` Set whether this state manager is ignoring changes.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StateManager

          public StateManager()

  - ### Method Detail

    - #### addState

          public void addState(@NotNull
                               State state)

      Add a state.
      Parameters:
        `state` - state to add

    - #### setActiveState

          void setActiveState(@Nullable
                              State state)

      Set the currently active state.
      Parameters:
        `state` - state to set active

    - #### getStates

          @NotNull
          public java.util.List<State> getStates()

      Get the list of known states.
      Returns:
        list of states

    - #### getActiveState

          @Nullable
          public State getActiveState()

      Get the active state.
      Returns:
        the active state (if states may be toggled this may be `null`)

    - #### mayActivate

          boolean mayActivate(@NotNull
                              AbstractState state)

      May a state be activated?
      Parameters:
        `state` - state to check
      Returns:
        `true` if the state is known and enabled

    - #### mayEnable

          boolean mayEnable(AbstractState state,
                            boolean enable)

      May the state be enabled or disabled?
      Parameters:
        `state` - the state
        `enable` - enable state
      Returns:
        `true` if enable is true or this is not the only enabled state

    - #### getFirstEnabledState

          protected State getFirstEnabledState(AbstractState ignore)

      Get the first state which is enabled.
      Parameters:
        `ignore` - state to be ignored during search
      Returns:
        first state which is enabled

    - #### propertyChange

          public void propertyChange(java.beans.PropertyChangeEvent evt)

      This method gets called when a bound property is changed.
      Specified by:
        `propertyChange` in interface `java.beans.PropertyChangeListener`
      Parameters:
        `evt` - A PropertyChangeEvent object describing the event source and the property that has changed.

    - #### isIgnoringChanges

          public boolean isIgnoringChanges()

      Is this state manager ignoring changes?
      Returns:
        ignoring changes
      See Also:
        `setIgnoringChanges(boolean)`

    - #### setIgnoringChanges

          public void setIgnoringChanges(boolean ignoringChanges)

      Set whether this state manager is ignoring changes. This should only be enabled temporarily when complex actions may cause conflicts by the automatisms of this manager. Making calling this method necessary is in most cases the result of a design flaw.
      Parameters:
        `ignoringChanges` - `true` the state manager is not propagating state changes
        `false` the state manager propagates state changes (normal mode)