1 |
/* AWTKeyStroke.java -- an immutable key stroke |
/* AWTKeyStroke.java -- an immutable key stroke |
2 |
Copyright (C) 2002, 2004 Free Software Foundation |
Copyright (C) 2002, 2004, 2005 Free Software Foundation |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
393 |
* </code> |
* </code> |
394 |
* |
* |
395 |
* @param s the string to parse |
* @param s the string to parse |
396 |
|
* @throws IllegalArgumentException if s is null or cannot be parsed |
397 |
* @return the specified keystroke |
* @return the specified keystroke |
|
* @throws NullPointerException if s is null |
|
|
* @throws IllegalArgumentException if s cannot be parsed |
|
398 |
*/ |
*/ |
399 |
public static AWTKeyStroke getAWTKeyStroke(String s) |
public static AWTKeyStroke getAWTKeyStroke(String s) |
400 |
{ |
{ |
401 |
|
if (s == null) |
402 |
|
throw new IllegalArgumentException("null argument"); |
403 |
StringTokenizer t = new StringTokenizer(s, " "); |
StringTokenizer t = new StringTokenizer(s, " "); |
404 |
if (! t.hasMoreTokens()) |
if (! t.hasMoreTokens()) |
405 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException("no tokens '" + s + "'"); |
406 |
int modifiers = 0; |
int modifiers = 0; |
407 |
boolean released = false; |
boolean released = false; |
408 |
String token = null; |
String token = null; |
433 |
KeyEvent.VK_UNDEFINED, modifiers, |
KeyEvent.VK_UNDEFINED, modifiers, |
434 |
false); |
false); |
435 |
} |
} |
436 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException("Invalid 'typed' argument '" |
437 |
|
+ s + "'"); |
438 |
} |
} |
439 |
else if ("pressed".equals(token)) |
else if ("pressed".equals(token)) |
440 |
{ |
{ |
455 |
while (t.hasMoreTokens()); |
while (t.hasMoreTokens()); |
456 |
// Now token contains the VK name we must parse. |
// Now token contains the VK name we must parse. |
457 |
Integer code = (Integer) vktable.get(token); |
Integer code = (Integer) vktable.get(token); |
458 |
if (code == null || t.hasMoreTokens()) |
if (code == null) |
459 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException("Unknown token '" + token |
460 |
|
+ "' in '" + s + "'"); |
461 |
|
if (t.hasMoreTokens()) |
462 |
|
throw new IllegalArgumentException("Too many tokens: " + s); |
463 |
return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, code.intValue(), |
return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, code.intValue(), |
464 |
modifiers, released); |
modifiers, released); |
465 |
} |
} |