 |
Gridarta Editor
|
Go to the documentation of this file.
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;
114 private void addKeyBinding(
final String keyBinding,
final ActionListener action) {
116 if (keyStroke !=
null) {
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 return modifiers == 0 ? KeyStroke.getKeyStroke(ch) : KeyStroke.getKeyStroke(ch, modifiers);
240 LOG.error(
"Invalid key stroke: " + keyStroke);
246 ch = KeyEvent.class.getField(
"VK_" + key).getInt(
null);
247 }
catch (
final IllegalAccessException | NoSuchFieldException ignored) {
248 LOG.error(
"Invalid key stroke: " + keyStroke);
252 return KeyStroke.getKeyStroke(ch, modifiers);
final ActionListener selectDocHome
final ActionListener selectPrevLine
final ActionListener nextPage
Classes for the script editor used within the editor to create and modify Python and Lua scripts.
final Map< KeyStroke, ActionListener > bindings
This package contains the other part of the script editor.
final ActionListener selectPrevWord
static KeyStroke parseKeyStroke(final String keyStroke)
Converts a string to a keystroke.
Base package of all Gridarta classes.
final ActionListener home
final ActionListener insertChar
final ActionListener prevChar
void keyPressed(final KeyEvent e)
Handle a key pressed event.
final ActionListener delete
An input handler converts the user's key strokes into concrete actions.
final ActionListener documentHome
static final Category LOG
The Logger for printing log messages.
final ActionListener overwrite
final ActionListener nextChar
final ActionListener nextWord
boolean isRepeatEnabled()
Returns if repetition is enabled.
void addDefaultKeyBindings()
Sets up the default key bindings.
final ActionListener insertBreak
final ActionListener nextLine
void setRepeatEnabled(final boolean repeat)
Sets the enabled state of repetition.
final InputActions inputActions
void keyTyped(final KeyEvent e)
Handle a key typed event.
final ActionListener selectHome
The default input handler.
final ActionListener selectPrevPage
DefaultInputHandler(final DefaultInputHandler copy)
final ActionListener selectDocEnd
final ActionListener insertTab
final ActionListener selectPrevChar
final ActionListener selectNextChar
final ActionListener documentEnd
final ActionListener selectEnd
final ActionListener toggleRectangle
final ActionListener selectNextWord
void addKeyBinding(final String keyBinding, final ActionListener action)
Adds a key binding to this input handler.
DefaultInputHandler(@NotNull final ScriptEditControl scriptEditControl, @NotNull final MenuEntries menuEntries)
Creates a new input handler with no key bindings defined.
void executeAction(final ActionListener listener, final Object source, @Nullable final String actionCommand)
Executes the specified action, repeating and recording it as necessary.
ScriptEditControl - Manages events and data flow for the script editor entity.
final ActionListener prevWord
boolean handleGrabAction(final KeyEvent evt)
If a key is being grabbed, this method should be called with the appropriate key event.
final ActionListener prevLine
final ActionListener prevPage
final ActionListener selectNextPage
final ActionListener functionMenu
void keyReleased(final KeyEvent e)
final ActionListener backspaceWord
final ActionListener selectNextLine
InputHandler copy()
Returns a copy of this input handler that shares the same key bindings.
final ActionListener backspace
final ActionListener deleteWord
final ActionListener repeat