package edu.jsu.leathrum.mathlets.shared; import java.text.ParsePosition; import java.text.DecimalFormat; public class IntInputSet extends InputSet implements FieldHandler { public IntInputSet(String namestr, int size) { super(namestr, size); } private int val = 0; public int getValue() { Number n = AMathlet.getNumberFormat().parse(getInput(), new ParsePosition(0)); if ((n == null) || (getInput().length() == 0)) setValue(0); else val = n.intValue(); return val; } public void setValue(int x) { val = x; DecimalFormat nf = (DecimalFormat) AMathlet.getNumberFormat().clone(); nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(0); super.setInputText(nf.format(val)); this.repaint(); super.select(0,0); } private int def = 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)).intValue(); } // this isn't part of the interface, but it seemed like a good idea here public void setDefault(int dval) { def = dval; } public void setToDefault() { setValue(def); } public void setField(String val) { setValue(AMathlet.getNumberFormat().parse(val, new ParsePosition(0)).intValue()); } public String getField() { DecimalFormat nf = (DecimalFormat) AMathlet.getNumberFormat().clone(); nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(0); return nf.format(val); } }