Class StateBasedUIComponent

All Implemented Interfaces:
UIKeyHandler, Hintable, Savable
Direct Known Subclasses:
AbstractLabelUIComponent, AbstractUITextEntryComponent

public abstract class StateBasedUIComponent extends UIComponent
StateBasedUIComponent describes a component that acts as a state machine, containing multiple states, one of which is currently active. Each of these states may override the current appearance and behavior of the component, making this class an ideal base for components such as "mouse over" buttons, components that can be visibly "disabled", toggleable components, etc.
  • Constructor Details

    • StateBasedUIComponent

      public StateBasedUIComponent()
  • Method Details

    • getDefaultState

      public abstract UIState getDefaultState()
      Returns:
      the state that represents the default appearance and behavior for this component.
    • getDisabledState

      public abstract UIState getDisabledState()
      Returns:
      the state that represents the disabled appearance and behavior for this component.
    • getCurrentState

      public UIState getCurrentState()
      Returns:
      this component's currently active state
    • setEnabled

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

      public final void switchState(UIState nextState)
      Set our current active state.
      Parameters:
      nextState - the state to set as active for this component. If null, this is a no-op.
    • refreshState

      public void refreshState()
      Re-apply the current state.
    • setForegroundColor

      public void setForegroundColor(ReadOnlyColorRGBA color, boolean allStates)
      Sets the text color on this component and (optionally) all contained states.
      Parameters:
      color - the new foreground color
      allStates - if true, set across all contained states as well as self.
    • mouseDeparted

      public void mouseDeparted(int mouseX, int mouseY, InputState state)
      Description copied from class: UIComponent
      Called when a mouse cursor leaves this component.
      Overrides:
      mouseDeparted in class UIComponent
      Parameters:
      mouseX - mouse x coordinate.
      mouseY - mouse y coordinate.
      state - the current tracked state of the input system.
    • mouseEntered

      public void mouseEntered(int mouseX, int mouseY, InputState state)
      Description copied from class: UIComponent
      Called when a mouse cursor enters this component.
      Overrides:
      mouseEntered in class UIComponent
      Parameters:
      mouseX - mouse x coordinate.
      mouseY - mouse y coordinate.
      state - the current tracked state of the input system.
    • mouseMoved

      public boolean mouseMoved(int mouseX, int mouseY, InputState state)
      Description copied from class: UIComponent
      Called when a mouse is moved while the cursor is over this component.
      Overrides:
      mouseMoved in class UIComponent
      Parameters:
      mouseX - mouse x coordinate.
      mouseY - mouse y coordinate.
      state - the current tracked state of the input system.
      Returns:
      true if we want to consider the event "consumed" by the UI system.
    • mousePressed

      public boolean mousePressed(MouseButton button, InputState state)
      Description copied from class: UIComponent
      Called when a mouse button is pressed while the cursor is over this component.
      Overrides:
      mousePressed in class UIComponent
      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)
      Description copied from class: UIComponent
      Called when a mouse button is released while the cursor is over this component.
      Overrides:
      mouseReleased in class UIComponent
      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.
    • mouseWheel

      public boolean mouseWheel(int wheelDx, InputState state)
      Description copied from class: UIComponent
      Called when the mouse wheel is moved while the cursor is over this component.
      Overrides:
      mouseWheel in class UIComponent
      Parameters:
      wheelDx - the last change of the wheel
      state - the current tracked state of the input system.
      Returns:
      true if we want to consider the event "consumed" by the UI system.
    • keyPressed

      public boolean keyPressed(Key key, InputState state)
      Description copied from class: UIComponent
      Called when this component has focus and a key is pressed.
      Specified by:
      keyPressed in interface UIKeyHandler
      Overrides:
      keyPressed in class UIComponent
      Parameters:
      key - the key pressed.
      state - the current tracked state of the input system.
      Returns:
      true if we want to consider the event "consumed" by the UI system.
    • keyReleased

      public boolean keyReleased(Key key, InputState state)
      Description copied from class: UIComponent
      Called when this component has focus and a key is released.
      Specified by:
      keyReleased in interface UIKeyHandler
      Overrides:
      keyReleased in class UIComponent
      Parameters:
      key - the key released.
      state - the current tracked state of the input system.
      Returns:
      true if we want to consider the event "consumed" by the UI system.
    • keyHeld

      public boolean keyHeld(Key key, InputState state)
      Description copied from class: UIComponent
      Called when this component has focus and a key is held down over more than 1 input cycle.
      Specified by:
      keyHeld in interface UIKeyHandler
      Overrides:
      keyHeld in class UIComponent
      Parameters:
      key - the key held.
      state - the current tracked state of the input system.
      Returns:
      true if we want to consider the event "consumed" by the UI system.
    • gainedFocus

      public void gainedFocus()
      Description copied from class: UIComponent
      Called by the hud when a component is given focus.
      Overrides:
      gainedFocus in class UIComponent
    • lostFocus

      public void lostFocus()
      Description copied from class: UIComponent
      Called by the hud when a component loses focus.
      Overrides:
      lostFocus in class UIComponent
    • getStates

      public abstract Set<UIState> getStates()
      Returns:
      an ImmutableSet of possible states for this component.