Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java @ 561:460b8e0f0563
Parse the min/max axes ranges for the ChartInfo and modified the zoom and pan actions to match the current server implementation.
flys-client/trunk@2096 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 09 Jun 2011 10:57:42 +0000 |
parents | 046f43e1d305 |
children | ab8eb2f544f2 |
comparison
equal
deleted
inserted
replaced
560:5274b9317e40 | 561:460b8e0f0563 |
---|---|
1 package de.intevation.flys.client.server; | 1 package de.intevation.flys.client.server; |
2 | 2 |
3 import java.io.InputStream; | 3 import java.io.InputStream; |
4 import java.io.IOException; | 4 import java.io.IOException; |
5 import java.util.ArrayList; | |
6 import java.util.List; | |
5 import java.util.Map; | 7 import java.util.Map; |
6 | 8 |
7 import javax.xml.xpath.XPathConstants; | 9 import javax.xml.xpath.XPathConstants; |
8 | 10 |
9 import org.w3c.dom.Document; | 11 import org.w3c.dom.Document; |
37 public class ChartInfoServiceImpl | 39 public class ChartInfoServiceImpl |
38 extends RemoteServiceServlet | 40 extends RemoteServiceServlet |
39 implements ChartInfoService | 41 implements ChartInfoService |
40 { | 42 { |
41 public static final String XPATH_TRANSFORM_MATRIX = | 43 public static final String XPATH_TRANSFORM_MATRIX = |
42 "/art:chartinfo/art:transformation-matrix"; | 44 "/art:chartinfo/art:transformation-matrix/art:matrix"; |
43 | 45 |
44 public static final String XPATH_X_AXES = | 46 public static final String XPATH_X_AXES = |
45 "/art:chartinfo/art:axes/art:domain"; | 47 "/art:chartinfo/art:axes/art:domain"; |
46 | 48 |
47 public static final String XPATH_Y_AXES = | 49 public static final String XPATH_Y_AXES = |
89 throw new ServerException(EXCEPTION_STRING); | 91 throw new ServerException(EXCEPTION_STRING); |
90 } | 92 } |
91 | 93 |
92 | 94 |
93 protected ChartInfo parseInfoDocument(Document doc) { | 95 protected ChartInfo parseInfoDocument(Document doc) { |
94 Transform2D transformer = parseTransformationMatrix(doc); | 96 Transform2D[] transformer = parseTransformationMatrix(doc); |
95 Axis[] xAxes = parseXAxes(doc); | 97 Axis[] xAxes = parseXAxes(doc); |
96 Axis[] yAxes = parseYAxes(doc); | 98 Axis[] yAxes = parseYAxes(doc); |
97 | 99 |
98 return new ChartInfo(xAxes, yAxes, transformer); | 100 return new ChartInfo(xAxes, yAxes, transformer); |
99 } | 101 } |
100 | 102 |
101 | 103 |
148 node, "@art:from", ArtifactNamespaceContext.INSTANCE); | 150 node, "@art:from", ArtifactNamespaceContext.INSTANCE); |
149 | 151 |
150 String toStr = XMLUtils.xpathString( | 152 String toStr = XMLUtils.xpathString( |
151 node, "@art:to", ArtifactNamespaceContext.INSTANCE); | 153 node, "@art:to", ArtifactNamespaceContext.INSTANCE); |
152 | 154 |
155 String minStr = XMLUtils.xpathString( | |
156 node, "@art:min", ArtifactNamespaceContext.INSTANCE); | |
157 | |
158 String maxStr = XMLUtils.xpathString( | |
159 node, "@art:max", ArtifactNamespaceContext.INSTANCE); | |
160 | |
153 try { | 161 try { |
154 int pos = Integer.parseInt(posStr); | 162 int pos = Integer.parseInt(posStr); |
155 double from = Double.parseDouble(fromStr); | 163 double from = Double.parseDouble(fromStr); |
156 double to = Double.parseDouble(toStr); | 164 double to = Double.parseDouble(toStr); |
165 double min = Double.parseDouble(minStr); | |
166 double max = Double.parseDouble(maxStr); | |
157 | 167 |
158 if (pos >= result.length) { | 168 if (pos >= result.length) { |
159 // this should never happen | 169 // this should never happen |
160 System.err.println("The axis is out of valid range: " + pos); | 170 System.err.println("The axis is out of valid range: " + pos); |
161 continue; | 171 continue; |
162 } | 172 } |
163 | 173 |
164 result[pos] = new Axis(pos, from, to); | 174 result[pos] = new Axis(pos, from, to, min, max); |
165 } | 175 } |
166 catch (NumberFormatException nfe) { | 176 catch (NumberFormatException nfe) { |
167 nfe.printStackTrace(); | 177 nfe.printStackTrace(); |
168 } | 178 } |
169 } | 179 } |
180 * @param doc The chart info document. | 190 * @param doc The chart info document. |
181 * | 191 * |
182 * @return a Transform2D object to transfrom pixel coordinates into chart | 192 * @return a Transform2D object to transfrom pixel coordinates into chart |
183 * coordinates. | 193 * coordinates. |
184 */ | 194 */ |
185 protected Transform2D parseTransformationMatrix(Document doc) { | 195 protected Transform2D[] parseTransformationMatrix(Document doc) { |
186 System.out.println("ChartInfoServiceImpl.parseTransformationMatrix"); | 196 System.out.println("ChartInfoServiceImpl.parseTransformationMatrix"); |
187 | 197 |
188 Node matrix = (Node) XMLUtils.xpath( | 198 NodeList matrix = (NodeList) XMLUtils.xpath( |
189 doc, | 199 doc, |
190 XPATH_TRANSFORM_MATRIX, | 200 XPATH_TRANSFORM_MATRIX, |
191 XPathConstants.NODE, | 201 XPathConstants.NODESET, |
192 ArtifactNamespaceContext.INSTANCE); | 202 ArtifactNamespaceContext.INSTANCE); |
193 | 203 |
194 if (matrix == null) { | 204 int num = matrix != null ? matrix.getLength() : 0; |
195 return new Transform2D(1d, 1d, 0d, 0d); | 205 |
196 } | 206 List<Transform2D> transformer = new ArrayList<Transform2D>(num); |
197 | 207 |
208 for (int i = 0; i < num; i++) { | |
209 Transform2D t = createTransformer(matrix.item(i)); | |
210 | |
211 if (t == null) { | |
212 System.err.println("Broken transformation matrix at pos: " + i); | |
213 continue; | |
214 } | |
215 | |
216 transformer.add(t); | |
217 } | |
218 | |
219 return (Transform2D[]) transformer.toArray(new Transform2D[num]); | |
220 } | |
221 | |
222 | |
223 protected Transform2D createTransformer(Node matrix) { | |
198 String sx = XMLUtils.xpathString( | 224 String sx = XMLUtils.xpathString( |
199 matrix, "@art:sx", ArtifactNamespaceContext.INSTANCE); | 225 matrix, "@art:sx", ArtifactNamespaceContext.INSTANCE); |
200 | 226 |
201 String sy = XMLUtils.xpathString( | 227 String sy = XMLUtils.xpathString( |
202 matrix, "@art:sy", ArtifactNamespaceContext.INSTANCE); | 228 matrix, "@art:sy", ArtifactNamespaceContext.INSTANCE); |