Example usage for org.eclipse.jface.bindings.keys IKeyLookup formalModifierLookup

List of usage examples for org.eclipse.jface.bindings.keys IKeyLookup formalModifierLookup

Introduction

In this page you can find the example usage for org.eclipse.jface.bindings.keys IKeyLookup formalModifierLookup.

Prototype

int formalModifierLookup(String name);

Source Link

Document

Looks up a single modifier key by its formal name, and returns the integer representation for this modifier key

Usage

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$
    }/* w w w.ja  v  a  2 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);
}