Search in sources :

Example 66 with InputMap

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

the class MultiPurposeTextPanel method getSearchTextField.

private JTextField getSearchTextField() {
    if (searchTextField == null) {
        try {
            searchTextField = new JTextField();
            searchTextField.setColumns(15);
            searchTextFieldBackground = searchTextField.getBackground();
            searchTextField.getDocument().addDocumentListener(eventHandler);
            InputMap im = searchTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
            im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION);
            ActionMap am = searchTextField.getActionMap();
            am.put(CANCEL_ACTION, new CancelSearchAction());
        } catch (java.lang.Throwable ivjExc) {
            ivjExc.printStackTrace();
        }
    }
    return searchTextField;
}
Also used : ActionMap(javax.swing.ActionMap) InputMap(javax.swing.InputMap) JTextField(javax.swing.JTextField)

Example 67 with InputMap

use of javax.swing.InputMap 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 68 with InputMap

use of javax.swing.InputMap 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 69 with InputMap

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

the class EditorTextField method initTabHandler.

private void initTabHandler() {
    this.combo.setFocusTraversalKeysEnabled(false);
    this.combo.getActionMap().put("tab-action", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            combo.setSelectedItem(getText());
            Component component = getParent().getParent();
            if (component instanceof JTable) {
                JTable table = (JTable) component;
                if ((e.getModifiers() & ActionEvent.SHIFT_MASK) > 0) {
                    table.changeSelection(table.getEditingRow(), table.getEditingColumn() - 1, false, false);
                } else {
                    table.changeSelection(table.getEditingRow(), table.getEditingColumn() + 1, false, false);
                }
            } else {
                if ((e.getModifiers() & ActionEvent.SHIFT_MASK) > 0) {
                    transferFocusBackward();
                } else {
                    transferFocus();
                }
            }
        }
    });
    InputMap inputMap = this.combo.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(KeyStroke.getKeyStroke("TAB"), "tab-action");
    inputMap.put(KeyStroke.getKeyStroke("shift TAB"), "tab-action");
}
Also used : ActionEvent(java.awt.event.ActionEvent) JTable(javax.swing.JTable) InputMap(javax.swing.InputMap) JComponent(javax.swing.JComponent) Component(java.awt.Component) AbstractAction(javax.swing.AbstractAction)

Aggregations

InputMap (javax.swing.InputMap)69 ActionMap (javax.swing.ActionMap)45 AbstractAction (javax.swing.AbstractAction)37 ActionEvent (java.awt.event.ActionEvent)35 Action (javax.swing.Action)19 JButton (javax.swing.JButton)12 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 JTextField (javax.swing.JTextField)10 BorderLayout (java.awt.BorderLayout)9 JPanel (javax.swing.JPanel)9 KeyStroke (javax.swing.KeyStroke)9 JCheckBox (javax.swing.JCheckBox)8 JDialog (javax.swing.JDialog)8 JScrollPane (javax.swing.JScrollPane)8 JComponent (javax.swing.JComponent)7 ActionListener (java.awt.event.ActionListener)6 JRootPane (javax.swing.JRootPane)6 JTable (javax.swing.JTable)5 ComponentInputMapUIResource (javax.swing.plaf.ComponentInputMapUIResource)5 FormBuilder (com.jgoodies.forms.builder.FormBuilder)4