Example #1
0
 /** 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;
 }
Example #2
0
 /** 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;
 }
Example #3
0
 /** 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;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /** Returns the state of the next checkbox. */
 public boolean getNextBoolean() {
   if (checkbox == null) return false;
   Checkbox cb = (Checkbox) (checkbox.elementAt(cbIndex));
   if (recorderOn) recordCheckboxOption(cb);
   boolean state = cb.getState();
   if (macro) {
     String label = (String) labels.get((Object) cb);
     String key = Macro.trimKey(label);
     state = isMatch(macroOptions, key + " ");
   }
   cbIndex++;
   return state;
 }
Example #6
0
 /** 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;
 }
Example #7
0
 /** 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;
 }
Example #8
0
 /** Creates a new GenericDialog using the specified title and parent frame. */
 public GenericDialog(String title, Frame parent) {
   super(parent == null ? new Frame() : parent, title, true);
   if (Prefs.blackCanvas) {
     setForeground(SystemColor.controlText);
     setBackground(SystemColor.control);
   }
   // if (IJ.isLinux())
   //	setBackground(new Color(238, 238, 238));
   grid = new GridBagLayout();
   c = new GridBagConstraints();
   setLayout(grid);
   macroOptions = Macro.getOptions();
   macro = macroOptions != null;
   addKeyListener(this);
   addWindowListener(this);
 }
Example #9
0
 /** Returns true if the user clicked on "Cancel". */
 public boolean wasCanceled() {
   if (wasCanceled) Macro.abort();
   return wasCanceled;
 }