Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/shared/model/DoubleProperty.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java@62332fa199bf |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.shared.model; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 import com.google.gwt.i18n.client.NumberFormat; | |
5 | |
6 import java.util.HashMap; | |
7 | |
8 /** | |
9 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
10 */ | |
11 public class DoubleProperty extends PropertySetting { | |
12 | |
13 /** | |
14 * Create a new DoubleProperty for settings. | |
15 */ | |
16 public DoubleProperty() { | |
17 this.attributes = new HashMap<String, String>(); | |
18 } | |
19 | |
20 | |
21 /** | |
22 * Create a new DoubleProperty. | |
23 * @param name The attribute name. | |
24 * @param value The current value. | |
25 */ | |
26 public DoubleProperty( | |
27 String name, | |
28 Double value) | |
29 { | |
30 this.name = name; | |
31 this.value = value.toString(); | |
32 this.attributes = new HashMap<String, String>(); | |
33 } | |
34 | |
35 @Override | |
36 public Double getValue() { | |
37 try { | |
38 Double value = Double.valueOf(this.value); | |
39 GWT.log("returning: " + value); | |
40 return value; | |
41 } | |
42 catch(NumberFormatException nfe) { | |
43 //Should never happen, if property is used correctly. | |
44 return null; | |
45 } | |
46 } | |
47 | |
48 | |
49 public void setValueFromUI(String value) { | |
50 NumberFormat nf = NumberFormat.getDecimalFormat(); | |
51 double d; | |
52 try { | |
53 d = nf.parse(value); | |
54 GWT.log("setting " + value + " as " + d); | |
55 this.value = Double.toString(d); | |
56 } | |
57 catch(NumberFormatException nfe) {} | |
58 } | |
59 | |
60 public void setValue(Double value) { | |
61 this.value = value.toString(); | |
62 } | |
63 | |
64 | |
65 public String toUIString() { | |
66 double dv; | |
67 NumberFormat nf = NumberFormat.getDecimalFormat(); | |
68 try { | |
69 dv = Double.parseDouble(this.value); | |
70 } | |
71 catch (NumberFormatException nfe) { | |
72 return null; | |
73 } | |
74 return nf.format(dv); | |
75 } | |
76 | |
77 @Override | |
78 public Object clone() { | |
79 DoubleProperty clone = new DoubleProperty(this.getName(), | |
80 this.getValue()); | |
81 for(String s: this.getAttributeList()) { | |
82 clone.setAttribute(s, this.getAttribute(s)); | |
83 } | |
84 return clone; | |
85 } | |
86 } |