[Thinlet-development] thinlet/src/java/thinlet Thinlet.java,1.3,1.4
Brought to you by:
bajzat
From: <ab...@us...> - 2003-08-08 20:32:38
|
Update of /cvsroot/thinlet/thinlet/src/java/thinlet In directory sc8-pr-cvs1:/tmp/cvs-serv31440 Modified Files: Thinlet.java Log Message: Fix spinbox bugs: * disable non-numeric input * re-parse text value when getting latest integer value Reported by: pb...@ds... (Paul Becker) Index: Thinlet.java =================================================================== RCS file: /cvsroot/thinlet/thinlet/src/java/thinlet/Thinlet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Thinlet.java 8 Jul 2003 01:29:01 -0000 1.3 +++ Thinlet.java 8 Aug 2003 20:32:34 -0000 1.4 @@ -3400,6 +3400,14 @@ return false; } if (insert != null) { + if (getClass(component).equals("spinbox") && !insert.equals("")) { + // allow only numeric values + try { + Integer.parseInt(insert); + } catch(NumberFormatException e) { + return false; + } + } int min = Math.min(movestart, moveend); set(component, "text", text.substring(0, min) + insert + text.substring(Math.max(movestart, moveend))); @@ -5981,6 +5989,16 @@ * Gets the int attribute value of the given component by the attribute key */ public int getInteger(Object component, String key) { + String classname = getClass(component); + // special case for spinbox - try to parse text to get the current value + // if it fails, then return last good value + if (classname.equals("spinbox") && key.equals("value")) { + try { + return Integer.parseInt((String)get(component, "text", "string")); + } catch (NumberFormatException e) { + // fall-through + } + } return ((Integer) get(component, key, "integer")).intValue(); } |