java.awt.AWTKeyStroke Java Examples
The following examples show how to use
java.awt.AWTKeyStroke.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XEmbedHelper.java From jdk8u60 with GNU General Public License v2.0 | 7 votes |
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); }
Example #2
Source File: SimpleField.java From wandora with GNU General Public License v3.0 | 6 votes |
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(); }
Example #3
Source File: XEmbedHelper.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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); }
Example #4
Source File: XEmbedHelper.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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); }
Example #5
Source File: ShortcutAndMenuKeyEventProcessor.java From netbeans with Apache License 2.0 | 6 votes |
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)) ); }
Example #6
Source File: TestAWTKeyStroke.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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); }
Example #7
Source File: InputContext.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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; }
Example #8
Source File: XEmbedClientHelper.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
void registerAccelerator(AWTKeyStroke stroke, int id) { if (active) { long sym = getX11KeySym(stroke); long mods = getX11Mods(stroke); sendMessage(server, XEMBED_REGISTER_ACCELERATOR, id, sym, mods); } }
Example #9
Source File: InputContext.java From hottub with GNU General Public License v2.0 | 5 votes |
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; }
Example #10
Source File: TestAWTKeyStroke.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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!"); } }
Example #11
Source File: XEmbedClientHelper.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
void registerAccelerator(AWTKeyStroke stroke, int id) { if (active) { long sym = getX11KeySym(stroke); long mods = getX11Mods(stroke); sendMessage(server, XEMBED_REGISTER_ACCELERATOR, id, sym, mods); } }
Example #12
Source File: InputContext.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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; }
Example #13
Source File: TestAWTKeyStroke.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void checkSerializedKeyStroke(AWTKeyStroke keyStroke) throws Exception { if (keyStroke != getSerializedAWTKeyStroke(keyStroke)) { throw new RuntimeException("New instance is returned during" + " serialization!"); } }
Example #14
Source File: InputContext.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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; } }
Example #15
Source File: XEmbedClientHelper.java From hottub with GNU General Public License v2.0 | 5 votes |
long getX11KeySym(AWTKeyStroke stroke) { XToolkit.awtLock(); try { return XWindow.getKeySymForAWTKeyCode(stroke.getKeyCode()); } finally { XToolkit.awtUnlock(); } }
Example #16
Source File: MetaData.java From JDKSourceCode1.8 with MIT License | 5 votes |
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 ); }
Example #17
Source File: SwingHelper.java From azure-devops-intellij with MIT License | 5 votes |
/** * 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); }
Example #18
Source File: InputContext.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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; }
Example #19
Source File: InputContext.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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; } }
Example #20
Source File: XEmbedClientHelper.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
long getX11KeySym(AWTKeyStroke stroke) { XToolkit.awtLock(); try { return XWindow.getKeySymForAWTKeyCode(stroke.getKeyCode()); } finally { XToolkit.awtUnlock(); } }
Example #21
Source File: XEmbedClientHelper.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
long getX11Mods(AWTKeyStroke stroke) { return XWindow.getXModifiers(stroke); }
Example #22
Source File: XEmbeddedFrame.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void unregisterAccelerator(AWTKeyStroke stroke) { XEmbeddedFramePeer xefp = (XEmbeddedFramePeer) getPeer(); if (xefp != null) { xefp.unregisterAccelerator(stroke); } }
Example #23
Source File: java_awt_AWTKeyStroke.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
protected AWTKeyStroke getObject() { return AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_A, InputEvent.SHIFT_DOWN_MASK, true); }
Example #24
Source File: CBiggerEditField.java From Zettelkasten with GNU General Public License v3.0 | 4 votes |
/** * Create a new bigger input dialog for editing new authors etc. * * @param parent the parent window * @param settings a reference to the settings class * @param title the dialog's title * @param val a default value which should be set to the textfield * @param textfieldval an optional value that should be set to the * bibkey-textfield. Usually only used when a new author is added / edited * and the bibkey is set or changed * @param edittype indicates which kind of data is being edited. */ public CBiggerEditField(java.awt.Frame parent, Settings settings, String title, String val, String textfieldval, int edittype) { super(parent); initComponents(); // set application icon setIconImage(Constants.zknicon.getImage()); initBorders(settings); // usually, the tab key inserts a tab in the textarea-fields, while a ctrl+tab moves // the focus to the next component. here we override this setting, changing the tab-key // to change the focus. if (settings.isSeaGlass()) { jButton1.putClientProperty("JComponent.sizeVariant", "small"); jButton2.putClientProperty("JComponent.sizeVariant", "small"); } // bind our new forward focus traversal keys Set<AWTKeyStroke> newForwardKeys = new HashSet<>(1); newForwardKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0)); jTextAreaBigEdit.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.unmodifiableSet(newForwardKeys)); // bind our new backward focus traversal keys Set<AWTKeyStroke> newBackwardKeys = new HashSet<>(1); newBackwardKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK + KeyEvent.SHIFT_DOWN_MASK)); jTextAreaBigEdit.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.unmodifiableSet(newBackwardKeys)); // these codelines add an escape-listener to the dialog. so, when the user // presses the escape-key, the same action is performed as if the user // presses the cancel button... KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); ActionListener cancelAction = new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent evt) { cancelButton(); } }; getRootPane().registerKeyboardAction(cancelAction, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); // reset return value newValue = null; newBibKey = null; // set dialog's title setTitle(title); // fill textarea with default value if (val != null) { jTextAreaBigEdit.setText(val); } switch (edittype) { case Constants.EDIT_AUTHOR: jPanel1.setVisible(true); if (textfieldval != null) { jTextFieldBibKey.setText(textfieldval); } else { jTextFieldBibKey.setText(""); } break; default: jPanel1.setVisible(false); jTextFieldBibKey.setText(""); break; } }
Example #25
Source File: java_awt_AWTKeyStroke.java From hottub with GNU General Public License v2.0 | 4 votes |
protected AWTKeyStroke getAnotherObject() { return AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK); }
Example #26
Source File: CViewEmbeddedFrame.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override public void unregisterAccelerator(AWTKeyStroke awtks) { }
Example #27
Source File: XEmbedClientHelper.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
long getX11Mods(AWTKeyStroke stroke) { return XWindow.getXModifiers(stroke); }
Example #28
Source File: EmbeddedFrame.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * 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; }
Example #29
Source File: java_awt_AWTKeyStroke.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
protected AWTKeyStroke getAnotherObject() { return AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK); }
Example #30
Source File: XEmbeddedFrame.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void unregisterAccelerator(AWTKeyStroke stroke) { XEmbeddedFramePeer xefp = (XEmbeddedFramePeer) getPeer(); if (xefp != null) { xefp.unregisterAccelerator(stroke); } }