/** Handle menu events. */ public void actionPerformed(ActionEvent e) { if ((e.getSource() instanceof MenuItem)) { MenuItem item = (MenuItem) e.getSource(); String cmd = e.getActionCommand(); commandName = cmd; ImagePlus imp = null; if (item.getParent() == Menus.getOpenRecentMenu()) { new RecentOpener(cmd); // open image in separate thread return; } else if (item.getParent() == Menus.getPopupMenu()) { Object parent = Menus.getPopupMenu().getParent(); if (parent instanceof ImageCanvas) imp = ((ImageCanvas) parent).getImage(); } int flags = e.getModifiers(); hotkey = false; actionPerformedTime = System.currentTimeMillis(); long ellapsedTime = actionPerformedTime - keyPressedTime; if (cmd != null && (ellapsedTime >= 200L || !cmd.equals(lastKeyCommand))) { if ((flags & Event.ALT_MASK) != 0) IJ.setKeyDown(KeyEvent.VK_ALT); if ((flags & Event.SHIFT_MASK) != 0) IJ.setKeyDown(KeyEvent.VK_SHIFT); new Executer(cmd, imp); } lastKeyCommand = null; if (IJ.debugMode) IJ.log("actionPerformed: time=" + ellapsedTime + ", " + e); } }
/** Handles CheckboxMenuItem state changes. */ public void itemStateChanged(ItemEvent e) { MenuItem item = (MenuItem) e.getSource(); MenuComponent parent = (MenuComponent) item.getParent(); String cmd = e.getItem().toString(); if ((Menu) parent == Menus.window) WindowManager.activateWindow(cmd, item); else doCommand(cmd); }
public void actionPerformed(ActionEvent evt) { String cmd = evt.getActionCommand(); ImageJ.setCommandName(cmd); MenuItem item = (MenuItem) evt.getSource(); MenuContainer parent = item.getParent(); if (parent instanceof PopupMenu) { for (int i = 0; i < nMacros; i++) { if (macroNames[i].equals("Popup Menu")) { new MacroRunner(pgm, macroStarts[i], "Popup Menu", cmd); return; } } } runMacro(cmd); }