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


Java KeyStroke.getKeyCode方法代码示例

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


在下文中一共展示了KeyStroke.getKeyCode方法的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:Actions.java

示例2: keyStrokeToString

import javax.swing.KeyStroke; //导入方法依赖的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:Utilities.java

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

示例4: keyCommand

import javax.swing.KeyStroke; //导入方法依赖的package包/类
/**
 * Classes other than the Chatter itself may forward KeyEvents
 * to the Chatter by using this method
 */
public void keyCommand(KeyStroke e) {
  if ((e.getKeyCode() == 0 || e.getKeyCode() == KeyEvent.CHAR_UNDEFINED)
      && !Character.isISOControl(e.getKeyChar())) {
    input.setText(input.getText() + e.getKeyChar());
  }
  else if (e.isOnKeyRelease()) {
    switch (e.getKeyCode()) {
      case KeyEvent.VK_ENTER:
        if (input.getText().length() > 0)
          send(formatChat(input.getText()));
        input.setText(""); //$NON-NLS-1$
        break;
      case KeyEvent.VK_BACK_SPACE:
      case KeyEvent.VK_DELETE:
        String s = input.getText();
        if (s.length() > 0)
          input.setText(s.substring(0, s.length() - 1));
        break;
    }
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:26,代码来源:Chatter.java

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

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

示例7: listKeyReleased

import javax.swing.KeyStroke; //导入方法依赖的package包/类
private void listKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listKeyReleased
    KeyStroke ks = KeyStroke.getKeyStrokeForEvent(evt);
    if ( ks.getKeyCode() == KeyEvent.VK_ENTER || 
         ks.getKeyCode() == KeyEvent.VK_SPACE ) {
        importClass( 
                getSelected(),
                (evt.getModifiers() & (org.openide.util.Utilities.isMac() ? InputEvent.META_MASK : InputEvent.ALT_MASK)) > 0,
                (evt.getModifiers() & InputEvent.SHIFT_MASK) > 0);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ImportClassPanel.java

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

示例9: 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();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:29,代码来源:OSUtils.java

示例10: 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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:18,代码来源:NamedHotKeyConfigurer.java

示例11: isNamed

import javax.swing.KeyStroke; //导入方法依赖的package包/类
/**
 * Return true if the supplied KeyStroke is in the range allocated
 * to NamedKeyStrokes
 * @param k KeyStroke
 * @return true if this was generated by us
 */
public static boolean isNamed(KeyStroke k) {
  if (k == null) {
    return false;
  }
  int code = k.getKeyCode();
  return code == NAMED_MARKER || (code >= NAMED_START && code <= NAMED_END);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:14,代码来源:NamedKeyManager.java

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

示例13: getAction

import javax.swing.KeyStroke; //导入方法依赖的package包/类
public Action getAction(final KeyStroke key) {
    switch (key.getKeyCode()) {
    case KeyEvent.VK_SHIFT:
    case KeyEvent.VK_CONTROL:
    case KeyEvent.VK_ALT:
    case KeyEvent.VK_ALT_GRAPH:
    case KeyEvent.VK_META:
    case KeyEvent.VK_UNDEFINED:
    case KeyEvent.CHAR_UNDEFINED:
            // Not actually a bindable key press.
            return null;
    }
    if (key.isOnKeyRelease()) {
        // Again, not really our business here.
        return null;
    }
    LOG.log(Level.FINE, "getAction {0}", key);
    Map<KeyStroke,Binding> binder = bindings();
    for (KeyStroke ctx : context) {
        Binding sub = binder.get(ctx);
        if (sub == null) {
            resetContext();
            return BROKEN; // no entry found after known prefix
        }
        binder = sub.nested;
        if (binder == null) {
            resetContext();
            return BROKEN; // anomalous, expected to find submap here
        }
    }
    Binding b = binder.get(key);
    if (b == null) {
        resetContext();
        return null; // normal, not found
    }
    if (b.nested == null) {
        resetContext();
        return b.loadAction(); // found real action
    } else {
        return new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                shiftContext(key); // entering submap
            }
        };
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:47,代码来源:NbKeymap.java

示例14: actionPerformed

import javax.swing.KeyStroke; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt) {
    boolean editors = true;
    boolean views = !documentsOnly;
    if( "immediately".equals( evt.getActionCommand() ) ) {
        TopComponent activeTc = TopComponent.getRegistry().getActivated();
        if( null != activeTc ) {
            if( TopComponentTracker.getDefault().isEditorTopComponent( activeTc ) ) {
                //switching in a document, go to some other document
                views = false;
            } else {
                //switching in a view, go to some other view
                editors = false;
                views = true;
            }
        }
    }
    
    TopComponent[] documents = getRecentWindows(editors, views);
    
    if (documents.length < 2) {
        return;
    }
    
    if(!"immediately".equals(evt.getActionCommand()) && // NOI18N
            !(evt.getSource() instanceof javax.swing.JMenuItem)) {
        // #46800: fetch key directly from action command
        KeyStroke keyStroke = Utilities.stringToKey(evt.getActionCommand());
        
        if(keyStroke != null) {
            int triggerKey = keyStroke.getKeyCode();
            int reverseKey = KeyEvent.VK_SHIFT;
            int releaseKey = 0;
            
            int modifiers = keyStroke.getModifiers();
            if((InputEvent.CTRL_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_CONTROL;
            } else if((InputEvent.ALT_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_ALT;
            } else if((InputEvent.META_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_META;
            }
            
            if(releaseKey != 0) {
                if (!KeyboardPopupSwitcher.isShown()) {
                    KeyboardPopupSwitcher.showPopup(documentsOnly, releaseKey, triggerKey, (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0);
                }
                return;
            }
        }
    }

    int documentIndex = (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0 ? 1 : documents.length-1;
    TopComponent tc = documents[documentIndex];
    // #37226 Unmaximized the other mode if needed.
    WindowManagerImpl wm = WindowManagerImpl.getInstance();
    ModeImpl mode = (ModeImpl) wm.findMode(tc);
    if(mode != null && mode != wm.getCurrentMaximizedMode()) {
        wm.switchMaximizedMode(null);
    }
    
    tc.requestActive();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:64,代码来源:RecentViewListAction.java

示例15: listKeyReleased

import javax.swing.KeyStroke; //导入方法依赖的package包/类
private void listKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listKeyReleased
    KeyStroke ks = KeyStroke.getKeyStrokeForEvent(evt);
    if (ks.getKeyCode() == KeyEvent.VK_ENTER || ks.getKeyCode() == KeyEvent.VK_SPACE) {
        invokeSelected();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:RemoveSurroundingCodePanel.java


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