本文整理匯總了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(" ");
}
}