Example usage for javax.swing KeyStroke getKeyStroke

List of usage examples for javax.swing KeyStroke getKeyStroke

Introduction

In this page you can find the example usage for javax.swing KeyStroke getKeyStroke.

Prototype

public static KeyStroke getKeyStroke(int keyCode, int modifiers, boolean onKeyRelease) 

Source Link

Document

Returns a shared instance of a KeyStroke, given a numeric key code and a set of modifiers, specifying whether the key is activated when it is pressed or released.

Usage

From source file:org.eclipse.wb.internal.swing.model.property.editor.accelerator.KeyStrokePropertyEditor.java

@Override
protected void openDialog(Property property) throws Exception {
    KeyStrokeDialog dialog = new KeyStrokeDialog(property.getTitle());
    // set initial KeyStroke
    {/*from w  ww  . j a  v  a  2  s. c  o  m*/
        Object value = property.getValue();
        if (value instanceof KeyStroke) {
            KeyStroke keyStroke = (KeyStroke) value;
            int modifiers = keyStroke.getModifiers();
            int keyCode = keyStroke.getKeyCode();
            boolean onKeyRelease = keyStroke.isOnKeyRelease();
            dialog.setKeyStroke(KeyStroke.getKeyStroke(keyCode, modifiers, onKeyRelease));
        } else {
            dialog.setKeyStroke(KeyStroke.getKeyStroke(0, 0));
        }
    }
    // open dialog
    if (dialog.open() == Window.OK) {
        KeyStroke keyStroke = dialog.getKeyStroke();
        GenericProperty genericProperty = (GenericProperty) property;
        // prepare source
        String source = getKeyStrokeSource(keyStroke);
        // update source
        genericProperty.setExpression(source, Property.UNKNOWN_VALUE);
    }
}