类java.awt.AWTKeyStroke源码实例Demo

下面列出了怎么用java.awt.AWTKeyStroke的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjdk-8-source   文件: XEmbedHelper.java
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
public static synchronized void install() {
    if(installed) {
        return;
    }
    
    ShortcutAndMenuKeyEventProcessor instance = getDefault();
    
    KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    keyboardFocusManager.addKeyEventDispatcher(instance);
    keyboardFocusManager.addKeyEventPostProcessor(instance);
    // #63252: Disable focus traversal functionality of Ctrl+Tab and Ctrl+Shift+Tab,
    // to allow our own document switching (RecentViewListAction)
    defaultForward = keyboardFocusManager.getDefaultFocusTraversalKeys(
                        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    defaultBackward = keyboardFocusManager.getDefaultFocusTraversalKeys(
                        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    keyboardFocusManager.setDefaultFocusTraversalKeys(
        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
        Collections.singleton(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0))
    );                
    keyboardFocusManager.setDefaultFocusTraversalKeys(
        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
        Collections.singleton(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK))
    );                
}
 
源代码3 项目: TencentKona-8   文件: XEmbedHelper.java
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
源代码4 项目: wandora   文件: SimpleField.java
public void initialize() {
    this.addMouseListener(this);
    // this.setFocusTraversalKeysEnabled(false);
    this.addKeyListener(this);
    this.setFocusable(true);
    this.addFocusListener(this);
    this.setFocusTraversalKeysEnabled(true);
    this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,new HashSet(new EasyVector(new Object[]{AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,0)})));
    this.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,new HashSet(new EasyVector(new Object[]{AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,InputEvent.SHIFT_DOWN_MASK)})));
    this.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    
    // undoManager = new UndoManager();
    // Document document = this.getDocument();
    // document.addUndoableEditListener(undoManager);
 
    this.setMargin(defaultMargins);
    
    this.setDragEnabled(true);
    dt = new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
    
    setPopupMenu();
}
 
源代码5 项目: openjdk-jdk9   文件: TestAWTKeyStroke.java
private static void checkAWTKeyStroke(int keyCode, int modifiers,
        boolean onKeyRelease) throws Exception {

    AWTKeyStroke awtKeyStroke1 = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, onKeyRelease);

    checkAWTKeyStroke(awtKeyStroke1, keyCode, modifiers, onKeyRelease);

    AWTKeyStroke awtKeyStroke2 = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, onKeyRelease);

    if (awtKeyStroke1 != awtKeyStroke2) {
        throw new RuntimeException("AWTKeyStroke is not cached!");
    }

    checkSerializedKeyStroke(awtKeyStroke1);
}
 
源代码6 项目: jdk8u60   文件: XEmbedHelper.java
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: InputContext.java
/**
 * Checks the key event is the input method selection key or not.
 */
private boolean checkInputMethodSelectionKey(KeyEvent event) {
    if (inputMethodSelectionKey != null) {
        AWTKeyStroke aKeyStroke = AWTKeyStroke.getAWTKeyStrokeForEvent(event);
        return inputMethodSelectionKey.equals(aKeyStroke);
    } else {
        return false;
    }
}
 
源代码8 项目: openjdk-8   文件: InputContext.java
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
源代码9 项目: openjdk-jdk9   文件: TestAWTKeyStroke.java
private static void checkSerializedKeyStroke(AWTKeyStroke keyStroke)
        throws Exception {
    if (keyStroke != getSerializedAWTKeyStroke(keyStroke)) {
        throw new RuntimeException("New instance is returned during"
                + " serialization!");
    }
}
 
源代码10 项目: openjdk-jdk9   文件: TestAWTKeyStroke.java
private static void checkAWTKeyStroke(AWTKeyStroke awtKeyStroke,
        int keyCode, int modifiers, boolean onKeyRelease) {

    if (awtKeyStroke.getKeyCode() != keyCode) {
        throw new RuntimeException("Wrong key code!");
    }

    if (awtKeyStroke.getModifiers() != modifiers) {
        throw new RuntimeException("Wrong modifiers!");
    }

    if (awtKeyStroke.isOnKeyRelease() != onKeyRelease) {
        throw new RuntimeException("Wrong on key release!");
    }
}
 
