List of usage examples for javax.swing.text JTextComponent loadKeymap
public static void loadKeymap(Keymap map, KeyBinding[] bindings, Action[] actions)
Loads a keymap with a bunch of bindings.
From source file:Main.java
/** * initialize keystroke bindings/* ww w .j a v a 2 s .c om*/ */ public final static void InitializeKeyStrokeBindings() { String selectAllAction = DefaultEditorKit.selectAllAction; String cutAction = DefaultEditorKit.cutAction; String copyAction = DefaultEditorKit.copyAction; String pasteAction = DefaultEditorKit.pasteAction; int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); JTextComponent.KeyBinding ctrlA = new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_A, mask), selectAllAction); JTextComponent.KeyBinding ctrlX = new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_X, mask), cutAction); JTextComponent.KeyBinding ctrlC = new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_C, mask), copyAction); JTextComponent.KeyBinding ctrlV = new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V, mask), pasteAction); JTextComponent.KeyBinding[] extraBindings = new JTextComponent.KeyBinding[] { ctrlA, ctrlX, ctrlC, ctrlV }; Keymap defaultKeyMap = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP); JTextComponent dummy = new JTextField(); JTextComponent.loadKeymap(defaultKeyMap, extraBindings, dummy.getActions()); }
From source file:com.mirth.connect.client.ui.Mirth.java
private static void keyMapBindings(JTextComponent comp, KeyBinding[] bindings) { JTextComponent.loadKeymap(comp.getKeymap(), bindings, comp.getActions()); }
From source file:net.sf.jabref.gui.keyboard.EmacsKeyBindings.java
/** * Activates Emacs keybindings for all text components extending {@link * JTextComponent}.//from w ww . ja v a2s . co m */ private static void loadEmacsKeyBindings() { EmacsKeyBindings.LOGGER.debug("Loading emacs keybindings"); for (JTextComponent jtc : EmacsKeyBindings.JTCS) { Action[] origActions = jtc.getActions(); Action[] actions = new Action[origActions.length + EmacsKeyBindings.EMACS_ACTIONS.length]; System.arraycopy(origActions, 0, actions, 0, origActions.length); System.arraycopy(EmacsKeyBindings.EMACS_ACTIONS, 0, actions, origActions.length, EmacsKeyBindings.EMACS_ACTIONS.length); Keymap k = jtc.getKeymap(); JTextComponent.KeyBinding[] keybindings; boolean rebindCA = JabRefPreferences.getInstance() .getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS_REBIND_CA); boolean rebindCF = JabRefPreferences.getInstance() .getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS_REBIND_CF); if (rebindCA || rebindCF) { // if we additionally rebind C-a or C-f, we have to add the shortcuts to EmacsKeyBindings.EMACS_KEY_BINDINGS_BASE // determine size of new array and position of the new key bindings in the array int size = EmacsKeyBindings.EMACS_KEY_BINDINGS_BASE.length; int posCA = -1; int posCF = -1; if (rebindCA) { posCA = size; size++; } if (rebindCF) { posCF = size; size++; } // generate new array keybindings = new JTextComponent.KeyBinding[size]; System.arraycopy(EmacsKeyBindings.EMACS_KEY_BINDINGS_BASE, 0, keybindings, 0, EmacsKeyBindings.EMACS_KEY_BINDINGS_BASE.length); if (rebindCA) { keybindings[posCA] = EmacsKeyBindings.EMACS_KEY_BINDING_C_A; } if (rebindCF) { keybindings[posCF] = EmacsKeyBindings.EMACS_KEY_BINDING_C_F; } } else { keybindings = EmacsKeyBindings.EMACS_KEY_BINDINGS_BASE; } JTextComponent.loadKeymap(k, keybindings, actions); } }