T
- Should always be itself, see AbstractComponent
public abstract class AbstractInteractableComponent<T extends AbstractInteractableComponent<T>> extends AbstractComponent<T> implements Interactable
Interactable
interfaceInteractable.FocusChangeDirection, Interactable.Result
Modifier | Constructor and Description |
---|---|
protected |
AbstractInteractableComponent()
Default constructor
|
Modifier and Type | Method and 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 |
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
|
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, getLayoutData, getParent, getPosition, getPreferredSize, getRendererFromTheme, getSize, getTextGUI, hasParent, invalidate, isInside, isInvalid, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, toBasePane, toGlobal, withBorder
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addTo, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, hasParent, invalidate, isInside, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, toBasePane, toGlobal, withBorder
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.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 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.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 interactableCopyright © 2016. All rights reserved.