T
- Should always be itself, see AbstractComponent
Component
, Interactable
, TextGUIElement
AbstractListBox
, Button
, CheckBox
, ComboBox
, ImageComponent
, MenuItem
, Table
, TextBox
public abstract class AbstractInteractableComponent<T extends AbstractInteractableComponent<T>> extends AbstractComponent<T> implements Interactable
Interactable
interfaceInteractable.FocusChangeDirection, Interactable.Result
Modifier | Constructor | Description |
---|---|---|
protected |
AbstractInteractableComponent() |
Default constructor
|
Modifier and Type | Method | Description |
---|---|---|
protected void |
afterEnterFocus(Interactable.FocusChangeDirection direction,
Interactable previouslyInFocus) |
Called by
AbstractInteractableComponent automatically after this component has received input focus. |
protected void |
afterLeaveFocus(Interactable.FocusChangeDirection direction,
Interactable nextInFocus) |
Called by
AbstractInteractableComponent automatically after this component has lost input focus. |
protected abstract 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).
|
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.
|
InteractableRenderer<T> |
getRenderer() |
Returns the renderer used to draw this component and measure its preferred size.
|
Interactable.Result |
handleInput(KeyStroke keyStroke) |
Accepts a KeyStroke as input and processes this as a user input.
|
protected 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.
|
boolean |
isActivationStroke(KeyStroke keyStroke) |
|
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. |
boolean |
isKeyboardActivationStroke(KeyStroke keyStroke) |
|
boolean |
isMouseActivationStroke(KeyStroke keyStroke) |
|
boolean |
isMouseDown(KeyStroke keyStroke) |
|
boolean |
isMouseDrag(KeyStroke keyStroke) |
|
boolean |
isMouseMove(KeyStroke keyStroke) |
|
boolean |
isMouseUp(KeyStroke keyStroke) |
|
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
|
T |
setEnabled(boolean enabled) |
Prevents the component from receiving input focus if this is called with a
false value. |
T |
setInputFilter(InputFilter inputFilter) |
Assigns an input filter to the interactable component.
|
T |
takeFocus() |
Moves focus in the
BasePane to this component. |
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
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
draw, isInvalid
protected AbstractInteractableComponent()
public T takeFocus()
Interactable
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
Interactable.setEnabled(boolean)
, this call also does nothing.takeFocus
in interface Interactable
public final void onEnterFocus(Interactable.FocusChangeDirection direction, Interactable previouslyInFocus)
This method is final in AbstractInteractableComponent
, please override afterEnterFocus
instead
onEnterFocus
in interface Interactable
direction
- What direction did the focus come frompreviouslyInFocus
- Which component had focus previously (null
if none)protected void afterEnterFocus(Interactable.FocusChangeDirection direction, Interactable previouslyInFocus)
AbstractInteractableComponent
automatically after this component has received input focus. You
can override this method if you need to trigger some action based on this.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 final void onLeaveFocus(Interactable.FocusChangeDirection direction, Interactable nextInFocus)
This method is final in AbstractInteractableComponent
, please override afterLeaveFocus
instead
onLeaveFocus
in interface Interactable
direction
- What direction is focus going innextInFocus
- Which component is receiving focus next (or null
if none)protected void afterLeaveFocus(Interactable.FocusChangeDirection direction, Interactable nextInFocus)
AbstractInteractableComponent
automatically after this component has lost input focus. You
can override this method if you need to trigger some action based on this.direction
- How focus was transferred, keep in mind this is from the this component's point of view so
if this parameter has value DOWN, focus is moving down to a component belownextInFocus
- Which interactable component is going to receive focusprotected abstract InteractableRenderer<T> createDefaultRenderer()
AbstractComponent
createDefaultRenderer
in class AbstractComponent<T extends AbstractInteractableComponent<T>>
public InteractableRenderer<T> getRenderer()
Component
getRenderer
in interface Component
getRenderer
in class AbstractComponent<T extends AbstractInteractableComponent<T>>
public boolean isFocused()
Interactable
true
if this component currently has input focus in its root container.isFocused
in interface Interactable
true
if the interactable has input focus, false
otherwisepublic T setEnabled(boolean enabled)
Interactable
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.setEnabled
in interface Interactable
enabled
- If called with false
, this interactable won't receive input focus until it's called again
with true
.public boolean isEnabled()
Interactable
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 Interactable.setEnabled(boolean)
.isEnabled
in interface Interactable
true
if this component can receive input focus, false
otherwisepublic 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
true
if this component wants to receive input focus, false
otherwise.public final Interactable.Result handleInput(KeyStroke keyStroke)
Interactable
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
handleKeyStroke(KeyStroke)
.
handleInput
in interface Interactable
keyStroke
- What input was entered by the userprotected Interactable.Result handleKeyStroke(KeyStroke keyStroke)
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.keyStroke
- What input was entered by the userpublic TerminalPosition getCursorLocation()
Interactable
getCursorLocation
in interface Interactable
public InputFilter getInputFilter()
Interactable
null
means there is no filter.getInputFilter
in interface Interactable
public T setInputFilter(InputFilter inputFilter)
Interactable
null
means there is no filter.setInputFilter
in interface Interactable
inputFilter
- Input filter to assign to the interactablepublic boolean isKeyboardActivationStroke(KeyStroke keyStroke)
public boolean isMouseActivationStroke(KeyStroke keyStroke)
public boolean isActivationStroke(KeyStroke keyStroke)
public boolean isMouseDown(KeyStroke keyStroke)
public boolean isMouseDrag(KeyStroke keyStroke)
public boolean isMouseMove(KeyStroke keyStroke)
public boolean isMouseUp(KeyStroke keyStroke)
Copyright © 2020. All rights reserved.