// Delete preferences file when ImageJ quits private void reset() { if (IJ.showMessageWithCancel( "Reset Preferences", "Preferences will be reset when ImageJ restarts.")) Prefs.resetPreferences(); }
public void run(String arg) { if (arg.equals("menus")) { updateMenus(); return; } if (IJ.getApplet() != null) return; // File file = new File(Prefs.getHomeDir() + File.separator + "ij.jar"); // if (isMac() && !file.exists()) // file = new File(Prefs.getHomeDir() + File.separator + // "ImageJ.app/Contents/Resources/Java/ij.jar"); URL url = getClass().getResource("/ij/IJ.class"); String ij_jar = url == null ? null : url.toString().replaceAll("%20", " "); if (ij_jar == null || !ij_jar.startsWith("jar:file:")) { error("Could not determine location of ij.jar"); return; } int exclamation = ij_jar.indexOf('!'); ij_jar = ij_jar.substring(9, exclamation); if (IJ.debugMode) IJ.log("Updater: " + ij_jar); File file = new File(ij_jar); if (!file.exists()) { error("File not found: " + file.getPath()); return; } if (!file.canWrite()) { String msg = "No write access: " + file.getPath(); if (IJ.isVista()) msg += Prefs.vistaHint; error(msg); return; } String[] list = openUrlAsList(IJ.URL + "/download/jars/list.txt"); int count = list.length + 2; String[] versions = new String[count]; String[] urls = new String[count]; String uv = getUpgradeVersion(); if (uv == null) return; versions[0] = "v" + uv; urls[0] = IJ.URL + "/upgrade/ij.jar"; if (versions[0] == null) return; for (int i = 1; i < count - 1; i++) { String version = list[i - 1]; versions[i] = version.substring(0, version.length() - 1); // remove letter urls[i] = IJ.URL + "/download/jars/ij" + version.substring(1, 2) + version.substring(3, 6) + ".jar"; } versions[count - 1] = "daily build"; urls[count - 1] = IJ.URL + "/ij.jar"; int choice = showDialog(versions); if (choice == -1) return; if (!versions[choice].startsWith("daily") && versions[choice].compareTo("v1.39") < 0 && Menus.getCommands().get("ImageJ Updater") == null) { String msg = "This command is not available in versions of ImageJ prior\n" + "to 1.39 so you will need to install the plugin version at\n" + "<" + IJ.URL + "/plugins/imagej-updater.html>."; if (!IJ.showMessageWithCancel("Update ImageJ", msg)) return; } byte[] jar = getJar(urls[choice]); // file.renameTo(new File(file.getParent()+File.separator+"ij.bak")); if (version().compareTo("1.37v") >= 0) Prefs.savePreferences(); // if (!renameJar(file)) return; // doesn't work on Vista saveJar(file, jar); if (choice < count - 1) // force macro Function Finder to download fresh list new File(IJ.getDirectory("macros") + "functions.html").delete(); System.exit(0); }
public void run(String arg) { imp = IJ.getImage(); int stackSize = imp.getStackSize(); if (imp == null) { IJ.noImage(); return; } // Make sure input image is a stack. if (stackSize == 1) { IJ.error("Z Project", "Stack required"); return; } // Check for inverting LUT. if (imp.getProcessor().isInvertedLut()) { if (!IJ.showMessageWithCancel("ZProjection", lutMessage)) return; } // Set default bounds. int channels = imp.getNChannels(); int frames = imp.getNFrames(); int slices = imp.getNSlices(); isHyperstack = imp.isHyperStack() || (ij.macro.Interpreter.isBatchMode() && ((frames > 1 && frames < stackSize) || (slices > 1 && slices < stackSize))); boolean simpleComposite = channels == stackSize; if (simpleComposite) isHyperstack = false; startSlice = 1; if (isHyperstack) { int nSlices = imp.getNSlices(); if (nSlices > 1) stopSlice = nSlices; else stopSlice = imp.getNFrames(); } else stopSlice = stackSize; // Build control dialog GenericDialog gd = buildControlDialog(startSlice, stopSlice); gd.showDialog(); if (gd.wasCanceled()) return; if (!imp.lock()) return; // exit if in use long tstart = System.currentTimeMillis(); setStartSlice((int) gd.getNextNumber()); setStopSlice((int) gd.getNextNumber()); method = gd.getNextChoiceIndex(); Prefs.set(METHOD_KEY, method); if (isHyperstack) { allTimeFrames = imp.getNFrames() > 1 && imp.getNSlices() > 1 ? gd.getNextBoolean() : false; doHyperStackProjection(allTimeFrames); } else if (imp.getType() == ImagePlus.COLOR_RGB) doRGBProjection(true); else doProjection(true); if (arg.equals("") && projImage != null) { long tstop = System.currentTimeMillis(); projImage.setCalibration(imp.getCalibration()); if (simpleComposite) IJ.run(projImage, "Grays", ""); projImage.show("ZProjector: " + IJ.d2s((tstop - tstart) / 1000.0, 2) + " seconds"); } imp.unlock(); IJ.register(ZProjector.class); return; }