Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java Tue Jun 07 13:07:27 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java Tue Jun 07 13:26:24 2011 +0000 @@ -8,6 +8,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import com.google.gwt.user.server.rpc.RemoteServiceServlet; @@ -20,6 +21,8 @@ import de.intevation.flys.client.shared.Transform2D; import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Axis; +import de.intevation.flys.client.shared.model.ChartInfo; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.client.services.ChartInfoService; @@ -38,10 +41,16 @@ public static final String XPATH_TRANSFORM_MATRIX = "/art:chartinfo/art:transformation-matrix"; + public static final String XPATH_X_AXES = + "/art:chartinfo/art:axes/art:domain"; + + public static final String XPATH_Y_AXES = + "/art:chartinfo/art:axes/art:range"; + public static final String EXCEPTION_STRING = "error_chart_info_service"; - public Transform2D getChartInfo( + public ChartInfo getChartInfo( Collection collection, String url, String locale, @@ -78,6 +87,86 @@ } + protected ChartInfo parseInfoDocument(Document doc) { + Transform2D transformer = parseTransformationMatrix(doc); + Axis[] xAxes = parseXAxes(doc); + Axis[] yAxes = parseYAxes(doc); + + de.intevation.flys.client.server.XMLDebug.out(doc); + + return new ChartInfo(xAxes, yAxes, transformer); + } + + + protected Axis[] parseXAxes(Document doc) { + System.out.println("ChartInfoServiceImpl.parseXAxes"); + + NodeList axes = (NodeList) XMLUtils.xpath( + doc, + XPATH_X_AXES, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + return parseAxes(axes); + } + + + protected Axis[] parseYAxes(Document doc) { + System.out.println("ChartInfoServiceImpl.parseYAxes"); + + NodeList axes = (NodeList) XMLUtils.xpath( + doc, + XPATH_Y_AXES, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + return parseAxes(axes); + } + + + protected Axis[] parseAxes(NodeList axes) { + System.out.println("ChartInfoServiceImpl.parseAxes"); + + int count = axes != null ? axes.getLength() : 0; + + System.out.println("Chart has " + count + " axes."); + + if (count == 0) { + return null; + } + + Axis[] result = new Axis[count]; + + for (int i = 0; i < count; i++) { + Node node = axes.item(i); + + String posStr = XMLUtils.xpathString( + node, "@art:pos", ArtifactNamespaceContext.INSTANCE); + + String fromStr = XMLUtils.xpathString( + node, "@art:from", ArtifactNamespaceContext.INSTANCE); + + String toStr = XMLUtils.xpathString( + node, "@art:to", ArtifactNamespaceContext.INSTANCE); + + try { + int pos = Integer.parseInt(posStr); + double from = Double.parseDouble(fromStr); + double to = Double.parseDouble(toStr); + + result[pos] = new Axis(pos, from, to); + } + catch (NumberFormatException nfe) { + nfe.printStackTrace(); + } + } + + System.out.println("Parsed " + result.length + " axes"); + + return result; + } + + /** * Parses the chart info document and extract the Transform2D values. * @@ -86,8 +175,8 @@ * @return a Transform2D object to transfrom pixel coordinates into chart * coordinates. */ - protected Transform2D parseInfoDocument(Document doc) { - System.out.println("ChartInfoServiceImpl.parseInfoDocument"); + protected Transform2D parseTransformationMatrix(Document doc) { + System.out.println("ChartInfoServiceImpl.parseTransformationMatrix"); Node matrix = (Node) XMLUtils.xpath( doc,