All Implemented Interfaces:
Component, Interactable, TextGUIElement
Direct Known Subclasses:
Menu

public class MenuItem extends AbstractInteractableComponent<MenuItem>
This class is a single item that appears in a Menu with an optional action attached to it
  • Field Details

  • Constructor Details

    • MenuItem

      public MenuItem(String label)
      Creates a MenuItem with a label that does nothing when activated
      Parameters:
      label - Label of the new MenuItem
    • MenuItem

      public MenuItem(String label, Runnable action)
      Creates a new MenuItem with a label and an action that will run on the GUI thread when activated. When the action has finished, the Menu containing this item will close.
      Parameters:
      label - Label of the new MenuItem
      action - Action to invoke on the GUI thread when the menu item is activated
  • Method Details

    • getLabel

      public String getLabel()
      Returns the label of this menu item
      Returns:
      Label of this menu item
    • createDefaultRenderer

      protected InteractableRenderer<MenuItem> createDefaultRenderer()
      Description copied from class: AbstractComponent
      When you create a custom component, you need to implement this method and return a Renderer which is responsible for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable). This value is intended to be overridden by custom themes.
      Specified by:
      createDefaultRenderer in class AbstractInteractableComponent<MenuItem>
      Returns:
      Renderer to use when sizing and drawing this component
    • onActivated

      protected boolean onActivated()
      Method to invoke when a menu item is "activated" by pressing the Enter key.
      Returns:
      Returns true if the action was performed successfully, otherwise false, which will not automatically close the popup window itself.
    • handleKeyStroke

      protected Interactable.Result handleKeyStroke(KeyStroke keyStroke)
      Description copied from class: AbstractInteractableComponent
      This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus. The input method from the interface, handleInput(..) is final in AbstractInteractableComponent to ensure the input filter is properly handled. If the filter decides that this event should be processed, it will call this method.
      Overrides:
      handleKeyStroke in class AbstractInteractableComponent<MenuItem>
      Parameters:
      keyStroke - What input was entered by the user
      Returns:
      Result of processing the key-stroke