11 package net.sf.gridarta.textedit.textarea;
13 import java.awt.event.ActionListener;
14 import java.awt.event.InputEvent;
15 import java.awt.event.KeyEvent;
16 import java.util.HashMap;
18 import javax.swing.KeyStroke;
22 import org.apache.log4j.Category;
23 import org.apache.log4j.Logger;
24 import org.jetbrains.annotations.NotNull;
25 import org.jetbrains.annotations.Nullable;
36 private final Map<KeyStroke, ActionListener>
bindings;
53 inputActions =
new InputActions(scriptEditControl, menuEntries);
54 bindings =
new HashMap<>();
114 private void addKeyBinding(
final String keyBinding,
final ActionListener action) {
116 if (keyStroke != null) {
117 bindings.put(keyStroke, action);
136 final int keyCode = e.getKeyCode();
137 final int modifiers = e.getModifiers();
139 if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT || keyCode == KeyEvent.VK_META) {
143 if ((modifiers & ~InputEvent.SHIFT_MASK) != 0 || e.isActionKey() || keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE || keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_ESCAPE) {
148 final KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, modifiers);
149 final ActionListener actionListener = bindings.get(keyStroke);
150 if (actionListener != null) {
166 final int modifiers = e.getModifiers();
167 final char c = e.getKeyChar();
169 if (c != KeyEvent.CHAR_UNDEFINED && (modifiers & InputEvent.ALT_MASK) == 0) {
170 if (c >= (
char) 0x20 && c != (
char) 0x7f) {
171 final KeyStroke keyStroke = KeyStroke.getKeyStroke(Character.toUpperCase(c));
172 final ActionListener actionListener = bindings.get(keyStroke);
174 if (actionListener != null) {
175 executeAction(actionListener, e.getSource(), String.valueOf(c));
209 if (keyStroke == null) {
214 final int index = keyStroke.indexOf(
'+');
216 for (
int i = 0; i < index; i++) {
217 switch (Character.toUpperCase(keyStroke.charAt(i))) {
219 modifiers |= InputEvent.ALT_MASK;
222 modifiers |= InputEvent.CTRL_MASK;
225 modifiers |= InputEvent.META_MASK;
228 modifiers |= InputEvent.SHIFT_MASK;
234 final String key = keyStroke.substring(index + 1);
235 if (key.length() == 1) {
236 final char ch = Character.toUpperCase(key.charAt(0));
237 if (modifiers == 0) {
238 return KeyStroke.getKeyStroke(ch);
240 return KeyStroke.getKeyStroke(ch, modifiers);
242 }
else if (key.isEmpty()) {
243 LOG.error(
"Invalid key stroke: " + keyStroke);
249 ch = KeyEvent.class.getField(
"VK_" + key).getInt(null);
250 }
catch (
final IllegalAccessException ignored) {
251 LOG.error(
"Invalid key stroke: " + keyStroke);
253 }
catch (
final NoSuchFieldException ignored) {
254 LOG.error(
"Invalid key stroke: " + keyStroke);
258 return KeyStroke.getKeyStroke(ch, modifiers);
final ActionListener toggleRectangle
void keyPressed(final KeyEvent e)
Handle a key pressed event.
boolean handleGrabAction(final KeyEvent evt)
If a key is being grabbed, this method should be called with the appropriate key event.
final ActionListener selectPrevPage
final ActionListener selectDocHome
final ActionListener documentHome
final ActionListener insertChar
final ActionListener prevPage
final ActionListener deleteWord
void keyReleased(final KeyEvent e)
static KeyStroke parseKeyStroke(final String keyStroke)
Converts a string to a keystroke.
final ActionListener selectHome
final ActionListener nextLine
final ActionListener selectNextPage
final ActionListener selectNextChar
final InputActions inputActions
InputHandler copy()
Returns a copy of this input handler that shares the same key bindings.
void addKeyBinding(final String keyBinding, final ActionListener action)
Adds a key binding to this input handler.
final ActionListener prevLine
An input handler converts the user's key strokes into concrete actions.
Base package of all Gridarta classes.
final ActionListener home
This package contains the classes for the script editor used within the editor to create and modify P...
boolean isRepeatEnabled()
Returns if repetition is enabled.
final ActionListener prevChar
final ActionListener selectPrevWord
final ActionListener selectNextWord
final ActionListener insertTab
final ActionListener selectPrevChar
final ActionListener selectDocEnd
final Map< KeyStroke, ActionListener > bindings
static final Category LOG
The Logger for printing log messages.
final ActionListener insertBreak
DefaultInputHandler(final DefaultInputHandler copy)
final ActionListener functionMenu
void addDefaultKeyBindings()
Sets up the default key bindings.
This package contains the other part of the script editor.
final ActionListener nextChar
ScriptEditControl - Manages events and data flow for the script editor entity.
final ActionListener repeat
final ActionListener selectNextLine
final ActionListener documentEnd
void setRepeatEnabled(final boolean repeat)
Sets the enabled state of repetition.
final ActionListener backspace
final ActionListener selectPrevLine
final ActionListener delete
final ActionListener nextWord
final ActionListener backspaceWord
final ActionListener prevWord
final ActionListener selectEnd
final ActionListener overwrite
DefaultInputHandler(@NotNull final ScriptEditControl scriptEditControl, @NotNull final MenuEntries menuEntries)
Creates a new input handler with no key bindings defined.
final ActionListener nextPage
void executeAction(final ActionListener listener, final Object source, @Nullable final String actionCommand)
Executes the specified action, repeating and recording it as necessary.
The default input handler.
void keyTyped(final KeyEvent e)
Handle a key typed event.