Class AbstractInteractableComponent<T extends AbstractInteractableComponent<T>>
java.lang.Object
com.googlecode.lanterna.gui2.AbstractComponent<T>
com.googlecode.lanterna.gui2.AbstractInteractableComponent<T>
- Type Parameters:
T- Should always be itself, seeAbstractComponent
- All Implemented Interfaces:
Component, Interactable, TextGUIElement
- Direct Known Subclasses:
AbstractListBox, Button, CheckBox, ComboBox, ImageComponent, MenuItem, Table, TextBox
public abstract class AbstractInteractableComponent<T extends AbstractInteractableComponent<T>>
extends AbstractComponent<T>
implements Interactable
Default implementation of Interactable that extends from AbstractComponent. If you want to write your own component
that is interactable, i.e. can receive keyboard (and mouse) input, you probably want to extend from this class as
it contains some common implementations of the methods from
Interactable interface-
Nested Class Summary
Nested classes/interfaces inherited from interface Interactable
Interactable.FocusChangeDirection, Interactable.Result -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterEnterFocus(Interactable.FocusChangeDirection direction, Interactable previouslyInFocus) Called byAbstractInteractableComponentautomatically after this component has received input focus.protected voidafterLeaveFocus(Interactable.FocusChangeDirection direction, Interactable nextInFocus) Called byAbstractInteractableComponentautomatically after this component has lost input focus.protected abstract InteractableRenderer<T> 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).Returns, in local coordinates, where to put the cursor on the screen when this component has focus.Returns the input filter currently assigned to the interactable component.Returns the renderer used to draw this component and measure its preferred size.final Interactable.ResulthandleInput(KeyStroke keyStroke) Accepts a KeyStroke as input and processes this as a user input.protected Interactable.ResulthandleKeyStroke(KeyStroke keyStroke) This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus.booleanisActivationStroke(KeyStroke keyStroke) booleanReturnstrueif this component is able to receive input as a regular interactable component.booleanReturnstrueif this interactable component is currently able to receive input focus.booleanReturnstrueif this component currently has input focus in its root container.booleanisKeyboardActivationStroke(KeyStroke keyStroke) booleanisMouseActivationStroke(KeyStroke keyStroke) booleanisMouseDown(KeyStroke keyStroke) booleanisMouseDrag(KeyStroke keyStroke) booleanisMouseMove(KeyStroke keyStroke) booleanfinal voidonEnterFocus(Interactable.FocusChangeDirection direction, Interactable previouslyInFocus) Method called when this component gained keyboard focus.final voidonLeaveFocus(Interactable.FocusChangeDirection direction, Interactable nextInFocus) Method called when keyboard focus moves away from this componentsetEnabled(boolean enabled) Prevents the component from receiving input focus if this is called with afalsevalue.setInputFilter(InputFilter inputFilter) Assigns an input filter to the interactable component.Moves focus in theBasePaneto this component.Methods inherited from class AbstractComponent
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, withBorderMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Component
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, withBorderMethods inherited from interface TextGUIElement
draw, isInvalid
-
Field Details
-
inputFilter
-
inFocus
private boolean inFocus -
enabled
private boolean enabled
-
-
Constructor Details
-
AbstractInteractableComponent
protected AbstractInteractableComponent()Default constructor
-
-
Method Details
-
takeFocus
Description copied from interface:InteractableMoves focus in theBasePaneto this component. If the component has not been added to aBasePane(i.e. aWindowmost of the time), does nothing. If the component has been disabled through a call toInteractable.setEnabled(boolean), this call also does nothing.- Specified by:
takeFocusin interfaceInteractable- Returns:
- Itself
-
onEnterFocus
public final void onEnterFocus(Interactable.FocusChangeDirection direction, Interactable previouslyInFocus) Method called when this component gained keyboard focus.This method is final in
AbstractInteractableComponent, please overrideafterEnterFocusinstead- Specified by:
onEnterFocusin interfaceInteractable- Parameters:
direction- What direction did the focus come frompreviouslyInFocus- Which component had focus previously (nullif none)
-
afterEnterFocus
protected void afterEnterFocus(Interactable.FocusChangeDirection direction, Interactable previouslyInFocus) Called byAbstractInteractableComponentautomatically after this component has received input focus. You can override this method if you need to trigger some action based on this.- Parameters:
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 previously
-
onLeaveFocus
public final void onLeaveFocus(Interactable.FocusChangeDirection direction, Interactable nextInFocus) Method called when keyboard focus moves away from this componentThis method is final in
AbstractInteractableComponent, please overrideafterLeaveFocusinstead- Specified by:
onLeaveFocusin interfaceInteractable- Parameters:
direction- What direction is focus going innextInFocus- Which component is receiving focus next (ornullif none)
-
afterLeaveFocus
protected void afterLeaveFocus(Interactable.FocusChangeDirection direction, Interactable nextInFocus) Called byAbstractInteractableComponentautomatically after this component has lost input focus. You can override this method if you need to trigger some action based on this.- Parameters:
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 focus
-
createDefaultRenderer
Description copied from class:AbstractComponentWhen 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). This value is intended to be overridden by custom themes.- Specified by:
createDefaultRendererin classAbstractComponent<T extends AbstractInteractableComponent<T>>- Returns:
- Renderer to use when sizing and drawing this component
-
getRenderer
Description copied from interface:ComponentReturns the renderer used to draw this component and measure its preferred size. You probably won't need to call this method unless you know exactly which ComponentRenderer implementation is used and you need to customize it.- Specified by:
getRendererin interfaceComponent- Overrides:
getRendererin classAbstractComponent<T extends AbstractInteractableComponent<T>>- Returns:
- Renderer this component is using
-
isFocused
public boolean isFocused()Description copied from interface:InteractableReturnstrueif this component currently has input focus in its root container.- Specified by:
isFocusedin interfaceInteractable- Returns:
trueif the interactable has input focus,falseotherwise
-
setEnabled
Description copied from interface:InteractablePrevents the component from receiving input focus if this is called with afalsevalue. 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.- Specified by:
setEnabledin interfaceInteractable- Parameters:
enabled- If called withfalse, this interactable won't receive input focus until it's called again withtrue.- Returns:
- Itself
-
isEnabled
public boolean isEnabled()Description copied from interface:InteractableReturnstrueif this component is able to receive input as a regular interactable component. This will returnfalseif input focus has been disabled through callingInteractable.setEnabled(boolean).- Specified by:
isEnabledin interfaceInteractable- Returns:
trueif this component can receive input focus,falseotherwise
-
isFocusable
public boolean isFocusable()Description copied from interface:InteractableReturnstrueif this interactable component is currently able to receive input focus. This is similar but different fromInteractable.isEnabled(), 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. TheAbstractInteractableComponentimplementation always returntruehere but for example the list box components will override and returnfalsehere if they are empty. Note that you can still programmatically force input focus onto the component, returningfalsehere won't prevent that.- Specified by:
isFocusablein interfaceInteractable- Returns:
trueif this component wants to receive input focus,falseotherwise.
-
handleInput
Description copied from interface:InteractableAccepts 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.UNHANDLEDshould 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
AbstractInteractableComponentwhich has a final implementation of this method. The method to override to handle input in that case ishandleKeyStroke(KeyStroke).- Specified by:
handleInputin interfaceInteractable- Parameters:
keyStroke- What input was entered by the user- Returns:
- Result of processing the key-stroke
-
handleKeyStroke
This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus. The input method from the interface,handleInput(..)is final inAbstractInteractableComponentto ensure the input filter is properly handled. If the filter decides that this event should be processed, it will call this method.- Parameters:
keyStroke- What input was entered by the user- Returns:
- Result of processing the key-stroke
-
getCursorLocation
Description copied from interface:InteractableReturns, 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.- Specified by:
getCursorLocationin interfaceInteractable- Returns:
- Coordinates of where to place the cursor when this component has focus
-
getInputFilter
Description copied from interface:InteractableReturns 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.nullmeans there is no filter.- Specified by:
getInputFilterin interfaceInteractable- Returns:
- Input filter currently assigned to the interactable component
-
setInputFilter
Description copied from interface:InteractableAssigns 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.nullmeans there is no filter.- Specified by:
setInputFilterin interfaceInteractable- Parameters:
inputFilter- Input filter to assign to the interactable- Returns:
- Itself
-
isKeyboardActivationStroke
-
isMouseActivationStroke
-
isActivationStroke
-
isMouseDown
-
isMouseDrag
-
isMouseMove
-
isMouseUp
-