- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractComponent<T>
-
- com.googlecode.lanterna.gui2.AbstractInteractableComponent<T>
-
- com.googlecode.lanterna.gui2.AbstractListBox<java.lang.Runnable,ActionListBox>
-
- com.googlecode.lanterna.gui2.ActionListBox
-
- All Implemented Interfaces:
Component
,Interactable
,TextGUIElement
public class ActionListBox extends AbstractListBox<java.lang.Runnable,ActionListBox>
This class is a list box implementation that displays a number of items that has actions associated with them. You can activate this action by pressing the Enter or Space keys on the keyboard and the action associated with the currently selected item will fire.
-
-
Nested Class Summary
-
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 inherited from class com.googlecode.lanterna.gui2.AbstractListBox
scrollOffset
-
-
Constructor Summary
Constructors Constructor Description ActionListBox()
Default constructor, creates anActionListBox
with no pre-defined size that will request to be big enough to display all itemsActionListBox(TerminalSize preferredSize)
Creates a newActionListBox
with a pre-set size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ActionListBox
addItem(java.lang.Runnable object)
Adds one more item to the list box, at the end.ActionListBox
addItem(java.lang.String label, java.lang.Runnable action)
Adds a new item to the list, which is displayed in the list using a supplied label.TerminalPosition
getCursorLocation()
Returns, in local coordinates, where to put the cursor on the screen when this component has focus.Interactable.Result
handleKeyStroke(KeyStroke keyStroke)
This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus.void
runSelectedItem()
-
Methods inherited from class com.googlecode.lanterna.gui2.AbstractListBox
afterEnterFocus, clearItems, createDefaultListItemRenderer, createDefaultRenderer, getIndexByMouseAction, getItemAt, getItemCount, getItems, getListItemRenderer, getSelectedIndex, getSelectedItem, indexOf, isEmpty, isFocusable, removeItem, setListItemRenderer, setSelectedIndex
-
Methods inherited from class com.googlecode.lanterna.gui2.AbstractInteractableComponent
afterLeaveFocus, 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
-
-
-
-
Constructor Detail
-
ActionListBox
public ActionListBox()
Default constructor, creates anActionListBox
with no pre-defined size that will request to be big enough to display all items
-
ActionListBox
public ActionListBox(TerminalSize preferredSize)
Creates a newActionListBox
with a pre-set size. If the items don't fit in within this size, scrollbars will be used to accommodate. Callingnew ActionListBox(null)
has the same effect as callingnew ActionListBox()
.- Parameters:
preferredSize
- Preferred size of thisActionListBox
-
-
Method Detail
-
addItem
public ActionListBox addItem(java.lang.Runnable object)
Adds one more item to the list box, at the end. The label of the item in the list box will be the result of calling.toString()
on the runnable, which might not be what you want to have unless you explicitly declare it. Consider usingaddItem(String label, Runnable action
instead, if you want to just set the label easily without having to override.toString()
.- Overrides:
addItem
in classAbstractListBox<java.lang.Runnable,ActionListBox>
- Parameters:
object
- Runnable to execute when the action was selected and fired in the list- Returns:
- Itself
-
addItem
public ActionListBox addItem(java.lang.String label, java.lang.Runnable action)
Adds a new item to the list, which is displayed in the list using a supplied label.- Parameters:
label
- Label to use in the list for the new itemaction
- Runnable to invoke when this action is selected and then triggered- Returns:
- Itself
-
getCursorLocation
public TerminalPosition getCursorLocation()
Description copied from interface:Interactable
Returns, in local coordinates, where to put the cursor on the screen when this component has focus. If null, the cursor should be hidden. If you component is 5x1 and you want to have the cursor in the middle (when in focus), return [2,0]. The GUI system will convert the position to global coordinates.- Specified by:
getCursorLocation
in interfaceInteractable
- Overrides:
getCursorLocation
in classAbstractInteractableComponent<ActionListBox>
- Returns:
- Coordinates of where to place the cursor when this component has focus
-
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<java.lang.Runnable,ActionListBox>
- Parameters:
keyStroke
- What input was entered by the user- Returns:
- Result of processing the key-stroke
-
runSelectedItem
public void runSelectedItem()
-
-