- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractComponent<T>
-
- com.googlecode.lanterna.gui2.AbstractInteractableComponent<T>
-
- com.googlecode.lanterna.gui2.AbstractListBox<V,CheckBoxList<V>>
-
- com.googlecode.lanterna.gui2.CheckBoxList<V>
-
- All Implemented Interfaces:
Component
,Interactable
,TextGUIElement
public class CheckBoxList<V> extends AbstractListBox<V,CheckBoxList<V>>
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 Classes Modifier and Type Class Description static class
CheckBoxList.CheckBoxListItemRenderer<V>
Default renderer for this component which is used unless overridden.static interface
CheckBoxList.Listener
Listener interface that can be attached to theCheckBoxList
in order to be notified on user actions-
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 java.util.List<java.lang.Boolean>
itemStatus
private java.util.List<CheckBoxList.Listener>
listeners
private int
maxIndexForMouseDragged
private int
minIndexForMouseDragged
private boolean
stateForMouseDragged
-
Fields inherited from class com.googlecode.lanterna.gui2.AbstractListBox
scrollOffset
-
-
Constructor Summary
Constructors Constructor Description 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(TerminalSize preferredSize)
Creates a newCheckBoxList
that is initially empty and has a pre-defined size that it will request.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CheckBoxList<V>
addItem(V object)
Adds one more item to the list box, at the end.CheckBoxList<V>
addItem(V object, boolean checkedState)
Adds an item to the checkbox list with an explicit checked statusCheckBoxList<V>
addListener(CheckBoxList.Listener listener)
Adds a new listener to theCheckBoxList
that will be called on certain user actionsCheckBoxList<V>
clearItems()
Removes all items from the list boxprotected AbstractListBox.ListItemRenderer<V,CheckBoxList<V>>
createDefaultListItemRenderer()
Method that constructs theListItemRenderer
that this list box should use to draw the elements of the list box.java.util.List<V>
getCheckedItems()
Returns all the items in the list box that have checked state, as a listInteractable.Result
handleKeyStroke(KeyStroke keyStroke)
This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus.java.lang.Boolean
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.java.lang.Boolean
isChecked(V object)
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.V
removeItem(int index)
Removes an item from the list box by its index.CheckBoxList<V>
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)
CheckBoxList<V>
setChecked(V object, boolean checked)
Programmatically sets the checked state of an item in the list boxCheckBoxList<V>
toggleChecked(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 Detail
-
listeners
private final java.util.List<CheckBoxList.Listener> listeners
-
itemStatus
private final java.util.List<java.lang.Boolean> itemStatus
-
stateForMouseDragged
private boolean stateForMouseDragged
-
minIndexForMouseDragged
private int minIndexForMouseDragged
-
maxIndexForMouseDragged
private int maxIndexForMouseDragged
-
-
Constructor Detail
-
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
public CheckBoxList(TerminalSize preferredSize)
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 Detail
-
createDefaultListItemRenderer
protected AbstractListBox.ListItemRenderer<V,CheckBoxList<V>> 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
public CheckBoxList<V> clearItems()
Description copied from class:AbstractListBox
Removes all items from the list box- Overrides:
clearItems
in classAbstractListBox<V,CheckBoxList<V>>
- Returns:
- Itself
-
addItem
public CheckBoxList<V> addItem(V object)
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
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 classAbstractListBox<V,CheckBoxList<V>>
- Parameters:
index
- Index of the item to remove- Returns:
- The item that was removed
-
addItem
public CheckBoxList<V> addItem(V object, boolean checkedState)
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
public java.lang.Boolean isChecked(V object)
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
public java.lang.Boolean 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.- 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
public CheckBoxList<V> toggleChecked(int index)
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
public CheckBoxList<V> setChecked(V object, boolean checked)
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
public java.util.List<V> 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
public CheckBoxList<V> addListener(CheckBoxList.Listener listener)
Adds a new listener to theCheckBoxList
that will be called on certain user actions- Parameters:
listener
- Listener to attach to thisCheckBoxList
- Returns:
- Itself
-
removeListener
public CheckBoxList<V> 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 actions- Parameters:
listener
- Listener to remove from thisCheckBoxList
- Returns:
- Itself
-
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 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
-
-