- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractComponent<T>
-
- com.googlecode.lanterna.gui2.AbstractInteractableComponent<T>
-
- com.googlecode.lanterna.gui2.AbstractListBox<V,RadioBoxList<V>>
-
- com.googlecode.lanterna.gui2.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRadioBoxList.ListenerListener interface that can be attached to theRadioBoxListin order to be notified on user actionsstatic classRadioBoxList.RadioBoxListItemRenderer<V>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
Fields Modifier and Type Field Description private intcheckedIndexprivate java.util.List<RadioBoxList.Listener>listeners-
Fields inherited from class com.googlecode.lanterna.gui2.AbstractListBox
scrollOffset
-
-
Constructor Summary
Constructors Constructor Description RadioBoxList()Creates a new RadioCheckBoxList with no items.RadioBoxList(TerminalSize preferredSize)Creates a new RadioCheckBoxList with a specified size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RadioBoxList<V>addListener(RadioBoxList.Listener listener)Adds a new listener to theRadioBoxListthat will be called on certain user actionsRadioBoxList<V>clearItems()Removes all items from the list boxvoidclearSelection()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>>createDefaultListItemRenderer()Method that constructs theListItemRendererthat this list box should use to draw the elements of the list box.VgetCheckedItem()intgetCheckedItemIndex()Interactable.ResulthandleKeyStroke(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 RadioCheckBoxListjava.lang.BooleanisChecked(V object)This method will see if an object is the currently selected item in this RadioCheckBoxListVremoveItem(int index)Removes an item from the list box by its index.RadioBoxList<V>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 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 Detail
-
listeners
private final java.util.List<RadioBoxList.Listener> listeners
-
checkedIndex
private int checkedIndex
-
-
Constructor Detail
-
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
public RadioBoxList(TerminalSize preferredSize)
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 Detail
-
createDefaultListItemRenderer
protected AbstractListBox.ListItemRenderer<V,RadioBoxList<V>> 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
public Interactable.Result handleKeyStroke(KeyStroke keyStroke)
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
public V removeItem(int index)
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
public RadioBoxList<V> clearItems()
Description copied from class:AbstractListBoxRemoves all items from the list box- Overrides:
clearItemsin classAbstractListBox<V,RadioBoxList<V>>- Returns:
- Itself
-
isChecked
public java.lang.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:
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
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 theRadioBoxListthat will be called on certain user actions- Parameters:
listener- Listener to attach to thisRadioBoxList- Returns:
- Itself
-
removeListener
public RadioBoxList<V> removeListener(RadioBoxList.Listener listener)
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)
-
-