Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | 0ca00d547f35 |
children | 8e66293c5369 |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
1 package de.intevation.flys.artifacts.states; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 | |
5 import org.w3c.dom.Element; | |
6 | |
7 import de.intevation.artifacts.Artifact; | |
8 import de.intevation.artifacts.CallContext; | |
9 | |
10 import de.intevation.artifacts.common.utils.XMLUtils; | |
11 | |
12 import de.intevation.artifactdatabase.ProtocolUtils; | |
13 import de.intevation.artifactdatabase.data.StateData; | |
14 | |
15 import de.intevation.flys.artifacts.FLYSArtifact; | |
16 | |
17 import de.intevation.flys.artifacts.model.FacetTypes; | |
18 import de.intevation.flys.artifacts.resources.Resources; | |
19 | |
20 import de.intevation.flys.utils.FLYSUtils; | |
21 | |
22 | |
23 /** | |
24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
25 */ | |
26 public class ComputationRangeState | |
27 extends RangeState | |
28 implements FacetTypes | |
29 { | |
30 private static Logger logger = | |
31 Logger.getLogger(ComputationRangeState.class); | |
32 | |
33 /** The name of the 'from' field. */ | |
34 public static final String FROM = "ld_from"; | |
35 | |
36 /** The name of the 'to' field. */ | |
37 public static final String TO = "ld_to"; | |
38 | |
39 /** The name of the 'step' field. */ | |
40 public static final String STEP = "ld_step"; | |
41 | |
42 /** The default step width. */ | |
43 public static final int DEFAULT_STEP = 100; | |
44 | |
45 | |
46 public ComputationRangeState() { | |
47 } | |
48 | |
49 | |
50 @Override | |
51 protected Element createData( | |
52 XMLUtils.ElementCreator cr, | |
53 Artifact artifact, | |
54 StateData data, | |
55 CallContext context) | |
56 { | |
57 Element select = ProtocolUtils.createArtNode( | |
58 cr, "select", null, null); | |
59 | |
60 cr.addAttr(select, "name", data.getName(), true); | |
61 | |
62 Element label = ProtocolUtils.createArtNode( | |
63 cr, "label", null, null); | |
64 | |
65 Element choices = ProtocolUtils.createArtNode( | |
66 cr, "choices", null, null); | |
67 | |
68 label.setTextContent(Resources.getMsg( | |
69 context.getMeta(), | |
70 data.getName(), | |
71 data.getName())); | |
72 | |
73 select.appendChild(label); | |
74 | |
75 return select; | |
76 } | |
77 | |
78 | |
79 @Override | |
80 protected Element[] createItems( | |
81 XMLUtils.ElementCreator cr, | |
82 Artifact artifact, | |
83 String name, | |
84 CallContext context) | |
85 { | |
86 double[] minmax = getMinMax(artifact); | |
87 | |
88 double minVal = Double.MIN_VALUE; | |
89 double maxVal = Double.MAX_VALUE; | |
90 | |
91 if (minmax != null) { | |
92 minVal = minmax[0]; | |
93 maxVal = minmax[1]; | |
94 } | |
95 else { | |
96 logger.warn("Could not read min/max distance values!"); | |
97 } | |
98 | |
99 if (name.equals("ld_from")) { | |
100 Element min = createItem( | |
101 cr, | |
102 new String[] {"min", new Double(minVal).toString()}); | |
103 | |
104 return new Element[] { min }; | |
105 } | |
106 else if (name.equals("ld_to")) { | |
107 Element max = createItem( | |
108 cr, | |
109 new String[] {"max", new Double(maxVal).toString()}); | |
110 | |
111 return new Element[] { max }; | |
112 } | |
113 else { | |
114 Element step = createItem( | |
115 cr, | |
116 new String[] {"step", String.valueOf(getDefaultStep())}); | |
117 return new Element[] { step }; | |
118 } | |
119 | |
120 } | |
121 | |
122 | |
123 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { | |
124 Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
125 Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
126 Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
127 | |
128 String[] arr = (String[]) obj; | |
129 | |
130 label.setTextContent(arr[0]); | |
131 value.setTextContent(arr[1]); | |
132 | |
133 item.appendChild(label); | |
134 item.appendChild(value); | |
135 | |
136 return item; | |
137 } | |
138 | |
139 | |
140 @Override | |
141 protected double[] getMinMax(Artifact artifact) { | |
142 FLYSArtifact flysArtifact = (FLYSArtifact) artifact; | |
143 return FLYSUtils.getRiverMinMax(flysArtifact); | |
144 } | |
145 | |
146 | |
147 protected double getDefaultStep() { | |
148 return DEFAULT_STEP; | |
149 } | |
150 | |
151 | |
152 @Override | |
153 protected String getLowerField() { | |
154 return FROM; | |
155 } | |
156 | |
157 | |
158 @Override | |
159 protected String getUpperField() { | |
160 return TO; | |
161 } | |
162 | |
163 | |
164 @Override | |
165 protected String getStepField() { | |
166 return STEP; | |
167 } | |
168 } | |
169 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |