comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/ComputationRangeState.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java@1358d0c8481c
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.artifacts.states;
2
3 import org.apache.log4j.Logger;
4
5 import org.w3c.dom.Element;
6
7 import org.dive4elements.artifacts.Artifact;
8 import org.dive4elements.artifacts.CallContext;
9
10 import org.dive4elements.artifacts.common.utils.XMLUtils;
11
12 import org.dive4elements.artifactdatabase.ProtocolUtils;
13 import org.dive4elements.artifactdatabase.data.StateData;
14
15 import org.dive4elements.river.artifacts.FLYSArtifact;
16
17 import org.dive4elements.river.artifacts.model.FacetTypes;
18 import org.dive4elements.river.artifacts.resources.Resources;
19
20 import org.dive4elements.river.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 default step width. */
34 public static final int DEFAULT_STEP = 100;
35
36
37 public ComputationRangeState() {
38 }
39
40
41 @Override
42 protected Element createData(
43 XMLUtils.ElementCreator cr,
44 Artifact artifact,
45 StateData data,
46 CallContext context)
47 {
48 Element select = ProtocolUtils.createArtNode(
49 cr, "select", null, null);
50
51 cr.addAttr(select, "name", data.getName(), true);
52
53 Element label = ProtocolUtils.createArtNode(
54 cr, "label", null, null);
55
56 // XXX: DEAD CODE
57 /*
58 Element choices = ProtocolUtils.createArtNode(
59 cr, "choices", null, null);
60 */
61
62 label.setTextContent(Resources.getMsg(
63 context.getMeta(),
64 data.getName(),
65 data.getName()));
66
67 select.appendChild(label);
68
69 return select;
70 }
71
72
73 @Override
74 protected Element[] createItems(
75 XMLUtils.ElementCreator cr,
76 Artifact artifact,
77 String name,
78 CallContext context)
79 {
80 double[] minmax = getMinMax(artifact);
81
82 double minVal = Double.MIN_VALUE;
83 double maxVal = Double.MAX_VALUE;
84
85 if (minmax != null) {
86 minVal = minmax[0];
87 maxVal = minmax[1];
88 }
89 else {
90 logger.warn("Could not read min/max distance values!");
91 }
92
93 if (name.equals("ld_from")) {
94 Element min = createItem(
95 cr,
96 new String[] {"min", new Double(minVal).toString()});
97
98 return new Element[] { min };
99 }
100 else if (name.equals("ld_to")) {
101 Element max = createItem(
102 cr,
103 new String[] {"max", new Double(maxVal).toString()});
104
105 return new Element[] { max };
106 }
107 else {
108 Element step = createItem(
109 cr,
110 new String[] {"step", String.valueOf(getDefaultStep())});
111 return new Element[] { step };
112 }
113
114 }
115
116
117 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) {
118 Element item = ProtocolUtils.createArtNode(cr, "item", null, null);
119 Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
120 Element value = ProtocolUtils.createArtNode(cr, "value", null, null);
121
122 String[] arr = (String[]) obj;
123
124 label.setTextContent(arr[0]);
125 value.setTextContent(arr[1]);
126
127 item.appendChild(label);
128 item.appendChild(value);
129
130 return item;
131 }
132
133
134 @Override
135 protected double[] getMinMax(Artifact artifact) {
136 FLYSArtifact flysArtifact = (FLYSArtifact) artifact;
137 return FLYSUtils.getRiverMinMax(flysArtifact);
138 }
139
140
141 protected double getDefaultStep() {
142 return DEFAULT_STEP;
143 }
144 }
145 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org