Class UIButton

All Implemented Interfaces:
UIKeyHandler, Textable, Hintable, Savable
Direct Known Subclasses:
UICheckBox, UIMenuItem, UIRadioButton, UITab

public class UIButton extends AbstractLabelUIComponent
A state based component that can be interacted with via the mouse to trigger actions.
  • Field Details

    • _defaultState

      protected LabelState _defaultState
      Default state to use for the button.
    • _disabledState

      protected LabelState _disabledState
      State to use when the mouse button is disabled.
    • _pressedState

      protected LabelState _pressedState
      State to use when the mouse button is pressed and held down over this button.
    • _mouseOverState

      protected LabelState _mouseOverState
      State to use when the mouse is hovering over this button.
    • _selectedState

      protected LabelState _selectedState
      State to use when the mouse button is currently selected.
    • _mouseOverSelectedState

      protected LabelState _mouseOverSelectedState
      State to use when the mouse is hovering over this button while currently selected.
    • _disabledSelectedState

      protected LabelState _disabledSelectedState
      State to use when the mouse button is disabled while currently selected.
  • Constructor Details

    • UIButton

      public UIButton()
      Construct a new, blank button
    • UIButton

      public UIButton(String text)
      Construct a new button with the given text.
      Parameters:
      text - the text
    • UIButton

      public UIButton(String text, SubTex icon)
      Construct a new button with the given text and icon.
      Parameters:
      text - the text
      icon - the icon
  • Method Details

    • isPressed

      public boolean isPressed()
      Returns:
      true if the pressed state is our current state.
    • isMouseOver

      public boolean isMouseOver()
      Returns:
      true if the mouse over state is our current state.
    • addActionListener

      public void addActionListener(ActionListener listener)
      Add the specified listener to this button's list of listeners notified when pressed.
      Parameters:
      listener - the listener
    • removeActionListener

      public boolean removeActionListener(ActionListener listener)
      Remove the given listener from the notification list.
      Parameters:
      listener - the listener
      Returns:
      true if the listener has been effectively removed
    • removeAllListeners

      public void removeAllListeners()
      Removes all of this button's listeners from notification list.
    • fireActionEvent

      public void fireActionEvent()
      Notifies all of this button's registered listeners that this button was pressed.
    • getMouseOverState

      public LabelState getMouseOverState()
    • getMouseOverSelectedState

      public LabelState getMouseOverSelectedState()
    • getPressedState

      public LabelState getPressedState()
    • getSelectedState

      public LabelState getSelectedState()
    • getDisabledSelectedState

      public LabelState getDisabledSelectedState()
    • mousePressed

      public boolean mousePressed(MouseButton button, InputState state)
      always mark consumed.
      Overrides:
      mousePressed in class StateBasedUIComponent
      Parameters:
      button - the button that was pressed
      state - the current tracked state of the input system.
      Returns:
      true if we want to consider the event "consumed" by the UI system.
    • mouseReleased

      public boolean mouseReleased(MouseButton button, InputState state)
      always mark consumed.
      Overrides:
      mouseReleased in class StateBasedUIComponent
      Parameters:
      button - the button that was released
      state - the current tracked state of the input system.
      Returns:
      true if we want to consider the event "consumed" by the UI system.
    • isSelected

      public boolean isSelected()
      Returns:
      true if button is selectable and is selected.
    • setSelected

      public void setSelected(boolean selected)
      If selectable, set this button's state to either selected (true) or default (false) - or disabled versions of each if currently disabled.
      Parameters:
      selected - the selection value to set
    • setSelectable

      public void setSelectable(boolean selectable)
      Parameters:
      selectable - true if this button should be selectable
    • isSelectable

      public boolean isSelectable()
      Returns:
      true if button is selectable
    • setGroup

      public void setGroup(ButtonGroup group)
      Parameters:
      group - the group this button should belong to. Removes the button from any group it currently belongs to.
    • getGroup

      public ButtonGroup getGroup()
      Returns:
      the button group this button belongs to or null if it belongs to none.
    • setEnabled

      public void setEnabled(boolean enabled)
      Overrides:
      setEnabled in class StateBasedUIComponent
      Parameters:
      enabled - if true, sets the defaultState to active, otherwise sets the disabledState or disabledSelectedState to active.
    • getDefaultState

      public LabelState getDefaultState()
      Specified by:
      getDefaultState in class StateBasedUIComponent
      Returns:
      the state that represents the default appearance and behavior for this component.
    • getDisabledState

      public LabelState getDisabledState()
      Specified by:
      getDisabledState in class StateBasedUIComponent
      Returns:
      the state that represents the disabled appearance and behavior for this component.
    • setButtonText

      public void setButtonText(String text)
      Sets the text on this button and all contained states.
      Parameters:
      text - the new text
    • setButtonText

      public void setButtonText(String text, boolean isStyled)
      Sets the text on this button and all contained states.
      Parameters:
      text - the new text
      isStyled - if true, the text may contain style markup.
    • setButtonIcon

      public void setButtonIcon(SubTex icon)
      Sets the icon on this button and all contained states.
      Parameters:
      icon - the new icon
    • getActionCommand

      public String getActionCommand()
    • setActionCommand

      public void setActionCommand(String actionCommand)
    • doClick

      public void doClick()
      Manually click the button.
    • getStates

      public Set<UIState> getStates()
      Specified by:
      getStates in class StateBasedUIComponent
      Returns:
      an ImmutableSet of possible states for this component.