/** Returns the contents of the next textarea. */ public String getNextText() { String text; if (textAreaIndex == 0 && textArea1 != null) { // textArea1.selectAll(); text = textArea1.getText(); textAreaIndex++; if (macro) text = Macro.getValue(macroOptions, "text1", text); if (recorderOn) { String text2 = text; String cmd = Recorder.getCommand(); if (cmd != null && cmd.equals("Convolve...")) { text2 = text.replaceAll("\n", "\\\\n"); if (!text.endsWith("\n")) text2 = text2 + "\\n"; } else text2 = text.replace('\n', ' '); Recorder.recordOption("text1", text2); } } else if (textAreaIndex == 1 && textArea2 != null) { textArea2.selectAll(); text = textArea2.getText(); textAreaIndex++; if (macro) text = Macro.getValue(macroOptions, "text2", text); if (recorderOn) Recorder.recordOption("text2", text.replace('\n', ' ')); } else text = null; return text; }
boolean updateMacroOptions() { String options = Macro.getOptions(); 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; }
/** Returns the contents of the next text field. */ public String getNextString() { String theText; if (stringField == null) return ""; TextField tf = (TextField) (stringField.elementAt(sfIndex)); theText = tf.getText(); if (macro) { String label = (String) labels.get((Object) tf); theText = Macro.getValue(macroOptions, label, theText); if (theText != null && (theText.startsWith("&") || label.toLowerCase(Locale.US).startsWith(theText))) { // Is the value a macro variable? if (theText.startsWith("&")) theText = theText.substring(1); Interpreter interp = Interpreter.getInstance(); String s = interp != null ? interp.getVariableAsString(theText) : null; if (s != null) theText = s; } } if (recorderOn) { String s = theText; if (s != null && s.length() >= 3 && Character.isLetter(s.charAt(0)) && s.charAt(1) == ':' && s.charAt(2) == '\\') s = s.replaceAll("\\\\", "\\\\\\\\"); // replace "\" with "\\" in Windows file paths if (!smartRecording || !s.equals((String) defaultStrings.elementAt(sfIndex))) recordOption(tf, s); else if (Recorder.getCommandOptions() == null) Recorder.recordOption(" "); } sfIndex++; return theText; }
/** Returns the index of the selected item in the next popup menu. */ public int getNextChoiceIndex() { if (choice == null) return -1; Choice thisChoice = (Choice) (choice.elementAt(choiceIndex)); int index = thisChoice.getSelectedIndex(); if (macro) { String label = (String) labels.get((Object) thisChoice); String oldItem = thisChoice.getSelectedItem(); int oldIndex = thisChoice.getSelectedIndex(); String item = Macro.getValue(macroOptions, label, oldItem); if (item != null && item.startsWith("&")) // value is macro variable item = getChoiceVariable(item); thisChoice.select(item); index = thisChoice.getSelectedIndex(); if (index == oldIndex && !item.equals(oldItem)) { // is value a macro variable? Interpreter interp = Interpreter.getInstance(); String s = interp != null ? interp.getStringVariable(item) : null; if (s == null) IJ.error(getTitle(), "\"" + item + "\" is not a valid choice for \"" + label + "\""); else item = s; } } if (recorderOn) { int defaultIndex = ((Integer) (defaultChoiceIndexes.elementAt(choiceIndex))).intValue(); if (!(smartRecording && index == defaultIndex)) { String item = thisChoice.getSelectedItem(); if (!(item.equals("*None*") && getTitle().equals("Merge Channels"))) recordOption(thisChoice, thisChoice.getSelectedItem()); } } choiceIndex++; return index; }
/** * Returns the contents of the next numeric field, or NaN if the field does not contain a number. */ public double getNextNumber() { if (numberField == null) return -1.0; TextField tf = (TextField) numberField.elementAt(nfIndex); String theText = tf.getText(); String label = null; if (macro) { label = (String) labels.get((Object) tf); theText = Macro.getValue(macroOptions, label, theText); // IJ.write("getNextNumber: "+label+" "+theText); } String originalText = (String) defaultText.elementAt(nfIndex); double defaultValue = ((Double) (defaultValues.elementAt(nfIndex))).doubleValue(); double value; boolean skipRecording = false; if (theText.equals(originalText)) { value = defaultValue; if (smartRecording) skipRecording = true; } else { Double d = getValue(theText); if (d != null) value = d.doubleValue(); else { // Is the value a macro variable? if (theText.startsWith("&")) theText = theText.substring(1); Interpreter interp = Interpreter.getInstance(); value = interp != null ? interp.getVariable2(theText) : Double.NaN; if (Double.isNaN(value)) { invalidNumber = true; errorMessage = "\"" + theText + "\" is an invalid number"; value = Double.NaN; if (macro) { IJ.error( "Macro Error", "Numeric value expected in run() function\n \n" + " Dialog box title: \"" + getTitle() + "\"\n" + " Key: \"" + label.toLowerCase(Locale.US) + "\"\n" + " Value or variable name: \"" + theText + "\""); } } } } if (recorderOn && !skipRecording) { recordOption(tf, trim(theText)); } nfIndex++; return value; }
/** Returns the selected item in the next radio button group. */ public String getNextRadioButton() { if (radioButtonGroups == null) return null; CheckboxGroup cg = (CheckboxGroup) (radioButtonGroups.elementAt(radioButtonIndex)); radioButtonIndex++; Checkbox checkbox = cg.getSelectedCheckbox(); String item = "null"; if (checkbox != null) item = checkbox.getLabel(); if (macro) { String label = (String) labels.get((Object) cg); item = Macro.getValue(macroOptions, label, item); } if (recorderOn) recordOption(cg, item); return item; }
/** Returns the selected item in the next popup menu. */ public String getNextChoice() { if (choice == null) return ""; Choice thisChoice = (Choice) (choice.elementAt(choiceIndex)); String item = thisChoice.getSelectedItem(); if (macro) { String label = (String) labels.get((Object) thisChoice); item = Macro.getValue(macroOptions, label, item); if (item != null && item.startsWith("&")) // value is macro variable item = getChoiceVariable(item); } if (recorderOn) recordOption(thisChoice, item); choiceIndex++; return item; }