Class ActionListBox
java.lang.Object
com.googlecode.lanterna.gui2.AbstractComponent<ActionListBox>
com.googlecode.lanterna.gui2.AbstractInteractableComponent<ActionListBox>
com.googlecode.lanterna.gui2.AbstractListBox<Runnable, ActionListBox>
com.googlecode.lanterna.gui2.ActionListBox
- All Implemented Interfaces:
Component, Interactable, TextGUIElement
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 AbstractListBox
AbstractListBox.DefaultListBoxRenderer<V,T>, AbstractListBox.ListItemRenderer<V, T> Nested classes/interfaces inherited from interface Interactable
Interactable.FocusChangeDirection, Interactable.Result -
Field Summary
Fields inherited from class AbstractListBox
scrollOffset -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, creates anActionListBoxwith no pre-defined size that will request to be big enough to display all itemsActionListBox(TerminalSize preferredSize) Creates a newActionListBoxwith a pre-set size. -
Method Summary
Modifier and TypeMethodDescriptionAdds one more item to the list box, at the end.Adds a new item to the list, which is displayed in the list using a supplied label.Returns, in local coordinates, where to put the cursor on the screen when this component has focus.handleKeyStroke(KeyStroke keyStroke) This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus.voidMethods inherited from class AbstractListBox
afterEnterFocus, clearItems, createDefaultListItemRenderer, createDefaultRenderer, getIndexByMouseAction, getItemAt, getItemCount, getItems, getListItemRenderer, getSelectedIndex, getSelectedItem, indexOf, isEmpty, isFocusable, removeItem, setListItemRenderer, setSelectedIndexMethods inherited from class AbstractInteractableComponent
afterLeaveFocus, getInputFilter, getRenderer, handleInput, isActivationStroke, isEnabled, isFocused, isKeyboardActivationStroke, isMouseActivationStroke, isMouseDown, isMouseDrag, isMouseMove, isMouseUp, onEnterFocus, onLeaveFocus, setEnabled, setInputFilter, takeFocusMethods inherited from class 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, withBorderMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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, withBorderMethods inherited from interface TextGUIElement
draw, isInvalid
-
Constructor Details
-
ActionListBox
public ActionListBox()Default constructor, creates anActionListBoxwith no pre-defined size that will request to be big enough to display all items -
ActionListBox
Creates a newActionListBoxwith 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 Details
-
addItem
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 actioninstead, if you want to just set the label easily without having to override.toString().- Overrides:
addItemin classAbstractListBox<Runnable, ActionListBox>- Parameters:
object- Runnable to execute when the action was selected and fired in the list- Returns:
- Itself
-
addItem
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
Description copied from interface:InteractableReturns, 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:
getCursorLocationin interfaceInteractable- Overrides:
getCursorLocationin classAbstractInteractableComponent<ActionListBox>- Returns:
- Coordinates of where to place the cursor when this component has focus
-
handleKeyStroke
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<Runnable, ActionListBox>- Parameters:
keyStroke- What input was entered by the user- Returns:
- Result of processing the key-stroke
-
runSelectedItem
public void runSelectedItem()
-