package edu.jsu.leathrum.mathlets.shared; import java.text.ParsePosition; public class DoubleInputSet extends InputSet implements FieldHandler { public DoubleInputSet(String namestr, int size) { super(namestr, size); } private double val = 0.0; public double getValue() { Number n = AMathlet.getNumberFormat().parse(getInput(), new ParsePosition(0)); if ((n == null) || (getInput().length() == 0)) val = Double.NaN; else val = n.doubleValue(); return val; } public void setValue(double x) { val = x; if (Double.isNaN(val) || Double.isInfinite(val)) super.setInputText(""); else super.setInputText(AMathlet.getNumberFormat().format(val)); this.repaint(); super.select(0,0); } private double def = 0.0; // need to override InputSet's versions of these to allow Locale data public void setDefault(String dval) { def = AMathlet.getNumberFormat().parse(dval, new ParsePosition(0)).doubleValue(); } // this isn't part of the interface, but it seemed like a good idea here public void setDefault(double dval) { def = dval; } public void setToDefault() { setValue(def); } public void setField(String val) { setValue(AMathlet.getNumberFormat().parse(val, new ParsePosition(0)).doubleValue()); } public String getField() { return AMathlet.getNumberFormat().format(val); } }