/** * Delegates to ImageJ 1.x' {@link Macro#setOptions(String)} function. * * @param options the macro options, or null to reset */ public void setOptions(final String options) { Macro.setOptions(options); }
static void options() { // Ensure backward compatibility with previous versions: String options = Macro.getOptions(); if (options == null || options.isEmpty()) return; options = options.replaceAll("additive","Additive"); options = options.replaceAll("multiplicative","Multiplicative"); options = options.replaceAll("modulatory","Modulatory"); Macro.setOptions(options); }
static void options() { // Ensure backward compatibility with previous versions: String options = Macro.getOptions(); if (options == null || options.isEmpty()) return; options = options.replaceAll("nearest neighbor",interpolations[0]); options = options.replaceAll("linear",interpolations[1]); options = options.replaceAll("cubic convolution",interpolations[2]); options = options.replaceAll("cubic B-spline",interpolations[3]); options = options.replaceAll("cubic O-MOMS",interpolations[4]); options = options.replaceAll("quintic B-spline",interpolations[5]); options = options.replaceAll("zero",fillings[0]); options = options.replaceAll("minimum",fillings[1]); options = options.replaceAll("maximum",fillings[2]); options = options.replaceAll("repeat",fillings[3]); options = options.replaceAll("mirror",fillings[4]); options = options.replaceAll("clamp",fillings[5]); options = options.replaceAll("translation","distance"); Macro.setOptions(options); }
boolean updateMacroOptions() { String options = Macro.getOptions(); options = options.replace("show=[Overlay Outlines]", "show=Overlay"); Macro.setOptions(options); int index = options.indexOf("maximum="); if (index==-1) return false; index +=8; int len = options.length(); while (index<len-1 && options.charAt(index)!=' ') index++; if (index==len-1) return false; int min = (int)Tools.parseDouble(Macro.getValue(options, "minimum", "1")); int max = (int)Tools.parseDouble(Macro.getValue(options, "maximum", "999999")); options = "size="+min+"-"+max+options.substring(index, len); Macro.setOptions(options); return true; }
boolean updateMacroOptions() { String options = Macro.getOptions(); options = options.replace("show=[Overlay Outlines]", "show=Overlay"); Macro.setOptions(options); int index = options.indexOf("maximum="); if (index==-1) return false; index +=8; int len = options.length(); while (index<len-1 && options.charAt(index)!=' ') index++; if (index==len-1) return false; int min = (int)Tools.parseDouble(Macro.getValue(options, "minimum", "1")); int max = (int)Tools.parseDouble(Macro.getValue(options, "maximum", "999999")); options = "size="+min+"-"+max+options.substring(index, len); Macro.setOptions(options); return true; }
@Override protected void clicked() { if(uiPanel.getParent() instanceof JTabbedPane) { JTabbedPane tabbedPane = (JTabbedPane) uiPanel.getParent(); tabbedPane.setSelectedComponent(uiPanel); } //change thread name temporarily beacuse Macro.getOptions() requires the thread name to start with "Run$_" Thread thr = Thread.currentThread(); String oldThreadName = thr.getName(); thr.setName("Run$_workaround"); //save old options values String oldOptions = Macro.getOptions(); //set macro options and read param values Macro.setOptions(options); params.readMacroOptions(); //restore options values and thread name Macro.setOptions(oldOptions); thr.setName(oldThreadName); params.updateComponents(); }
/** Runs an ImageJ command, with options that are passed to the GenericDialog and OpenDialog classes. Does not return until the command has finished executing. To generate run() calls, start the recorder (Plugins/Macro/Record) and run commands from the ImageJ menu bar. */ public static void run(String command, String options) { //IJ.log("run1: "+command+" "+Thread.currentThread().hashCode()+" "+options); if (ij==null && Menus.getCommands()==null) init(); Macro.abort = false; Macro.setOptions(options); Thread thread = Thread.currentThread(); if (previousThread==null || thread!=previousThread) { String name = thread.getName(); if (!name.startsWith("Run$_")) thread.setName("Run$_"+name); } command = convert(command); previousThread = thread; macroRunning = true; Executer e = new Executer(command); e.run(); macroRunning = false; Macro.setOptions(null); testAbort(); macroInterpreter = null; //IJ.log("run2: "+command+" "+Thread.currentThread().hashCode()); }
String showDialog() { String options = Macro.getOptions(); if (options!=null && !options.contains("slices=")) { Macro.setOptions(options.replace("channels=", "slices=")); Macro.setOptions(options.replace("frames=", "slices=")); } GenericDialog gd = new GenericDialog("Substack Maker"); gd.setInsets(10,45,0); gd.addMessage("Enter a range (e.g. 2-14), a range with increment\n(e.g. 1-100-2) or a list (e.g. 7,9,25,27)", null, Color.darkGray); gd.addStringField("Slices:", "", 40); gd.addCheckbox("Delete slices from original stack", delete); gd.showDialog(); if (gd.wasCanceled()) return null; else { delete = gd.getNextBoolean(); return gd.getNextString(); } }
String showDialog() { String options = Macro.getOptions(); if (options!=null && !options.contains("slices=")) { Macro.setOptions(options.replace("channels=", "slices=")); Macro.setOptions(options.replace("frames=", "slices=")); } GenericDialog gd = new GenericDialog("Substack Maker"); gd.setInsets(10,45,0); gd.addMessage("Enter a range (e.g. 2-14), a range with increment\n(e.g. 1-100-2) or a list (e.g. 7,9,25,27)", null, Color.darkGray); gd.addStringField("Slices:", "", 40); gd.addCheckbox("Delete slices from original stack", delete); gd.showDialog(); if (gd.wasCanceled()) return null; else { delete = gd.getNextBoolean(); return gd.getNextString(); } }
public static void runNestedWithRecording(String command, String options){ String oldCommand = Recorder.getCommand(); Recorder.setCommand(command); Macro.setOptions(options); Executer ex = new Executer(command); ex.run(); Recorder.setCommand(oldCommand); } }
private ImporterOptions getOptions(String macro) { // Manually set the current thread's name, so that Macro.setOptions and // Macro.getOptions will behave as expected. See the implementation of // Macro.getOptions() for more information. Thread current = Thread.currentThread(); current.setName("Run$_" + current.getName()); try { Macro.setOptions(macro); ImporterOptions options = new ImporterOptions(); options.parseArg(macro); options.checkObsoleteOptions(); return options; } catch (IOException e) { fail(e.getMessage()); } return null; }
void open(String path) { Macro.setOptions(null); String name = null; if (path==null || path.equals("")) {
/** Ask the user for the parameters */ public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { String options = Macro.getOptions(); boolean oldMacro = false; //for old macros, "gaussian radius" was 2.5 sigma if (options!=null) { if (options.indexOf("gaussian=") >= 0) { oldMacro = true; Macro.setOptions(options.replaceAll("gaussian=", "radius=")); } } GenericDialog gd = new GenericDialog(command); sigma = Math.abs(sigma); if (weight<0) weight = 0; if (weight>0.99) weight = 0.99; gd.addNumericField("Radius (Sigma)", sigma, 1, 6, "pixels"); gd.addNumericField("Mask Weight (0.1-0.9)", weight,2); gd.addPreviewCheckbox(pfr); gd.addDialogListener(this); gd.showDialog(); //input by the user (or macro) happens here if (gd.wasCanceled()) return DONE; if (oldMacro) sigma /= 2.5; IJ.register(this.getClass()); //protect static class variables (parameters) from garbage collection return IJ.setupDialog(imp, flags); //ask whether to process all slices of stack (if a stack) }
private boolean showDialog(ImagePlus imp) { String options = Macro.getOptions(); if (options!=null) { if (!options.contains("compression=")) options = "compression=JPEG "+options; options = options.replace("compression=Uncompressed", "compression=None"); Macro.setOptions(options); } double fps = getFrameRate(imp); int decimalPlaces = (int) fps == fps?0:1; GenericDialog gd = new GenericDialog("Save as AVI..."); gd.addChoice("Compression:", COMPRESSION_STRINGS, COMPRESSION_STRINGS[compressionIndex]); gd.addNumericField("Frame Rate:", fps, decimalPlaces, 3, "fps"); gd.showDialog(); // user input (or reading from macro) happens here if (gd.wasCanceled()) // dialog cancelled? return false; compressionIndex = gd.getNextChoiceIndex(); fps = gd.getNextNumber(); if (fps<=0.5) fps = 0.5; imp.getCalibration().fps = fps; return true; }
private boolean showDialog(ImagePlus imp) { String options = Macro.getOptions(); if (options!=null) { if (!options.contains("compression=")) options = "compression=JPEG "+options; options = options.replace("compression=Uncompressed", "compression=None"); Macro.setOptions(options); } double fps = getFrameRate(imp); int decimalPlaces = (int) fps == fps?0:1; GenericDialog gd = new GenericDialog("Save as AVI..."); gd.addChoice("Compression:", COMPRESSION_STRINGS, COMPRESSION_STRINGS[compressionIndex]); gd.addNumericField("Frame Rate:", fps, decimalPlaces, 3, "fps"); gd.showDialog(); // user input (or reading from macro) happens here if (gd.wasCanceled()) // dialog cancelled? return false; compressionIndex = gd.getNextChoiceIndex(); fps = gd.getNextNumber(); if (fps<=0.5) fps = 0.5; imp.getCalibration().fps = fps; return true; }
void getMacro(String macro) { String options = Macro.getOptions(); if (options!=null && options.startsWith("v=")) Macro.setOptions("code="+options); gd = new GenericDialog("Expression Evaluator"); gd.addStringField("Code:", macro, 42); gd.setInsets(0,40,0); gd.addMessage("v=pixel value, x,y&z=pixel coordinates, w=image width,\nh=image height, a=angle, d=distance from center\n"); gd.setInsets(5,40,0); gd.addPreviewCheckbox(pfr); gd.addDialogListener(this); gd.addHelp(IJ.URL+"/docs/menus/process.html#math-macro"); gd.showDialog(); }
void getMacro(String macro) { String options = Macro.getOptions(); if (options!=null && options.startsWith("v=")) Macro.setOptions("code="+options); gd = new GenericDialog("Expression Evaluator"); gd.addStringField("Code:", macro, 42); gd.setInsets(0,40,0); gd.addMessage("v=pixel value, x,y&z=pixel coordinates, w=image width,\nh=image height, a=angle, d=distance from center\n"); gd.setInsets(5,40,0); gd.addPreviewCheckbox(pfr); gd.addDialogListener(this); gd.addHelp(IJ.URL+"/docs/menus/process.html#math-macro"); gd.showDialog(); }
/** Ask the user for the parameters */ public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { calledAsPlugin = true;; String options = Macro.getOptions(); boolean oldMacro = false; nChannels = imp.getProcessor().getNChannels(); if (options!=null) { if (options.indexOf("radius=") >= 0) { // ensure compatibility with old macros oldMacro = true; // specifying "radius=", not "sigma= Macro.setOptions(options.replaceAll("radius=", "sigma=")); } } GenericDialog gd = new GenericDialog(command); sigma = Math.abs(sigma); gd.addNumericField("Sigma (Radius):", sigma, 2); if (imp.getCalibration()!=null && !imp.getCalibration().getUnits().equals("pixels")) { hasScale = true; gd.addCheckbox("Scaled Units ("+imp.getCalibration().getUnits()+")", sigmaScaled); } else sigmaScaled = false; gd.addPreviewCheckbox(pfr); gd.addDialogListener(this); gd.showDialog(); // input by the user (or macro) happens here if (gd.wasCanceled()) return DONE; if (oldMacro) sigma /= 2.5; // for old macros, "radius" was 2.5 sigma IJ.register(this.getClass()); // protect static class variables (parameters) from garbage collection return IJ.setupDialog(imp, flags); // ask whether to process all slices of stack (if a stack) }
void showError(String title, String msg, String[] variables) { Macro.setOptions(null); GenericDialog gd = new GenericDialog(title); gd.setInsets(6,5,0); gd.addMessage(msg); gd.setInsets(15,30,5); gd.addCheckbox("Show \"Debug\" Window", showVariables); gd.hideCancelButton(); gd.showDialog(); showVariables = gd.getNextBoolean(); if (!gd.wasCanceled() && showVariables) updateDebugWindow(variables, null); }
void showError(String title, String msg, String[] variables) { Macro.setOptions(null); GenericDialog gd = new GenericDialog(title); gd.setInsets(6,5,0); gd.addMessage(msg); gd.setInsets(15,30,5); gd.addCheckbox("Show \"Debug\" Window", showVariables); gd.hideCancelButton(); gd.showDialog(); showVariables = gd.getNextBoolean(); if (!gd.wasCanceled() && showVariables) updateDebugWindow(variables, null); }