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; }
/** * 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; }
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; }