Search in sources :

Example 21 with InputMap

use of javax.swing.InputMap in project jabref by JabRef.

the class MergeDialog method jbInit.

private void jbInit() {
    panel1.setLayout(borderLayout1);
    ok.setText(Localization.lang("OK"));
    ok.addActionListener(e -> {
        okPressed = true;
        dispose();
    });
    cancel.setText(Localization.lang("Cancel"));
    cancel.addActionListener(e -> dispose());
    jPanel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    jPanel1.setLayout(gridBagLayout1);
    entries.setSelected(true);
    entries.setText(Localization.lang("Import entries"));
    strings.setSelected(true);
    strings.setText(Localization.lang("Import strings"));
    groups.setText(Localization.lang("Import group definitions"));
    selector.setText(Localization.lang("Import word selector definitions"));
    this.setModal(true);
    this.setResizable(false);
    getContentPane().add(panel1);
    panel1.add(jPanel2, BorderLayout.SOUTH);
    jPanel2.add(ok, null);
    jPanel2.add(cancel, null);
    panel1.add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(entries, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(strings, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(groups, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(selector, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    // Key bindings:
    ActionMap am = jPanel1.getActionMap();
    InputMap im = jPanel1.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Example 22 with InputMap

use of javax.swing.InputMap in project cytoscape-api by cytoscape.

the class LookAndFeelUtil method setDefaultOkCancelKeyStrokes.

/**
	 * Maps the standard key strokes (usually ENTER and ESCAPE) to the passed OK and/or Cancel actions.
	 * @param rootPane A {@link javax.swing.JDialog}'s root pane, for instance.
	 * @param okAction The main {@link Action} of a {@link javax.swing.JDialog}, for instance. It can be null.
	 * @param cancelAction The {@link Action} that cancels or closes a {@link javax.swing.JDialog}, for instance.
	 *                     It can be null.
	 */
public static void setDefaultOkCancelKeyStrokes(final JRootPane rootPane, final Action okAction, final Action cancelAction) {
    final InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (okAction != null) {
        final String OK_ACTION_KEY = "OK_ACTION_KEY";
        final KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
        inputMap.put(enterKey, OK_ACTION_KEY);
        rootPane.getActionMap().put(OK_ACTION_KEY, okAction);
    }
    if (cancelAction != null) {
        final String CANCEL_ACTION_KEY = "CANCEL_ACTION_KEY";
        final KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
        inputMap.put(escapeKey, CANCEL_ACTION_KEY);
        rootPane.getActionMap().put(CANCEL_ACTION_KEY, cancelAction);
    }
}
Also used : KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap)

Example 23 with InputMap

use of javax.swing.InputMap in project processdash by dtuma.

the class PersonLookupDialog method enableEnterKey.

/** Pressing the space bar activates the focused button.  This method
     * will allow the Enter key to have the same effect. */
private void enableEnterKey(JButton c) {
    InputMap m = c.getInputMap();
    Object key = m.get(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false));
    m.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), key);
    key = m.get(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true));
    m.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), key);
}
Also used : InputMap(javax.swing.InputMap)

Example 24 with InputMap

use of javax.swing.InputMap in project processdash by dtuma.

the class LOCDiffDialog method setupWindowKeyBindings.

private void setupWindowKeyBindings(JComponent c) {
    InputMap inputMap = c.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "closeDialog");
    c.getActionMap().put("closeDialog", new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            closeDialog();
        }
    });
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "doCount");
    c.getActionMap().put("doCount", new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            doCount();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Example 25 with InputMap

use of javax.swing.InputMap in project binnavi by google.

the class CDebuggerToolbar method addHotkey.

/**
   * Assigns a hotkey to an action.
   *
   * @param button The button the action belongs to.
   * @param keyStroke The hotkey.
   * @param action The action to be triggered on the hotkey.
   * @param name The name of the hotkey.
   */
private static void addHotkey(final JButton button, final KeyStroke keyStroke, final Action action, final String name) {
    final InputMap windowImap = button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    windowImap.put(keyStroke, name);
    button.getActionMap().put(name, action);
}
Also used : InputMap(javax.swing.InputMap)

Aggregations

InputMap (javax.swing.InputMap)59 ActionMap (javax.swing.ActionMap)38 AbstractAction (javax.swing.AbstractAction)32 ActionEvent (java.awt.event.ActionEvent)30 Action (javax.swing.Action)18 JButton (javax.swing.JButton)12 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 BorderLayout (java.awt.BorderLayout)9 JPanel (javax.swing.JPanel)9 JCheckBox (javax.swing.JCheckBox)8 JDialog (javax.swing.JDialog)8 JScrollPane (javax.swing.JScrollPane)8 JTextField (javax.swing.JTextField)7 KeyStroke (javax.swing.KeyStroke)7 JComponent (javax.swing.JComponent)6 JRootPane (javax.swing.JRootPane)6 FormBuilder (com.jgoodies.forms.builder.FormBuilder)5 FormLayout (com.jgoodies.forms.layout.FormLayout)5 ComponentInputMapUIResource (javax.swing.plaf.ComponentInputMapUIResource)5 Insets (java.awt.Insets)4