Example #1
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 #2
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 #3
0
 public double parseDouble(String s) {
   if (s == null) return Double.NaN;
   double value = Tools.parseDouble(s);
   if (Double.isNaN(value)) {
     if (s.startsWith("&")) s = s.substring(1);
     Interpreter interp = Interpreter.getInstance();
     value = interp != null ? interp.getVariable2(s) : Double.NaN;
   }
   return value;
 }
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
 private String getChoiceVariable(String item) {
   item = item.substring(1);
   Interpreter interp = Interpreter.getInstance();
   String s = interp != null ? interp.getStringVariable(item) : null;
   if (s == null) {
     double value = interp != null ? interp.getVariable2(item) : Double.NaN;
     if (!Double.isNaN(value)) {
       if ((int) value == value) s = "" + (int) value;
       else s = "" + value;
     }
   }
   if (s != null) item = s;
   return item;
 }
 void drawAllROIs(Graphics g) {
   RoiManager rm = RoiManager.getInstance();
   if (rm == null) {
     rm = Interpreter.getBatchModeRoiManager();
     if (rm != null && rm.getList().getItemCount() == 0) rm = null;
   }
   if (rm == null) {
     // if (showAllList!=null)
     //	overlay = showAllList;
     showAllROIs = false;
     repaint();
     return;
   }
   initGraphics(g, null, showAllColor);
   Hashtable rois = rm.getROIs();
   java.awt.List list = rm.getList();
   boolean drawLabels = rm.getDrawLabels();
   currentRoi = null;
   int n = list.getItemCount();
   if (IJ.debugMode) IJ.log("paint: drawing " + n + " \"Show All\" ROIs");
   if (labelRects == null || labelRects.length != n) labelRects = new Rectangle[n];
   if (!drawLabels) showAllList = new Overlay();
   else showAllList = null;
   if (imp == null) return;
   int currentImage = imp.getCurrentSlice();
   int channel = 0, slice = 0, frame = 0;
   boolean hyperstack = imp.isHyperStack();
   if (hyperstack) {
     channel = imp.getChannel();
     slice = imp.getSlice();
     frame = imp.getFrame();
   }
   drawNames = Prefs.useNamesAsLabels;
   for (int i = 0; i < n; i++) {
     String label = list.getItem(i);
     Roi roi = (Roi) rois.get(label);
     if (roi == null) continue;
     if (showAllList != null) showAllList.add(roi);
     if (i < 200 && drawLabels && roi == imp.getRoi()) currentRoi = roi;
     if (Prefs.showAllSliceOnly && imp.getStackSize() > 1) {
       if (hyperstack && roi.getPosition() == 0) {
         int c = roi.getCPosition();
         int z = roi.getZPosition();
         int t = roi.getTPosition();
         if ((c == 0 || c == channel) && (z == 0 || z == slice) && (t == 0 || t == frame))
           drawRoi(g, roi, drawLabels ? i : -1);
       } else {
         int position = roi.getPosition();
         if (position == 0) position = getSliceNumber(roi.getName());
         if (position == 0 || position == currentImage) drawRoi(g, roi, drawLabels ? i : -1);
       }
     } else drawRoi(g, roi, drawLabels ? i : -1);
   }
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   drawNames = false;
 }
 public void run(String path) {
   if (path == null || path.equals("")) path = showDialog();
   if (path == null) return;
   openingStartupMacrosInEditor = path.indexOf("StartupMacros") != -1;
   String text = open(path);
   if (text != null) {
     String functions = Interpreter.getAdditionalFunctions();
     if (functions != null) {
       if (!(text.endsWith("\n") || functions.startsWith("\n"))) text = text + "\n" + functions;
       else text = text + functions;
     }
     install(text);
   }
 }
 public void installLibrary(String path) {
   String text = open(path);
   if (text != null) Interpreter.setAdditionalFunctions(text);
 }