397 |
* </code> |
* </code> |
398 |
* |
* |
399 |
* @param s the string to parse |
* @param s the string to parse |
400 |
|
* @throws IllegalArgumentException if s is null or cannot be parsed |
401 |
* @return the specified keystroke |
* @return the specified keystroke |
|
* @throws NullPointerException if s is null |
|
|
* @throws IllegalArgumentException if s cannot be parsed |
|
402 |
*/ |
*/ |
403 |
public static AWTKeyStroke getAWTKeyStroke(String s) |
public static AWTKeyStroke getAWTKeyStroke(String s) |
404 |
{ |
{ |
405 |
|
if (s == null) |
406 |
|
throw new IllegalArgumentException("null argument"); |
407 |
StringTokenizer t = new StringTokenizer(s, " "); |
StringTokenizer t = new StringTokenizer(s, " "); |
408 |
if (! t.hasMoreTokens()) |
if (! t.hasMoreTokens()) |
409 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException("no tokens '" + s + "'"); |
410 |
int modifiers = 0; |
int modifiers = 0; |
411 |
boolean released = false; |
boolean released = false; |
412 |
String token = null; |
String token = null; |
437 |
KeyEvent.VK_UNDEFINED, modifiers, |
KeyEvent.VK_UNDEFINED, modifiers, |
438 |
false); |
false); |
439 |
} |
} |
440 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException("Invalid 'typed' argument '" |
441 |
|
+ s + "'"); |
442 |
} |
} |
443 |
else if ("pressed".equals(token)) |
else if ("pressed".equals(token)) |
444 |
{ |
{ |
459 |
while (t.hasMoreTokens()); |
while (t.hasMoreTokens()); |
460 |
// Now token contains the VK name we must parse. |
// Now token contains the VK name we must parse. |
461 |
Integer code = (Integer) vktable.get(token); |
Integer code = (Integer) vktable.get(token); |
462 |
if (code == null || t.hasMoreTokens()) |
if (code == null) |
463 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException("Unknown token '" + token |
464 |
|
+ "' in '" + s + "'"); |
465 |
|
if (t.hasMoreTokens()) |
466 |
|
throw new IllegalArgumentException("Too many tokens: " + s); |
467 |
return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, code.intValue(), |
return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, code.intValue(), |
468 |
modifiers, released); |
modifiers, released); |
469 |
} |
} |