源代码11 项目: jdk8u-jdk   文件: XEmbedClientHelper.java
void registerAccelerator(AWTKeyStroke stroke, int id) {
    if (active) {
        long sym = getX11KeySym(stroke);
        long mods = getX11Mods(stroke);
        sendMessage(server, XEMBED_REGISTER_ACCELERATOR, id, sym, mods);
    }
}
 
源代码12 项目: azure-devops-intellij   文件: SwingHelper.java
/**
 * This method sets the FocusTraversalKeys for a component to be the standard keys.
 * Use this on Tables or TextAreas where you want the tab keys to leave the control.
 *
 * @param component the component that you want to fix tab keys for
 */
public static void fixTabKeys(final JComponent component) {
    final Set<AWTKeyStroke> forward = new HashSet<AWTKeyStroke>(
            component.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    forward.add(KeyStroke.getKeyStroke("TAB"));
    component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forward);
    final Set<AWTKeyStroke> backward = new HashSet<AWTKeyStroke>(
            component.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
    backward.add(KeyStroke.getKeyStroke("shift TAB"));
    component.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backward);
}
 
源代码13 项目: jdk8u-jdk   文件: XEmbedClientHelper.java
void registerAccelerator(AWTKeyStroke stroke, int id) {
    if (active) {
        long sym = getX11KeySym(stroke);
        long mods = getX11Mods(stroke);
        sendMessage(server, XEMBED_REGISTER_ACCELERATOR, id, sym, mods);
    }
}
 
源代码14 项目: hottub   文件: InputContext.java
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
源代码15 项目: jdk8u60   文件: InputContext.java
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
源代码16 项目: jdk8u_jdk   文件: InputContext.java
/**
 * Checks the key event is the input method selection key or not.
 */
private boolean checkInputMethodSelectionKey(KeyEvent event) {
    if (inputMethodSelectionKey != null) {
        AWTKeyStroke aKeyStroke = AWTKeyStroke.getAWTKeyStrokeForEvent(event);
        return inputMethodSelectionKey.equals(aKeyStroke);
    } else {
        return false;
    }
}
 
源代码17 项目: jdk8u_jdk   文件: InputContext.java
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
源代码18 项目: hottub   文件: XEmbedClientHelper.java
long getX11KeySym(AWTKeyStroke stroke) {
    XToolkit.awtLock();
    try {
        return XWindow.getKeySymForAWTKeyCode(stroke.getKeyCode());
    } finally {
        XToolkit.awtUnlock();
    }
}
 
源代码19 项目: JDKSourceCode1.8   文件: MetaData.java
protected Expression instantiate(Object oldInstance, Encoder out) {
    AWTKeyStroke key = (AWTKeyStroke) oldInstance;

    char ch = key.getKeyChar();
    int code = key.getKeyCode();
    int mask = key.getModifiers();
    boolean onKeyRelease = key.isOnKeyRelease();

    Object[] args = null;
    if (ch == KeyEvent.CHAR_UNDEFINED) {
        args = !onKeyRelease
                ? new Object[]{code, mask}
                : new Object[]{code, mask, onKeyRelease};
    } else if (code == KeyEvent.VK_UNDEFINED) {
        if (!onKeyRelease) {
            args = (mask == 0)
                    ? new Object[]{ch}
                    : new Object[]{ch, mask};
        } else if (mask == 0) {
            args = new Object[]{ch, onKeyRelease};
        }
    }
    if (args == null) {
        throw new IllegalStateException("Unsupported KeyStroke: " + key);
    }
    Class<?> type = key.getClass();
    String name = type.getName();
    // get short name of the class
    int index = name.lastIndexOf('.') + 1;
    if (index > 0) {
        name = name.substring(index);
    }
    return new Expression( key, type, "get" + name, args );
}
 
