Example usage for javax.swing.text JTextComponent getActions

List of usage examples for javax.swing.text JTextComponent getActions

Introduction

In this page you can find the example usage for javax.swing.text JTextComponent getActions.

Prototype

@BeanProperty(bound = false)
public Action[] getActions() 

Source Link

Document

Fetches the command list for the editor.

Usage

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

/**
 * Activates Emacs keybindings for all text components extending {@link
 * JTextComponent}.//from  w  w  w .  j  a  v a 2  s.c om
 */
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);
    }
}

From source file:TextComponentDemo.java

private void createActionTable(JTextComponent textComponent) {
    actions = new HashMap<Object, Action>();
    Action[] actionsArray = textComponent.getActions();
    for (int i = 0; i < actionsArray.length; i++) {
        Action a = actionsArray[i];
        actions.put(a.getValue(Action.NAME), a);
    }//w  w  w  .j  av  a2  s.  co  m
}

From source file:TextComponentDemo.java

private void createActionTable(JTextComponent textComponent) {
    actions = new HashMap();
    Action[] actionsArray = textComponent.getActions();
    for (int i = 0; i < actionsArray.length; i++) {
        Action a = actionsArray[i];
        actions.put(a.getValue(Action.NAME), a);
    }// w ww.  ja  va 2 s.  c om
}

From source file:TextComponentDemo.java

private HashMap<Object, Action> createActionTable(JTextComponent textComponent) {
    HashMap<Object, Action> actions = new HashMap<Object, Action>();
    Action[] actionsArray = textComponent.getActions();
    for (int i = 0; i < actionsArray.length; i++) {
        Action a = actionsArray[i];
        actions.put(a.getValue(Action.NAME), a);
    }//w w w .  j  a  v  a 2  s.  c o  m
    return actions;
}

From source file:plugin.notes.gui.NotesView.java

/**
 *  Searches a text component for a particular action.
 *
 *@param  textComponent  Text component to search for the action in
 *@param  name           name of the action to get
 *@return                the action// ww w.  j  a  va  2 s. c o m
 */
private Action getActionByName(JTextComponent textComponent, String name) {
    // TODO: This should be static in a GUIUtilities file
    for (Action a : textComponent.getActions()) {
        if (a.getValue(Action.NAME).equals(name)) {
            return a;
        }
    }

    return null;
}