Class RadioBoxList<V>

All Implemented Interfaces:
Component, Interactable, TextGUIElement

public class RadioBoxList<V> extends AbstractListBox<V,RadioBoxList<V>>
The list box will display a number of items, of which one and only one can be marked as selected. The user can select an item in the list box by pressing the return key or space bar key. If you select one item when another item is already selected, the previously selected item will be deselected and the highlighted item will be the selected one instead.
  • Field Details

  • Constructor Details

    • RadioBoxList

      public RadioBoxList()
      Creates a new RadioCheckBoxList with no items. The size of the RadioBoxList will be as big as is required to display all items.
    • RadioBoxList

      public RadioBoxList(TerminalSize preferredSize)
      Creates a new RadioCheckBoxList with a specified size. If the items in the RadioBoxList cannot fit in the size specified, scrollbars will be used
      Parameters:
      preferredSize - Size of the RadioBoxList or null to have it try to be as big as necessary to be able to draw all items
  • Method Details

    • createDefaultListItemRenderer

      protected AbstractListBox.ListItemRenderer<V,RadioBoxList<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,RadioBoxList<V>>
      Returns:
      ListItemRenderer to use when drawing the items in the list
    • 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,RadioBoxList<V>>
      Parameters:
      keyStroke - What input was entered by the user
      Returns:
      Result of processing the key-stroke
    • 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,RadioBoxList<V>>
      Parameters:
      index - Index of the item to remove
      Returns:
      The item that was removed
    • clearItems

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

      public Boolean isChecked(V object)
      This method will see if an object is the currently selected item in this RadioCheckBoxList
      Parameters:
      object - Object to test if it's the selected one
      Returns:
      true if the supplied object is what's currently selected in the list box, false otherwise. Returns null if the supplied object is not an item in the list box.
    • isChecked

      public boolean isChecked(int index)
      This method will see if an item, addressed by index, is the currently selected item in this RadioCheckBoxList
      Parameters:
      index - Index of the item to check if it's currently selected
      Returns:
      true if the currently selected object is at the supplied index, false otherwise. Returns false if the index is out of range.
    • setCheckedItem

      public void setCheckedItem(V item)
      Sets the currently checked item by the value itself. If null, the selection is cleared. When changing selection, any previously selected item is deselected.
      Parameters:
      item - Item to be checked
    • setCheckedItemIndex

      public void setCheckedItemIndex(int index)
      Sets the currently selected item by index. If the index is out of range, it does nothing.
      Parameters:
      index - Index of the item to be selected
    • getCheckedItemIndex

      public int getCheckedItemIndex()
      Returns:
      The index of the item which is currently selected, or -1 if there is no selection
    • getCheckedItem

      public V getCheckedItem()
      Returns:
      The object currently selected, or null if there is no selection
    • clearSelection

      public void clearSelection()
      Un-checks the currently checked item (if any) and leaves the radio check box in a state where no item is checked.
    • addListener

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

      public RadioBoxList<V> removeListener(RadioBoxList.Listener listener)
      Removes a listener from this RadioBoxList so that if it had been added earlier, it will no longer be called on user actions
      Parameters:
      listener - Listener to remove from this RadioBoxList
      Returns:
      Itself
    • setCheckedIndex

      private void setCheckedIndex(int index)