package edu.jsu.leathrum.mathlets.shared; import java.text.DecimalFormat; import java.text.ParsePosition; public class IntButtonSet extends AButtonSet { int val = 0; int inc = 1; int def = 0; int min = 0; int max = 10000; boolean cycling = false; DecimalFormat nf; ActionWrapper act = new NullAction(); public void setValue(int newValue) { if (nf == null) { nf = (DecimalFormat) AMathlet.getNumberFormat().clone(); nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(0); } if ((newValue > min - 1) && (newValue < max + 1)) { val = newValue; setValueString(nf.format(newValue)); } } public int getValue() { return val; } public void setRange(int newmin, int newmax) { min = newmin; max = newmax; val = min; def = min; } public void setIncrement(int newinc) { inc = newinc; } public void setButtonAction(ActionWrapper newact) { act = newact; } public void setCycling(boolean newcyc) { cycling = newcyc; } public void setDefault(int newdef) { def = newdef; } // not overriding, but use this instead of AButtonSet version public void setToDefault() { setValue(def); } // overrides // do *not* need to override AButtonSet.getField() public void setField(String s) { if (nf == null) { nf = (DecimalFormat) AMathlet.getNumberFormat().clone(); nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(0); } Number n = nf.parse(s, new ParsePosition(0)); if ((n == null) || (s.length() == 0)) { val = 0; setValueString(""); } else setValue(n.intValue()); } // overrides protected void plusAction() { if (val+incmin-1) { setValue(val-inc); act.doThis(); } else if (cycling) { setValue(max); act.doThis(); } } }