Java Swing KeyStroke convertShortcutMask(KeyStroke ks, int shortcutMask)

Here you can find the source of convertShortcutMask(KeyStroke ks, int shortcutMask)

Description

convert Shortcut Mask

License

Apache License

Declaration

static KeyStroke convertShortcutMask(KeyStroke ks, int shortcutMask) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import static java.awt.event.InputEvent.CTRL_DOWN_MASK;
import static java.awt.event.InputEvent.CTRL_MASK;
import java.awt.*;

import javax.swing.*;

public class Main {
    static KeyStroke convertShortcutMask(KeyStroke ks, int shortcutMask) {
        final int mod = ks.getModifiers();
        if ((mod & (CTRL_DOWN_MASK | CTRL_MASK)) != 0) {
            final int newmod = mod & ~(CTRL_DOWN_MASK | CTRL_MASK) | shortcutMask;
            return KeyStroke.getKeyStroke(ks.getKeyCode(), newmod);
        }/*from  w w  w  . j  a  v a  2s. c o m*/
        return ks;
    }

    static KeyStroke getKeyStroke(String s) {
        KeyStroke ks = KeyStroke.getKeyStroke(s);
        if (ks != null && s.matches("(?i).*Ctrl.*")) {
            return convertShortcutMask(ks, getMenuShortcutKeyMask());
        }
        return ks;
    }

    static int getMenuShortcutKeyMask() {
        return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    }
}

Related

  1. clearActionBinding(final JComponent component, final KeyStroke keyStroke, final int condition)
  2. clearKeyStroke(JComponent component)
  3. closeOnKeyStroke(JRootPane rootPane, KeyStroke keyStroke)
  4. componentListensForKey(JComponent component, int keyCode)
  5. configAction(Action action, String text, Icon icon, KeyStroke keyStroke)
  6. createItem(String name, Integer mnem, KeyStroke accel)
  7. createKeyMask(final int aKeyStroke, final int... aMasks)
  8. fixTabKeys(final JComponent component)
  9. getAccelerator(final int key)