本文整理汇总了Java中java.awt.event.KeyEvent.getKeyModifiersText方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.getKeyModifiersText方法的具体用法?Java KeyEvent.getKeyModifiersText怎么用?Java KeyEvent.getKeyModifiersText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.event.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.getKeyModifiersText方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findKey
import java.awt.event.KeyEvent; //导入方法依赖的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: getAccText
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
private String getAccText(String acceleratorDelimiter) {
String accText = "";
KeyStroke accelerator = mi.getAccelerator();
if (accelerator != null) {
int modifiers = accelerator.getModifiers();
if (modifiers > 0) {
accText = KeyEvent.getKeyModifiersText(modifiers);
accText += acceleratorDelimiter;
}
int keyCode = accelerator.getKeyCode();
if (keyCode != 0) {
accText += KeyEvent.getKeyText(keyCode);
} else {
accText += accelerator.getKeyChar();
}
}
return accText;
}
示例3: getAccText
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private String getAccText(String acceleratorDelimiter) {
String accText = "";
KeyStroke accelerator = mi.getAccelerator();
if (accelerator != null) {
int modifiers = accelerator.getModifiers();
if (modifiers > 0) {
accText = KeyEvent.getKeyModifiersText(modifiers);
accText += acceleratorDelimiter;
}
int keyCode = accelerator.getKeyCode();
if (keyCode != 0) {
accText += KeyEvent.getKeyText(keyCode);
} else {
accText += accelerator.getKeyChar();
}
}
return accText;
}
示例4: getKeyText
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
private static String getKeyText (KeyStroke keyStroke) {
if (keyStroke == null) return ""; // NOI18N
String modifText = KeyEvent.getKeyModifiersText
(keyStroke.getModifiers ());
String suffix = org.openide.util.Utilities.keyToString (
KeyStroke.getKeyStroke (keyStroke.getKeyCode (), 0)
);
if (suffix == null) {
return ""; // NOI18N
}
if ("".equals (modifText)) // NOI18N
return suffix;
return modifText + "+" + // NOI18N
suffix;
}
示例5: keyStrokeToString
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
* Creates nice textual representation of KeyStroke.
* Modifiers and an actual key label are concated by plus signs
* @param the KeyStroke to get description of
* @return String describing the KeyStroke
*/
public static String keyStrokeToString( KeyStroke stroke ) {
String modifText = KeyEvent.getKeyModifiersText( stroke.getModifiers() );
String keyText = (stroke.getKeyCode() == KeyEvent.VK_UNDEFINED) ?
String.valueOf(stroke.getKeyChar()) : getKeyText(stroke.getKeyCode());
if( modifText.length() > 0 ) return modifText + '+' + keyText;
else return keyText;
}
示例6: getKeyText
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
private static String getKeyText (KeyStroke keyStroke) {
if (keyStroke == null) return "";
String modifText = KeyEvent.getKeyModifiersText
(keyStroke.getModifiers ());
if ("".equals (modifText))
return KeyEvent.getKeyText (keyStroke.getKeyCode ());
return modifText + "+" + // NOI18N
KeyEvent.getKeyText (keyStroke.getKeyCode ());
}
示例7: findKeyBinding
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
private static String findKeyBinding(String actionName) {
KeyBindingSettings kbs = MimeLookup.getLookup(MimePath.get("text/x-java")).lookup(KeyBindingSettings.class); //NOI18N
for (MultiKeyBinding mkb : kbs.getKeyBindings()) {
if (actionName.equals(mkb.getActionName())) {
KeyStroke ks = mkb.getKeyStrokeCount() > 0 ? mkb.getKeyStroke(0) : null;
return ks != null ? KeyEvent.getKeyModifiersText(ks.getModifiers()) + '+' + KeyEvent.getKeyText(ks.getKeyCode()) : null;
}
}
return null;
}
示例8: keyAcceleratorString
import java.awt.event.KeyEvent; //导入方法依赖的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;
}
示例9: formatKeyStroke
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
* Converts {@link KeyStroke} to a human-readable string.
*
* @param keyStroke
* the keystroke
* @return a human-readable string like 'Ctrl+E'
*/
public static String formatKeyStroke(KeyStroke keyStroke) {
StringBuilder builder = new StringBuilder();
String modifierString = KeyEvent.getKeyModifiersText(keyStroke.getModifiers());
String keyString = KeyEvent.getKeyText(keyStroke.getKeyCode());
if (modifierString != null && !modifierString.trim().isEmpty()) {
builder.append(modifierString);
builder.append("+");
}
builder.append(keyString);
return builder.toString();
}
示例10: setLines2and3
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
private void setLines2and3(KeyEvent event)
{
line2 = String.format("This key is %san action key",
(event.isActionKey() ? "" : "not "));
String temp = KeyEvent.getKeyModifiersText(event.getModifiers());
line3 = String.format("Modifier keys pressed: %s",
(temp.equals("") ? "none" : temp)); // output modifiers
textArea.setText(String.format("%s\n%s\n%s\n",
line1, line2, line3)); // output three lines of text
}
示例11: getHumanKeyStrokeText
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
* Gets a string to represent the given {@code KeyStroke} to the user.
*
* @param keyStroke {@code java.awt.event.KeyStroke}
* @return String
*/
public static String getHumanKeyStrokeText(KeyStroke keyStroke) {
if (keyStroke == null) {
return " ";
}
String s = KeyEvent.getKeyModifiersText(keyStroke.getModifiers());
if (!s.isEmpty()) s += "+";
return s + KeyEvent.getKeyText(keyStroke.getKeyCode());
}
示例12: toString
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
* Returns an internationalized description of the MenuShortcut.
* @return a string representation of this MenuShortcut.
* @since JDK1.1
*/
public String toString() {
int modifiers = 0;
if (!GraphicsEnvironment.isHeadless()) {
modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
}
if (usesShiftModifier()) {
modifiers |= Event.SHIFT_MASK;
}
return KeyEvent.getKeyModifiersText(modifiers) + "+" +
KeyEvent.getKeyText(key);
}
示例13: toString
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
* Returns an internationalized description of the MenuShortcut.
* @return a string representation of this MenuShortcut.
* @since 1.1
*/
@SuppressWarnings("deprecation")
public String toString() {
int modifiers = 0;
if (!GraphicsEnvironment.isHeadless()) {
modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
}
if (usesShiftModifier()) {
modifiers |= Event.SHIFT_MASK;
}
return KeyEvent.getKeyModifiersText(modifiers) + "+" +
KeyEvent.getKeyText(key);
}
示例14: toString
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
* returns String representation of shortcut
*
* @return String representation of shortcut
*/
@Override
public String toString() {
String s = KeyEvent.getKeyModifiersText(getKeyModifiers());
return s + (s.length() > 0 ? "+" : "") + KeyEvent.getKeyText(getKeyCode());
}