Example usage for javax.swing.text Keymap getDefaultAction

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

Introduction

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

Prototype

public Action getDefaultAction();

Source Link

Document

Fetches the default action to fire if a key is typed (i.e.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextComponent component = new JTextField();
    if (component instanceof JTextComponent) {
        JTextComponent textComp = (JTextComponent) component;
        Keymap keymap = textComp.getKeymap();

        while (keymap != null) {
            Action[] actions = keymap.getBoundActions();
            for (int i = 0; i < actions.length; i++) {
                Action action = actions[i];
            }//w w w . j a v  a 2  s. c  o  m
            Action defaultAction = keymap.getDefaultAction();
            keymap = keymap.getResolveParent();
        }
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextArea component = new JTextArea();
    Keymap map = component.getKeymap();

    while (map != null) {
        KeyStroke[] keys = map.getBoundKeyStrokes();

        for (int i = 0; i < keys.length; i++) {
            System.out.println(keys[i].getKeyChar());
            Action action = (Action) map.getAction(keys[i]);
            System.out.println(action);
        }/*from  w w w . j a v  a  2  s .  c  om*/
        Action defAction = map.getDefaultAction();
        System.out.println(defAction);
        map = map.getResolveParent();
    }
}

From source file:Main.java

public static Action findDefaultAction(JTextComponent c) {
    Keymap kmap = c.getKeymap();
    if (kmap.getDefaultAction() != null) {
        return kmap.getDefaultAction();
    }//w ww  . j a  va  2s.c  o  m

    kmap = kmap.getResolveParent();
    while (kmap != null) {
        if (kmap.getDefaultAction() != null) {
            return kmap.getDefaultAction();
        }
        kmap = kmap.getResolveParent();
    }
    return null;
}

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;// w w  w  .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}.//  w  w w.j  a  va 2 s .c  o  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());
        }
    }
}