源代码20 项目: jdk8u60   文件: XEmbedClientHelper.java
long getX11KeySym(AWTKeyStroke stroke) {
    XToolkit.awtLock();
    try {
        return XWindow.getKeySymForAWTKeyCode(stroke.getKeyCode());
    } finally {
        XToolkit.awtUnlock();
    }
}
 
源代码21 项目: openjdk-jdk8u   文件: CViewEmbeddedFrame.java
@Override
public void unregisterAccelerator(AWTKeyStroke awtks) {
}
 
源代码22 项目: jdk8u-jdk   文件: CViewEmbeddedFrame.java
@Override
public void registerAccelerator(AWTKeyStroke awtks) {
}
 
源代码23 项目: jdk8u-dev-jdk   文件: EmbeddedFrame.java
/**
 * Need this method to detect when the focus may have chance to leave the
 * focus cycle root which is EmbeddedFrame. Mostly, the code here is copied
 * from DefaultKeyboardFocusManager.processKeyEvent with some minor
 * modifications.
 */
public boolean dispatchKeyEvent(KeyEvent e) {

    Container currentRoot = AWTAccessor.getKeyboardFocusManagerAccessor()
                                .getCurrentFocusCycleRoot();

    // if we are not in EmbeddedFrame's cycle, we should not try to leave.
    if (this != currentRoot) {
        return false;
    }

    // KEY_TYPED events cannot be focus traversal keys
    if (e.getID() == KeyEvent.KEY_TYPED) {
        return false;
    }

    if (!getFocusTraversalKeysEnabled() || e.isConsumed()) {
        return false;
    }

    AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e);
    Set<AWTKeyStroke> toTest;
    Component currentFocused = e.getComponent();

    toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    if (toTest.contains(stroke)) {
        // 6581899: performance improvement for SortingFocusTraversalPolicy
        Component last = getFocusTraversalPolicy().getLastComponent(this);
        if (currentFocused == last || last == null) {
            if (traverseOut(FORWARD)) {
                e.consume();
                return true;
            }
        }
    }

    toTest = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    if (toTest.contains(stroke)) {
        // 6581899: performance improvement for SortingFocusTraversalPolicy
        Component first = getFocusTraversalPolicy().getFirstComponent(this);
        if (currentFocused == first || first == null) {
            if (traverseOut(BACKWARD)) {
                e.consume();
                return true;
            }
        }
    }
    return false;
}
 
源代码24 项目: openjdk-jdk9   文件: EmbeddedFrame.java
/**
 * Need this method to detect when the focus may have chance to leave the
 * focus cycle root which is EmbeddedFrame. Mostly, the code here is copied
 * from DefaultKeyboardFocusManager.processKeyEvent with some minor
 * modifications.
 */
public boolean dispatchKeyEvent(KeyEvent e) {

    Container currentRoot = AWTAccessor.getKeyboardFocusManagerAccessor()
                                .getCurrentFocusCycleRoot();

    // if we are not in EmbeddedFrame's cycle, we should not try to leave.
    if (this != currentRoot) {
        return false;
    }

    // KEY_TYPED events cannot be focus traversal keys
    if (e.getID() == KeyEvent.KEY_TYPED) {
        return false;
    }

    if (!getFocusTraversalKeysEnabled() || e.isConsumed()) {
        return false;
    }

    AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e);
    Set<AWTKeyStroke> toTest;
    Component currentFocused = e.getComponent();

    toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    if (toTest.contains(stroke)) {
        // 6581899: performance improvement for SortingFocusTraversalPolicy
        Component last = getFocusTraversalPolicy().getLastComponent(this);
        if (currentFocused == last || last == null) {
            if (traverseOut(FORWARD)) {
                e.consume();
                return true;
            }
        }
    }

    toTest = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    if (toTest.contains(stroke)) {
        // 6581899: performance improvement for SortingFocusTraversalPolicy
        Component first = getFocusTraversalPolicy().getFirstComponent(this);
        if (currentFocused == first || first == null) {
            if (traverseOut(BACKWARD)) {
                e.consume();
                return true;
            }
        }
    }
    return false;
}
 
