Component
, TextGUIElement
AbstractInteractableComponent
, AbstractListBox
, ActionListBox
, Button
, CheckBox
, CheckBoxList
, ComboBox
, RadioBoxList
, Table
, TextBox
public interface Interactable extends Component
AbstractInteractableComponent
instead of implementing this one directly.AbstractInteractableComponent
Modifier and Type | Interface | Description |
---|---|---|
static class |
Interactable.FocusChangeDirection |
When focus has changed, which direction.
|
static class |
Interactable.Result |
Enum to represent the various results coming out of the handleKeyStroke method
|
Modifier and Type | Method | Description |
---|---|---|
TerminalPosition |
getCursorLocation() |
Returns, in local coordinates, where to put the cursor on the screen when this component has focus.
|
InputFilter |
getInputFilter() |
Returns the input filter currently assigned to the interactable component.
|
Interactable.Result |
handleInput(KeyStroke keyStroke) |
Accepts a KeyStroke as input and processes this as a user input.
|
boolean |
isEnabled() |
Returns
true if this component is able to receive input as a regular interactable component. |
boolean |
isFocusable() |
Returns
true if this interactable component is currently able to receive input focus. |
boolean |
isFocused() |
Returns
true if this component currently has input focus in its root container. |
void |
onEnterFocus(Interactable.FocusChangeDirection direction,
Interactable previouslyInFocus) |
Method called when this component gained keyboard focus.
|
void |
onLeaveFocus(Interactable.FocusChangeDirection direction,
Interactable nextInFocus) |
Method called when keyboard focus moves away from this component
|
Interactable |
setEnabled(boolean enabled) |
Prevents the component from receiving input focus if this is called with a
false value. |
Interactable |
setInputFilter(InputFilter inputFilter) |
Assigns an input filter to the interactable component.
|
Interactable |
takeFocus() |
Moves focus in the
BasePane to this component. |
addTo, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, setTheme, toBasePane, toGlobal, withBorder
draw, isInvalid
TerminalPosition getCursorLocation()
Interactable.Result handleInput(KeyStroke keyStroke)
Result.UNHANDLED
should be returned. This will tell the GUI system that
the key stroke was not understood by this component and may be dealt with in another way. If event was processed
properly, it should return Result.HANDLED
, which will make the GUI system stop processing this particular
key-stroke. Furthermore, if the component understood the key-stroke and would like to move focus to a different
component, there are the Result.MOVE_FOCUS_*
values. This method should be invoking the input filter, if
it is set, to see if the input should be processed or not.
Notice that most of the built-in components in Lanterna extends from AbstractInteractableComponent
which
has a final implementation of this method. The method to override to handle input in that case is
AbstractInteractableComponent.handleKeyStroke(KeyStroke)
.
keyStroke
- What input was entered by the userInteractable takeFocus()
BasePane
to this component. If the component has not been added to a BasePane
(i.e. a Window
most of the time), does nothing. If the component has been disabled through a call to
setEnabled(boolean)
, this call also does nothing.void onEnterFocus(Interactable.FocusChangeDirection direction, Interactable previouslyInFocus)
direction
- What direction did the focus come frompreviouslyInFocus
- Which component had focus previously (null
if none)void onLeaveFocus(Interactable.FocusChangeDirection direction, Interactable nextInFocus)
direction
- What direction is focus going innextInFocus
- Which component is receiving focus next (or null
if none)boolean isFocused()
true
if this component currently has input focus in its root container.true
if the interactable has input focus, false
otherwiseInteractable setInputFilter(InputFilter inputFilter)
null
means there is no filter.inputFilter
- Input filter to assign to the interactableInputFilter getInputFilter()
null
means there is no filter.Interactable setEnabled(boolean enabled)
false
value. The component
will then behave as a mainly non-interactable component. Input focus can be re-enabled by calling this with
true
. If the component already has input focus when calling this method, it will release focus and no
component is focused until there is user action or code that chooses a new focus.enabled
- If called with false
, this interactable won't receive input focus until it's called again
with true
.boolean isEnabled()
true
if this component is able to receive input as a regular interactable component. This will
return false
if input focus has been disabled through calling setEnabled(boolean)
.true
if this component can receive input focus, false
otherwiseboolean isFocusable()
true
if this interactable component is currently able to receive input focus. This is similar but
different from 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.true
if this component wants to receive input focus, false
otherwise.Copyright © 2020. All rights reserved.