Package docking.menu

Class MultiStateButton<T>

Type Parameters:
T - The type of the user data associated with the ButtonStates
All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants

public class MultiStateButton<T> extends JButton
A button that has a drop-down list of choosable ButtonStates. When a state is selected, it changes the behavior of the action associated with the button. This code is based on code for the MultipleActionDockingToolbarButton.
See Also:
  • Constructor Details

  • Method Details

    • setButtonStates

      public void setButtonStates(List<ButtonState<T>> buttonStates)
    • setStateChangedListener

      public void setStateChangedListener(Consumer<ButtonState<T>> consumer)
      Sets a consumer to be called when the user changes the active ButtonState.
      Parameters:
      consumer - the consumer to be called when the button state changes
    • setCurrentButtonState

      public void setCurrentButtonState(ButtonState<T> buttonState)
      Sets the active button state for this button.
      Parameters:
      buttonState - the button state to be made active
    • setSelectedStateByClientData

      public void setSelectedStateByClientData(T clientData)
      Sets the active button state to the state that is associated with the given client data.
      Parameters:
      clientData - the client data to make its associated button state the active state
    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JButton
    • getActionContext

      protected ActionContext getActionContext()
    • showPopup

      protected JPopupMenu showPopup()
      Show a popup containing all the actions below the button
      Returns:
      the popup menu that was shown
    • doCreateMenu

      protected JPopupMenu doCreateMenu()
    • getPopupPoint

      public Point getPopupPoint()