de.caff.gimmicks.swing

## Class AbstractState

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

- All Implemented Interfaces:
    State, ToolBarElement, java.awt.event.ActionListener, java.util.EventListener, javax.swing.Action
  Direct Known Subclasses:
    VisibleState

      public abstract class AbstractState
      extends java.lang.Object
      implements State

  Basic implementation of a state. It takes care of listeners and activation.
  Author:
    Rammi

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected StateManager` | `manager` The state manager where we are registered.
    `protected java.util.Map<java.lang.String,java.lang.Object>` | `properties` Property list.
    `protected java.beans.PropertyChangeSupport` | `propertyChangeSupport` Property change support for standard handling of property changes.

    - ### Fields inherited from interface de.caff.gimmicks.swing.State

      `ACTIVATION_PROPERTY, ACTIVE_ICON_PROPERTY, DISABLED_ICON_PROPERTY, ENABLE_PROPERTY, INACTIVE_ICON_PROPERTY, LABEL_TEXT_PROPERTY, POPUP_PROPERTY, TOOLTIP_TEXT_PROPERTY`

    - ### Fields inherited from interface javax.swing.Action

      `ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractState()` Create a new abstract state.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `actionPerformed(java.awt.event.ActionEvent e)` An action is performed.
    `boolean` | `activate()` Activate this state.
    `void` | `addPropertyChangeListener(java.beans.PropertyChangeListener listener)` Add a property change listener.
    `void` | `addPropertyChangeListener(java.lang.String property, java.beans.PropertyChangeListener listener)` Add a property change listener for a special property.
    `javax.swing.JComponent[]` | `addToToolBar(javax.swing.JToolBar toolBar)` Add this element to the toolbar.
    `javax.swing.JComponent[]` | `addToToolBar(javax.swing.JToolBar toolBar, int index)` Add this element to the toolbar.
    `void` | `deactivate()` Deactivate this state.
    `java.lang.Object` | `getValue(java.lang.String name)` Get the value of a given property.
    `boolean` | `isActivated()` Is this state activated?
    `boolean` | `isEnabled()` Is this state enabled?
    `boolean` | `isToggleEnabled()` Is it possible to switch this state off by clicking on it with the mouse?
    `void` | `putValue(java.lang.String key, java.lang.Object value)` Set the value of a given property,
    `void` | `refresh()` Refresh state.
    `void` | `removePropertyChangeListener(java.beans.PropertyChangeListener listener)` Remove a property change listener.
    `void` | `removePropertyChangeListener(java.lang.String property, java.beans.PropertyChangeListener listener)` Remove a property change listener for a special property.
    `void` | `setEnabled(boolean state)` Enable or disable this state.
    `void` | `setManager(StateManager stateManager)` Set the state manager which handles this state.
    `protected void` | `setProperty(java.lang.String name, java.lang.Object value)` Set a property to a new value.
    `void` | `showPopup(java.awt.Component comp, int x, int y)` Show a popup menu.

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

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

    - ### Methods inherited from interface de.caff.gimmicks.swing.State

      `hasPopup`

- - ### Field Detail

    - #### propertyChangeSupport

          protected final java.beans.PropertyChangeSupport propertyChangeSupport

      Property change support for standard handling of property changes.

    - #### properties

          protected final java.util.Map<java.lang.String,java.lang.Object> properties

      Property list.

    - #### manager

          protected StateManager manager

      The state manager where we are registered.

  - ### Constructor Detail

    - #### AbstractState

          public AbstractState()

      Create a new abstract state.

  - ### Method Detail

    - #### setManager

          public void setManager(@NotNull
                                 StateManager stateManager)

      Set the state manager which handles this state.
      Specified by:
        `setManager` in interface `State`
      Parameters:
        `stateManager` - state manager

    - #### addPropertyChangeListener

          public void addPropertyChangeListener(@NotNull
                                                java.beans.PropertyChangeListener listener)

      Add a property change listener.
      Specified by:
        `addPropertyChangeListener` in interface `javax.swing.Action`
      Parameters:
        `listener` - listener to add

    - #### addPropertyChangeListener

          public void addPropertyChangeListener(@NotNull
                                                java.lang.String property,
                                                @NotNull
                                                java.beans.PropertyChangeListener listener)

      Add a property change listener for a special property.
      Specified by:
        `addPropertyChangeListener` in interface `State`
      Parameters:
        `property` - property identifier
        `listener` - listener to add

    - #### removePropertyChangeListener

          public void removePropertyChangeListener(@NotNull
                                                   java.beans.PropertyChangeListener listener)

      Remove a property change listener.
      Specified by:
        `removePropertyChangeListener` in interface `javax.swing.Action`
      Parameters:
        `listener` - listener to remove

    - #### removePropertyChangeListener

          public void removePropertyChangeListener(@NotNull
                                                   java.lang.String property,
                                                   @NotNull
                                                   java.beans.PropertyChangeListener listener)

      Remove a property change listener for a special property.
      Specified by:
        `removePropertyChangeListener` in interface `State`
      Parameters:
        `property` - property identifier
        `listener` - listener to remove

    - #### activate

          public boolean activate()

      Activate this state.
      Specified by:
        `activate` in interface `State`
      Returns:
        `true` if the activation was possible, `false` otherwise

    - #### actionPerformed

          public void actionPerformed(java.awt.event.ActionEvent e)

      An action is performed. This is just handled as a call to activate().
      Specified by:
        `actionPerformed` in interface `java.awt.event.ActionListener`
      Parameters:
        `e` - unused

    - #### isActivated

          public boolean isActivated()

      Is this state activated?
      Specified by:
        `isActivated` in interface `State`
      Returns:
        the answer

    - #### deactivate

          public void deactivate()

      Deactivate this state.
      Specified by:
        `deactivate` in interface `State`

    - #### setEnabled

          public void setEnabled(boolean state)

      Enable or disable this state.
      Specified by:
        `setEnabled` in interface `javax.swing.Action`
      Parameters:
        `state` - if `true` enable this state, otherwise disable it

    - #### isEnabled

          public boolean isEnabled()

      Is this state enabled?
      Specified by:
        `isEnabled` in interface `javax.swing.Action`
      Returns:
        the answer

    - #### getValue

          public java.lang.Object getValue(@NotNull
                                           java.lang.String name)

      Get the value of a given property.
      Specified by:
        `getValue` in interface `javax.swing.Action`
      Parameters:
        `name` - property name

    - #### putValue

          public void putValue(@NotNull
                               java.lang.String key,
                               java.lang.Object value)

      Set the value of a given property,
      Specified by:
        `putValue` in interface `javax.swing.Action`
      Parameters:
        `key` - property key
        `value` - new value of property

    - #### setProperty

          protected void setProperty(@NotNull
                                     java.lang.String name,
                                     java.lang.Object value)

      Set a property to a new value.
      Parameters:
        `name` - property name
        `value` - new value

    - #### showPopup

          public void showPopup(@NotNull
                                java.awt.Component comp,
                                int x,
                                int y)

      Show a popup menu. Implementations are free to do nothing.
      Specified by:
        `showPopup` in interface `State`
      Parameters:
        `comp` - component where to show the popup menu
        `x` - x position in component
        `y` - y position in component
      See Also:
        `State.hasPopup()`

    - #### addToToolBar

          @NotNull
          public javax.swing.JComponent[] addToToolBar(@NotNull
                                                                javax.swing.JToolBar toolBar)

      Add this element to the toolbar.
      Specified by:
        `addToToolBar` in interface `ToolBarElement`
      Parameters:
        `toolBar` - toolbar to add to
      Returns:
        components added to toolbar

    - #### addToToolBar

          @NotNull
          public javax.swing.JComponent[] addToToolBar(@NotNull
                                                                javax.swing.JToolBar toolBar,
                                                                int index)

      Add this element to the toolbar.
      Specified by:
        `addToToolBar` in interface `ToolBarElement`
      Parameters:
        `toolBar` - toolbar to add to
        `index` - position where to add the item
      Returns:
        actually inserted components

    - #### isToggleEnabled

          public boolean isToggleEnabled()

      Is it possible to switch this state off by clicking on it with the mouse?
      Specified by:
        `isToggleEnabled` in interface `State`
      Returns:
        the answer

    - #### refresh

          public void refresh()

      Refresh state.
      Specified by:
        `refresh` in interface `State`