List of usage examples for org.eclipse.jface.bindings.keys KeyStroke KEY_DELIMITERS
String KEY_DELIMITERS
To view the source code for org.eclipse.jface.bindings.keys KeyStroke KEY_DELIMITERS.
Click Source Link
Key objects allowed during parsing of the formal string representation. From source file:org.eclipse.rcptt.tesla.ecl.internal.impl.commands.ActionService.java
License:Open Source License
private KeyStroke parseKey(final String string) { if (string == null) { throw new NullPointerException("Cannot parse a null string"); //$NON-NLS-1$ }/* www . j ava2 s .com*/ final IKeyLookup lookup = KeyLookupFactory.getDefault(); int modifierKeys = KeyStroke.NO_KEY; int naturalKey = KeyStroke.NO_KEY; final StringTokenizer stringTokenizer = new StringTokenizer(string, KeyStroke.KEY_DELIMITERS, true); int i = 0; while (stringTokenizer.hasMoreTokens()) { String token = stringTokenizer.nextToken(); if (i % 2 == 0) { if (stringTokenizer.hasMoreTokens()) { token = token.toUpperCase(); final int modifierKey = lookup.formalModifierLookup(token); if (modifierKey == KeyStroke.NO_KEY) { throw new IllegalArgumentException(); } modifierKeys |= modifierKey; } else if (token.length() == 1) { naturalKey = token.charAt(0); } else { token = token.toUpperCase(); try { naturalKey = lookup.formalKeyLookup(token); } catch (IllegalArgumentException e) { naturalKey = lookup.formalModifierLookup(token); } if (naturalKey == KeyStroke.NO_KEY) { throw new IllegalArgumentException(); } } } i++; } return KeyStroke.getInstance(modifierKeys, naturalKey); }