Search in sources :

Example 51 with ActionMap

use of javax.swing.ActionMap in project vcell by virtualcell.

the class EditorKeyboardHandler method createActionMap.

/**
 * Return the mapping between JTree's input map and JGraph's actions.
 */
protected ActionMap createActionMap() {
    ActionMap map = super.createActionMap();
    map.put("save", new EditorActions.SaveAction(false));
    map.put("saveAs", new EditorActions.SaveAction(true));
    map.put("new", new EditorActions.NewAction());
    map.put("open", new EditorActions.OpenAction());
    map.put("undo", new EditorActions.HistoryAction(true));
    map.put("redo", new EditorActions.HistoryAction(false));
    map.put("selectVertices", mxGraphActions.getSelectVerticesAction());
    map.put("selectEdges", mxGraphActions.getSelectEdgesAction());
    return map;
}
Also used : ActionMap(javax.swing.ActionMap)

Example 52 with ActionMap

use of javax.swing.ActionMap in project sulky by huxi.

the class SwingLogging method logInputMaps.

public static void logInputMaps(JComponent component) {
    final Logger logger = LoggerFactory.getLogger(SwingLogging.class);
    if (logger.isDebugEnabled()) {
        final int[] conditions = { JComponent.WHEN_IN_FOCUSED_WINDOW, JComponent.WHEN_FOCUSED, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT };
        final String[] conditionStrings = { "WHEN_IN_FOCUSED_WINDOW", "WHEN_FOCUSED", "WHEN_ANCESTOR_OF_FOCUSED_COMPONENT" };
        StringBuilder msg = new StringBuilder();
        for (int i = 0; i < conditions.length; i++) {
            @SuppressWarnings("MagicConstant") InputMap inputMap = component.getInputMap(conditions[i]);
            msg.append("InputMap for '").append(conditionStrings[i]).append("':\n");
            for (; ; ) {
                KeyStroke[] keyStrokes = inputMap.keys();
                if (keyStrokes != null) {
                    for (KeyStroke ks : keyStrokes) {
                        msg.append("\tKeyStroke: ").append(ks).append("\n\tActionMapKey: ").append(inputMap.get(ks)).append("\n\n");
                    }
                }
                msg.append("######################################\n");
                inputMap = inputMap.getParent();
                if (inputMap == null) {
                    msg.append("No parent.\n\n");
                    break;
                } else {
                    msg.append("Parent:\n");
                }
            }
        }
        ActionMap actionMap = component.getActionMap();
        msg.append("ActionMap:\n");
        for (; ; ) {
            Object[] keys = actionMap.keys();
            if (keys != null) {
                for (Object key : keys) {
                    msg.append("\tKey: ").append(key).append("\n\tAction: ").append(actionMap.get(key)).append("\n\n");
                }
            }
            msg.append("######################################\n");
            actionMap = actionMap.getParent();
            if (actionMap == null) {
                msg.append("No parent.\n\n");
                break;
            } else {
                msg.append("Parent:\n");
            }
        }
        if (logger.isDebugEnabled())
            logger.debug(msg.toString());
    }
}
Also used : ActionMap(javax.swing.ActionMap) Logger(org.slf4j.Logger) KeyStroke(javax.swing.KeyStroke) AWTKeyStroke(java.awt.AWTKeyStroke) InputMap(javax.swing.InputMap)

Example 53 with ActionMap

use of javax.swing.ActionMap in project sulky by huxi.

the class KeyStrokes method registerCommand.

public static void registerCommand(JComponent component, Action action, String commandName) {
    KeyStroke keyStroke = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
    if (keyStroke == null) {
        return;
    }
    logInputMaps(component, "BEFORE");
    InputMap inputMap = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = component.getActionMap();
    inputMap.put(keyStroke, commandName);
    actionMap.put(commandName, action);
    Object value;
    inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
    value = inputMap.get(keyStroke);
    if (value != null) {
        inputMap.put(keyStroke, commandName);
    }
    inputMap = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    value = inputMap.get(keyStroke);
    if (value != null) {
        inputMap.put(keyStroke, commandName);
    }
    logInputMaps(component, "AFTER");
}
Also used : ActionMap(javax.swing.ActionMap) KeyStroke(javax.swing.KeyStroke) AWTKeyStroke(java.awt.AWTKeyStroke) InputMap(javax.swing.InputMap)

Example 54 with ActionMap

use of javax.swing.ActionMap in project cayenne by apache.

the class DefaultActionManager method setupCutCopyPaste.

public void setupCutCopyPaste(JComponent comp, Class<? extends Action> cutActionType, Class<? extends Action> copyActionType) {
    ActionMap map = comp.getActionMap();
    map.put(TransferHandler.getCutAction().getValue(Action.NAME), getAction(cutActionType));
    map.put(TransferHandler.getCopyAction().getValue(Action.NAME), getAction(copyActionType));
    map.put(TransferHandler.getPasteAction().getValue(Action.NAME), getAction(PasteAction.class));
}
Also used : ActionMap(javax.swing.ActionMap)

Aggregations

ActionMap (javax.swing.ActionMap)54 InputMap (javax.swing.InputMap)45 AbstractAction (javax.swing.AbstractAction)27 ActionEvent (java.awt.event.ActionEvent)23 Action (javax.swing.Action)14 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 JButton (javax.swing.JButton)11 BorderLayout (java.awt.BorderLayout)9 JTextField (javax.swing.JTextField)9 JDialog (javax.swing.JDialog)8 JPanel (javax.swing.JPanel)8 JScrollPane (javax.swing.JScrollPane)7 JComponent (javax.swing.JComponent)6 FormBuilder (com.jgoodies.forms.builder.FormBuilder)5 FormLayout (com.jgoodies.forms.layout.FormLayout)5 ActionListener (java.awt.event.ActionListener)5 KeyStroke (javax.swing.KeyStroke)5 AWTKeyStroke (java.awt.AWTKeyStroke)3 Component (java.awt.Component)3 Insets (java.awt.Insets)3