public void keyStrokePressed(KeyStroke keystroke, KeyEvent ke) { if (!keystroke.equals(this.fullscreen_keystroke)) return; if (ke.getComponent() == this.canvas) { this.escapeFromFullsreen(); } else if (ke.getComponent() == this.scrollFrame.getView()) { this.switchToFullsreen(); } }
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_TAB) { if (e.getModifiers() == KeyEvent.SHIFT_MASK) { e.getComponent().transferFocusBackward(); } else { e.getComponent().transferFocus(); } e.consume(); } }
/** * Show popup menu in response to a key event. * * @param e Event. */ @Override protected void showPopup(KeyEvent e) { // Retrieve information if (!(e.getComponent() instanceof MWPane)) { return; } MWPane textPane = (MWPane) e.getComponent(); try { Rectangle rect = textPane.modelToView(textPane.getCaretPosition()); showPopup(textPane, textPane.getSelectionStart(), rect.x, rect.y); } catch (BadLocationException e1) { // } }
public void actionPerformed(@NotNull AnActionEvent event) { if (logger.isDebugEnabled()) { logger.debug("actionPerformed=" + event); } if (!VimPlugin.isEnabled()) { return; } if (event.getInputEvent() instanceof KeyEvent) { KeyEvent ke = (KeyEvent) event.getInputEvent(); Editor editor = event.getData(PlatformDataKeys.EDITOR); if (editor != null) { KeyStroke key = KeyStroke.getKeyStrokeForEvent(ke); KeyHandler.getInstance().handleKey(editor, key, event.getDataContext()); } else { if (ExEntryPanel.getInstance().isActive()) { KeyEvent e = new KeyEvent( ke.getComponent(), ke.getID(), ke.getWhen(), ke.getModifiers(), ke.getKeyCode(), ke.getKeyChar(), ke.getKeyLocation()); ExEntryPanel.getInstance().processKey(e); } } } }
public void keyPressed(KeyEvent e) { KeyStroke currentStroke = KeyStroke.getKeyStrokeForEvent(e); if (e.getKeyCode() == KeyEvent.VK_ENTER) { TreePath path = ((JTree) e.getSource()).getSelectionPath(); if (path == null) { return; } AWorkspaceTreeNode node = (AWorkspaceTreeNode) path.getLastPathComponent(); if (node instanceof IWorkspaceNodeActionListener) { ((IWorkspaceNodeActionListener) node) .handleAction( new WorkspaceActionEvent( node, WorkspaceActionEvent.WSNODE_OPEN_DOCUMENT, 0, 0, e.getComponent())); e.consume(); } } else { for (HotKeyIdentifier id : actionKeyMap.keySet()) { if (currentStroke.equals(id.getKeyStroke())) { if (id.accept(e)) { AFreeplaneAction action = WorkspaceController.getAction(actionKeyMap.get(id)); if (action != null) { action.actionPerformed(new ActionEvent(e.getSource(), 0, null)); } else { LogUtils.info("No action set for: " + id.getKeyStroke()); } } e.consume(); break; } } } }
public static boolean processKeyBindings(final KeyEvent event) { if (event == null || event.isConsumed()) { return false; } Component source = event.getComponent(); return JComponent.processKeyBindings(event, source); }
/** * Processes a key event forwarded from the <code>MenuSelectionManager</code> and changes the menu * selection, if necessary, by using <code>MenuSelectionManager</code>'s API. * * <p>Note: you do not have to forward the event to sub-components. This is done automatically by * the <code>MenuSelectionManager</code>. * * @param e a <code>KeyEvent</code> * @param path the <code>MenuElement</code> path array * @param manager the <code>MenuSelectionManager</code> */ public void processKeyEvent(KeyEvent e, MenuElement path[], MenuSelectionManager manager) { MenuKeyEvent mke = new MenuKeyEvent( e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), path, manager); processMenuKeyEvent(mke); if (mke.isConsumed()) { e.consume(); } }
/** * Redefine some keys behavior. We can't use key listeners, because we have to make something * AFTER standard keys processing. */ @Override protected void processKeyEvent(KeyEvent e) { if (e.getID() != KeyEvent.KEY_PRESSED) { // key released super.processKeyEvent(e); return; } boolean processed = false; boolean mac = StaticUtils.onMacOSX(); Document3 doc = getOmDocument(); // non-standard processing if (isKey(e, KeyEvent.VK_TAB, 0)) { // press TAB when 'Use TAB to advance' if (controller.settings.isUseTabForAdvance()) { controller.nextEntry(); processed = true; } } else if (isKey(e, KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK)) { // press Shift+TAB when 'Use TAB to advance' if (controller.settings.isUseTabForAdvance()) { controller.prevEntry(); processed = true; } } else if (isKey(e, KeyEvent.VK_ENTER, 0)) { // press ENTER if (!controller.settings.isUseTabForAdvance()) { controller.nextEntry(); processed = true; } else { processed = true; } } else if ((!mac && isKey(e, KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK)) || (mac && isKey(e, KeyEvent.VK_ENTER, KeyEvent.META_MASK))) { // press Ctrl+ENTER (Cmd+Enter for MacOS) if (!controller.settings.isUseTabForAdvance()) { controller.prevEntry(); processed = true; } } else if (isKey(e, KeyEvent.VK_ENTER, KeyEvent.SHIFT_MASK)) { // convert Shift+Enter event to straight enter key KeyEvent ke = new KeyEvent(e.getComponent(), e.getID(), e.getWhen(), 0, KeyEvent.VK_ENTER, '\n'); super.processKeyEvent(ke); processed = true; } else if ((!mac && isKey(e, KeyEvent.VK_A, KeyEvent.CTRL_MASK)) || (mac && isKey(e, KeyEvent.VK_A, KeyEvent.META_MASK))) { // handling Ctrl+A manually (Cmd+A for MacOS) setSelectionStart(doc.getTranslationStart()); setSelectionEnd(doc.getTranslationEnd()); processed = true; } else if (isKey(e, KeyEvent.VK_O, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK)) { // handle Ctrl+Shift+O - toggle orientation LTR-RTL controller.toggleOrientation(); processed = true; } else if ((!mac && isKey(e, KeyEvent.VK_BACK_SPACE, KeyEvent.CTRL_MASK)) || (mac && isKey(e, KeyEvent.VK_BACK_SPACE, KeyEvent.ALT_MASK))) { // handle Ctrl+Backspace (Alt+Backspace for MacOS) try { int offset = getCaretPosition(); int prevWord = Utilities.getPreviousWord(this, offset); int c = Math.max(prevWord, doc.getTranslationStart()); setSelectionStart(c); setSelectionEnd(offset); replaceSelection(""); processed = true; } catch (BadLocationException ex) { // do nothing } } else if ((!mac && isKey(e, KeyEvent.VK_DELETE, KeyEvent.CTRL_MASK)) || (mac && isKey(e, KeyEvent.VK_DELETE, KeyEvent.ALT_MASK))) { // handle Ctrl+Backspace (Alt+Delete for MacOS) try { int offset = getCaretPosition(); int nextWord = Utilities.getNextWord(this, offset); int c = Math.min(nextWord, doc.getTranslationEnd()); setSelectionStart(offset); setSelectionEnd(c); replaceSelection(""); processed = true; } catch (BadLocationException ex) { // do nothing } } else if ((!mac && isKey(e, KeyEvent.VK_PAGE_UP, KeyEvent.CTRL_MASK)) || (mac && isKey(e, KeyEvent.VK_PAGE_UP, KeyEvent.META_MASK))) { // Ctrl+PgUp - to the begin of document(Cmd+PgUp for MacOS) setCaretPosition(0); processed = true; } else if ((!mac && isKey(e, KeyEvent.VK_PAGE_DOWN, KeyEvent.CTRL_MASK)) || (mac && isKey(e, KeyEvent.VK_PAGE_DOWN, KeyEvent.META_MASK))) { // Ctrl+PgDn - to the end of document(Cmd+PgDn for MacOS) setCaretPosition(getOmDocument().getLength()); processed = true; } // leave standard processing if need if (processed) { e.consume(); } else { if ((e.getModifiers() & (KeyEvent.CTRL_MASK | KeyEvent.META_MASK | KeyEvent.ALT_MASK)) == 0) { // there is no Alt,Ctrl,Cmd keys, i.e. it's char if (e.getKeyCode() != KeyEvent.VK_SHIFT) { // it's not a single 'shift' press checkAndFixCaret(); } } super.processKeyEvent(e); } controller.showLengthMessage(); // some after-processing catches if (!processed && e.getKeyChar() != 0) { switch (e.getKeyCode()) { case KeyEvent.VK_HOME: case KeyEvent.VK_END: case KeyEvent.VK_LEFT: case KeyEvent.VK_RIGHT: case KeyEvent.VK_UP: case KeyEvent.VK_DOWN: checkAndFixCaret(); } } }
protected void showPopupMenu(final KeyEvent e) { jTree.setSelectionPath(m_Path); final Rectangle pathBounds = jTree.getPathBounds(m_Path); popupMenu.show(e.getComponent(), pathBounds.x, pathBounds.y); }
/** * 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) { // We can't guarantee that this is called on the same AppContext as EmbeddedFrame // belongs to. That's why we can't use public methods to find current focus cycle // root. Instead, we access KFM's private field directly. if (currentCycleRoot == null) { currentCycleRoot = (Field) AccessController.doPrivileged( new PrivilegedAction() { public Object run() { try { Field unaccessibleRoot = KeyboardFocusManager.class.getDeclaredField("currentFocusCycleRoot"); if (unaccessibleRoot != null) { unaccessibleRoot.setAccessible(true); } return unaccessibleRoot; } catch (NoSuchFieldException e1) { assert false; } catch (SecurityException e2) { assert false; } return null; } }); } Container currentRoot = null; if (currentCycleRoot != null) { try { // The field is static, so we can pass null to Field.get() as the argument. currentRoot = (Container) currentCycleRoot.get(null); } catch (IllegalAccessException e3) { // This is impossible: currentCycleRoot would be null if setAccessible failed. assert false; } } // 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 toTest; Component currentFocused = e.getComponent(); Component last = getFocusTraversalPolicy().getLastComponent(this); toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); if (toTest.contains(stroke) && (currentFocused == last || last == null)) { if (traverseOut(FORWARD)) { e.consume(); return true; } } Component first = getFocusTraversalPolicy().getFirstComponent(this); toTest = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); if (toTest.contains(stroke) && (currentFocused == first || first == null)) { if (traverseOut(BACKWARD)) { e.consume(); return true; } } return false; }
/** * implements KeyListener * * @param arg0 */ public void keyTyped(java.awt.event.KeyEvent arg0) { if (bKeyListener) System.out.println("keyTyped=" + arg0.getKeyChar() + ":" + arg0.getComponent().getName()); }