2 * This file is part of lanterna (http://code.google.com/p/lanterna/).
4 * lanterna is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) 2010-2015 Martin
19 package com
.googlecode
.lanterna
.gui2
;
21 import com
.googlecode
.lanterna
.TerminalPosition
;
22 import com
.googlecode
.lanterna
.input
.KeyStroke
;
25 * This interface marks a component as able to receive keyboard input from the user. Components that do not implement
26 * this interface in some way will not be able to receive input focus. Normally if you create a new component, you'll
27 * probably want to extend from {@code AbstractInteractableComponent} instead of implementing this one directly.
29 * @see AbstractInteractableComponent
32 public interface Interactable
extends Component
{
34 * Returns, in local coordinates, where to put the cursor on the screen when this component has focus. If null, the
35 * cursor should be hidden. If you component is 5x1 and you want to have the cursor in the middle (when in focus),
36 * return [2,0]. The GUI system will convert the position to global coordinates.
37 * @return Coordinates of where to place the cursor when this component has focus
39 TerminalPosition
getCursorLocation();
42 * Accepts a KeyStroke as input and processes this as a user input. Depending on what the component does with this
43 * key-stroke, there are several results passed back to the GUI system that will decide what to do next. If the
44 * event was not handled or ignored, {@code Result.UNHANDLED} should be returned. This will tell the GUI system that
45 * the key stroke was not understood by this component and may be dealt with in another way. If event was processed
46 * properly, it should return {@code Result.HANDLED}, which will make the GUI system stop processing this particular
47 * key-stroke. Furthermore, if the component understood the key-stroke and would like to move focus to a different
48 * component, there are the {@code Result.MOVE_FOCUS_*} values. This method should be invoking the input filter, if
49 * it is set, to see if the input should be processed or not.
50 * @param keyStroke What input was entered by the user
51 * @return Result of processing the key-stroke
53 Result
handleInput(KeyStroke keyStroke
);
56 * Moves focus in the {@code BasePane} to this component. If the component has not been added to a {@code BasePane}
57 * (i.e. a {@code Window} most of the time), does nothing.
60 Interactable
takeFocus();
63 * Method called when this component gained keyboard focus.
64 * @param direction What direction did the focus come from
65 * @param previouslyInFocus Which component had focus previously ({@code null} if none)
67 void onEnterFocus(FocusChangeDirection direction
, Interactable previouslyInFocus
);
70 * Method called when keyboard focus moves away from this component
71 * @param direction What direction is focus going in
72 * @param nextInFocus Which component is receiving focus next (or {@code null} if none)
74 void onLeaveFocus(FocusChangeDirection direction
, Interactable nextInFocus
);
77 * Returns {@code true} if this component currently has input focus in its root container.
78 * @return {@code true} if the interactable has input focus, {@code false} otherwise
83 * Assigns an input filter to the interactable component. This will intercept any user input and decide if the input
84 * should be passed on to the component or not. {@code null} means there is no filter.
85 * @param inputFilter Input filter to assign to the interactable
88 Interactable
setInputFilter(InputFilter inputFilter
);
91 * Returns the input filter currently assigned to the interactable component. This will intercept any user input and
92 * decide if the input should be passed on to the component or not. {@code null} means there is no filter.
93 * @return Input filter currently assigned to the interactable component
95 InputFilter
getInputFilter();
98 * Enum to represent the various results coming out of the handleKeyStroke method
102 * This component didn't handle the key-stroke, either because it was not recognized or because it chose to
107 * This component has handled the key-stroke and it should be considered consumed.
111 * This component has handled the key-stroke and requests the GUI system to switch focus to next component in
112 * an ordered list of components. This should generally be returned if moving focus by using the tab key.
116 * This component has handled the key-stroke and requests the GUI system to switch focus to previous component
117 * in an ordered list of components. This should generally be returned if moving focus by using the reverse tab
122 * This component has handled the key-stroke and requests the GUI system to switch focus to next component in
123 * the general left direction. By convention in Lanterna, if there is no component to the left, it will move up
124 * instead. This should generally be returned if moving focus by using the left array key.
128 * This component has handled the key-stroke and requests the GUI system to switch focus to next component in
129 * the general right direction. By convention in Lanterna, if there is no component to the right, it will move
130 * down instead. This should generally be returned if moving focus by using the right array key.
134 * This component has handled the key-stroke and requests the GUI system to switch focus to next component in
135 * the general up direction. By convention in Lanterna, if there is no component above, it will move left
136 * instead. This should generally be returned if moving focus by using the up array key.
140 * This component has handled the key-stroke and requests the GUI system to switch focus to next component in
141 * the general down direction. By convention in Lanterna, if there is no component below, it will move up
142 * instead. This should generally be returned if moving focus by using the down array key.
149 * When focus has changed, which direction.
151 enum FocusChangeDirection
{
153 * The next interactable component, going down. This direction usually comes from the user pressing down array.
157 * The next interactable component, going right. This direction usually comes from the user pressing right array.
161 * The next interactable component, going up. This direction usually comes from the user pressing up array.
165 * The next interactable component, going left. This direction usually comes from the user pressing left array.
169 * The next interactable component, in layout manager order (usually left->right, up->down). This direction
170 * usually comes from the user pressing tab key.
174 * The previous interactable component, reversed layout manager order (usually right->left, down->up). This
175 * direction usually comes from the user pressing shift and tab key (reverse tab).
179 * Focus was changed by calling the {@code RootContainer.setFocusedInteractable(..)} method directly.
183 * Focus has gone away and no component is now in focus