Java Code Examples for javax.swing.text.JTextComponent#addKeymap()

The following examples show how to use javax.swing.text.JTextComponent#addKeymap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiKeymap.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Loads key to action mappings into this keymap
* @param bindings array of bindings
* @param actions map of [action_name, action] pairs
*/
public void load(JTextComponent.KeyBinding[] bindings, Map actions) {
    // now create bindings in keymap(s)
    for (int i = 0; i < bindings.length; i++) {
        Action a = (Action)actions.get(bindings[i].actionName);
        if (a != null) {
            boolean added = false;
            if (bindings[i] instanceof MultiKeyBinding) {
                MultiKeyBinding mb = (MultiKeyBinding)bindings[i];
                if (mb.keys != null) {
                    Keymap cur = delegate;
                    for (int j = 0; j < mb.keys.length; j++) {
                        if (j == mb.keys.length - 1) { // last keystroke in sequence
                            cur.addActionForKeyStroke(mb.keys[j], a);
                        } else { // not the last keystroke
                            Action sca = cur.getAction(mb.keys[j]);
                            if (!(sca instanceof KeymapSetContextAction)) {
                                sca = new KeymapSetContextAction(JTextComponent.addKeymap(null, null));
                                cur.addActionForKeyStroke(mb.keys[j], sca);
                            }
                            cur = ((KeymapSetContextAction)sca).contextKeymap;
                        }
                    }
                    added = true;
                }
            }
            if (!added) {
                if (bindings[i].key != null) {
                    delegate.addActionForKeyStroke(bindings[i].key, a);
                } else { // key is null -> set default action
                    setDefaultAction(a);
                }
            }
        }
    }
}
 
Example 2
Source File: MultiKeymap.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Construct new keymap.
* @param name name of new keymap
*/
public MultiKeymap(String name) {
    delegate = JTextComponent.addKeymap(name, null);
    contextKeys = new ArrayList();
}