comparison flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java @ 1507:c21d14e48040

Improved validation and property handling. flys-client/trunk@3645 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 11 Jan 2012 10:21:22 +0000
parents 3304608baf35
children bf080e932d54
comparison
equal deleted inserted replaced
1506:339f8aa641b5 1507:c21d14e48040
1 package de.intevation.flys.client.shared.model; 1 package de.intevation.flys.client.shared.model;
2 2
3 import java.util.HashMap; 3 import java.util.HashMap;
4
5 import com.google.gwt.i18n.client.NumberFormat;
6 import com.google.gwt.core.client.GWT;
4 7
5 /** 8 /**
6 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 9 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
7 */ 10 */
8 public class DoubleProperty extends PropertySetting { 11 public class DoubleProperty extends PropertySetting {
20 * @param name The attribute name. 23 * @param name The attribute name.
21 * @param value The current value. 24 * @param value The current value.
22 */ 25 */
23 public DoubleProperty( 26 public DoubleProperty(
24 String name, 27 String name,
25 String value) 28 Double value)
26 { 29 {
27 this.name = name; 30 this.name = name;
28 this.value = value; 31 this.value = value.toString();
29 this.attributes = new HashMap<String, String>(); 32 this.attributes = new HashMap<String, String>();
30 } 33 }
31 34
35 @Override
36 public Double getValue() {
37 try {
38 GWT.log("returning: " + Double.valueOf(this.value));
39 return Double.valueOf(this.value);
40 }
41 catch(NumberFormatException nfe) {
42 //Should never happen, if property is used correctly.
43 return null;
44 }
45 }
46
47
48 public void setValueFromUI(String value) {
49 NumberFormat nf = NumberFormat.getDecimalFormat();
50 double d;
51 try {
52 d = nf.parse(value);
53 GWT.log("setting " + value + " as " + d);
54 this.value = Double.toString(d);
55 }
56 catch(NumberFormatException nfe) {}
57 }
58
59 public void setValue(Double value) {
60 this.value = value.toString();
61 }
62
63
64 public String toUIString() {
65 double dv;
66 NumberFormat nf = NumberFormat.getDecimalFormat();
67 try {
68 dv = Double.valueOf(this.value).doubleValue();
69 }
70 catch (NumberFormatException nfe) {
71 return null;
72 }
73 return nf.format(dv);
74 }
32 75
33 public Object clone() { 76 public Object clone() {
34 DoubleProperty clone = new DoubleProperty(this.getName(), 77 DoubleProperty clone = new DoubleProperty(this.getName(),
35 this.getValue()); 78 this.getValue());
36 for(String s: this.getAttributeList()) { 79 for(String s: this.getAttributeList()) {
37 clone.setAttribute(s, this.getAttribute(s)); 80 clone.setAttribute(s, this.getAttribute(s));
38 } 81 }
39 return clone; 82 return clone;
40 } 83 }

http://dive4elements.wald.intevation.org