Example usage for org.eclipse.jface.action Action findModifier

List of usage examples for org.eclipse.jface.action Action findModifier

Introduction

In this page you can find the example usage for org.eclipse.jface.action Action findModifier.

Prototype

public static int findModifier(String token) 

Source Link

Document

Maps standard keyboard modifier key names to the corresponding SWT modifier bit.

Usage

From source file:org.eclipse.wst.sse.ui.internal.extension.ActionDescriptor.java

License:Open Source License

/**
 * Parses the given accelerator text, and converts it to an accelerator
 * key code./*from  w  w w  .  j  av  a2  s  .  co m*/
 * 
 * @param acceleratorText
 *            the accelerator text
 * @result the SWT key code, or 0 if there is no accelerator
 */
private int convertAccelerator(String acceleratorText) {
    int accelerator = 0;
    StringTokenizer stok = new StringTokenizer(acceleratorText, "+"); //$NON-NLS-1$

    int keyCode = -1;

    boolean hasMoreTokens = stok.hasMoreTokens();
    while (hasMoreTokens) {
        String token = stok.nextToken();
        hasMoreTokens = stok.hasMoreTokens();
        // Every token except the last must be one of the modifiers
        // Ctrl, Shift, or Alt.
        if (hasMoreTokens) {
            int modifier = Action.findModifier(token);
            if (modifier != 0) {
                accelerator |= modifier;
            } else { //Leave if there are none
                return 0;
            }
        } else {
            keyCode = Action.findKeyCode(token);
        }
    }
    if (keyCode != -1) {
        accelerator |= keyCode;
    }
    return accelerator;
}

From source file:org.gotpike.pdt.preferences.PikeEditorPreferencePage.java

License:Open Source License

/**
 * Computes the state mask for the given modifier string.
 *
 * @param modifiers   the string with the modifiers, separated by '+', '-', ';', ',' or '.'
 * @return the state mask or -1 if the input is invalid
 *//* ww  w  .  j  av a  2 s  .  c  o  m*/
private int computeStateMask(String modifiers) {
    if (modifiers == null)
        return -1;

    if (modifiers.length() == 0)
        return SWT.NONE;

    int stateMask = 0;
    StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* ");
    while (modifierTokenizer.hasMoreTokens()) {
        int modifier = Action.findModifier(modifierTokenizer.nextToken());
        if (modifier == 0 || (stateMask & modifier) == modifier)
            return -1;
        stateMask = stateMask | modifier;
    }
    return stateMask;
}