Class RadioBoxList<V>
java.lang.Object
com.googlecode.lanterna.gui2.AbstractComponent<RadioBoxList<V>>
com.googlecode.lanterna.gui2.AbstractInteractableComponent<RadioBoxList<V>>
com.googlecode.lanterna.gui2.AbstractListBox<V, RadioBoxList<V>>
com.googlecode.lanterna.gui2.RadioBoxList<V>
- All Implemented Interfaces:
Component, Interactable, TextGUIElement
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceListener interface that can be attached to theRadioBoxListin order to be notified on user actionsstatic classDefault renderer for this component which is used unless overridden.Nested classes/interfaces inherited from class AbstractListBox
AbstractListBox.DefaultListBoxRenderer<V,T>, AbstractListBox.ListItemRenderer<V, T> Nested classes/interfaces inherited from interface Interactable
Interactable.FocusChangeDirection, Interactable.Result -
Field Summary
FieldsFields inherited from class AbstractListBox
scrollOffset -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new RadioCheckBoxList with no items.RadioBoxList(TerminalSize preferredSize) Creates a new RadioCheckBoxList with a specified size. -
Method Summary
Modifier and TypeMethodDescriptionaddListener(RadioBoxList.Listener listener) Adds a new listener to theRadioBoxListthat will be called on certain user actionsRemoves all items from the list boxvoidUn-checks the currently checked item (if any) and leaves the radio check box in a state where no item is checked.protected AbstractListBox.ListItemRenderer<V, RadioBoxList<V>> Method that constructs theListItemRendererthat this list box should use to draw the elements of the list box.inthandleKeyStroke(KeyStroke keyStroke) This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus.booleanisChecked(int index) This method will see if an item, addressed by index, is the currently selected item in this RadioCheckBoxListThis method will see if an object is the currently selected item in this RadioCheckBoxListremoveItem(int index) Removes an item from the list box by its index.removeListener(RadioBoxList.Listener listener) Removes a listener from thisRadioBoxListso that if it had been added earlier, it will no longer be called on user actionsprivate voidsetCheckedIndex(int index) voidsetCheckedItem(V item) Sets the currently checked item by the value itself.voidsetCheckedItemIndex(int index) Sets the currently selected item by index.Methods inherited from class AbstractListBox
addItem, afterEnterFocus, createDefaultRenderer, getIndexByMouseAction, getItemAt, getItemCount, getItems, getListItemRenderer, getSelectedIndex, getSelectedItem, indexOf, isEmpty, isFocusable, setListItemRenderer, setSelectedIndexMethods inherited from class AbstractInteractableComponent
afterLeaveFocus, getCursorLocation, getInputFilter, getRenderer, handleInput, isActivationStroke, isEnabled, isFocused, isKeyboardActivationStroke, isMouseActivationStroke, isMouseDown, isMouseDrag, isMouseMove, isMouseUp, onEnterFocus, onLeaveFocus, setEnabled, setInputFilter, takeFocusMethods inherited from class AbstractComponent
addTo, calculatePreferredSize, draw, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, isVisible, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorderMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Component
addTo, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isVisible, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorderMethods inherited from interface TextGUIElement
draw, isInvalid
-
Field Details
-
listeners
-
checkedIndex
private int checkedIndex
-
-
Constructor Details
-
RadioBoxList
public RadioBoxList()Creates a new RadioCheckBoxList with no items. The size of theRadioBoxListwill be as big as is required to display all items. -
RadioBoxList
Creates a new RadioCheckBoxList with a specified size. If the items in theRadioBoxListcannot fit in the size specified, scrollbars will be used- Parameters:
preferredSize- Size of theRadioBoxListornullto have it try to be as big as necessary to be able to draw all items
-
-
Method Details
-
createDefaultListItemRenderer
Description copied from class:AbstractListBoxMethod that constructs theListItemRendererthat 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:
createDefaultListItemRendererin classAbstractListBox<V, RadioBoxList<V>>- Returns:
ListItemRendererto use when drawing the items in the list
-
handleKeyStroke
Description copied from class:AbstractInteractableComponentThis 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 inAbstractInteractableComponentto ensure the input filter is properly handled. If the filter decides that this event should be processed, it will call this method.- Overrides:
handleKeyStrokein classAbstractListBox<V, RadioBoxList<V>>- Parameters:
keyStroke- What input was entered by the user- Returns:
- Result of processing the key-stroke
-
removeItem
Description copied from class:AbstractListBoxRemoves an item from the list box by its index. The current selection in the list box will be adjusted accordingly.- Overrides:
removeItemin classAbstractListBox<V, RadioBoxList<V>>- Parameters:
index- Index of the item to remove- Returns:
- The item that was removed
-
clearItems
Description copied from class:AbstractListBoxRemoves all items from the list box- Overrides:
clearItemsin classAbstractListBox<V, RadioBoxList<V>>- Returns:
- Itself
-
isChecked
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:
trueif the supplied object is what's currently selected in the list box,falseotherwise. 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:
trueif the currently selected object is at the supplied index,falseotherwise. Returns false if the index is out of range.
-
setCheckedItem
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
- 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
Adds a new listener to theRadioBoxListthat will be called on certain user actions- Parameters:
listener- Listener to attach to thisRadioBoxList- Returns:
- Itself
-
removeListener
Removes a listener from thisRadioBoxListso that if it had been added earlier, it will no longer be called on user actions- Parameters:
listener- Listener to remove from thisRadioBoxList- Returns:
- Itself
-
setCheckedIndex
private void setCheckedIndex(int index)
-