Package docking.menu

Class MultiStateDockingAction<T>

java.lang.Object
docking.action.DockingAction
docking.menu.MultiStateDockingAction<T>
Type Parameters:
T - the type of the user data
All Implemented Interfaces:
DockingActionIf, HelpDescriptor
Direct Known Subclasses:
NonToolbarMultiStateAction

public abstract class MultiStateDockingAction<T> extends DockingAction
An action that can be in one of multiple states.

The button of this action has a drop-down icon that allows users to change the state of the button. As the user changes the state of this action, actionStateChanged(ActionState, EventTrigger) will be called. Clients may also use the button of this action to respond to button presses by overriding actionPerformed(ActionContext).

This action is intended primarily for use as toolbar actions. Alternatively, some clients use this action to add a button to custom widgets. In the custom use case, clients should use NonToolbarMultiStateAction.

See Also:
  • Constructor Details

    • MultiStateDockingAction

      public MultiStateDockingAction(String name, String owner)
      Constructor
      Parameters:
      name - the action name
      owner - the owner
  • Method Details

    • actionStateChanged

      public abstract void actionStateChanged(ActionState<T> newActionState, EventTrigger trigger)
      This method will be called as the user changes the selected button state
      Parameters:
      newActionState - the newly selected state
      trigger - the source of the event
    • actionPerformed

      public void actionPerformed(ActionContext context)
      This method is called when the user clicks the button when this action is used as part of the default DockingAction framework.

      This is the callback to be overridden when the child wishes to respond to user button presses that are on the button and not the drop-down. The default behavior is to show the popup menu when the button is clicked.

      Specified by:
      actionPerformed in interface DockingActionIf
      Specified by:
      actionPerformed in class DockingAction
      Parameters:
      context - the ActionContext object that provides information about where and how this action was invoked.
    • setUseCheckboxForIcons

      public void setUseCheckboxForIcons(boolean useCheckboxForIcons)
      Overrides the default icons for actions shown in popup menu of the multi-state action.

      By default, the popup menu items will use the icons as provided by the ActionState. By passing true to this method, icons will not be used in the popup menu. Instead, a checkbox icon will be used to show the active action state.

      Parameters:
      useCheckboxForIcons - true to use a checkbox
    • setDefaultIcon

      public void setDefaultIcon(Icon icon)
      Sets the icon to use if the active action state does not supply an icon.

      This is useful if you wish for your action states to not use icon, but desire the action itself to have an icon.

      Parameters:
      icon - the icon
    • getStates

      protected List<ActionState<T>> getStates()
      Extension point: Get the states to display when the button is clicked

      This is called when the button is clicked, immediately before the menu is displayed. It is generally recommended to ensure the current state is included in this list. The states will be displayed in the order of the returned list.

      Returns:
      the list of possible states
    • isStateEnabled

      protected boolean isStateEnabled(ActionState<T> state)
      Check if the given state can be selected
      Parameters:
      state - the state to check
      Returns:
      true (the default) if selectable, false to disable
    • getStateActions

      protected List<DockingActionIf> getStateActions()
    • setGroup

      public void setGroup(String group)
    • setSubGroup

      public void setSubGroup(String subGroup)
    • addActionState

      public void addActionState(ActionState<T> actionState)
      Add the supplied ActionState.
      Parameters:
      actionState - the ActionState to add
    • setActionStates

      public void setActionStates(List<ActionState<T>> newStates)
    • getCurrentUserData

      public T getCurrentUserData()
    • getCurrentState

      public ActionState<T> getCurrentState()
    • getAllActionStates

      public List<ActionState<T>> getAllActionStates()
    • setCurrentActionStateByUserData

      public void setCurrentActionStateByUserData(T t)
    • setCurrentActionState

      public void setCurrentActionState(ActionState<T> actionState)
    • setCurrentActionStateWithTrigger

      public void setCurrentActionStateWithTrigger(ActionState<T> actionState, EventTrigger trigger)
    • doSetCurrentActionState

      protected void doSetCurrentActionState(ActionState<T> actionState, EventTrigger trigger)
    • doCreateButton

      public JButton doCreateButton()
      Overrides:
      doCreateButton in class DockingAction
    • setMenuBarData

      public void setMenuBarData(MenuData newMenuData)
      Description copied from class: DockingAction
      Sets the MenuData to be used to put this action on the tool's menu bar
      Overrides:
      setMenuBarData in class DockingAction
      Parameters:
      newMenuData - the MenuData to be used to put this action on the tool's menu bar
    • superSetMenuBarData

      protected void superSetMenuBarData(MenuData newMenuData)
    • setPopupMenuData

      public void setPopupMenuData(MenuData newMenuData)
      Description copied from class: DockingAction
      Sets the MenuData to be used to put this action in the tool's popup menu
      Overrides:
      setPopupMenuData in class DockingAction
      Parameters:
      newMenuData - the MenuData to be used to put this action on the tool's popup menu
    • getToolTipText

      public String getToolTipText()
    • showPopup

      protected void showPopup()