src/share/classes/java/awt/AWTKeyStroke.java

Print this page




 468             // Invalid ID for this KeyEvent
 469             return null;
 470         }
 471     }
 472 
 473     /**
 474      * Parses a string and returns an <code>AWTKeyStroke</code>.
 475      * The string must have the following syntax:
 476      * <pre>
 477      *    &lt;modifiers&gt;* (&lt;typedID&gt; | &lt;pressedReleasedID&gt;)
 478      *
 479      *    modifiers := shift | control | ctrl | meta | alt | altGraph
 480      *    typedID := typed &lt;typedKey&gt;
 481      *    typedKey := string of length 1 giving Unicode character.
 482      *    pressedReleasedID := (pressed | released) key
 483      *    key := KeyEvent key code name, i.e. the name following "VK_".
 484      * </pre>
 485      * If typed, pressed or released is not specified, pressed is assumed. Here
 486      * are some examples:
 487      * <pre>
 488      *     "INSERT" => getAWTKeyStroke(KeyEvent.VK_INSERT, 0);
 489      *     "control DELETE" => getAWTKeyStroke(KeyEvent.VK_DELETE, InputEvent.CTRL_MASK);
 490      *     "alt shift X" => getAWTKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK);
 491      *     "alt shift released X" => getAWTKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, true);
 492      *     "typed a" => getAWTKeyStroke('a');
 493      * </pre>
 494      *
 495      * @param s a String formatted as described above
 496      * @return an <code>AWTKeyStroke</code> object for that String
 497      * @throws IllegalArgumentException if <code>s</code> is <code>null</code>,
 498      *        or is formatted incorrectly
 499      */
 500     public static AWTKeyStroke getAWTKeyStroke(String s) {
 501         if (s == null) {
 502             throw new IllegalArgumentException("String cannot be null");
 503         }
 504 
 505         final String errmsg = "String formatted incorrectly";
 506 
 507         StringTokenizer st = new StringTokenizer(s, " ");
 508 
 509         int mask = 0;
 510         boolean released = false;
 511         boolean typed = false;
 512         boolean pressed = false;




 468             // Invalid ID for this KeyEvent
 469             return null;
 470         }
 471     }
 472 
 473     /**
 474      * Parses a string and returns an <code>AWTKeyStroke</code>.
 475      * The string must have the following syntax:
 476      * <pre>
 477      *    &lt;modifiers&gt;* (&lt;typedID&gt; | &lt;pressedReleasedID&gt;)
 478      *
 479      *    modifiers := shift | control | ctrl | meta | alt | altGraph
 480      *    typedID := typed &lt;typedKey&gt;
 481      *    typedKey := string of length 1 giving Unicode character.
 482      *    pressedReleasedID := (pressed | released) key
 483      *    key := KeyEvent key code name, i.e. the name following "VK_".
 484      * </pre>
 485      * If typed, pressed or released is not specified, pressed is assumed. Here
 486      * are some examples:
 487      * <pre>
 488      *     "INSERT" =&gt; getAWTKeyStroke(KeyEvent.VK_INSERT, 0);
 489      *     "control DELETE" =&gt; getAWTKeyStroke(KeyEvent.VK_DELETE, InputEvent.CTRL_MASK);
 490      *     "alt shift X" =&gt; getAWTKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK);
 491      *     "alt shift released X" =&gt; getAWTKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, true);
 492      *     "typed a" =&gt; getAWTKeyStroke('a');
 493      * </pre>
 494      *
 495      * @param s a String formatted as described above
 496      * @return an <code>AWTKeyStroke</code> object for that String
 497      * @throws IllegalArgumentException if <code>s</code> is <code>null</code>,
 498      *        or is formatted incorrectly
 499      */
 500     public static AWTKeyStroke getAWTKeyStroke(String s) {
 501         if (s == null) {
 502             throw new IllegalArgumentException("String cannot be null");
 503         }
 504 
 505         final String errmsg = "String formatted incorrectly";
 506 
 507         StringTokenizer st = new StringTokenizer(s, " ");
 508 
 509         int mask = 0;
 510         boolean released = false;
 511         boolean typed = false;
 512         boolean pressed = false;