Class ActionListBox

All Implemented Interfaces:
Component, Interactable, TextGUIElement

public class ActionListBox extends AbstractListBox<Runnable,ActionListBox>
This class is a list box implementation that displays a number of items that has actions associated with them. You can activate this action by pressing the Enter or Space keys on the keyboard and the action associated with the currently selected item will fire.
  • Constructor Details

    • ActionListBox

      public ActionListBox()
      Default constructor, creates an ActionListBox with no pre-defined size that will request to be big enough to display all items
    • ActionListBox

      public ActionListBox(TerminalSize preferredSize)
      Creates a new ActionListBox with a pre-set size. If the items don't fit in within this size, scrollbars will be used to accommodate. Calling new ActionListBox(null) has the same effect as calling new ActionListBox().
      Parameters:
      preferredSize - Preferred size of this ActionListBox
  • Method Details

    • addItem

      public ActionListBox addItem(Runnable object)
      Adds one more item to the list box, at the end. The label of the item in the list box will be the result of calling .toString() on the runnable, which might not be what you want to have unless you explicitly declare it. Consider using addItem(String label, Runnable action instead, if you want to just set the label easily without having to override .toString().
      Overrides:
      addItem in class AbstractListBox<Runnable,ActionListBox>
      Parameters:
      object - Runnable to execute when the action was selected and fired in the list
      Returns:
      Itself
    • addItem

      public ActionListBox addItem(String label, Runnable action)
      Adds a new item to the list, which is displayed in the list using a supplied label.
      Parameters:
      label - Label to use in the list for the new item
      action - Runnable to invoke when this action is selected and then triggered
      Returns:
      Itself
    • getCursorLocation

      public TerminalPosition getCursorLocation()
      Description copied from interface: Interactable
      Returns, in local coordinates, where to put the cursor on the screen when this component has focus. If null, the cursor should be hidden. If you component is 5x1 and you want to have the cursor in the middle (when in focus), return [2,0]. The GUI system will convert the position to global coordinates.
      Specified by:
      getCursorLocation in interface Interactable
      Overrides:
      getCursorLocation in class AbstractInteractableComponent<ActionListBox>
      Returns:
      Coordinates of where to place the cursor when this component has focus
    • handleKeyStroke

      public 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 AbstractListBox<Runnable,ActionListBox>
      Parameters:
      keyStroke - What input was entered by the user
      Returns:
      Result of processing the key-stroke
    • runSelectedItem

      public void runSelectedItem()