T
- Should always be itself, see AbstractComponent
V
- Type of items this list box containsComponent
, Interactable
, TextGUIElement
ActionListBox
, CheckBoxList
, RadioBoxList
public abstract class AbstractListBox<V,T extends AbstractListBox<V,T>> extends AbstractInteractableComponent<T>
Modifier and Type | Class | Description |
---|---|---|
static class |
AbstractListBox.DefaultListBoxRenderer<V,T extends AbstractListBox<V,T>> |
The default renderer for
AbstractListBox and all its subclasses. |
static class |
AbstractListBox.ListItemRenderer<V,T extends AbstractListBox<V,T>> |
The default list item renderer class, this can be extended and customized it needed.
|
Interactable.FocusChangeDirection, Interactable.Result
Modifier | Constructor | Description |
---|---|---|
protected |
AbstractListBox() |
This constructor sets up the component so it has no preferred size but will ask to be as big as the list is.
|
protected |
AbstractListBox(TerminalSize size) |
This constructor sets up the component with a preferred size that is will always request, no matter what items
are in the list box.
|
Modifier and Type | Method | Description |
---|---|---|
T |
addItem(V item) |
Adds one more item to the list box, at the end.
|
protected void |
afterEnterFocus(Interactable.FocusChangeDirection direction,
Interactable previouslyInFocus) |
Called by
AbstractInteractableComponent automatically after this component has received input focus. |
T |
clearItems() |
Removes all items from the list box
|
protected AbstractListBox.ListItemRenderer<V,T> |
createDefaultListItemRenderer() |
Method that constructs the
ListItemRenderer that this list box should use to draw the elements of the
list box. |
protected InteractableRenderer<T> |
createDefaultRenderer() |
When you create a custom component, you need to implement this method and return a Renderer which is responsible
for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable).
|
V |
getItemAt(int index) |
Retrieves the item at the specified index in the list box
|
int |
getItemCount() |
Returns the number of items currently in the list box
|
List<V> |
getItems() |
Returns a copy of the items in the list box as a
List |
int |
getSelectedIndex() |
Returns the index of the currently selected item in the list box.
|
V |
getSelectedItem() |
Returns the currently selected item in the list box.
|
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.
|
int |
indexOf(V item) |
Looks for the particular item in the list and returns the index within the list (starting from zero) of that item
if it is found, or -1 otherwise
|
boolean |
isEmpty() |
Checks if the list box has no items
|
boolean |
isFocusable() |
Returns
true if this interactable component is currently able to receive input focus. |
V |
removeItem(int index) |
Removes an item from the list box by its index.
|
T |
setListItemRenderer(AbstractListBox.ListItemRenderer<V,T> listItemRenderer) |
This method overrides the
ListItemRenderer that is used to draw each element in the list box. |
T |
setSelectedIndex(int index) |
Sets which item in the list box that is currently selected.
|
addTo, calculatePreferredSize, draw, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, toBasePane, toGlobal, withBorder
afterLeaveFocus, getCursorLocation, getInputFilter, getRenderer, handleInput, isEnabled, isFocused, onEnterFocus, onLeaveFocus, setEnabled, setInputFilter, takeFocus
addTo, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, setTheme, toBasePane, toGlobal, withBorder
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
draw, isInvalid
protected AbstractListBox()
protected AbstractListBox(TerminalSize size)
null
value has the same effect as calling the default
constructor.size
- Preferred size that the list should be asking for instead of invoking the preferred size calculation,
or if set to null
will ask to be big enough to display all items.protected InteractableRenderer<T> createDefaultRenderer()
AbstractComponent
createDefaultRenderer
in class AbstractInteractableComponent<T extends AbstractListBox<V,T>>
protected AbstractListBox.ListItemRenderer<V,T> createDefaultListItemRenderer()
ListItemRenderer
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.ListItemRenderer
to use when drawing the items in the listpublic T setListItemRenderer(AbstractListBox.ListItemRenderer<V,T> listItemRenderer)
ListItemRenderer
that is used to draw each element in the list box. Note that
this is not the renderer used for the entire list box but for each item, called one by one.listItemRenderer
- New renderer to use when drawing the items in the list boxpublic Interactable.Result handleKeyStroke(KeyStroke keyStroke)
AbstractInteractableComponent
handleInput(..)
is final in
AbstractInteractableComponent
to ensure the input filter is properly handled. If the filter decides that
this event should be processed, it will call this method.handleKeyStroke
in class AbstractInteractableComponent<T extends AbstractListBox<V,T>>
keyStroke
- What input was entered by the userprotected void afterEnterFocus(Interactable.FocusChangeDirection direction, Interactable previouslyInFocus)
AbstractInteractableComponent
AbstractInteractableComponent
automatically after this component has received input focus. You
can override this method if you need to trigger some action based on this.afterEnterFocus
in class AbstractInteractableComponent<T extends AbstractListBox<V,T>>
direction
- How focus was transferred, keep in mind this is from the previous component's point of view so
if this parameter has value DOWN, focus came in from abovepreviouslyInFocus
- Which interactable component had focus previouslypublic T addItem(V item)
item
- Item to add to the list boxpublic V removeItem(int index)
index
- Index of the item to removeIndexOutOfBoundsException
- if the index is out of bounds in regards to the list of itemspublic T clearItems()
public boolean isFocusable()
Interactable
true
if this interactable component is currently able to receive input focus. This is similar but
different from Interactable.isEnabled()
, which tells lanterna that the entire component is disabled when it is
returning false
, compared to this method which simply claims that the component is currently not ready
to handle input. The AbstractInteractableComponent
implementation always return true
here but
for example the list box components will override and return false
here if they are empty. Note that you
can still programmatically force input focus onto the component, returning false
here won't prevent that.isFocusable
in interface Interactable
isFocusable
in class AbstractInteractableComponent<T extends AbstractListBox<V,T>>
true
if this component wants to receive input focus, false
otherwise.public int indexOf(V item)
item
- What item to search for in the list boxpublic V getItemAt(int index)
index
- Index of the item to fetchIndexOutOfBoundsException
- If the index is less than zero or equals/greater than the number of items in
the list boxpublic boolean isEmpty()
true
if the list box has no items, false
otherwisepublic int getItemCount()
public List<V> getItems()
List
public T setSelectedIndex(int index)
CheckBoxList
where individual items have a certain checked/unchecked state.index
- Index of the item that should be currently selectedpublic int getSelectedIndex()
CheckBoxList
where individual items have a certain checked/unchecked state.public V getSelectedItem()
CheckBoxList
where individual items have a certain checked/unchecked state.null
if there are no itemsCopyright © 2020. All rights reserved.