当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent.getKeyText方法代码示例

本文整理汇总了Java中java.awt.event.KeyEvent.getKeyText方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.getKeyText方法的具体用法?Java KeyEvent.getKeyText怎么用?Java KeyEvent.getKeyText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.event.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.getKeyText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:Actions.java

示例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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:MenuItemLayoutHelper.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:MenuItemLayoutHelper.java

示例4: getKeyText

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/** @return slight modification of what KeyEvent.getKeyText() returns.
 *  The numpad Left, Right, Down, Up get extra result.
 */
private static String getKeyText(int keyCode) {
    String ret = KeyEvent.getKeyText(keyCode);
    if (ret != null) {
        switch (keyCode) {
            case KeyEvent.VK_KP_DOWN:
                ret = prefixNumpad(ret, KeyEvent.VK_DOWN);
                break;
            case KeyEvent.VK_KP_LEFT:
                ret = prefixNumpad(ret, KeyEvent.VK_LEFT);
                break;
            case KeyEvent.VK_KP_RIGHT:
                ret = prefixNumpad(ret, KeyEvent.VK_RIGHT);
                break;
            case KeyEvent.VK_KP_UP:
                ret = prefixNumpad(ret, KeyEvent.VK_UP);
                break;
        }
    }
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Utilities.java

示例5: 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 ()); 
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:NbKeymap.java

示例6: 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ComputeAnnotations.java

示例7: 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ActionsSupport.java

示例8: 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();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:22,代码来源:SwingTools.java

示例9: 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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:MenuShortcut.java

示例10: getString

import java.awt.event.KeyEvent; //导入方法依赖的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();
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:25,代码来源:HotKeyConfigurer.java

示例11: getString

import java.awt.event.KeyEvent; //导入方法依赖的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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:17,代码来源:HotkeySpecifier.java

示例12: 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());
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:16,代码来源:FreeColActionUI.java

示例13: 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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:Action.java

示例14: getAsciiKeycodes

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
private List<Integer> getAsciiKeycodes() {
    CharsetEncoder asciiEncoder = Charset.forName("ascii").newEncoder();
    Set<Entry<Integer, String>> entrySet = keyCodeText.entrySet();
    List<Integer> out = new ArrayList<Integer>();
    for (Entry<Integer, String> entry : entrySet) {
        String keyText = KeyEvent.getKeyText(entry.getKey());
        if (keyText.length() == 1 && asciiEncoder.canEncode(keyText)) {
            out.add(entry.getKey());
        }
    }
    return out;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:13,代码来源:Generator.java

示例15: recordRawKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
@Override public void recordRawKeyEvent(RComponent r, KeyEvent e) {
    JSONObject event = new JSONObject();
    event.put("type", "key_raw");
    int keyCode = e.getKeyCode();
    if (keyCode == KeyEvent.VK_META || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT
            || keyCode == KeyEvent.VK_CONTROL) {
        return;
    }
    if ((e.isActionKey() || e.isControlDown() || e.isMetaDown() || e.isAltDown()) && e.getID() == KeyEvent.KEY_PRESSED) {
        String mtext = buildModifiersText(e);
        event.put("modifiersEx", mtext);
        KeysMap keysMap = KeysMap.findMap(e.getKeyCode());
        if (keysMap == KeysMap.NULL) {
            return;
        }
        String keyText;
        if (keysMap == null) {
            keyText = KeyEvent.getKeyText(e.getKeyCode());
        } else {
            keyText = keysMap.toString();
        }
        event.put("keyCode", keyText);
    } else if (e.getID() == KeyEvent.KEY_TYPED && !e.isControlDown()) {
        if (Character.isISOControl(e.getKeyChar()) && hasMapping(e.getKeyChar())) {
            event.put("keyChar", getMapping(e.getKeyChar()));
        } else {
            event.put("keyChar", "" + e.getKeyChar());
        }
    } else {
        return;
    }
    recordEvent(r, event);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:34,代码来源:WSRecorder.java


注:本文中的java.awt.event.KeyEvent.getKeyText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。