-
- All Superinterfaces:
Component
,TextGUIElement
- All Known Implementing Classes:
AbstractInteractableComponent
,AbstractListBox
,ActionListBox
,Button
,CheckBox
,CheckBoxList
,ComboBox
,ImageComponent
,Menu
,MenuItem
,RadioBoxList
,Table
,TextBox
public interface Interactable extends Component
This interface marks a component as able to receive keyboard input from the user. Components that do not implement this interface in some way will not be able to receive input focus. Normally if you create a new component, you'll probably want to extend fromAbstractInteractableComponent
instead of implementing this one directly.- See Also:
AbstractInteractableComponent
-
-
Nested Class Summary
Nested Classes 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
-
Method Summary
All Methods Instance Methods Abstract Methods 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()
Returnstrue
if this component is able to receive input as a regular interactable component.boolean
isFocusable()
Returnstrue
if this interactable component is currently able to receive input focus.boolean
isFocused()
Returnstrue
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 componentInteractable
setEnabled(boolean enabled)
Prevents the component from receiving input focus if this is called with afalse
value.Interactable
setInputFilter(InputFilter inputFilter)
Assigns an input filter to the interactable component.Interactable
takeFocus()
Moves focus in theBasePane
to this component.-
Methods inherited from interface com.googlecode.lanterna.gui2.Component
addTo, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, 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
-
-
-
-
Method Detail
-
getCursorLocation
TerminalPosition getCursorLocation()
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.- Returns:
- Coordinates of where to place the cursor when this component has focus
-
handleInput
Interactable.Result handleInput(KeyStroke keyStroke)
Accepts a KeyStroke as input and processes this as a user input. Depending on what the component does with this key-stroke, there are several results passed back to the GUI system that will decide what to do next. If the event was not handled or ignored,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 returnResult.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 theResult.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 isAbstractInteractableComponent.handleKeyStroke(KeyStroke)
.- Parameters:
keyStroke
- What input was entered by the user- Returns:
- Result of processing the key-stroke
-
takeFocus
Interactable takeFocus()
Moves focus in theBasePane
to this component. If the component has not been added to aBasePane
(i.e. aWindow
most of the time), does nothing. If the component has been disabled through a call tosetEnabled(boolean)
, this call also does nothing.- Returns:
- Itself
-
onEnterFocus
void onEnterFocus(Interactable.FocusChangeDirection direction, Interactable previouslyInFocus)
Method called when this component gained keyboard focus.- Parameters:
direction
- What direction did the focus come frompreviouslyInFocus
- Which component had focus previously (null
if none)
-
onLeaveFocus
void onLeaveFocus(Interactable.FocusChangeDirection direction, Interactable nextInFocus)
Method called when keyboard focus moves away from this component- Parameters:
direction
- What direction is focus going innextInFocus
- Which component is receiving focus next (ornull
if none)
-
isFocused
boolean isFocused()
Returnstrue
if this component currently has input focus in its root container.- Returns:
true
if the interactable has input focus,false
otherwise
-
setInputFilter
Interactable setInputFilter(InputFilter inputFilter)
Assigns an input filter to the interactable component. This will intercept any user input and decide if the input should be passed on to the component or not.null
means there is no filter.- Parameters:
inputFilter
- Input filter to assign to the interactable- Returns:
- Itself
-
getInputFilter
InputFilter getInputFilter()
Returns the input filter currently assigned to the interactable component. This will intercept any user input and decide if the input should be passed on to the component or not.null
means there is no filter.- Returns:
- Input filter currently assigned to the interactable component
-
setEnabled
Interactable setEnabled(boolean enabled)
Prevents the component from receiving input focus if this is called with afalse
value. The component will then behave as a mainly non-interactable component. Input focus can be re-enabled by calling this withtrue
. 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.- Parameters:
enabled
- If called withfalse
, this interactable won't receive input focus until it's called again withtrue
.- Returns:
- Itself
-
isEnabled
boolean isEnabled()
Returnstrue
if this component is able to receive input as a regular interactable component. This will returnfalse
if input focus has been disabled through callingsetEnabled(boolean)
.- Returns:
true
if this component can receive input focus,false
otherwise
-
isFocusable
boolean isFocusable()
Returnstrue
if this interactable component is currently able to receive input focus. This is similar but different fromisEnabled()
, which tells lanterna that the entire component is disabled when it is returningfalse
, compared to this method which simply claims that the component is currently not ready to handle input. TheAbstractInteractableComponent
implementation always returntrue
here but for example the list box components will override and returnfalse
here if they are empty. Note that you can still programmatically force input focus onto the component, returningfalse
here won't prevent that.- Returns:
true
if this component wants to receive input focus,false
otherwise.
-
-