public Channels() { super("Channels"); if (instance != null) { instance.toFront(); return; } WindowManager.addWindow(this); instance = this; GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); int y = 0; c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; int margin = 32; if (IJ.isMacOSX()) margin = 20; c.insets = new Insets(10, margin, 10, margin); choice = new Choice(); for (int i = 0; i < modes.length; i++) choice.addItem(modes[i]); choice.select(0); choice.addItemListener(this); add(choice, c); CompositeImage ci = getImage(); int nCheckBoxes = ci != null ? ci.getNChannels() : 3; if (nCheckBoxes > CompositeImage.MAX_CHANNELS) nCheckBoxes = CompositeImage.MAX_CHANNELS; checkbox = new Checkbox[nCheckBoxes]; for (int i = 0; i < nCheckBoxes; i++) { checkbox[i] = new Checkbox("Channel " + (i + 1), true); c.insets = new Insets(0, 25, i < nCheckBoxes - 1 ? 0 : 10, 5); c.gridy = y++; add(checkbox[i], c); checkbox[i].addItemListener(this); } c.insets = new Insets(0, 15, 10, 15); c.fill = GridBagConstraints.NONE; c.gridy = y++; moreButton = new Button(moreLabel); moreButton.addActionListener(this); add(moreButton, c); update(); pm = new PopupMenu(); for (int i = 0; i < menuItems.length; i++) addPopupItem(menuItems[i]); add(pm); addKeyListener(IJ.getInstance()); // ImageJ handles keyboard shortcuts setResizable(false); pack(); if (location == null) { GUI.center(this); location = getLocation(); } else setLocation(location); show(); }
public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY); DataFlavor[] flavors = null; try { Transferable t = dtde.getTransferable(); iterator = null; flavors = t.getTransferDataFlavors(); if (IJ.debugMode) IJ.log("DragAndDrop.drop: " + flavors.length + " flavors"); for (int i = 0; i < flavors.length; i++) { if (IJ.debugMode) IJ.log(" flavor[" + i + "]: " + flavors[i].getMimeType()); if (flavors[i].isFlavorJavaFileListType()) { Object data = t.getTransferData(DataFlavor.javaFileListFlavor); iterator = ((List) data).iterator(); break; } else if (flavors[i].isFlavorTextType()) { Object ob = t.getTransferData(flavors[i]); if (!(ob instanceof String)) continue; String s = ob.toString().trim(); if (IJ.isLinux() && s.length() > 1 && (int) s.charAt(1) == 0) s = fixLinuxString(s); ArrayList list = new ArrayList(); if (s.indexOf("href=\"") != -1 || s.indexOf("src=\"") != -1) { s = parseHTML(s); if (IJ.debugMode) IJ.log(" url: " + s); list.add(s); this.iterator = list.iterator(); break; } BufferedReader br = new BufferedReader(new StringReader(s)); String tmp; while (null != (tmp = br.readLine())) { tmp = java.net.URLDecoder.decode(tmp.replaceAll("\\+", "%2b"), "UTF-8"); if (tmp.startsWith("file://")) tmp = tmp.substring(7); if (IJ.debugMode) IJ.log(" content: " + tmp); if (tmp.startsWith("http://")) list.add(s); else list.add(new File(tmp)); } this.iterator = list.iterator(); break; } } if (iterator != null) { Thread thread = new Thread(this, "DrawAndDrop"); thread.setPriority(Math.max(thread.getPriority() - 1, Thread.MIN_PRIORITY)); thread.start(); } } catch (Exception e) { dtde.dropComplete(false); return; } dtde.dropComplete(true); if (flavors == null || flavors.length == 0) { if (IJ.isMacOSX()) IJ.error( "First drag and drop ignored. Please try again. You can avoid this\n" + "problem by dragging to the toolbar instead of the status bar."); else IJ.error("Drag and drop failed"); } }
// Input/Output options void io() { GenericDialog gd = new GenericDialog("I/O Options"); gd.addNumericField("JPEG quality (0-100):", FileSaver.getJpegQuality(), 0, 3, ""); gd.addNumericField("GIF and PNG transparent index:", Prefs.getTransparentIndex(), 0, 3, ""); gd.addStringField( "File extension for tables (.txt, .xls or .csv):", Prefs.get("options.ext", ".csv"), 4); gd.addCheckbox("Use JFileChooser to open/save", Prefs.useJFileChooser); if (!IJ.isMacOSX()) gd.addCheckbox("Use_file chooser to import sequences", Prefs.useFileChooser); gd.addCheckbox("Save TIFF and raw in Intel byte order", Prefs.intelByteOrder); gd.addCheckbox("Skip dialog when opening .raw files", Prefs.skipRawDialog); gd.setInsets(15, 20, 0); gd.addMessage("Results Table Options"); gd.setInsets(3, 40, 0); gd.addCheckbox("Copy_column headers", Prefs.copyColumnHeaders); gd.setInsets(0, 40, 0); gd.addCheckbox("Copy_row numbers", !Prefs.noRowNumbers); gd.setInsets(0, 40, 0); gd.addCheckbox("Save_column headers", !Prefs.dontSaveHeaders); gd.setInsets(0, 40, 0); gd.addCheckbox("Save_row numbers", !Prefs.dontSaveRowNumbers); gd.showDialog(); if (gd.wasCanceled()) return; int quality = (int) gd.getNextNumber(); if (quality < 0) quality = 0; if (quality > 100) quality = 100; FileSaver.setJpegQuality(quality); int transparentIndex = (int) gd.getNextNumber(); Prefs.setTransparentIndex(transparentIndex); String extension = gd.getNextString(); if (!extension.startsWith(".")) extension = "." + extension; Prefs.set("options.ext", extension); Prefs.useJFileChooser = gd.getNextBoolean(); if (!IJ.isMacOSX()) Prefs.useFileChooser = gd.getNextBoolean(); Prefs.intelByteOrder = gd.getNextBoolean(); Prefs.skipRawDialog = gd.getNextBoolean(); Prefs.copyColumnHeaders = gd.getNextBoolean(); Prefs.noRowNumbers = !gd.getNextBoolean(); Prefs.dontSaveHeaders = !gd.getNextBoolean(); Prefs.dontSaveRowNumbers = !gd.getNextBoolean(); return; }
// Miscellaneous Options void miscOptions() { String key = IJ.isMacintosh() ? "command" : "control"; GenericDialog gd = new GenericDialog("Miscellaneous Options", IJ.getInstance()); gd.addStringField("Divide by zero value:", "" + FloatBlitter.divideByZeroValue, 10); gd.addCheckbox("Use pointer cursor", Prefs.usePointerCursor); gd.addCheckbox("Hide \"Process Stack?\" dialog", IJ.hideProcessStackDialog); gd.addCheckbox("Require " + key + " key for shortcuts", Prefs.requireControlKey); gd.addCheckbox("Move isolated plugins to Misc. menu", Prefs.moveToMisc); if (!IJ.isMacOSX()) gd.addCheckbox("Run single instance listener", Prefs.runSocketListener); gd.addCheckbox("Enhanced line tool", Prefs.enhancedLineTool); gd.addCheckbox("Reverse CZT order of \">\" and \"<\"", Prefs.reverseNextPreviousOrder); gd.addCheckbox("Debug mode", IJ.debugMode); gd.addHelp(IJ.URL + "/docs/menus/edit.html#misc"); gd.showDialog(); if (gd.wasCanceled()) return; String divValue = gd.getNextString(); if (divValue.equalsIgnoreCase("infinity") || divValue.equalsIgnoreCase("infinite")) FloatBlitter.divideByZeroValue = Float.POSITIVE_INFINITY; else if (divValue.equalsIgnoreCase("NaN")) FloatBlitter.divideByZeroValue = Float.NaN; else if (divValue.equalsIgnoreCase("max")) FloatBlitter.divideByZeroValue = Float.MAX_VALUE; else { Float f; try { f = new Float(divValue); } catch (NumberFormatException e) { f = null; } if (f != null) FloatBlitter.divideByZeroValue = f.floatValue(); } IJ.register(FloatBlitter.class); Prefs.usePointerCursor = gd.getNextBoolean(); IJ.hideProcessStackDialog = gd.getNextBoolean(); Prefs.requireControlKey = gd.getNextBoolean(); Prefs.moveToMisc = gd.getNextBoolean(); if (!IJ.isMacOSX()) Prefs.runSocketListener = gd.getNextBoolean(); Prefs.enhancedLineTool = gd.getNextBoolean(); Prefs.reverseNextPreviousOrder = gd.getNextBoolean(); IJ.setDebugMode(gd.getNextBoolean()); }
public static void main(String args[]) { if (System.getProperty("java.version").substring(0, 3).compareTo("1.5") < 0) { javax.swing.JOptionPane.showMessageDialog( null, "ImageJ " + VERSION + " requires Java 1.5 or later."); System.exit(0); } boolean noGUI = false; int mode = STANDALONE; arguments = args; // System.setProperty("file.encoding", "UTF-8"); int nArgs = args != null ? args.length : 0; boolean commandLine = false; for (int i = 0; i < nArgs; i++) { String arg = args[i]; if (arg == null) continue; if (args[i].startsWith("-")) { if (args[i].startsWith("-batch")) noGUI = true; else if (args[i].startsWith("-debug")) IJ.setDebugMode(true); else if (args[i].startsWith("-ijpath") && i + 1 < nArgs) { if (IJ.debugMode) IJ.log("-ijpath: " + args[i + 1]); Prefs.setHomeDir(args[i + 1]); commandLine = true; args[i + 1] = null; } else if (args[i].startsWith("-port")) { int delta = (int) Tools.parseDouble(args[i].substring(5, args[i].length()), 0.0); commandLine = true; if (delta == 0) mode = EMBEDDED; else if (delta > 0 && DEFAULT_PORT + delta < 65536) port = DEFAULT_PORT + delta; } } } // If existing ImageJ instance, pass arguments to it and quit. boolean passArgs = mode == STANDALONE && !noGUI; if (IJ.isMacOSX() && !commandLine) passArgs = false; if (passArgs && isRunning(args)) return; ImageJ ij = IJ.getInstance(); if (!noGUI && (ij == null || (ij != null && !ij.isShowing()))) { ij = new ImageJ(null, mode); ij.exitWhenQuitting = true; } int macros = 0; for (int i = 0; i < nArgs; i++) { String arg = args[i]; if (arg == null) continue; if (arg.startsWith("-")) { if ((arg.startsWith("-macro") || arg.startsWith("-batch")) && i + 1 < nArgs) { String arg2 = i + 2 < nArgs ? args[i + 2] : null; Prefs.commandLineMacro = true; if (noGUI && args[i + 1].endsWith(".js")) Interpreter.batchMode = true; IJ.runMacroFile(args[i + 1], arg2); break; } else if (arg.startsWith("-eval") && i + 1 < nArgs) { String rtn = IJ.runMacro(args[i + 1]); if (rtn != null) System.out.print(rtn); args[i + 1] = null; } else if (arg.startsWith("-run") && i + 1 < nArgs) { IJ.run(args[i + 1]); args[i + 1] = null; } } else if (macros == 0 && (arg.endsWith(".ijm") || arg.endsWith(".txt"))) { IJ.runMacroFile(arg); macros++; } else if (arg.length() > 0 && arg.indexOf("ij.ImageJ") == -1) { File file = new File(arg); IJ.open(file.getAbsolutePath()); } } if (IJ.debugMode && IJ.getInstance() == null) new JavaProperties().run(""); if (noGUI) System.exit(0); }
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; } } }
/** * If 'applet' is not null, creates a new ImageJ frame that runs as an applet. If 'mode' is * ImageJ.EMBEDDED and 'applet is null, creates an embedded (non-standalone) version of ImageJ. */ public ImageJ(java.applet.Applet applet, int mode) { super("ImageJ"); if ((mode & DEBUG) != 0) IJ.setDebugMode(true); mode = mode & 255; if (IJ.debugMode) IJ.log("ImageJ starting in debug mode: " + mode); embedded = applet == null && (mode == EMBEDDED || mode == NO_SHOW); this.applet = applet; String err1 = Prefs.load(this, applet); setBackground(backgroundColor); Menus m = new Menus(this, applet); String err2 = m.addMenuBar(); m.installPopupMenu(this); setLayout(new BorderLayout()); // Tool bar toolbar = new Toolbar(); toolbar.addKeyListener(this); add("Center", toolbar); // Status bar statusBar = new Panel(); statusBar.setLayout(new BorderLayout()); statusBar.setForeground(Color.black); statusBar.setBackground(backgroundColor); statusLine = new JLabel(); statusLine.setFont(new Font("SansSerif", Font.PLAIN, 13)); statusLine.addKeyListener(this); statusLine.addMouseListener(this); statusBar.add("Center", statusLine); progressBar = new ProgressBar(120, 20); progressBar.addKeyListener(this); progressBar.addMouseListener(this); statusBar.add("East", progressBar); add("South", statusBar); IJ.init(this, applet); addKeyListener(this); addWindowListener(this); setFocusTraversalKeysEnabled(false); m.installStartupMacroSet(); // add custom tools runStartupMacro(); Point loc = getPreferredLocation(); Dimension tbSize = toolbar.getPreferredSize(); setCursor(Cursor.getDefaultCursor()); // work-around for JDK 1.1.8 bug if (mode != NO_SHOW) { if (IJ.isWindows()) try { setIcon(); } catch (Exception e) { } setLocation(loc.x, loc.y); setResizable(!IJ.isMacOSX()); pack(); setVisible(true); } if (err1 != null) IJ.error(err1); if (err2 != null) { IJ.error(err2); IJ.runPlugIn("ij.plugin.ClassChecker", ""); } if (IJ.isMacintosh() && applet == null) { Object qh = null; qh = IJ.runPlugIn("MacAdapter", ""); if (qh == null) IJ.runPlugIn("QuitHandler", ""); } if (applet == null) IJ.runPlugIn("ij.plugin.DragAndDrop", ""); String str = m.getMacroCount() == 1 ? " macro" : " macros"; IJ.showStatus(version() + m.getPluginCount() + " commands; " + m.getMacroCount() + str); configureProxy(); if (applet == null) loadCursors(); }
public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) { if (IJ.isMacOSX()) IJ.wait(50); Calibration cal = imp.getCalibration(); width = gd.getNextNumber(); height = gd.getNextNumber(); xRoi = gd.getNextNumber(); yRoi = gd.getNextNumber(); if (stackSize > 1) iSlice = (int) gd.getNextNumber(); oval = gd.getNextBoolean(); square = gd.getNextBoolean(); centered = gd.getNextBoolean(); if (cal.scaled()) scaledUnits = gd.getNextBoolean(); if (gd.invalidNumber() || width <= 0 || height <= 0) return false; // Vector numFields = gd.getNumericFields(); Vector checkboxes = gd.getCheckboxes(); boolean newWidth = false, newHeight = false, newXY = false; if (e != null && e.getSource() == checkboxes.get(SQUARE) && square) { width = 0.5 * (width + height); // make square: same width&height height = width; newWidth = true; newHeight = true; } if (e != null && e.getSource() == checkboxes.get(CENTERED)) { double shiftBy = centered ? 0.5 : -0.5; // 'centered' changed: xRoi += shiftBy * width; // shift x, y to keep roi the same yRoi += shiftBy * height; newXY = true; } if (square && width != height && e != null) { // in 'square' mode, synchronize width&height if (e.getSource() == numFields.get(WIDTH)) { height = width; newHeight = true; } else if (e.getSource() == numFields.get(HEIGHT)) { width = height; newWidth = true; } } if (e != null && cal.scaled() && e.getSource() == checkboxes.get(SCALED_UNITS)) { double xFactor = scaledUnits ? cal.pixelWidth : 1. / cal.pixelWidth; double yFactor = scaledUnits ? cal.pixelHeight : 1. / cal.pixelHeight; width *= xFactor; // transform everything to keep roi the same height *= yFactor; xRoi *= xFactor; yRoi *= yFactor; newWidth = true; newHeight = true; newXY = true; } int digits = (scaledUnits || (int) width != width) ? 2 : 0; if (newWidth) ((TextField) (numFields.get(WIDTH))).setText(IJ.d2s(width, digits)); if (newHeight) ((TextField) (numFields.get(HEIGHT))).setText(IJ.d2s(height, digits)); digits = (scaledUnits || (int) xRoi != xRoi || (int) yRoi != yRoi) ? 2 : 0; if (newXY) { ((TextField) (numFields.get(X_ROI))).setText(IJ.d2s(xRoi, digits)); ((TextField) (numFields.get(Y_ROI))).setText(IJ.d2s(yRoi, digits)); } if (stackSize > 1 && iSlice > 0 && iSlice <= stackSize) imp.setSlice(iSlice); if (!newWidth && !newHeight && !newXY) // don't draw if an update will come immediately drawRoi(); return true; }