org.openide.util.Utilities.stringToKey()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(84)

本文整理了Java中org.openide.util.Utilities.stringToKey()方法的一些代码示例,展示了Utilities.stringToKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities.stringToKey()方法的具体详情如下:
包路径:org.openide.util.Utilities
类名称:Utilities
方法名:stringToKey

Utilities.stringToKey介绍

[英]Construct a new key description from a given universal string description. Provides mapping between Emacs-like textual key descriptions and the KeyStroke object used in Swing.

This format has following form:

[C][A][S][M]-*identifier*

Where:

  • C stands for the Control key

  • A stands for the Alt key

  • S stands for the Shift key

  • M stands for the Meta key
    The format also supports two wildcard codes, to support differences in platforms. These are the preferred choices for registering keystrokes, since platform conflicts will automatically be handled:

  • D stands for the default menu accelerator - the Control key on most platforms, the Command (meta) key on Macintosh

  • O stands for the alternate accelerator - the Alt key on most platforms, the Ctrl key on Macintosh (Macintosh uses Alt as a secondary shift key for composing international characters - if you bind Alt-8 to an action, a mac user with a French keyboard will not be able to type the [ character, which is a significant handicap
    If you use the wildcard characters, and specify a key which will conflict with keys the operating system consumes, it will be mapped to whichever choice can work - for example, on Macintosh, Command-Q is always consumed by the operating system, so D-Q will always map to Control-Q.

Every modifier before the hyphen must be pressed. identifier can be any text constant from KeyEvent but without the leading VK_ characters. So KeyEvent#VK_ENTER is described as ENTER.
[中]根据给定的通用字符串描述构造新的密钥描述。提供文本键描述等Emacs与Swing中使用的KeyStroke对象之间的映射。
此格式有以下格式:
[C][A][S][M]-*identifier*
哪里:
*C代表控制键
*A代表Alt键
*S代表Shift键
*M代表元密钥
该格式还支持两个通配符代码,以支持平台差异。这些是注册击键的首选选项,因为平台冲突将自动处理:
D代表默认的菜单加速器——在大多数平台上是控制键,在Macintosh上是命令(meta)键
O代表备用加速键——在大多数平台上是Alt键,在Macintosh上是Ctrl键(Macintosh使用Alt作为第二个shift键来组合国际字符——如果将Alt-8绑定到某个动作,使用法语键盘的mac用户将无法键入[字符,这是一个重大障碍
如果使用通配符,并指定一个与操作系统使用的密钥冲突的密钥,它将被映射到任何可以工作的选项上——例如,在Macintosh上,Command-Q始终由操作系统使用,因此D-Q将始终映射到Control-Q。
必须按下连字符前的每个修饰符
标识符
可以是KeyEvent中的任何文本常量,但不包含前导VK_字符。所以KeyEvent#VK_ENTER被描述为[$11$]。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-util

/** Convert a space-separated list of user-friendly key binding names to a list of Swing key strokes.
* @param s the string with keys
* @return array of key strokes, or <code>null</code> if the string description is not valid
* @see #stringToKey
*/
public static KeyStroke[] stringToKeys(String s) {
  StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); // NOI18N
  ArrayList<KeyStroke> arr = new ArrayList<KeyStroke>();
  while (st.hasMoreElements()) {
    s = st.nextToken();
    KeyStroke k = stringToKey(s);
    if (k == null) {
      return null;
    }
    arr.add(k);
  }
  return arr.toArray(new KeyStroke[arr.size()]);
}

代码示例来源:origin: org.netbeans.api/org-openide-util-ui

/** Convert a space-separated list of user-friendly key binding names to a list of Swing key strokes.
* @param s the string with keys
* @return array of key strokes, or <code>null</code> if the string description is not valid
* @see #stringToKey
*/
public static KeyStroke[] stringToKeys(String s) {
  StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); // NOI18N
  ArrayList<KeyStroke> arr = new ArrayList<KeyStroke>();
  while (st.hasMoreElements()) {
    s = st.nextToken();
    KeyStroke k = stringToKey(s);
    if (k == null) {
      return null;
    }
    arr.add(k);
  }
  return arr.toArray(new KeyStroke[arr.size()]);
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

/** Convert a space-separated list of user-friendly key binding names to a list of Swing key strokes.
* @param s the string with keys
* @return array of key strokes, or <code>null</code> if the string description is not valid
* @see #stringToKey
*/
public static KeyStroke[] stringToKeys (String s) {
  StringTokenizer st = new StringTokenizer (s.toUpperCase (), " "); // NOI18N
  ArrayList arr = new ArrayList ();
  while (st.hasMoreElements ()) {
    s = st.nextToken ();
    KeyStroke k = stringToKey (s);
    if (k == null) return null;
    arr.add (k);
  }
  return (KeyStroke[])arr.toArray (new KeyStroke[arr.size ()]);
}

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

/** Convert a space-separated list of user-friendly key binding names to a list of Swing key strokes.
* @param s the string with keys
* @return array of key strokes, or <code>null</code> if the string description is not valid
* @see #stringToKey
*/
public static KeyStroke[] stringToKeys (String s) {
  StringTokenizer st = new StringTokenizer (s.toUpperCase (), " "); // NOI18N
  ArrayList arr = new ArrayList ();
  while (st.hasMoreElements ()) {
    s = st.nextToken ();
    KeyStroke k = stringToKey (s);
    if (k == null) return null;
    arr.add (k);
  }
  return (KeyStroke[])arr.toArray (new KeyStroke[arr.size ()]);
}

代码示例来源:origin: uk.gov.nationalarchives.thirdparty.netbeans/org-openide-util

/** Convert a space-separated list of user-friendly key binding names to a list of Swing key strokes.
* @param s the string with keys
* @return array of key strokes, or <code>null</code> if the string description is not valid
* @see #stringToKey
*/
public static KeyStroke[] stringToKeys(String s) {
  StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); // NOI18N
  ArrayList<KeyStroke> arr = new ArrayList<KeyStroke>();
  while (st.hasMoreElements()) {
    s = st.nextToken();
    KeyStroke k = stringToKey(s);
    if (k == null) {
      return null;
    }
    arr.add(k);
  }
  return arr.toArray(new KeyStroke[arr.size()]);
}

代码示例来源:origin: in.jlibs/org-openide-util

/** Convert a space-separated list of user-friendly key binding names to a list of Swing key strokes.
* @param s the string with keys
* @return array of key strokes, or <code>null</code> if the string description is not valid
* @see #stringToKey
*/
public static KeyStroke[] stringToKeys(String s) {
  StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); // NOI18N
  ArrayList<KeyStroke> arr = new ArrayList<KeyStroke>();
  while (st.hasMoreElements()) {
    s = st.nextToken();
    KeyStroke k = stringToKey(s);
    if (k == null) {
      return null;
    }
    arr.add(k);
  }
  return arr.toArray(new KeyStroke[arr.size()]);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-apisupport-wizards

public static KeyStroke stringToKeyStroke(String keyStroke) {
  int modifiers = 0;
  if (keyStroke.startsWith("Ctrl+")) { // NOI18N
    modifiers |= InputEvent.CTRL_DOWN_MASK;
    keyStroke = keyStroke.substring(5);
  }
  if (keyStroke.startsWith("Alt+")) { // NOI18N
    modifiers |= InputEvent.ALT_DOWN_MASK;
    keyStroke = keyStroke.substring(4);
  }
  if (keyStroke.startsWith("Shift+")) { // NOI18N
    modifiers |= InputEvent.SHIFT_DOWN_MASK;
    keyStroke = keyStroke.substring(6);
  }
  if (keyStroke.startsWith("Meta+")) { // NOI18N
    modifiers |= InputEvent.META_DOWN_MASK;
    keyStroke = keyStroke.substring(5);
  }
  KeyStroke ks = Utilities.stringToKey(keyStroke);
  if (ks == null) {
    return null;
  }
  KeyStroke result = KeyStroke.getKeyStroke(ks.getKeyCode(), modifiers);
  return result;
}

相关文章

微信公众号

最新文章

更多