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 interface
Listener interface that can be attached to theRadioBoxList
in order to be notified on user actionsstatic class
Default renderer for this component which is used unless overridden.Nested classes/interfaces inherited from class com.googlecode.lanterna.gui2.AbstractListBox
AbstractListBox.DefaultListBoxRenderer<V,
T extends AbstractListBox<V, T>>, AbstractListBox.ListItemRenderer<V, T extends AbstractListBox<V, T>> Nested classes/interfaces inherited from interface com.googlecode.lanterna.gui2.Interactable
Interactable.FocusChangeDirection, Interactable.Result
-
Field Summary
FieldsFields inherited from class com.googlecode.lanterna.gui2.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 theRadioBoxList
that will be called on certain user actionsRemoves all items from the list boxvoid
Un-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 theListItemRenderer
that this list box should use to draw the elements of the list box.int
handleKeyStroke
(KeyStroke keyStroke) This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus.boolean
isChecked
(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 thisRadioBoxList
so that if it had been added earlier, it will no longer be called on user actionsprivate void
setCheckedIndex
(int index) void
setCheckedItem
(V item) Sets the currently checked item by the value itself.void
setCheckedItemIndex
(int index) Sets the currently selected item by index.Methods inherited from class com.googlecode.lanterna.gui2.AbstractListBox
addItem, afterEnterFocus, createDefaultRenderer, getIndexByMouseAction, getItemAt, getItemCount, getItems, getListItemRenderer, getSelectedIndex, getSelectedItem, indexOf, isEmpty, isFocusable, setListItemRenderer, setSelectedIndex
Methods inherited from class com.googlecode.lanterna.gui2.AbstractInteractableComponent
afterLeaveFocus, getCursorLocation, getInputFilter, getRenderer, handleInput, isActivationStroke, isEnabled, isFocused, isKeyboardActivationStroke, isMouseActivationStroke, isMouseDown, isMouseDrag, isMouseMove, isMouseUp, onEnterFocus, onLeaveFocus, setEnabled, setInputFilter, takeFocus
Methods inherited from class com.googlecode.lanterna.gui2.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, withBorder
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.googlecode.lanterna.gui2.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, withBorder
Methods inherited from interface com.googlecode.lanterna.gui2.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 theRadioBoxList
will be as big as is required to display all items. -
RadioBoxList
Creates a new RadioCheckBoxList with a specified size. If the items in theRadioBoxList
cannot fit in the size specified, scrollbars will be used- Parameters:
preferredSize
- Size of theRadioBoxList
ornull
to have it try to be as big as necessary to be able to draw all items
-
-
Method Details
-
createDefaultListItemRenderer
Description copied from class:AbstractListBox
Method that constructs theListItemRenderer
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 classAbstractListBox<V,
RadioBoxList<V>> - Returns:
ListItemRenderer
to use when drawing the items in the list
-
handleKeyStroke
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 inAbstractInteractableComponent
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 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: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 classAbstractListBox<V,
RadioBoxList<V>> - Parameters:
index
- Index of the item to remove- Returns:
- The item that was removed
-
clearItems
Description copied from class:AbstractListBox
Removes all items from the list box- Overrides:
clearItems
in 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:
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
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 theRadioBoxList
that will be called on certain user actions- Parameters:
listener
- Listener to attach to thisRadioBoxList
- Returns:
- Itself
-
removeListener
Removes a listener from thisRadioBoxList
so 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)
-