java.lang.Object
com.googlecode.lanterna.gui2.AbstractComponent<CheckBoxList<V>>
com.googlecode.lanterna.gui2.AbstractInteractableComponent<CheckBoxList<V>>
com.googlecode.lanterna.gui2.AbstractListBox<V,CheckBoxList<V>>
com.googlecode.lanterna.gui2.CheckBoxList<V>
- All Implemented Interfaces:
Component
,Interactable
,TextGUIElement
This is a list box implementation where each item has its own checked state that can be toggled on and off
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Default renderer for this component which is used unless overridden.static interface
Listener interface that can be attached to theCheckBoxList
in order to be notified on user actionsNested 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
FieldsModifier and TypeFieldDescriptionprivate final List
<CheckBoxList.Listener> private int
private int
private boolean
Fields inherited from class com.googlecode.lanterna.gui2.AbstractListBox
scrollOffset
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newCheckBoxList
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
(TerminalSize preferredSize) Creates a newCheckBoxList
that is initially empty and has a pre-defined size that it will request. -
Method Summary
Modifier and TypeMethodDescriptionAdds one more item to the list box, at the end.Adds an item to the checkbox list with an explicit checked statusaddListener
(CheckBoxList.Listener listener) Adds a new listener to theCheckBoxList
that will be called on certain user actionsRemoves all items from the list boxprotected AbstractListBox.ListItemRenderer
<V, CheckBoxList<V>> Method that constructs theListItemRenderer
that this list box should use to draw the elements of the list box.Returns all the items in the list box that have checked state, as a listhandleKeyStroke
(KeyStroke keyStroke) This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus.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.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.removeItem
(int index) Removes an item from the list box by its index.removeListener
(CheckBoxList.Listener listener) Removes a listener from thisCheckBoxList
so that if it had been added earlier, it will no longer be called on user actionsprivate void
setChecked
(int index, boolean checked) setChecked
(V object, boolean checked) Programmatically sets the checked state of an item in the list boxtoggleChecked
(int index) Programmatically sets the checked state of an item in the list box.Methods inherited from class com.googlecode.lanterna.gui2.AbstractListBox
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
-
itemStatus
-
stateForMouseDragged
private boolean stateForMouseDragged -
minIndexForMouseDragged
private int minIndexForMouseDragged -
maxIndexForMouseDragged
private int maxIndexForMouseDragged
-
-
Constructor Details
-
CheckBoxList
public CheckBoxList()Creates a newCheckBoxList
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
Creates a newCheckBoxList
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
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,
CheckBoxList<V>> - Returns:
ListItemRenderer
to use when drawing the items in the list
-
clearItems
Description copied from class:AbstractListBox
Removes all items from the list box- Overrides:
clearItems
in classAbstractListBox<V,
CheckBoxList<V>> - Returns:
- Itself
-
addItem
Description copied from class:AbstractListBox
Adds one more item to the list box, at the end.- Overrides:
addItem
in classAbstractListBox<V,
CheckBoxList<V>> - Parameters:
object
- Item to add to the list box- Returns:
- Itself
-
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,
CheckBoxList<V>> - Parameters:
index
- Index of the item to remove- Returns:
- The item that was removed
-
addItem
Adds an item to the checkbox list with an explicit checked status- Parameters:
object
- Object to add to the listcheckedState
- Iftrue
, the new item will be initially checked- Returns:
- Itself
-
isChecked
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, otherwisetrue
orfalse
depending on checked state of the item
-
isChecked
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, otherwisetrue
orfalse
depending on checked state of the item at that index
-
toggleChecked
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
Programmatically sets the checked state of an item in the list box- Parameters:
object
- Object to set the checked state ofchecked
- Iftrue
, then the item is set to checked, otherwise not- Returns:
- Itself
-
setChecked
private void setChecked(int index, boolean checked) -
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
Adds a new listener to theCheckBoxList
that will be called on certain user actions- Parameters:
listener
- Listener to attach to thisCheckBoxList
- Returns:
- Itself
-
removeListener
Removes a listener from thisCheckBoxList
so that if it had been added earlier, it will no longer be called on user actions- Parameters:
listener
- Listener to remove from thisCheckBoxList
- Returns:
- Itself
-
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,
CheckBoxList<V>> - Parameters:
keyStroke
- What input was entered by the user- Returns:
- Result of processing the key-stroke
-