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

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

Introduction

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

Prototype

String formalNameLookup(int key);

Source Link

Document

Looks up a key value, and returns the formal string representation for that key

Usage

From source file:de.xirp.util.XirpKeyFormatter.java

License:Open Source License

/**
 * Formats an individual key into a human readable format. It uses
 * the Application I18n bundle./*from   ww w. j  a  v a2 s  .  c om*/
 * 
 * @see org.eclipse.jface.bindings.keys.formatting.AbstractKeyFormatter#format(org.eclipse.jface.bindings.keys.KeySequence)
 */
@Override
public String format(final int key) {
    final IKeyLookup lookup = KeyLookupFactory.getDefault();
    final String name = lookup.formalNameLookup(key);

    // NL issue. Possible problem with 4-byte characters.
    if (name.length() == 1) {
        return name;
    }

    return I18n.getString(name);
}

From source file:org.eclipse.birt.chart.ui.swt.fieldassist.preferences.CustomKeyRadioGroupFieldEditor.java

License:Open Source License

/**
 * Returns this field editor's radio group control.
 * @param parent The parent to create the radioBox in
 * @return the radio group control// www.ja v a 2s . com
 */
public Composite getRadioBoxControl(Composite parent) {
    if (radioBox == null) {

        Font font = parent.getFont();

        if (useGroup) {
            Group group = new Group(parent, SWT.NONE);
            group.setFont(font);
            String text = getLabelText();
            if (text != null) {
                group.setText(text);
            }
            radioBox = group;
            GridLayout layout = new GridLayout();
            layout.horizontalSpacing = HORIZONTAL_GAP;
            layout.numColumns = customKeyName == null ? 1 : 2;
            radioBox.setLayout(layout);
        } else {
            radioBox = new Composite(parent, SWT.NONE);
            GridLayout layout = new GridLayout();
            layout.marginWidth = 0;
            layout.marginHeight = 0;
            layout.horizontalSpacing = HORIZONTAL_GAP;
            layout.numColumns = customKeyName == null ? 1 : 2;
            ;
            radioBox.setLayout(layout);
            radioBox.setFont(font);
        }

        radioBox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        radioButtons = new Button[labelsAndValues.length];
        for (int i = 0; i < labelsAndValues.length; i++) {
            Button radio = new Button(radioBox, SWT.RADIO | SWT.LEFT);
            if (hasCustomKeyName() && i != (labelsAndValues.length - 1)) {
                GridData gd = new GridData(GridData.FILL_HORIZONTAL);
                gd.horizontalSpan = 2;
                radio.setLayoutData(gd);
            }

            radioButtons[i] = radio;
            String[] labelAndValue = labelsAndValues[i];
            radio.setText(labelAndValue[0]);
            radio.setData(labelAndValue[1]);
            radio.setFont(font);
            radio.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent event) {
                    String oldValue = value;
                    value = (String) event.widget.getData();
                    setPresentsDefaultValue(false);
                    fireValueChanged(VALUE, oldValue, value);
                }
            });
        }

        if (hasCustomKeyName()) {
            customKeyText = new Text(radioBox, SWT.BORDER);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            customKeyText.setLayoutData(gd);
            customKeyText.addKeyListener(new KeyListener() {

                public void keyPressed(KeyEvent e) {

                }

                public void keyReleased(KeyEvent e) {
                    if (e.keyCode == SWT.CTRL || e.keyCode == SWT.ALT || e.keyCode == SWT.SHIFT) {
                        return;
                    }
                    final IKeyLookup lookup = KeyLookupFactory.getDefault();
                    String key = lookup.formalNameLookup(e.keyCode);

                    if (key == null) {
                        return;
                    }

                    StringBuffer txt = new StringBuffer();
                    if ((e.stateMask & SWT.CTRL) != 0) {
                        txt.append("Ctrl"); //$NON-NLS-1$
                    }
                    if ((e.stateMask & SWT.ALT) != 0) {
                        if (txt.length() > 0)
                            txt.append("+"); //$NON-NLS-1$
                        txt.append("Alt"); //$NON-NLS-1$
                    } else if ((e.stateMask & SWT.SHIFT) != 0) {
                        if (txt.length() > 0)
                            txt.append("+"); //$NON-NLS-1$
                        txt.append("Shift"); //$NON-NLS-1$
                    }
                    if (txt.length() > 0) {
                        txt.append("+"); //$NON-NLS-1$
                        txt.append(key);
                        customKeyText.setText(txt.toString());
                    }
                }
            });
        }

        radioButtons[labelsAndValues.length - 1].addSelectionListener(new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
                // TODO Auto-generated method stub
            }

            public void widgetSelected(SelectionEvent e) {
                customKeyText.setEnabled(radioButtons[labelsAndValues.length - 1].getSelection());
            }
        });
        radioBox.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent event) {
                radioBox = null;
                radioButtons = null;
            }
        });
    } else {
        checkParent(radioBox, parent);
    }
    return radioBox;
}

From source file:org.eclipse.ui.keys.Key.java

License:Open Source License

/**
 * Returns the formal string representation for this key.
 * /*w  w  w .  j  a v a 2s.  c o  m*/
 * @return The formal string representation for this key. Guaranteed not to
 *         be <code>null</code>.
 * @see java.lang.Object#toString()
 */
public final String toString() {
    final IKeyLookup lookup = KeyLookupFactory.getDefault();
    return lookup.formalNameLookup(key);
}