javax.swing.KeyStroke#toString ( )源码实例Demo

下面列出了javax.swing.KeyStroke#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mars-sim   文件: TransportWizard.java
private void setKeyBindings() {
   int condition = javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW;
   final javax.swing.InputMap inputMap = mapPanel.getInputMap(condition);
   final javax.swing.ActionMap actionMap = mapPanel.getActionMap();
   boolean[] keyPressed = { true, false };

   //boolean[] keys = new boolean[KeyEvent.KEY_TYPED];
//keys[evt.getKeyCode()] = true;

   for (Integer keyCode : keyboardMap.keySet()) {
      KeyboardDirection dir = keyboardMap.get(keyCode);
      for (boolean onKeyPress : keyPressed) {
         boolean onKeyRelease = !onKeyPress;
         KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, 0, onKeyRelease);
         Object key = keyStroke.toString();
         inputMap.put(keyStroke, key);
         actionMap.put(key, new KeyBindingsAction(dir, onKeyPress));
      }
   }
}
 
源代码2 项目: netbeans   文件: OutlineView.java
private void putActionDelegate(InputMap map, KeyStroke ks) {
    String binding = COPY_ACTION_DELEGATE+ks.toString();
    Action action = getCopyActionDelegate(map, ks);
    if (action != null) {
        getActionMap().put(binding, action);
        map.put(ks, binding);
    }
}
 
源代码3 项目: netbeans   文件: CodeTemplateManagerOperation.java
private static String getExpandKeyStrokeText(KeyStroke keyStroke) {
    String expandKeyStrokeText;
    if (keyStroke.equals(KeyStroke.getKeyStroke(' '))) { //NOI18N
        expandKeyStrokeText = "SPACE"; // NOI18N
    } else if (keyStroke.equals(KeyStroke.getKeyStroke(new Character(' '), InputEvent.SHIFT_MASK))) { //NOI18N
        expandKeyStrokeText = "Shift-SPACE"; // NOI18N
    } else if (keyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0))) {
        expandKeyStrokeText = "TAB"; // NOI18N
    } else if (keyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0))) {
        expandKeyStrokeText = "ENTER"; // NOI18N
    } else {
        expandKeyStrokeText = keyStroke.toString();
    }
    return expandKeyStrokeText;
}
 
源代码4 项目: pgptool   文件: JCheckList.java
private void addSpaceActionhandler(JComponent host) {
	InputMap inputMap = host.getInputMap();
	ActionMap actionMap = host.getActionMap();
	KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
	String key = keyStroke.toString();
	inputMap.put(keyStroke, key);
	actionMap.put(key, invertCheckAction);
}
 
源代码5 项目: gcs   文件: MenuKeyPreferences.java
private void setAccelerator(JButton button, KeyStroke ks) {
    Command cmd = mMap.get(button);
    cmd.setAccelerator(ks);
    button.setText(getAcceleratorText(cmd));
    button.invalidate();
    Preferences prefs    = Preferences.getInstance();
    String      key      = cmd.getCommand();
    String      override = null;
    if (!cmd.hasOriginalAccelerator()) {
        override = ks != null ? ks.toString() : NONE;
    }
    prefs.setKeyBindingOverride(key, override);
}
 
源代码6 项目: freecol   文件: FreeColAction.java
/**
 * Creates a {@code String} that keeps the attributes given
 * {@code KeyStroke}. This {@code String} can be used to
 * store the key stroke in an XML-file.
 *
 * @param keyStroke The {@code KeyStroke}.
 * @return A {@code String} that produces a key stroke equal to the
 *         given {@code KeyStroke} if passed as a parameter to
 *         {@code getAWTKeyStroke(String)}.
 */
private static String getKeyStrokeText(KeyStroke keyStroke) {
    return (keyStroke == null) ? "" : keyStroke.toString();
}