private void handleKey(final KeyEvent e) { int modifiers = e.getModifiers(); if (modifiers == myStoredModifiers) { return; } BrowseMode browseMode = getBrowseMode(modifiers); if (browseMode != BrowseMode.None) { TooltipProvider tooltipProvider = myTooltipProvider; if (tooltipProvider != null) { if (browseMode != tooltipProvider.getBrowseMode()) { disposeHighlighter(); } myStoredModifiers = modifiers; cancelPreviousTooltip(); myTooltipProvider = new TooltipProvider(tooltipProvider.myEditor, tooltipProvider.myPosition); myTooltipProvider.execute(browseMode); } } else { disposeHighlighter(); cancelPreviousTooltip(); } }
@SuppressWarnings("HardCodedStringLiteral") private boolean togglePopup(KeyEvent e) { final KeyStroke stroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers()); final Object action = ((InputMap) UIManager.get("ComboBox.ancestorInputMap")).get(stroke); if ("selectNext".equals(action)) { if (!isPopupShowing()) { return true; } else { return false; } } else if ("togglePopup".equals(action)) { if (isPopupShowing()) { closePopup(); } else { suggestCompletion(true, true); } return true; } else { final Keymap active = KeymapManager.getInstance().getActiveKeymap(); final String[] ids = active.getActionIds(stroke); if (ids.length > 0 && IdeActions.ACTION_CODE_COMPLETION.equals(ids[0])) { suggestCompletion(true, true); } } return false; }
private void txtHotkeyKeyPressed(KeyEvent e) { int code = e.getKeyCode(); int mod = e.getModifiers(); Debug.log(7, "" + code + " " + mod); setTxtHotkey(code, mod); _txtHotkey.setEditable(false); }
public void keyReleased(KeyEvent e) { int keyCode = e.getKeyCode(); IJ.setKeyUp(keyCode); int flags = e.getModifiers(); boolean control = (flags & KeyEvent.CTRL_MASK) != 0; boolean meta = (flags & KeyEvent.META_MASK) != 0; boolean shift = (flags & e.SHIFT_MASK) != 0; if (keyCode == KeyEvent.VK_G && shift && (control || meta)) new ScreenGrabber().run(""); }
private boolean proceedKeyEvent(KeyEvent event, KeyStroke stroke) { if (myInputMap.get(stroke) != null) { final Action action = myActionMap.get(myInputMap.get(stroke)); if (action != null && action.isEnabled()) { action.actionPerformed( new ActionEvent( getContent(), event.getID(), "", event.getWhen(), event.getModifiers())); return true; } } return false; }
private void processTerminalKeyPressed(KeyEvent e) { try { final int keycode = e.getKeyCode(); final char keychar = e.getKeyChar(); // numLock does not change the code sent by keypad VK_DELETE // although it send the char '.' if (keycode == KeyEvent.VK_DELETE && keychar == '.') { myTerminalStarter.sendBytes(new byte[] {'.'}); return; } // CTRL + Space is not handled in KeyEvent; handle it manually else if (keychar == ' ' && (e.getModifiers() & InputEvent.CTRL_MASK) != 0) { myTerminalStarter.sendBytes(new byte[] {Ascii.NUL}); return; } final byte[] code = myTerminalStarter.getCode(keycode, e.getModifiers()); if (code != null) { myTerminalStarter.sendBytes(code); if (mySettingsProvider.scrollToBottomOnTyping() && isCodeThatScrolls(keycode)) { scrollToBottom(); } } else if ((keychar & 0xff00) == 0) { final byte[] obuffer; if (mySettingsProvider.altSendsEscape() && (e.getModifiers() & InputEvent.ALT_MASK) != 0) { obuffer = new byte[] {Ascii.ESC, (byte) keychar}; } else { obuffer = new byte[] {(byte) keychar}; } myTerminalStarter.sendBytes(obuffer); if (mySettingsProvider.scrollToBottomOnTyping()) { scrollToBottom(); } } } catch (final Exception ex) { LOG.error("Error sending key to emulator", ex); } }
public final boolean dispatch(KeyEvent event) { if (event.getID() != KeyEvent.KEY_PRESSED && event.getID() != KeyEvent.KEY_RELEASED) { return false; } if (event.getID() == KeyEvent.KEY_PRESSED) { final KeyStroke stroke = KeyStroke.getKeyStroke(event.getKeyCode(), event.getModifiers(), false); if (proceedKeyEvent(event, stroke)) return false; } if (event.getID() == KeyEvent.KEY_RELEASED) { final KeyStroke stroke = KeyStroke.getKeyStroke(event.getKeyCode(), event.getModifiers(), true); return proceedKeyEvent(event, stroke); } myMnemonicsSearch.process(event); mySpeedSearch.process(event); if (event.isConsumed()) return true; process(event); return event.isConsumed(); }
@Override public boolean dispatchKeyEvent(KeyEvent e) { int code = e.getKeyCode(); int modifiers = e.getModifiers(); if (code == KeyEvent.VK_ESCAPE) { if (isShowingSheet()) { discardTopSheet(); return true; } } if (code == KeyEvent.VK_Q && modifiers == Platform.getPlatform().getCommandModifierMask()) { shutdown(); return true; } return false; }
/** * 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(); } }
public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); IJ.setKeyDown(keyCode); if (keyCode == KeyEvent.VK_ENTER && textArea1 == null && okay != null && okay.isEnabled()) { wasOKed = true; if (IJ.isMacOSX()) accessTextFields(); dispose(); } else if (keyCode == KeyEvent.VK_ESCAPE) { wasCanceled = true; dispose(); IJ.resetEscape(); } else if (keyCode == KeyEvent.VK_W && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) { wasCanceled = true; dispose(); } }
public void keyTyped(KeyEvent e) { char keyChar = e.getKeyChar(); int flags = e.getModifiers(); if (IJ.debugMode) IJ.log( "keyTyped: char=\"" + keyChar + "\" (" + (int) keyChar + "), flags= " + Integer.toHexString(flags) + " (" + KeyEvent.getKeyModifiersText(flags) + ")"); if (keyChar == '\\' || keyChar == 171 || keyChar == 223) { if (((flags & Event.ALT_MASK) != 0)) doCommand("Animation Options..."); else doCommand("Start Animation [\\]"); } }
private void processTerminalKeyTyped(KeyEvent e) { final char keychar = e.getKeyChar(); if ((keychar & 0xff00) != 0) { final char[] foo; if (mySettingsProvider.altSendsEscape() && (e.getModifiers() & InputEvent.ALT_MASK) != 0) { foo = new char[] {Ascii.ESC, keychar}; } else { foo = new char[] {keychar}; } try { myTerminalStarter.sendString(new String(foo)); if (mySettingsProvider.scrollToBottomOnTyping()) { scrollToBottom(); } } catch (final RuntimeException ex) { LOG.error("Error sending key to emulator", ex); } } }
private void handleKey(final KeyEvent e) { int modifiers = e.getModifiers(); if (modifiers == myStoredModifiers) { return; } BrowseMode browseMode = getBrowseMode(modifiers); if (browseMode != BrowseMode.None) { if (myTooltipProvider != null) { if (browseMode != myTooltipProvider.getBrowseMode()) { disposeHighlighter(); } myStoredModifiers = modifiers; myTooltipProvider.execute(browseMode); } } else { disposeHighlighter(); myTooltipProvider = null; } }
@SuppressWarnings("HardCodedStringLiteral") private void processListSelection(final KeyEvent e) { if (togglePopup(e)) return; if (!isPopupShowing()) return; final InputMap map = myPathTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); if (map != null) { final Object object = map.get(KeyStroke.getKeyStrokeForEvent(e)); if (object instanceof Action) { final Action action = (Action) object; if (action.isEnabled()) { action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "action")); e.consume(); return; } } } final Object action = getAction(e, myList); if ("selectNextRow".equals(action)) { if (ensureSelectionExists()) { ListScrollingUtil.moveDown(myList, e.getModifiersEx()); } } else if ("selectPreviousRow".equals(action)) { ListScrollingUtil.moveUp(myList, e.getModifiersEx()); } else if ("scrollDown".equals(action)) { ListScrollingUtil.movePageDown(myList); } else if ("scrollUp".equals(action)) { ListScrollingUtil.movePageUp(myList); } else if (getSelectedFileFromCompletionPopup() != null && (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB) && e.getModifiers() == 0) { hideCurrentPopup(); e.consume(); processChosenFromCompletion(e.getKeyCode() == KeyEvent.VK_TAB); } }
public void keyTyped(KeyEvent e) { char code = e.getKeyChar(); if (code == e.VK_ENTER) { // if (dataField != null) { e.setKeyChar(e.CHAR_UNDEFINED); e.setKeyCode(-1); // only fire this event, if the data has been changed if (textField.isDataChanged()) { fireActionPerformed("enter"); } // not shift + enter => focus to next if ((e.getModifiers() & e.SHIFT_MASK) != e.SHIFT_MASK) { this.changeFocusToNext(); } } } else { if (!TKeyLock.keys.isLocked()) { textField.setDataChanged(true); } } }
public void keyTyped(KeyEvent e) { if (debug) { System.out.println( "--- RecordingModule: key typed = " + e + "\n > Key char->int = " + (int) e.getKeyChar()); System.out.println(" -- isActionKey() = " + e.isActionKey()); System.out.println(" -- isISOControl() = " + Character.isISOControl(e.getKeyChar())); System.out.println(" -- isWhitespace() = " + Character.isWhitespace(e.getKeyChar())); } if (isKeyReserved(e)) { return; } if (enabled && !readOnly && lastKeyPressEvent != null) { if (enableKeyboard) { boolean replace = false; String text = ""; if (isControl(e)) { if (lastKeyPressEvent.getKeyCode() == KeyEvent.VK_ENTER) { // Change the Type cmd prior to Typeline if the delay from the last type key is less // than 1 sec if (useTypeline && e.getModifiers() == 0 && lastElement != null) { String s = DocumentUtils.getElementText(lastElement); if (s.startsWith("Type ") && (System.currentTimeMillis() - lastInsertTime) < typelineDelay) { replace = true; text = s.replaceFirst("Type", "Typeline"); } } } if ("".equals(text)) { int count = 1; KeyEvent e2; long lastEventTime = e.getWhen(); // We go through the vector of events and check whether there are events corresponding // to a typed text. for (int i = 0; i < events.size() && events.get(i) instanceof KeyEvent; i++) { e2 = (KeyEvent) events.get(i); if (e.getID() == e2.getID() && e.getKeyChar() == e2.getKeyChar() && e.getKeyCode() == e2.getKeyCode() && e.getModifiers() == e2.getModifiers() && (lastEventTime - e2.getWhen() < keyMutiDelay)) { count++; replace = true; lastEventTime = e2.getWhen(); } else { break; } } text = "Press "; // String modifiers = KeyEvent.getKeyModifiersText(e.getModifiers()); String modifiers = parser.modifiersToString(e.getModifiers()); if (!"".equals(modifiers)) { text += modifiers + "+"; } String charText = KeyEvent.getKeyText(lastKeyPressEvent.getKeyCode()); if (charText == null) { charText = "<unknown>"; } text += charText; if (count > 1) { text += " " + PressCommand.PARAM_COUNT + "=" + count; } if (debug) { System.out.println("--- RecordingModule: Inserting '" + text + "'"); } } } else { text = "" + e.getKeyChar(); KeyEvent e2; // We go through the vector of events and check whether there are events corresponding to // a typed text. for (int i = 0; i < events.size() && events.get(i) instanceof KeyEvent; i++) { e2 = (KeyEvent) events.get(i); if (!isControl(e2) && !e2.isActionKey()) { text = e2.getKeyChar() + text; replace = true; } else { break; } } text = "Type \"" + Utils.escapeUnescapedDoubleQuotes(text) + "\""; } // Insert the command to the current editor insertLine(text, replace, true, false); } insertEvent(e); } }
/** * This method is called when the focused component (and none of its ancestors) want the key * event. This will look up the keystroke to see if any chidren (or subchildren) of the specified * container want a crack at the event. If one of them wants it, then it will "DO-THE-RIGHT-THING" */ public boolean fireKeyboardAction(KeyEvent e, boolean pressed, Container topAncestor) { if (e.isConsumed()) { System.out.println("Acquired pre-used event!"); Thread.dumpStack(); } // There may be two keystrokes associated with a low-level key event; // in this case a keystroke made of an extended key code has a priority. KeyStroke ks; KeyStroke ksE = null; if (e.getID() == KeyEvent.KEY_TYPED) { ks = KeyStroke.getKeyStroke(e.getKeyChar()); } else { if (e.getKeyCode() != e.getExtendedKeyCode()) { ksE = KeyStroke.getKeyStroke(e.getExtendedKeyCode(), e.getModifiers(), !pressed); } ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers(), !pressed); } Hashtable keyMap = containerMap.get(topAncestor); if (keyMap != null) { // this container isn't registered, so bail Object tmp = null; // extended code has priority if (ksE != null) { tmp = keyMap.get(ksE); if (tmp != null) { ks = ksE; } } if (tmp == null) { tmp = keyMap.get(ks); } if (tmp == null) { // don't do anything } else if (tmp instanceof JComponent) { JComponent c = (JComponent) tmp; if (c.isShowing() && c.isEnabled()) { // only give it out if enabled and visible fireBinding(c, ks, e, pressed); } } else if (tmp instanceof Vector) { // more than one comp registered for this Vector v = (Vector) tmp; // There is no well defined order for WHEN_IN_FOCUSED_WINDOW // bindings, but we give precedence to those bindings just // added. This is done so that JMenus WHEN_IN_FOCUSED_WINDOW // bindings are accessed before those of the JRootPane (they // both have a WHEN_IN_FOCUSED_WINDOW binding for enter). for (int counter = v.size() - 1; counter >= 0; counter--) { JComponent c = (JComponent) v.elementAt(counter); // System.out.println("Trying collision: " + c + " vector = "+ v.size()); if (c.isShowing() && c.isEnabled()) { // don't want to give these out fireBinding(c, ks, e, pressed); if (e.isConsumed()) return true; } } } else { System.out.println("Unexpected condition in fireKeyboardAction " + tmp); // This means that tmp wasn't null, a JComponent, or a Vector. What is it? Thread.dumpStack(); } } if (e.isConsumed()) { return true; } // if no one else handled it, then give the menus a crack // The're handled differently. The key is to let any JMenuBars // process the event if (keyMap != null) { Vector v = (Vector) keyMap.get(JMenuBar.class); if (v != null) { Enumeration iter = v.elements(); while (iter.hasMoreElements()) { JMenuBar mb = (JMenuBar) iter.nextElement(); if (mb.isShowing() && mb.isEnabled()) { // don't want to give these out boolean extended = (ksE != null) && !ksE.equals(ks); if (extended) { fireBinding(mb, ksE, e, pressed); } if (!extended || !e.isConsumed()) { fireBinding(mb, ks, e, pressed); } if (e.isConsumed()) { return true; } } } } } return e.isConsumed(); }
private synchronized void type(KeyEvent e) { switch (e.getKeyCode()) { case (KeyEvent.VK_ENTER): if (e.getID() == KeyEvent.KEY_PRESSED) { processCommand(); initCommandPos(); text.setCaretPosition(commandPos); } e.consume(); text.repaint(); break; case (KeyEvent.VK_UP): if (e.getID() == KeyEvent.KEY_PRESSED) prevHistory(); e.consume(); break; case (KeyEvent.VK_DOWN): if (e.getID() == KeyEvent.KEY_PRESSED) nextHistory(); e.consume(); break; case (KeyEvent.VK_LEFT): case (KeyEvent.VK_BACK_SPACE): case (KeyEvent.VK_DELETE): if (text.getCaretPosition() <= commandPos) e.consume(); break; case (KeyEvent.VK_HOME): text.setCaretPosition(commandPos); e.consume(); break; case (KeyEvent.VK_U): if ((e.getModifiers() & InputEvent.CTRL_MASK) > 0) { replaceConsoleText("", commandPos, textLength()); commandHistoryIndex = 0; e.consume(); } break; case (KeyEvent.VK_ALT): case (KeyEvent.VK_CAPS_LOCK): case (KeyEvent.VK_CONTROL): case (KeyEvent.VK_META): case (KeyEvent.VK_SHIFT): case (KeyEvent.VK_PRINTSCREEN): case (KeyEvent.VK_SCROLL_LOCK): case (KeyEvent.VK_PAUSE): case (KeyEvent.VK_INSERT): case (KeyEvent.VK_F1): case (KeyEvent.VK_F2): case (KeyEvent.VK_F3): case (KeyEvent.VK_F4): case (KeyEvent.VK_F5): case (KeyEvent.VK_F6): case (KeyEvent.VK_F7): case (KeyEvent.VK_F8): case (KeyEvent.VK_F9): case (KeyEvent.VK_F10): case (KeyEvent.VK_F11): case (KeyEvent.VK_F12): case (KeyEvent.VK_ESCAPE): case (KeyEvent.VK_C): break; default: if ((e.getModifiers() & (InputEvent.CTRL_MASK | InputEvent.ALT_MASK | InputEvent.META_MASK)) == 0) { moveCaret(); } if ((e.paramString().contains("Backspace")) && (text.getCaretPosition() <= commandPos)) { e.consume(); } break; } }
private static Object getAction(final KeyEvent e, final JComponent comp) { final KeyStroke stroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers()); return comp.getInputMap().get(stroke); }
/** * Notification that a key is released. * * @param e The event that caused this method to be called */ public void keyReleased(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_A: console.messageReport("Antialiasing not supported on Java3D yet."); /* if((e.getModifiers() & KeyEvent.ALT_MASK) != 0) { numSamples = numSamples * 2; int max = getMaximumNumSamples(); // Busy wait till answer comes. Should already be here while(max < 0) { try { Thread.sleep(50); } catch(Exception e2) {} max = getMaximumNumSamples(); } if (numSamples > max) numSamples = 1; statusLabel.setText("Antialiasing samples: " + numSamples + " out of max: " + max); caps.setSampleBuffers(true); caps.setNumSamples(numSamples); resetSurface(); } */ break; case KeyEvent.VK_PAGE_DOWN: vpManager.nextViewpoint(); break; case KeyEvent.VK_PAGE_UP: vpManager.previousViewpoint(); break; case KeyEvent.VK_HOME: vpManager.firstViewpoint(); break; case KeyEvent.VK_END: vpManager.lastViewpoint(); break; case KeyEvent.VK_F: if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) { universe.setNavigationMode("FLY"); } break; case KeyEvent.VK_W: if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) { universe.setNavigationMode("WALK"); } else if ((e.getModifiers() & KeyEvent.ALT_MASK) != 0) { console.messageReport("Wireframe mode not supported on Java3D."); } break; case KeyEvent.VK_E: if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) { universe.setNavigationMode("EXAMINE"); } break; case KeyEvent.VK_Z: if ((e.getModifiers() & KeyEvent.ALT_MASK) != 0) { // Enter/Exit Elumens mode elumensMode = !elumensMode; // JC: We're not dealing with this right now. // resetSurface(); } break; } }
public void keyPressed(KeyEvent e) { if (debug) { System.out.println( "--- RecordingModule: key pressed = " + e + "\n > Key char->int = " + (int) e.getKeyChar()); } // Here we process just action keys because they do not generate KEY_TYPED events. // Other key events are handled by the keyTyped method. lastInteractionTime = System.currentTimeMillis(); if (isKeyReserved(e)) { return; } if (enabled && !readOnly) { // System.out.println("keyPressed (e.isActionKey()=)"+e.isActionKey()+": // "+e.toString()); // TODO: implement text corrections in type like Delete, Backspace if (e.isActionKey()) { if (enableKeyboard) { int count = 1; KeyEvent e2; long lastEventTime = e.getWhen(); // We go through the vector of events and check whether there are events corresponding to // a typed text. for (int i = 0; i < events.size() && events.get(i) instanceof KeyEvent; i++) { e2 = (KeyEvent) events.get(i); if (e.getID() == e2.getID() && e.getKeyChar() == e2.getKeyChar() && e.getKeyCode() == e2.getKeyCode() && e.getModifiers() == e2.getModifiers() && (lastEventTime - e2.getWhen() < keyMutiDelay)) { count++; lastEventTime = e2.getWhen(); } else { break; } } String text = "Press "; // String modifiers = KeyEvent.getKeyModifiersText(e.getModifiers()); String modifiers = parser.modifiersToString(e.getModifiers()); if (!"".equals(modifiers)) { text += modifiers + "+"; } String charText = (String) keyCodes.get(new Integer(e.getKeyCode())); if (charText == null) { charText = "<unknown>"; } text += charText; if (count > 1) { text += " " + PressCommand.PARAM_COUNT + "=" + count; } // text += '\n'; if (debug) { System.out.println("--- RecordingModule: Inserting '" + text + "'"); } // Insert the command to the current editor insertLine(text, count > 1, true, false); } insertEvent(e); } lastKeyPressEvent = e; } }
public void keyPressed(KeyEvent e) { // if (e.isConsumed()) return; int keyCode = e.getKeyCode(); IJ.setKeyDown(keyCode); hotkey = false; if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT) return; char keyChar = e.getKeyChar(); int flags = e.getModifiers(); if (IJ.debugMode) IJ.log( "keyPressed: code=" + keyCode + " (" + KeyEvent.getKeyText(keyCode) + "), char=\"" + keyChar + "\" (" + (int) keyChar + "), flags=" + KeyEvent.getKeyModifiersText(flags)); boolean shift = (flags & KeyEvent.SHIFT_MASK) != 0; boolean control = (flags & KeyEvent.CTRL_MASK) != 0; boolean alt = (flags & KeyEvent.ALT_MASK) != 0; boolean meta = (flags & KeyEvent.META_MASK) != 0; String cmd = null; ImagePlus imp = WindowManager.getCurrentImage(); boolean isStack = (imp != null) && (imp.getStackSize() > 1); if (imp != null && !control && ((keyChar >= 32 && keyChar <= 255) || keyChar == '\b' || keyChar == '\n')) { Roi roi = imp.getRoi(); if (roi instanceof TextRoi) { if ((flags & KeyEvent.META_MASK) != 0 && IJ.isMacOSX()) return; if (alt) { switch (keyChar) { case 'u': case 'm': keyChar = IJ.micronSymbol; break; case 'A': keyChar = IJ.angstromSymbol; break; default: } } ((TextRoi) roi).addChar(keyChar); return; } } // Handle one character macro shortcuts if (!control && !meta) { Hashtable macroShortcuts = Menus.getMacroShortcuts(); if (macroShortcuts.size() > 0) { if (shift) cmd = (String) macroShortcuts.get(new Integer(keyCode + 200)); else cmd = (String) macroShortcuts.get(new Integer(keyCode)); if (cmd != null) { // MacroInstaller.runMacroCommand(cmd); commandName = cmd; MacroInstaller.runMacroShortcut(cmd); return; } } } if ((!Prefs.requireControlKey || control || meta) && keyChar != '+') { Hashtable shortcuts = Menus.getShortcuts(); if (shift) cmd = (String) shortcuts.get(new Integer(keyCode + 200)); else cmd = (String) shortcuts.get(new Integer(keyCode)); } if (cmd == null) { switch (keyChar) { case '<': case ',': if (isStack) cmd = "Previous Slice [<]"; break; case '>': case '.': case ';': if (isStack) cmd = "Next Slice [>]"; break; case '+': case '=': cmd = "In [+]"; break; case '-': cmd = "Out [-]"; break; case '/': cmd = "Reslice [/]..."; break; default: } } if (cmd == null) { switch (keyCode) { case KeyEvent.VK_TAB: WindowManager.putBehind(); return; case KeyEvent.VK_BACK_SPACE: // delete if (deleteOverlayRoi(imp)) return; cmd = "Clear"; hotkey = true; break; // case KeyEvent.VK_BACK_SLASH: cmd=IJ.altKeyDown()?"Animation Options...":"Start // Animation"; break; case KeyEvent.VK_EQUALS: cmd = "In [+]"; break; case KeyEvent.VK_MINUS: cmd = "Out [-]"; break; case KeyEvent.VK_SLASH: case 0xbf: cmd = "Reslice [/]..."; break; case KeyEvent.VK_COMMA: case 0xbc: if (isStack) cmd = "Previous Slice [<]"; break; case KeyEvent.VK_PERIOD: case 0xbe: if (isStack) cmd = "Next Slice [>]"; break; case KeyEvent.VK_LEFT: case KeyEvent.VK_RIGHT: case KeyEvent.VK_UP: case KeyEvent.VK_DOWN: // arrow keys if (imp == null) return; Roi roi = imp.getRoi(); if (IJ.shiftKeyDown() && imp == Orthogonal_Views.getImage()) return; boolean stackKey = imp.getStackSize() > 1 && (roi == null || IJ.shiftKeyDown()); boolean zoomKey = roi == null || IJ.shiftKeyDown() || IJ.controlKeyDown(); if (stackKey && keyCode == KeyEvent.VK_RIGHT) cmd = "Next Slice [>]"; else if (stackKey && keyCode == KeyEvent.VK_LEFT) cmd = "Previous Slice [<]"; else if (zoomKey && keyCode == KeyEvent.VK_DOWN && !ignoreArrowKeys(imp) && Toolbar.getToolId() < Toolbar.SPARE6) cmd = "Out [-]"; else if (zoomKey && keyCode == KeyEvent.VK_UP && !ignoreArrowKeys(imp) && Toolbar.getToolId() < Toolbar.SPARE6) cmd = "In [+]"; else if (roi != null) { if ((flags & KeyEvent.ALT_MASK) != 0) roi.nudgeCorner(keyCode); else roi.nudge(keyCode); return; } break; case KeyEvent.VK_ESCAPE: abortPluginOrMacro(imp); return; case KeyEvent.VK_ENTER: WindowManager.toFront(this); return; default: break; } } if (cmd != null && !cmd.equals("")) { commandName = cmd; if (cmd.equals("Fill") || cmd.equals("Draw")) hotkey = true; if (cmd.charAt(0) == MacroInstaller.commandPrefix) MacroInstaller.runMacroShortcut(cmd); else { doCommand(cmd); keyPressedTime = System.currentTimeMillis(); lastKeyCommand = cmd; } } }
@Override protected void processKeyEvent(KeyEvent evt) { if (evt.getID() == KeyEvent.KEY_PRESSED) { ActionContext ac = VFSBrowser.getActionContext(); int row = parentDirectories.getSelectedIndex(); switch (evt.getKeyCode()) { case KeyEvent.VK_DOWN: evt.consume(); if (row < parentDirectories.getSize().height - 1) parentDirectories.setSelectedIndex(++row); break; case KeyEvent.VK_LEFT: if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) { evt.consume(); browser.previousDirectory(); } else super.processEvent(evt); break; case KeyEvent.VK_RIGHT: if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) { evt.consume(); browser.nextDirectory(); } else super.processEvent(evt); break; case KeyEvent.VK_TAB: evt.consume(); if ((evt.getModifiers() & InputEvent.SHIFT_MASK) > 0) browser.focusOnDefaultComponent(); else table.requestFocus(); break; case KeyEvent.VK_UP: evt.consume(); if (row > 0) { parentDirectories.setSelectedIndex(--row); } break; case KeyEvent.VK_BACK_SPACE: evt.consume(); EditAction up = ac.getAction("vfs.browser.up"); ac.invokeAction(evt, up); break; case KeyEvent.VK_F5: evt.consume(); EditAction reload = ac.getAction("vfs.browser.reload"); ac.invokeAction(evt, reload); break; case KeyEvent.VK_ENTER: evt.consume(); if (row != -1) { // basically the same handling as in ParentMouseHandler#mouseReleased Object obj = parentDirectories.getModel().getElementAt(row); if (obj instanceof VFSFile) { VFSFile dirEntry = (VFSFile) obj; browser.setDirectory(dirEntry.getPath()); if (browser.getMode() == VFSBrowser.BROWSER) focusOnFileView(); } } break; /* These actions don't work because they look at the EntryTable for the current selected * item. We need actions that look at the parentDirectoryList item instead. * case KeyEvent.VK_DELETE: evt.consume(); ea = ac.getAction("vfs.browser.delete"); ac.invokeAction(evt, ea); break; case KeyEvent.CTRL_MASK | KeyEvent.VK_N: evt.consume(); ea = ac.getAction("vfs.browser.new-file"); ac.invokeAction(evt, ea); break; case KeyEvent.VK_INSERT: evt.consume(); ea = ac.getAction("vfs.browser.new-directory"); ac.invokeAction(evt, ea); break; */ } } else if (evt.getID() == KeyEvent.KEY_TYPED) { if (evt.isControlDown() || evt.isAltDown() || evt.isMetaDown()) { evt.consume(); return; } switch (evt.getKeyChar()) { case '~': evt.consume(); if (browser.getMode() == VFSBrowser.BROWSER) browser.setDirectory(System.getProperty("user.home")); break; case '/': evt.consume(); if (browser.getMode() == VFSBrowser.BROWSER) browser.rootDirectory(); break; case '-': evt.consume(); if (browser.getMode() == VFSBrowser.BROWSER) { browser.setDirectory(browser.getView().getBuffer().getDirectory()); } break; } } if (!evt.isConsumed()) super.processKeyEvent(evt); }