Search in sources :

Example 11 with KeyStroke

use of javax.swing.KeyStroke in project processing by processing.

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) {
    Map 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 Map)
                current = (Map) o;
            else {
                o = new HashMap();
                current.put(keyStroke, o);
                current = (Map) o;
            }
        } else
            current.put(keyStroke, action);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) HashMap(java.util.HashMap) KeyStroke(javax.swing.KeyStroke) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with KeyStroke

use of javax.swing.KeyStroke in project processing by processing.

the class DefaultInputHandler method keyTyped.

/**
         * Handle a key typed event. This inserts the key into the text area.
         */
public void keyTyped(KeyEvent evt) {
    int modifiers = evt.getModifiers();
    char c = evt.getKeyChar();
    // in an attempt to prevent.
    if ((modifiers & InputEvent.META_MASK) != 0)
        return;
    // http://code.google.com/p/processing/issues/detail?id=596
    if ((modifiers & InputEvent.CTRL_MASK) != 0 && c == '/')
        return;
    if (// &&
    c != KeyEvent.CHAR_UNDEFINED) //                (modifiers & KeyEvent.ALT_MASK) == 0)
    {
        if (c >= 0x20 && c != 0x7f) {
            KeyStroke keyStroke = KeyStroke.getKeyStroke(Character.toUpperCase(c));
            Object o = currentBindings.get(keyStroke);
            if (o instanceof Map) {
                currentBindings = (Map) o;
                return;
            } else if (o instanceof ActionListener) {
                currentBindings = bindings;
                executeAction((ActionListener) o, evt.getSource(), String.valueOf(c));
                return;
            }
            currentBindings = bindings;
            if (grabAction != null) {
                handleGrabAction(evt);
                return;
            }
            // 0-9 adds another 'digit' to the repeat number
            if (repeat && Character.isDigit(c)) {
                repeatCount *= 10;
                repeatCount += (c - '0');
                return;
            }
            executeAction(INSERT_CHAR, evt.getSource(), String.valueOf(evt.getKeyChar()));
            repeatCount = 0;
            repeat = false;
        }
    }
}
Also used : KeyStroke(javax.swing.KeyStroke) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with KeyStroke

use of javax.swing.KeyStroke in project GCViewer by chewiebug.

the class ScreenCenteredDialog method createRootPane.

protected JRootPane createRootPane() {
    KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    KeyStroke enterStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    JRootPane rootPane = new JRootPane();
    rootPane.registerKeyboardAction(this, escapeStroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    rootPane.registerKeyboardAction(this, enterStroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    return rootPane;
}
Also used : KeyStroke(javax.swing.KeyStroke) JRootPane(javax.swing.JRootPane)

Example 14 with KeyStroke

use of javax.swing.KeyStroke in project languagetool by languagetool-org.

the class LanguageManagerDialog method show.

public void show() {
    dialog = new JDialog(owner, true);
    dialog.setTitle(messages.getString("guiLanguageManagerDialog"));
    // close dialog when user presses Escape key:
    // TODO: taken from ConfigurationDialog, avoid duplication:
    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    ActionListener actionListener = new ActionListener() {

        @Override
        @SuppressWarnings("unused")
        public void actionPerformed(ActionEvent actionEvent) {
            dialog.setVisible(false);
        }
    };
    JRootPane rootPane = dialog.getRootPane();
    rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new GridBagLayout());
    list = new JList<>(ruleFiles.toArray(new File[ruleFiles.size()]));
    GridBagConstraints cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.fill = GridBagConstraints.BOTH;
    cons.weightx = 2.0f;
    cons.weighty = 2.0f;
    contentPane.add(new JScrollPane(list), cons);
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.fill = GridBagConstraints.HORIZONTAL;
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    addButton = new JButton(messages.getString("guiAddButton"));
    addButton.addActionListener(this);
    cons.gridx = 1;
    cons.gridy = 0;
    buttonPanel.add(addButton, cons);
    removeButton = new JButton(messages.getString("guiRemoveButton"));
    removeButton.addActionListener(this);
    cons.gridx = 1;
    cons.gridy = 1;
    buttonPanel.add(removeButton, cons);
    closeButton = new JButton(messages.getString("guiCloseButton"));
    closeButton.addActionListener(this);
    cons.gridx = 1;
    cons.gridy = 2;
    buttonPanel.add(closeButton, cons);
    cons.gridx = 1;
    cons.gridy = 0;
    cons = new GridBagConstraints();
    cons.anchor = GridBagConstraints.NORTH;
    contentPane.add(buttonPanel, cons);
    dialog.pack();
    dialog.setSize(300, 200);
    dialog.setLocationByPlatform(true);
    dialog.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Container(java.awt.Container) ActionListener(java.awt.event.ActionListener) KeyStroke(javax.swing.KeyStroke) JRootPane(javax.swing.JRootPane) JDialog(javax.swing.JDialog)

Example 15 with KeyStroke

use of javax.swing.KeyStroke in project zaproxy by zaproxy.

the class DialogEditShortcut method save.

@Override
public void save() {
    KeyboardShortcut ksDup = this.getDuplicate();
    if (ksDup != null) {
        // used for another menu item, so remove it from that
        ksDup.setKeyStroke(null);
    }
    KeyStroke ks = getKeyStroke();
    shortcut.setKeyStroke(ks);
}
Also used : 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