本文整理汇总了Java中javax.swing.KeyStroke.getModifiers方法的典型用法代码示例。如果您正苦于以下问题:Java KeyStroke.getModifiers方法的具体用法?Java KeyStroke.getModifiers怎么用?Java KeyStroke.getModifiers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.KeyStroke
的用法示例。
在下文中一共展示了KeyStroke.getModifiers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findKey
import javax.swing.KeyStroke; //导入方法依赖的package包/类
/** Same method as above, but works just with plain actions.
*/
private static String findKey(Action action) {
if (action == null) {
return null;
}
KeyStroke accelerator = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
if (accelerator == null) {
return null;
}
int modifiers = accelerator.getModifiers();
String acceleratorText = ""; // NOI18N
if (modifiers > 0) {
acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
acceleratorText += "+"; // NOI18N
} else if (accelerator.getKeyCode() == KeyEvent.VK_UNDEFINED) {
return ""; // NOI18N
}
acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode());
return acceleratorText;
}
示例2: getHelp
import javax.swing.KeyStroke; //导入方法依赖的package包/类
private String getHelp() {
String ret = "";
TreeMap<String,String> helpText = new TreeMap<String, String>();
for (KeyStroke key : panel.getInputMap().allKeys()) {
if (key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_0,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_1,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_2,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_3,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_4,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_5,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_6,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_7,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_8,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_9,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS,0)) ||
key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_COMMA,0)))
continue;
if (key.getModifiers() != 0) helpText.put(key.toString().replaceAll("pressed ", "").replaceAll(" ", "-"), panel.getInputMap().get(key).toString());
else helpText.put(key.toString().replaceAll("pressed ", ""), panel.getInputMap().get(key).toString());
}
for (Entry<String,String> en : helpText.entrySet()) {
ret += en.getKey() + ": " + en.getValue() + "\n";
}
return ret;
}
示例3: appendKeyMnemonic
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public static String appendKeyMnemonic(StringBuilder sb, KeyStroke key) {
String sk = org.openide.util.Utilities.keyToString(key);
int mods = key.getModifiers();
if ((mods & KeyEvent.CTRL_MASK) != 0) {
sb.append("Ctrl+"); // NOI18N
}
if ((mods & KeyEvent.ALT_MASK) != 0) {
sb.append("Alt+"); // NOI18N
}
if ((mods & KeyEvent.SHIFT_MASK) != 0) {
sb.append("Shift+"); // NOI18N
}
if ((mods & KeyEvent.META_MASK) != 0) {
sb.append("Meta+"); // NOI18N
}
int i = sk.indexOf('-'); //NOI18N
if (i != -1) {
sk = sk.substring(i + 1);
}
sb.append(sk);
return sb.toString();
}
示例4: keyAcceleratorString
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public static String keyAcceleratorString(KeyStroke keyStroke) {
if (keyStroke == null || NO_KEYSTROKE.equals(keyStroke)) return null;
String keyText = KeyEvent.getKeyText(keyStroke.getKeyCode());
int modifiers = keyStroke.getModifiers();
if (modifiers == 0) return keyText;
if (ACC_DELIMITER == null) {
ACC_DELIMITER = UIManager.getString("MenuItem.acceleratorDelimiter"); // NOI18N
if (ACC_DELIMITER == null) ACC_DELIMITER = "+"; // NOI18N // Note: NetBeans default, Swing uses '-' by default
}
return KeyEvent.getKeyModifiersText(modifiers) + ACC_DELIMITER + keyText;
}
示例5: keyStrokeToString
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public static String keyStrokeToString(KeyStroke keyStroke) {
int modifiers = keyStroke.getModifiers();
StringBuffer sb = new StringBuffer();
if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0) {
sb.append("Ctrl+"); // NOI18N
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0) {
sb.append("Alt+"); // NOI18N
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0) {
sb.append("Shift+"); // NOI18N
}
if ((modifiers & InputEvent.META_DOWN_MASK) > 0) {
sb.append("Meta+"); // NOI18N
}
if (keyStroke.getKeyCode() != KeyEvent.VK_SHIFT &&
keyStroke.getKeyCode() != KeyEvent.VK_CONTROL &&
keyStroke.getKeyCode() != KeyEvent.VK_META &&
keyStroke.getKeyCode() != KeyEvent.VK_ALT &&
keyStroke.getKeyCode() != KeyEvent.VK_ALT_GRAPH) {
sb.append(Utilities.keyToString(
KeyStroke.getKeyStroke(keyStroke.getKeyCode(), 0)));
}
return sb.toString();
}
示例6: getOSKey
import javax.swing.KeyStroke; //导入方法依赖的package包/类
private JavaAgentKeys getOSKey() {
KeyStroke selectall = null;
InputMap inputMap = new JTextField().getInputMap();
KeyStroke[] allKeys = inputMap.allKeys();
for (KeyStroke keyStroke : allKeys) {
Object object = inputMap.get(keyStroke);
if (object.equals("select-all")) {
selectall = keyStroke;
break;
}
}
if ((selectall.getModifiers() & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
return JavaAgentKeys.CONTROL;
}
if ((selectall.getModifiers() & InputEvent.META_DOWN_MASK) == InputEvent.META_DOWN_MASK) {
return JavaAgentKeys.META;
}
throw new RuntimeException("Which key?");
}
示例7: getString
import javax.swing.KeyStroke; //导入方法依赖的package包/类
/**
* A plain text representation of a KeyStroke. Doesn't differ much
* from {@link KeyEvent#getKeyText}
*/
public static String getString(KeyStroke k) {
if (k == null) {
return null;
}
String s = KeyEvent.getKeyText(k.getKeyCode());
s = s.replace(' ', '_');
if ((k.getModifiers() & KeyEvent.SHIFT_MASK) > 0) {
s = Resources.getString("Keys.shift") + " " + s; //$NON-NLS-1$ //$NON-NLS-2$
}
if ((k.getModifiers() & KeyEvent.CTRL_MASK) > 0) {
s = Resources.getString("Keys.ctrl") + " " + s; //$NON-NLS-1$ //$NON-NLS-2$
}
if ((k.getModifiers() & KeyEvent.META_MASK) > 0) {
s = Resources.getString("Keys.meta") + " " + s; //$NON-NLS-1$ //$NON-NLS-2$
}
if ((k.getModifiers() & KeyEvent.ALT_MASK) > 0) {
s = Resources.getString("Keys.alt") + " " + s; //$NON-NLS-1$ //$NON-NLS-2$
}
return s.toUpperCase();
}
示例8: getString
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public static String getString(KeyStroke k) {
String s = KeyEvent.getKeyText(k.getKeyCode());
if ((k.getModifiers() & KeyEvent.SHIFT_MASK) > 0) {
s = KeyEvent.getKeyText(KeyEvent.VK_SHIFT) + "+" + s;
}
if ((k.getModifiers() & KeyEvent.CTRL_MASK) > 0) {
s = KeyEvent.getKeyText(KeyEvent.VK_CONTROL) + "+" + s;
}
if ((k.getModifiers() & KeyEvent.META_MASK) > 0) {
s = KeyEvent.getKeyText(KeyEvent.VK_META) + "+" + s;
}
if ((k.getModifiers() & KeyEvent.ALT_MASK) > 0) {
s = KeyEvent.getKeyText(KeyEvent.VK_ALT) + "+" + s;
}
return s;
}
示例9: getKeyStrokeAsText
import javax.swing.KeyStroke; //导入方法依赖的package包/类
/**
* Get human-readable name for a {@link KeyStroke}.
*/
public static String getKeyStrokeAsText(@NonNull KeyStroke keyStroke) {
int modifiers = keyStroke.getModifiers ();
StringBuilder sb = new StringBuilder ();
if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0) {
sb.append(EMACS_CTRL);
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0) {
sb.append(STRING_ALT);
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0) {
sb.append (EMACS_SHIFT);
}
if ((modifiers & InputEvent.META_DOWN_MASK) > 0) {
sb.append(STRING_META);
}
if (keyStroke.getKeyCode () != KeyEvent.VK_SHIFT &&
keyStroke.getKeyCode () != KeyEvent.VK_CONTROL &&
keyStroke.getKeyCode () != KeyEvent.VK_META &&
keyStroke.getKeyCode () != KeyEvent.VK_ALT &&
keyStroke.getKeyCode () != KeyEvent.VK_ALT_GRAPH) {
sb.append (Utilities.keyToString (
KeyStroke.getKeyStroke (keyStroke.getKeyCode (), 0)
));
}
return sb.toString ();
}
示例10: getKeyStrokeAsText
import javax.swing.KeyStroke; //导入方法依赖的package包/类
private static String getKeyStrokeAsText(KeyStroke keyStroke) {
int modifiers = keyStroke.getModifiers();
StringBuilder sb = new StringBuilder();
sb.append('\'');
if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0) {
sb.append("Ctrl+"); //NOI18N
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0) {
sb.append("Alt+"); //NOI18N
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0) {
sb.append("Shift+"); //NOI18N
}
if ((modifiers & InputEvent.META_DOWN_MASK) > 0) {
sb.append("Meta+"); //NOI18N
}
if (keyStroke.getKeyCode() != KeyEvent.VK_SHIFT
&& keyStroke.getKeyCode() != KeyEvent.VK_CONTROL
&& keyStroke.getKeyCode() != KeyEvent.VK_META
&& keyStroke.getKeyCode() != KeyEvent.VK_ALT
&& keyStroke.getKeyCode() != KeyEvent.VK_ALT_GRAPH) {
sb.append(org.openide.util.Utilities.keyToString(
KeyStroke.getKeyStroke(keyStroke.getKeyCode(), 0)
));
}
sb.append('\'');
return sb.toString();
}
示例11: getKeyStrokeAsText
import javax.swing.KeyStroke; //导入方法依赖的package包/类
static String getKeyStrokeAsText (KeyStroke keyStroke) {
if (keyStroke == null)
return "";
int modifiers = keyStroke.getModifiers ();
StringBuffer sb = new StringBuffer ();
if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0)
sb.append ("Ctrl+");
if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0)
sb.append ("Alt+");
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0)
sb.append ("Shift+");
if ((modifiers & InputEvent.META_DOWN_MASK) > 0)
if (Utilities.isMac()) {
// Mac cloverleaf symbol
sb.append ("\u2318+");
} else if (isSolaris()) {
// Sun meta symbol
sb.append ("\u25C6+");
} else {
sb.append ("Meta+");
}
if (keyStroke.getKeyCode () != KeyEvent.VK_SHIFT &&
keyStroke.getKeyCode () != KeyEvent.VK_CONTROL &&
keyStroke.getKeyCode () != KeyEvent.VK_META &&
keyStroke.getKeyCode () != KeyEvent.VK_ALT &&
keyStroke.getKeyCode () != KeyEvent.VK_ALT_GRAPH
)
sb.append (Utilities.keyToString (
KeyStroke.getKeyStroke (keyStroke.getKeyCode (), 0)
));
return sb.toString ();
}
示例12: getCharSequence
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public String getCharSequence(String keys) {
StringBuilder sb = new StringBuilder();
if (keys.length() == 1) {
sb.append(keys);
} else {
KeyStrokeParser ksp = new KeyStrokeParser(keys);
KeyStroke ks = ksp.getKeyStroke();
CharSequence keys2 = keyMapping.get(ks.getKeyCode());
if (keys2 == null) {
String keysText = KeyEvent.getKeyText(ks.getKeyCode());
if (keysText.length() == 1 && Character.isUpperCase(keysText.charAt(0))) {
keysText = keysText.toLowerCase();
}
keys2 = keysText;
}
int modifiers = ks.getModifiers();
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
sb.append(Keys.SHIFT);
}
if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
sb.append(Keys.CONTROL);
}
if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
sb.append(Keys.META);
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
sb.append(Keys.ALT);
}
sb.append(keys2);
}
return sb.toString();
}
示例13: getKeys
import javax.swing.KeyStroke; //导入方法依赖的package包/类
private static CharSequence getKeys(String keysFor, String sKeyStroke) {
KeyStroke ks = KeyStroke.getKeyStroke(sKeyStroke);
if (ks == null) {
throw new WebDriverException("Unable to parse keystroke for " + keysFor + " trying to parse " + sKeyStroke);
}
StringBuilder sb = new StringBuilder();
int modifiers = ks.getModifiers();
if ((modifiers & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
sb.append(Keys.CONTROL);
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) == InputEvent.ALT_DOWN_MASK) {
sb.append(Keys.ALT);
}
if ((modifiers & InputEvent.META_DOWN_MASK) == InputEvent.META_DOWN_MASK) {
sb.append(Keys.META);
}
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) {
sb.append(Keys.SHIFT);
}
int keyCode = ks.getKeyCode();
if (keyCode == KeyEvent.VK_UNDEFINED) {
sb.append(ks.getKeyChar());
} else {
sb.append(keyCharFromKeyCode(keyCode, keysFor));
}
sb.append(Keys.NULL);
return sb.toString();
}
示例14: encode
import javax.swing.KeyStroke; //导入方法依赖的package包/类
/**
* Encode a NamedKeyStroke into a String
*/
public static String encode(NamedKeyStroke stroke) {
if (stroke == null) {
return "";
}
KeyStroke key = stroke.getStroke();
if (key == null) {
return "";
}
String s = key.getKeyCode() + "," + key.getModifiers();
if (stroke.isNamed()) {
s += "," + stroke.getName();
}
return s;
}
示例15: removeKeyStroke
import javax.swing.KeyStroke; //导入方法依赖的package包/类
/**
* Removes the given {@code KeyStroke}. That is:
* This action's {@code KeyStroke} is set to
* {@code null} if it is the same as the given
* {@code KeyStroke}.
*
* @param k The {@code KeyStroke} to be removed.
*/
public void removeKeyStroke(KeyStroke k) {
if (k != null && keyStroke != null
&& k.getKeyCode() == keyStroke.getKeyCode()
&& k.getModifiers() == keyStroke.getModifiers()) {
keyStroke = null;
bl.setText(" ");
}
}