Search in sources :

Example 56 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 57 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 58 with InputMap

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

the class WBSJTable method buildCustomActionMaps.

/** Populate the <tt>customActions</tt> list with actions for editing
     * the work breakdown structure. */
private void buildCustomActionMaps() {
    // Map "Tab" and "Shift-Tab" to the demote/promote actions
    customActions.add(new WbsActionMapping(KeyEvent.VK_TAB, 0, "Demote", DEMOTE_ACTION));
    customActions.add(new WbsActionMapping(KeyEvent.VK_TAB, SHIFT, "Promote", PROMOTE_ACTION));
    customActions.add(new ActionMapping(KeyEvent.VK_INSERT, 0, "Insert", INSERT_ACTION));
    customActions.add(new ActionMapping(KeyEvent.VK_ENTER, 0, "Enter", ENTER_ACTION));
    customActions.add(new ActionMapping(KeyEvent.VK_ENTER, SHIFT, "InsertAfter", INSERT_AFTER_ACTION));
    customActions.add(new ActionMapping("collapseTree", COLLAPSE_ACTION));
    customActions.add(new ActionMapping("expandTree", EXPAND_ACTION));
    customActions.add(new ActionMapping("moveTreeUp", MOVEUP_ACTION));
    customActions.add(new ActionMapping("moveTreeDown", MOVEDOWN_ACTION));
    // Find the default row navigation actions for the table, and replace
    // them with new actions which (1) perform the original action, then
    // (2) restart editing on the newly selected cell.
    InputMap inputMap = getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap actionMap = getActionMap();
    List filter = Arrays.asList(new String[] { "selectPreviousRow", "selectNextRow", "selectFirstRow", "selectLastRow", "scrollUpChangeSelection", "scrollDownChangeSelection" });
    KeyStroke[] keys = inputMap.allKeys();
    for (int i = 0; i < keys.length; i++) {
        Object actionKey = inputMap.get(keys[i]);
        if (!filter.contains(actionKey))
            continue;
        Action action = actionMap.get(actionKey);
        if (action == null)
            continue;
        customActions.add(new ActionMapping(keys[i], actionKey + "-WBS", new DelegateActionRestartEditing(action, actionKey)));
    }
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) ActionMap(javax.swing.ActionMap) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) JList(javax.swing.JList) EventObject(java.util.EventObject) Point(java.awt.Point)

Example 59 with InputMap

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

the class WBSJTable method installTableActions.

/** Install actions that are appropriate only for the table (not for any
     * other component). */
void installTableActions() {
    InputMap inputMap = getInputMap();
    InputMap inputMap2 = getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    InputMap inputMap3 = getInputMap(WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = getActionMap();
    ClipboardBridge clipboardBridge = new ClipboardBridge(this);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, CTRL), "Cut");
    actionMap.put("Cut", new WbsNodeKeystrokeDelegatingAction(CUT_ACTION, null));
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, CTRL), "Copy");
    actionMap.put("Copy", new WbsNodeKeystrokeDelegatingAction(COPY_ACTION, clipboardBridge.getCopyAction()));
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, CTRL), "Paste");
    inputMap2.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, CTRL), "Paste");
    actionMap.put("Paste", new WbsNodeKeystrokeDelegatingAction(PASTE_ACTION, clipboardBridge.getPasteAction()));
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "Delete");
    actionMap.put("Delete", new WbsNodeKeystrokeDelegatingAction(DELETE_ACTION, TABLE_DELETE_ACTION));
    // the expand/collapse icons have accelerators assigned for the plus
    // and minus keys.  Register some additional accelerator keys based on
    // other places where plus and minus appear on the keyboard.
    inputMap3.put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, ALT), "collapseTree");
    inputMap3.put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, ALT), "expandTree");
    inputMap3.put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, ALT), "expandTree");
    inputMap3.put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, ALT | SHIFT), "expandTree");
}
Also used : ActionMap(javax.swing.ActionMap) 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