/** 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); } }
@Override public void actionPerformed(ActionEvent e) { // System.out.println("MergeAction"); OutlinerCellRendererImpl textArea = null; boolean isIconFocused = true; Component c = (Component) e.getSource(); if (c instanceof OutlineButton) { textArea = ((OutlineButton) c).renderer; } else if (c instanceof OutlineLineNumber) { textArea = ((OutlineLineNumber) c).renderer; } else if (c instanceof OutlineCommentIndicator) { textArea = ((OutlineCommentIndicator) c).renderer; } else if (c instanceof OutlinerCellRendererImpl) { textArea = (OutlinerCellRendererImpl) c; isIconFocused = false; } // Shorthand Node node = textArea.node; JoeTree tree = node.getTree(); OutlineLayoutManager layout = tree.getDocument().panel.layout; // System.out.println(e.getModifiers()); switch (e.getModifiers()) { case 2: if (isIconFocused) { merge(node, tree, layout, false); } break; case 3: if (isIconFocused) { merge(node, tree, layout, true); } break; } }
public void actionPerformed(ActionEvent e) { if (isDirectorySelected()) { File dir = getDirectory(); if (dir != null) { try { // Strip trailing ".." dir = ShellFolder.getNormalizedFile(dir); } catch (IOException ex) { // Ok, use f as is } changeDirectory(dir); return; } } JFileChooser chooser = getFileChooser(); String filename = getFileName(); FileSystemView fs = chooser.getFileSystemView(); File dir = chooser.getCurrentDirectory(); if (filename != null) { // Remove whitespaces from end of filename int i = filename.length() - 1; while (i >= 0 && filename.charAt(i) <= ' ') { i--; } filename = filename.substring(0, i + 1); } if (filename == null || filename.length() == 0) { // no file selected, multiple selection off, therefore cancel the approve action resetGlobFilter(); return; } File selectedFile = null; File[] selectedFiles = null; // Unix: Resolve '~' to user's home directory if (File.separatorChar == '/') { if (filename.startsWith("~/")) { filename = System.getProperty("user.home") + filename.substring(1); } else if (filename.equals("~")) { filename = System.getProperty("user.home"); } } if (chooser.isMultiSelectionEnabled() && filename.length() > 1 && filename.charAt(0) == '"' && filename.charAt(filename.length() - 1) == '"') { List<File> fList = new ArrayList<File>(); String[] files = filename.substring(1, filename.length() - 1).split("\" \""); // Optimize searching files by names in "children" array Arrays.sort(files); File[] children = null; int childIndex = 0; for (String str : files) { File file = fs.createFileObject(str); if (!file.isAbsolute()) { if (children == null) { children = fs.getFiles(dir, false); Arrays.sort(children); } for (int k = 0; k < children.length; k++) { int l = (childIndex + k) % children.length; if (children[l].getName().equals(str)) { file = children[l]; childIndex = l + 1; break; } } } fList.add(file); } if (!fList.isEmpty()) { selectedFiles = fList.toArray(new File[fList.size()]); } resetGlobFilter(); } else { selectedFile = fs.createFileObject(filename); if (!selectedFile.isAbsolute()) { selectedFile = fs.getChild(dir, filename); } // check for wildcard pattern FileFilter currentFilter = chooser.getFileFilter(); if (!selectedFile.exists() && isGlobPattern(filename)) { changeDirectory(selectedFile.getParentFile()); if (globFilter == null) { globFilter = new GlobFilter(); } try { globFilter.setPattern(selectedFile.getName()); if (!(currentFilter instanceof GlobFilter)) { actualFileFilter = currentFilter; } chooser.setFileFilter(null); chooser.setFileFilter(globFilter); return; } catch (PatternSyntaxException pse) { // Not a valid glob pattern. Abandon filter. } } resetGlobFilter(); // Check for directory change action boolean isDir = (selectedFile != null && selectedFile.isDirectory()); boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile)); boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled(); boolean isFileSelEnabled = chooser.isFileSelectionEnabled(); boolean isCtrl = (e != null && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0); if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) { changeDirectory(selectedFile); return; } else if ((isDir || !isFileSelEnabled) && (!isDir || !isDirSelEnabled) && (!isDirSelEnabled || selectedFile.exists())) { selectedFile = null; } } if (selectedFiles != null || selectedFile != null) { if (selectedFiles != null || chooser.isMultiSelectionEnabled()) { if (selectedFiles == null) { selectedFiles = new File[] {selectedFile}; } chooser.setSelectedFiles(selectedFiles); // Do it again. This is a fix for bug 4949273 to force the // selected value in case the ListSelectionModel clears it // for non-existing file names. chooser.setSelectedFiles(selectedFiles); } else { chooser.setSelectedFile(selectedFile); } chooser.approveSelection(); } else { if (chooser.isMultiSelectionEnabled()) { chooser.setSelectedFiles(null); } else { chooser.setSelectedFile(null); } chooser.cancelSelection(); } }
/** * Converts a new event to an old one (used for compatibility). If the new event cannot be * converted (because no old equivalent exists) then this returns null. * * <p>Note: this method is here instead of in each individual new event class in java.awt.event * because we don't want to make it public and it needs to be called from java.awt. */ Event convertToOld() { Object src = getSource(); int newid = id; switch (id) { case KeyEvent.KEY_PRESSED: case KeyEvent.KEY_RELEASED: KeyEvent ke = (KeyEvent) this; if (ke.isActionKey()) { newid = (id == KeyEvent.KEY_PRESSED ? Event.KEY_ACTION : Event.KEY_ACTION_RELEASE); } int keyCode = ke.getKeyCode(); if (keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_ALT) { return null; // suppress modifier keys in old event model. } // no mask for button1 existed in old Event - strip it out return new Event( src, ke.getWhen(), newid, 0, 0, Event.getOldEventKey(ke), (ke.getModifiers() & ~InputEvent.BUTTON1_MASK)); case MouseEvent.MOUSE_PRESSED: case MouseEvent.MOUSE_RELEASED: case MouseEvent.MOUSE_MOVED: case MouseEvent.MOUSE_DRAGGED: case MouseEvent.MOUSE_ENTERED: case MouseEvent.MOUSE_EXITED: MouseEvent me = (MouseEvent) this; // no mask for button1 existed in old Event - strip it out Event olde = new Event( src, me.getWhen(), newid, me.getX(), me.getY(), 0, (me.getModifiers() & ~InputEvent.BUTTON1_MASK)); olde.clickCount = me.getClickCount(); return olde; case FocusEvent.FOCUS_GAINED: return new Event(src, Event.GOT_FOCUS, null); case FocusEvent.FOCUS_LOST: return new Event(src, Event.LOST_FOCUS, null); case WindowEvent.WINDOW_CLOSING: case WindowEvent.WINDOW_ICONIFIED: case WindowEvent.WINDOW_DEICONIFIED: return new Event(src, newid, null); case ComponentEvent.COMPONENT_MOVED: if (src instanceof Frame || src instanceof Dialog) { Point p = ((Component) src).getLocation(); return new Event(src, 0, Event.WINDOW_MOVED, p.x, p.y, 0, 0); } break; case ActionEvent.ACTION_PERFORMED: ActionEvent ae = (ActionEvent) this; String cmd; if (src instanceof Button) { cmd = ((Button) src).getLabel(); } else if (src instanceof MenuItem) { cmd = ((MenuItem) src).getLabel(); } else { cmd = ae.getActionCommand(); } return new Event(src, 0, newid, 0, 0, 0, ae.getModifiers(), cmd); case ItemEvent.ITEM_STATE_CHANGED: ItemEvent ie = (ItemEvent) this; Object arg; if (src instanceof List) { newid = (ie.getStateChange() == ItemEvent.SELECTED ? Event.LIST_SELECT : Event.LIST_DESELECT); arg = ie.getItem(); } else { newid = Event.ACTION_EVENT; if (src instanceof Choice) { arg = ie.getItem(); } else { // Checkbox arg = new Boolean(ie.getStateChange() == ItemEvent.SELECTED); } } return new Event(src, newid, arg); case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED: AdjustmentEvent aje = (AdjustmentEvent) this; switch (aje.getAdjustmentType()) { case AdjustmentEvent.UNIT_INCREMENT: newid = Event.SCROLL_LINE_DOWN; break; case AdjustmentEvent.UNIT_DECREMENT: newid = Event.SCROLL_LINE_UP; break; case AdjustmentEvent.BLOCK_INCREMENT: newid = Event.SCROLL_PAGE_DOWN; break; case AdjustmentEvent.BLOCK_DECREMENT: newid = Event.SCROLL_PAGE_UP; break; case AdjustmentEvent.TRACK: if (aje.getValueIsAdjusting()) { newid = Event.SCROLL_ABSOLUTE; } else { newid = Event.SCROLL_END; } break; default: return null; } return new Event(src, newid, new Integer(aje.getValue())); default: } return null; }