Class CheckBoxList<V>

All Implemented Interfaces:
Component, Interactable, TextGUIElement

public class CheckBoxList<V> extends AbstractListBox<V,CheckBoxList<V>>
This is a list box implementation where each item has its own checked state that can be toggled on and off
  • Field Details

    • listeners

      private final List<CheckBoxList.Listener> listeners
    • itemStatus

      private final List<Boolean> itemStatus
    • stateForMouseDragged

      private boolean stateForMouseDragged
    • minIndexForMouseDragged

      private int minIndexForMouseDragged
    • maxIndexForMouseDragged

      private int maxIndexForMouseDragged
  • Constructor Details

    • CheckBoxList

      public CheckBoxList()
      Creates a new CheckBoxList that is initially empty and has no hardcoded preferred size, so it will attempt to be as big as necessary to draw all items.
    • CheckBoxList

      public CheckBoxList(TerminalSize preferredSize)
      Creates a new CheckBoxList that is initially empty and has a pre-defined size that it will request. If there are more items that can fit in this size, the list box will use scrollbars.
      Parameters:
      preferredSize - Size the list box should request, no matter how many items it contains
  • Method Details

    • createDefaultListItemRenderer

      protected AbstractListBox.ListItemRenderer<V,CheckBoxList<V>> createDefaultListItemRenderer()
      Description copied from class: AbstractListBox
      Method that constructs the ListItemRenderer that this list box should use to draw the elements of the list box. This can be overridden to supply a custom renderer. Note that this is not the renderer used for the entire list box but for each item, called one by one.
      Overrides:
      createDefaultListItemRenderer in class AbstractListBox<V,CheckBoxList<V>>
      Returns:
      ListItemRenderer to use when drawing the items in the list
    • clearItems

      public CheckBoxList<V> clearItems()
      Description copied from class: AbstractListBox
      Removes all items from the list box
      Overrides:
      clearItems in class AbstractListBox<V,CheckBoxList<V>>
      Returns:
      Itself
    • addItem

      public CheckBoxList<V> addItem(V object)
      Description copied from class: AbstractListBox
      Adds one more item to the list box, at the end.
      Overrides:
      addItem in class AbstractListBox<V,CheckBoxList<V>>
      Parameters:
      object - Item to add to the list box
      Returns:
      Itself
    • removeItem

      public V removeItem(int index)
      Description copied from class: AbstractListBox
      Removes an item from the list box by its index. The current selection in the list box will be adjusted accordingly.
      Overrides:
      removeItem in class AbstractListBox<V,CheckBoxList<V>>
      Parameters:
      index - Index of the item to remove
      Returns:
      The item that was removed
    • addItem

      public CheckBoxList<V> addItem(V object, boolean checkedState)
      Adds an item to the checkbox list with an explicit checked status
      Parameters:
      object - Object to add to the list
      checkedState - If true, the new item will be initially checked
      Returns:
      Itself
    • isChecked

      public Boolean isChecked(V object)
      Checks if a particular item is part of the check box list and returns a boolean value depending on the toggle state of the item.
      Parameters:
      object - Object to check the status of
      Returns:
      If the item wasn't found in the list box, null is returned, otherwise true or false depending on checked state of the item
    • isChecked

      public Boolean isChecked(int index)
      Checks if a particular item is part of the check box list and returns a boolean value depending on the toggle state of the item.
      Parameters:
      index - Index of the item to check the status of
      Returns:
      If the index was not valid in the list box, null is returned, otherwise true or false depending on checked state of the item at that index
    • toggleChecked

      public CheckBoxList<V> toggleChecked(int index)
      Programmatically sets the checked state of an item in the list box. If the state was already true, it is set to false, otherwise it is set to true.
      Parameters:
      index - Index of the item to toggle the status of
      Returns:
      Itself
    • setChecked

      public CheckBoxList<V> setChecked(V object, boolean checked)
      Programmatically sets the checked state of an item in the list box
      Parameters:
      object - Object to set the checked state of
      checked - If true, then the item is set to checked, otherwise not
      Returns:
      Itself
    • setChecked

      private void setChecked(int index, boolean checked)
    • getCheckedItems

      public List<V> getCheckedItems()
      Returns all the items in the list box that have checked state, as a list
      Returns:
      List of all items in the list box that has checked state on
    • addListener

      public CheckBoxList<V> addListener(CheckBoxList.Listener listener)
      Adds a new listener to the CheckBoxList that will be called on certain user actions
      Parameters:
      listener - Listener to attach to this CheckBoxList
      Returns:
      Itself
    • removeListener

      public CheckBoxList<V> removeListener(CheckBoxList.Listener listener)
      Removes a listener from this CheckBoxList so that if it had been added earlier, it will no longer be called on user actions
      Parameters:
      listener - Listener to remove from this CheckBoxList
      Returns:
      Itself
    • 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<V,CheckBoxList<V>>
      Parameters:
      keyStroke - What input was entered by the user
      Returns:
      Result of processing the key-stroke