Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java @ 552:6050d49eaba3
Adapted the ChartInfoService to return more information about charts than before. In addition, the PanControl is added to the chart toolbar.
flys-client/trunk@2066 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 07 Jun 2011 13:26:24 +0000 |
parents | e74bf6bfeeb6 |
children | c5fc3fa02edb |
comparison
equal
deleted
inserted
replaced
551:13c7f90917fc | 552:6050d49eaba3 |
---|---|
6 | 6 |
7 import javax.xml.xpath.XPathConstants; | 7 import javax.xml.xpath.XPathConstants; |
8 | 8 |
9 import org.w3c.dom.Document; | 9 import org.w3c.dom.Document; |
10 import org.w3c.dom.Node; | 10 import org.w3c.dom.Node; |
11 import org.w3c.dom.NodeList; | |
11 | 12 |
12 import com.google.gwt.user.server.rpc.RemoteServiceServlet; | 13 import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
13 | 14 |
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; | 15 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
15 import de.intevation.artifacts.common.utils.ClientProtocolUtils; | 16 import de.intevation.artifacts.common.utils.ClientProtocolUtils; |
18 import de.intevation.artifacts.httpclient.http.HttpClient; | 19 import de.intevation.artifacts.httpclient.http.HttpClient; |
19 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | 20 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
20 | 21 |
21 import de.intevation.flys.client.shared.Transform2D; | 22 import de.intevation.flys.client.shared.Transform2D; |
22 import de.intevation.flys.client.shared.exceptions.ServerException; | 23 import de.intevation.flys.client.shared.exceptions.ServerException; |
24 import de.intevation.flys.client.shared.model.Axis; | |
25 import de.intevation.flys.client.shared.model.ChartInfo; | |
23 import de.intevation.flys.client.shared.model.Collection; | 26 import de.intevation.flys.client.shared.model.Collection; |
24 | 27 |
25 import de.intevation.flys.client.client.services.ChartInfoService; | 28 import de.intevation.flys.client.client.services.ChartInfoService; |
26 | 29 |
27 | 30 |
36 implements ChartInfoService | 39 implements ChartInfoService |
37 { | 40 { |
38 public static final String XPATH_TRANSFORM_MATRIX = | 41 public static final String XPATH_TRANSFORM_MATRIX = |
39 "/art:chartinfo/art:transformation-matrix"; | 42 "/art:chartinfo/art:transformation-matrix"; |
40 | 43 |
44 public static final String XPATH_X_AXES = | |
45 "/art:chartinfo/art:axes/art:domain"; | |
46 | |
47 public static final String XPATH_Y_AXES = | |
48 "/art:chartinfo/art:axes/art:range"; | |
49 | |
41 public static final String EXCEPTION_STRING = "error_chart_info_service"; | 50 public static final String EXCEPTION_STRING = "error_chart_info_service"; |
42 | 51 |
43 | 52 |
44 public Transform2D getChartInfo( | 53 public ChartInfo getChartInfo( |
45 Collection collection, | 54 Collection collection, |
46 String url, | 55 String url, |
47 String locale, | 56 String locale, |
48 String type, | 57 String type, |
49 Map<String, String> attr) | 58 Map<String, String> attr) |
76 | 85 |
77 throw new ServerException(EXCEPTION_STRING); | 86 throw new ServerException(EXCEPTION_STRING); |
78 } | 87 } |
79 | 88 |
80 | 89 |
90 protected ChartInfo parseInfoDocument(Document doc) { | |
91 Transform2D transformer = parseTransformationMatrix(doc); | |
92 Axis[] xAxes = parseXAxes(doc); | |
93 Axis[] yAxes = parseYAxes(doc); | |
94 | |
95 de.intevation.flys.client.server.XMLDebug.out(doc); | |
96 | |
97 return new ChartInfo(xAxes, yAxes, transformer); | |
98 } | |
99 | |
100 | |
101 protected Axis[] parseXAxes(Document doc) { | |
102 System.out.println("ChartInfoServiceImpl.parseXAxes"); | |
103 | |
104 NodeList axes = (NodeList) XMLUtils.xpath( | |
105 doc, | |
106 XPATH_X_AXES, | |
107 XPathConstants.NODESET, | |
108 ArtifactNamespaceContext.INSTANCE); | |
109 | |
110 return parseAxes(axes); | |
111 } | |
112 | |
113 | |
114 protected Axis[] parseYAxes(Document doc) { | |
115 System.out.println("ChartInfoServiceImpl.parseYAxes"); | |
116 | |
117 NodeList axes = (NodeList) XMLUtils.xpath( | |
118 doc, | |
119 XPATH_Y_AXES, | |
120 XPathConstants.NODESET, | |
121 ArtifactNamespaceContext.INSTANCE); | |
122 | |
123 return parseAxes(axes); | |
124 } | |
125 | |
126 | |
127 protected Axis[] parseAxes(NodeList axes) { | |
128 System.out.println("ChartInfoServiceImpl.parseAxes"); | |
129 | |
130 int count = axes != null ? axes.getLength() : 0; | |
131 | |
132 System.out.println("Chart has " + count + " axes."); | |
133 | |
134 if (count == 0) { | |
135 return null; | |
136 } | |
137 | |
138 Axis[] result = new Axis[count]; | |
139 | |
140 for (int i = 0; i < count; i++) { | |
141 Node node = axes.item(i); | |
142 | |
143 String posStr = XMLUtils.xpathString( | |
144 node, "@art:pos", ArtifactNamespaceContext.INSTANCE); | |
145 | |
146 String fromStr = XMLUtils.xpathString( | |
147 node, "@art:from", ArtifactNamespaceContext.INSTANCE); | |
148 | |
149 String toStr = XMLUtils.xpathString( | |
150 node, "@art:to", ArtifactNamespaceContext.INSTANCE); | |
151 | |
152 try { | |
153 int pos = Integer.parseInt(posStr); | |
154 double from = Double.parseDouble(fromStr); | |
155 double to = Double.parseDouble(toStr); | |
156 | |
157 result[pos] = new Axis(pos, from, to); | |
158 } | |
159 catch (NumberFormatException nfe) { | |
160 nfe.printStackTrace(); | |
161 } | |
162 } | |
163 | |
164 System.out.println("Parsed " + result.length + " axes"); | |
165 | |
166 return result; | |
167 } | |
168 | |
169 | |
81 /** | 170 /** |
82 * Parses the chart info document and extract the Transform2D values. | 171 * Parses the chart info document and extract the Transform2D values. |
83 * | 172 * |
84 * @param doc The chart info document. | 173 * @param doc The chart info document. |
85 * | 174 * |
86 * @return a Transform2D object to transfrom pixel coordinates into chart | 175 * @return a Transform2D object to transfrom pixel coordinates into chart |
87 * coordinates. | 176 * coordinates. |
88 */ | 177 */ |
89 protected Transform2D parseInfoDocument(Document doc) { | 178 protected Transform2D parseTransformationMatrix(Document doc) { |
90 System.out.println("ChartInfoServiceImpl.parseInfoDocument"); | 179 System.out.println("ChartInfoServiceImpl.parseTransformationMatrix"); |
91 | 180 |
92 Node matrix = (Node) XMLUtils.xpath( | 181 Node matrix = (Node) XMLUtils.xpath( |
93 doc, | 182 doc, |
94 XPATH_TRANSFORM_MATRIX, | 183 XPATH_TRANSFORM_MATRIX, |
95 XPathConstants.NODE, | 184 XPathConstants.NODE, |