Search in sources :

Example 61 with InputMap

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

the class PushToApplicationButton method showSettingsDialog.

public static void showSettingsDialog(JFrame parent, PushToApplication toApp, JPanel options) {
    final BooleanHolder okPressed = new BooleanHolder(false);
    final JDialog diag = new JDialog(parent, Localization.lang("Settings"), true);
    options.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    diag.getContentPane().add(options, BorderLayout.CENTER);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    ok.addActionListener(e -> {
        okPressed.value = true;
        diag.dispose();
    });
    cancel.addActionListener(e -> diag.dispose());
    // Key bindings:
    ActionMap am = bb.getPanel().getActionMap();
    InputMap im = bb.getPanel().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) {
            diag.dispose();
        }
    });
    diag.pack();
    diag.setLocationRelativeTo(parent);
    // Show the dialog:
    diag.setVisible(true);
    // to store its settings:
    if (okPressed.value) {
        toApp.storeSettings();
    }
}
Also used : ActionMap(javax.swing.ActionMap) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 62 with InputMap

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

the class HierarchyNoteEditorDialog method setupWindowKeyBindings.

private void setupWindowKeyBindings(JComponent c) {
    InputMap inputMap = c.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK), "saveAndClose");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.META_DOWN_MASK), "saveAndClose");
    c.getActionMap().put("saveAndClose", new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            if (isDirty())
                saveComment();
            close();
        }
    });
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "confirmClose");
    c.getActionMap().put("confirmClose", new AbstractAction() {

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

Example 63 with InputMap

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

the class AssignedToComboBox method tweakKeyBindings.

private void tweakKeyBindings(JTextComponent textComponent) {
    InputMap inputMap = textComponent.getInputMap();
    // special handling for backspace
    inputMap.put(KeyStroke.getKeyStroke("BACK_SPACE"), BACKSPACE_ACTION);
    // set left and right to move whole words
    inputMap.put(KeyStroke.getKeyStroke("LEFT"), MOVE_LEFT_ACTION);
    inputMap.put(KeyStroke.getKeyStroke("RIGHT"), MOVE_RIGHT_ACTION);
    // ignore CTRL-X and beep instead
    inputMap.put(KeyStroke.getKeyStroke("ctrl X"), ERROR_ACTION);
}
Also used : InputMap(javax.swing.InputMap)

Example 64 with InputMap

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

the class WBSTabPanel method installKeyboardShortcuts.

/**
     * Configure a number of keyboard shortcuts for navigating within the
     * contents of the WBS tab panel
     */
private void installKeyboardShortcuts() {
    InputMap inputMap = dataTable.getInputMap();
    ActionMap actionMap = dataTable.getActionMap();
    inputMap.put(KeyStroke.getKeyStroke("HOME"), "focusTree");
    inputMap.put(KeyStroke.getKeyStroke("shift SPACE"), "focusTree");
    actionMap.put("focusTree", new TransferFocusToWbsNode());
    new MoveLeftFromDataCell().install(dataTable);
    inputMap = wbsTable.getInputMap();
    actionMap = wbsTable.getActionMap();
    inputMap.put(KeyStroke.getKeyStroke("END"), "lastDataCol");
    actionMap.put("lastDataCol", new TransferFocusToDataTable(true));
    inputMap.put(KeyStroke.getKeyStroke("RIGHT"), "firstDataCol");
    actionMap.put("firstDataCol", new TransferFocusToDataTable(false));
    inputMap.put(KeyStroke.getKeyStroke("LEFT"), "startEditing");
    inputMap = this.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(//
    KeyStroke.getKeyStroke(//
    KeyEvent.VK_T, MacGUIUtils.getCtrlModifier()), "focusTabs");
    this.getActionMap().put("focusTabs", new TransferFocusToTabs());
}
Also used : ActionMap(javax.swing.ActionMap) InputMap(javax.swing.InputMap)

Example 65 with InputMap

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

the class PDEPlotControlPanel method sliderUpDownBusyActions.

private void sliderUpDownBusyActions() {
    // map KeyStroke to actionID (for WHEN_FOCUS condition)
    InputMap im_focus = ivjJSliderTime.getInputMap();
    // map actionID to Action
    ActionMap am = ivjJSliderTime.getActionMap();
    // Get actionID for DOWN-ARROW keystroke
    Object downArrowActionID = im_focus.get(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0));
    // Get actionID for UP-ARROW keystroke
    Object upArrowActionID = im_focus.get(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0));
    // remove any currently defined actions for up and down actionIDs
    am.remove(downArrowActionID);
    am.remove(upArrowActionID);
    // redefine Actions of up and down arrows on JSlider
    // If getPdeDataContext isBusy then ignore up and down arrow actions to avoid
    // having the "wait" popup appear when using the up and down arrows on the JSlider
    am.put(downArrowActionID, new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            if (ClientTaskDispatcher.isBusy(null, null)) {
                return;
            }
            if (ivjJSliderTime.getValue() == ivjJSliderTime.getMaximum()) {
                return;
            }
            if (arrowTimer == null) {
                arrowTimer = new Timer(100, new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        synchronized (arrowTimer) {
                            PDEPlotControlPanel.this.arrowTimer.stop();
                            PDEPlotControlPanel.this.arrowTimer = null;
                        }
                        ivjJSliderTime.setValue(ivjJSliderTime.getValue() + 1);
                    }
                });
                arrowTimer.setRepeats(false);
                arrowTimer.start();
            } else {
                return;
            }
        }
    });
    am.put(upArrowActionID, new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            if (ClientTaskDispatcher.isBusy(null, null)) {
                return;
            }
            if (ivjJSliderTime.getValue() == ivjJSliderTime.getMinimum()) {
                return;
            }
            if (arrowTimer == null) {
                arrowTimer = new Timer(100, new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        synchronized (arrowTimer) {
                            PDEPlotControlPanel.this.arrowTimer.stop();
                            PDEPlotControlPanel.this.arrowTimer = null;
                        }
                        ivjJSliderTime.setValue(ivjJSliderTime.getValue() - 1);
                    }
                });
                arrowTimer.setRepeats(false);
                arrowTimer.start();
            } else {
                return;
            }
        }
    });
}
Also used : Timer(javax.swing.Timer) BlockingTimer(cbit.vcell.client.task.ClientTaskDispatcher.BlockingTimer) ActionListener(java.awt.event.ActionListener) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) InputMap(javax.swing.InputMap) 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