Search in sources :

Example 41 with KeyStroke

use of javax.swing.KeyStroke in project knime-core by knime.

the class TableView method registerGotoRowAction.

/**
 * Creates and registers the "Go to Row" action on this component. Multiple invocation of this method have no effect
 * (lazy initialization).
 *
 * @return The non-null action representing the go to row task.
 * @see #registerNavigationActions()
 */
public TableAction registerGotoRowAction() {
    if (m_gotoRowAction == null) {
        String name = "Go to Row...";
        KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
        TableAction action = new TableAction(stroke, name) {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (!hasData()) {
                    return;
                }
                String rowString = JOptionPane.showInputDialog(TableView.this, "Enter row number:", "Go to Row", JOptionPane.QUESTION_MESSAGE);
                if (rowString == null) {
                    // canceled
                    return;
                }
                try {
                    int row = Integer.parseInt(rowString);
                    gotoCell(row - 1, 0);
                } catch (NumberFormatException nfe) {
                    JOptionPane.showMessageDialog(TableView.this, "Can't parse " + rowString, "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        };
        registerAction(action);
        m_gotoRowAction = action;
    }
    return m_gotoRowAction;
}
Also used : ActionEvent(java.awt.event.ActionEvent) KeyStroke(javax.swing.KeyStroke) Point(java.awt.Point)

Example 42 with KeyStroke

use of javax.swing.KeyStroke in project knime-core by knime.

the class TableView method createFontSizeAction.

/**
 * Implementation of {@link #registerIncreaseFontSizeAction()} and {@link #registerDecreaseFontSizeAction()}.
 * @return a new registered action
 */
private TableAction createFontSizeAction(final boolean isIncrease) {
    String name = (isIncrease ? "Increase" : "Decrease") + " Font Size";
    // increase has two keystrokes - Ctrl-+ and Ctrl-= (due to US keyboard layouts)
    KeyStroke[] keyStrokes;
    // CTRL on Windows, Apple key on Mac
    int shortcut = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    final int sizeIncrement;
    if (isIncrease) {
        sizeIncrement = +1;
        keyStrokes = new KeyStroke[] { // on US layout this is next to '-'
        KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, shortcut), KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, shortcut) };
    } else {
        sizeIncrement = -1;
        keyStrokes = new KeyStroke[] { KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, shortcut) };
    }
    TableAction action = null;
    for (KeyStroke keyStroke : keyStrokes) {
        action = new TableAction(keyStroke, name) {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (!hasData()) {
                    return;
                }
                int curFontSize = getContentTable().getFont().getSize();
                setFontSize(curFontSize + sizeIncrement);
            }
        };
        registerAction(action);
    }
    return action;
}
Also used : ActionEvent(java.awt.event.ActionEvent) KeyStroke(javax.swing.KeyStroke) Point(java.awt.Point)

Example 43 with KeyStroke

use of javax.swing.KeyStroke 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 44 with KeyStroke

use of javax.swing.KeyStroke in project chipKIT32-MAX by chipKIT32.

the class DefaultInputHandler method keyPressed.

/**
         * Handle a key pressed event. This will look up the binding for
         * the key stroke and execute it.
         */
public void keyPressed(KeyEvent evt) {
    int keyCode = evt.getKeyCode();
    int modifiers = evt.getModifiers();
    // moved this earlier so it doesn't get random meta clicks
    if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT || keyCode == KeyEvent.VK_META) {
        return;
    }
    //if ((modifiers & KeyEvent.META_MASK) != 0) return;
    if ((modifiers & KeyEvent.META_MASK) != 0) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, modifiers);
        if (currentBindings.get(keyStroke) == null) {
            return;
        }
    }
    if ((modifiers & ~KeyEvent.SHIFT_MASK) != 0 || evt.isActionKey() || keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE || keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_ESCAPE) {
        if (grabAction != null) {
            handleGrabAction(evt);
            return;
        }
        KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, modifiers);
        Object o = currentBindings.get(keyStroke);
        if (o == null) {
            // beep when caps lock is pressed, etc.
            if (currentBindings != bindings) {
                Toolkit.getDefaultToolkit().beep();
                // F10 should be passed on, but C+e F10
                // shouldn't
                repeatCount = 0;
                repeat = false;
                evt.consume();
            }
            currentBindings = bindings;
            return;
        } else if (o instanceof ActionListener) {
            currentBindings = bindings;
            executeAction(((ActionListener) o), evt.getSource(), null);
            evt.consume();
            return;
        } else if (o instanceof Hashtable) {
            currentBindings = (Hashtable) o;
            evt.consume();
            return;
        }
    }
}
Also used : Hashtable(java.util.Hashtable) KeyStroke(javax.swing.KeyStroke)

Example 45 with KeyStroke

use of javax.swing.KeyStroke in project chipKIT32-MAX by chipKIT32.

the class DefaultInputHandler method addKeyBinding.

/**
         * Adds a key binding to this input handler. The key binding is
         * a list of white space separated key strokes of the form
         * <i>[modifiers+]key</i> where modifier is C for Control, A for Alt,
         * or S for Shift, and key is either a character (a-z) or a field
         * name in the KeyEvent class prefixed with VK_ (e.g., BACK_SPACE)
         * @param keyBinding The key binding
         * @param action The action
         */
public void addKeyBinding(String keyBinding, ActionListener action) {
    Hashtable current = bindings;
    StringTokenizer st = new StringTokenizer(keyBinding);
    while (st.hasMoreTokens()) {
        KeyStroke keyStroke = parseKeyStroke(st.nextToken());
        if (keyStroke == null)
            return;
        if (st.hasMoreTokens()) {
            Object o = current.get(keyStroke);
            if (o instanceof Hashtable)
                current = (Hashtable) o;
            else {
                o = new Hashtable();
                current.put(keyStroke, o);
                current = (Hashtable) o;
            }
        } else
            current.put(keyStroke, action);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Hashtable(java.util.Hashtable) KeyStroke(javax.swing.KeyStroke)

Aggregations

KeyStroke (javax.swing.KeyStroke)68 ActionEvent (java.awt.event.ActionEvent)27 ActionListener (java.awt.event.ActionListener)15 AbstractAction (javax.swing.AbstractAction)13 JRootPane (javax.swing.JRootPane)13 Action (javax.swing.Action)10 InputMap (javax.swing.InputMap)9 WindowEvent (java.awt.event.WindowEvent)6 ActionMap (javax.swing.ActionMap)5 GridBagLayout (java.awt.GridBagLayout)4 Point (java.awt.Point)4 ArrayList (java.util.ArrayList)4 JMenuItem (javax.swing.JMenuItem)4 JPanel (javax.swing.JPanel)4 JScrollPane (javax.swing.JScrollPane)4 AWTKeyStroke (java.awt.AWTKeyStroke)3 Dimension (java.awt.Dimension)3 GridBagConstraints (java.awt.GridBagConstraints)3 Insets (java.awt.Insets)3 KeyEvent (java.awt.event.KeyEvent)3