源代码25 项目: dragonwell8_jdk   文件: EmbeddedFrame.java
/**
 * Need this method to detect when the focus may have chance to leave the
 * focus cycle root which is EmbeddedFrame. Mostly, the code here is copied
 * from DefaultKeyboardFocusManager.processKeyEvent with some minor
 * modifications.
 */
public boolean dispatchKeyEvent(KeyEvent e) {

    Container currentRoot = AWTAccessor.getKeyboardFocusManagerAccessor()
                                .getCurrentFocusCycleRoot();

    // if we are not in EmbeddedFrame's cycle, we should not try to leave.
    if (this != currentRoot) {
        return false;
    }

    // KEY_TYPED events cannot be focus traversal keys
    if (e.getID() == KeyEvent.KEY_TYPED) {
        return false;
    }

    if (!getFocusTraversalKeysEnabled() || e.isConsumed()) {
        return false;
    }

    AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e);
    Set<AWTKeyStroke> toTest;
    Component currentFocused = e.getComponent();

    toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    if (toTest.contains(stroke)) {
        // 6581899: performance improvement for SortingFocusTraversalPolicy
        Component last = getFocusTraversalPolicy().getLastComponent(this);
        if (currentFocused == last || last == null) {
            if (traverseOut(FORWARD)) {
                e.consume();
                return true;
            }
        }
    }

    toTest = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    if (toTest.contains(stroke)) {
        // 6581899: performance improvement for SortingFocusTraversalPolicy
        Component first = getFocusTraversalPolicy().getFirstComponent(this);
        if (currentFocused == first || first == null) {
            if (traverseOut(BACKWARD)) {
                e.consume();
                return true;
            }
        }
    }
    return false;
}
 
源代码26 项目: jdk8u_jdk   文件: WrongKeyTypedConsumedTest.java
public void start ()
{
    setSize (200,200);
    setVisible(true);
    validate();

    JFrame frame = new JFrame("The Frame");
    Set ftk = new HashSet();
    ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    frame.getContentPane().
        setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
                              ftk);

    JCheckBox checkbox = new JCheckBox("test");
    frame.getContentPane().add(checkbox, BorderLayout.NORTH);

    JTextArea textarea = new JTextArea(40, 10);
    frame.getContentPane().add(textarea);

    frame.pack();
    frame.setVisible(true);
    Util.waitForIdle(robot);

    if (!frame.isActive()) {
        throw new RuntimeException("Test Fialed: frame isn't active");
    }

    // verify if checkbox has focus
    if (!checkbox.isFocusOwner()) {
        checkbox.requestFocusInWindow();
        Util.waitForIdle(robot);
        if (!checkbox.isFocusOwner()) {
            throw new RuntimeException("Test Failed: checkbox doesn't have focus");
        }
    }

    // press VK_DOWN
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if text area has focus
    if (!textarea.isFocusOwner()) {
        throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
    }
    // press '1'
    robot.keyPress(KeyEvent.VK_1);
    robot.delay(50);
    robot.keyRelease(KeyEvent.VK_1);
    robot.delay(50);

    Util.waitForIdle(robot);

    // verify if KEY_TYPED arrived
    if (!"1".equals(textarea.getText())) {
        throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
    }
    System.out.println("Test Passed");
}
 
源代码27 项目: jdk8u-jdk   文件: XEmbedClientHelper.java
long getX11Mods(AWTKeyStroke stroke) {
    return XWindow.getXModifiers(stroke);
}
 
源代码28 项目: jdk8u-dev-jdk   文件: java_awt_AWTKeyStroke.java
protected AWTKeyStroke getObject() {
    return AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_A, InputEvent.SHIFT_DOWN_MASK, true);
}
 
源代码29 项目: openjdk-jdk9   文件: CViewEmbeddedFrame.java
@Override
public void registerAccelerator(AWTKeyStroke awtks) {
}
 
源代码30 项目: openjdk-8-source   文件: java_awt_AWTKeyStroke.java
protected AWTKeyStroke getAnotherObject() {
    return AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK);
}
 
 类所在包
 同包方法