Example usage for javax.swing.text Keymap getKeyStrokesForAction

List of usage examples for javax.swing.text Keymap getKeyStrokesForAction

Introduction

In this page you can find the example usage for javax.swing.text Keymap getKeyStrokesForAction.

Prototype

public KeyStroke[] getKeyStrokesForAction(Action a);

Source Link

Document

Fetches the keystrokes that will result in the given action.

Usage

From source file:net.sf.jabref.gui.keyboard.EmacsKeyBindings.java

private static void createBackup() {
    Keymap oldBackup = JTextComponent.getKeymap(EmacsKeyBindings.JTCS[0].getClass().getName());
    if (oldBackup != null) {
        // if there is already a backup, do not create a new backup
        return;//from   www . ja v  a  2s . c om
    }

    for (JTextComponent jtc : EmacsKeyBindings.JTCS) {
        Keymap orig = jtc.getKeymap();
        Keymap backup = JTextComponent.addKeymap(jtc.getClass().getName(), null);
        Action[] bound = orig.getBoundActions();
        for (Action aBound : bound) {
            KeyStroke[] strokes = orig.getKeyStrokesForAction(aBound);
            for (KeyStroke stroke : strokes) {
                backup.addActionForKeyStroke(stroke, aBound);
            }
        }
        backup.setDefaultAction(orig.getDefaultAction());
    }
}

From source file:net.sf.jabref.gui.keyboard.EmacsKeyBindings.java

/**
 * Restores the original keybindings for the concrete subclasses of
 * {@link JTextComponent}./*from  w  w  w .  jav a2  s . co  m*/
 *
 */
public static void unload() {
    for (int i = 0; i < EmacsKeyBindings.JTCS.length; i++) {
        Keymap backup = JTextComponent.getKeymap(EmacsKeyBindings.JTCS[i].getClass().getName());

        if (backup != null) {
            Keymap current = EmacsKeyBindings.JTCS[i].getKeymap();
            current.removeBindings();

            Action[] bound = backup.getBoundActions();
            for (Action aBound : bound) {
                KeyStroke[] strokes = backup.getKeyStrokesForAction(bound[i]);
                for (KeyStroke stroke : strokes) {
                    current.addActionForKeyStroke(stroke, aBound);
                }
            }
            current.setDefaultAction(backup.getDefaultAction());
        }
    }
}