changeset 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 13c7f90917fc
children c5fc3fa02edb
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoService.java flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Axis.java flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartInfo.java
diffstat 8 files changed, 300 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Jun 07 13:07:27 2011 +0000
+++ b/flys-client/ChangeLog	Tue Jun 07 13:26:24 2011 +0000
@@ -1,3 +1,29 @@
+2011-06-07  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/Axis.java: New.
+	  This class should represent an axis in a chart.
+
+	* src/main/java/de/intevation/flys/client/shared/model/ChartInfo.java:
+	  New. This class is used by the ChartInfoService to retrieve more
+	  information about a Chart that just the Transform2D object to reproject
+	  points. It currently stores x and y axes and the Transform2D object of a
+	  chart.
+
+	* src/main/java/de/intevation/flys/client/client/services/ChartInfoServiceAsync.java,
+	  src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java,
+	  src/main/java/de/intevation/flys/client/client/services/ChartInfoService.java:
+	  Changed the return value of this service from Transform2D to ChartInfo.
+	  The Transform2D object is included in this new ChartInfo.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java:
+	  Implements the PanHandler interface. If a PanEvent is fired by the
+	  PanControl, a new chart range is computed using the axes information
+	  provided by the ChartInfo object (that has been retrieved by the
+	  ChartInfoService).
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java:
+	  Added the PanControl to the toolbar.
+
 2011-06-07  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/event/HasPanHandlers.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoService.java	Tue Jun 07 13:07:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoService.java	Tue Jun 07 13:26:24 2011 +0000
@@ -5,8 +5,8 @@
 import com.google.gwt.user.client.rpc.RemoteService;
 import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
 
-import de.intevation.flys.client.shared.Transform2D;
 import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.ChartInfo;
 import de.intevation.flys.client.shared.model.Collection;
 
 /**
@@ -15,7 +15,7 @@
 @RemoteServiceRelativePath("chart-info")
 public interface ChartInfoService extends RemoteService {
 
-    Transform2D getChartInfo(
+    ChartInfo getChartInfo(
         Collection          collection,
         String              url,
         String              locale,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoServiceAsync.java	Tue Jun 07 13:07:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoServiceAsync.java	Tue Jun 07 13:26:24 2011 +0000
@@ -4,7 +4,7 @@
 
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
-import de.intevation.flys.client.shared.Transform2D;
+import de.intevation.flys.client.shared.model.ChartInfo;
 import de.intevation.flys.client.shared.model.Collection;
 
 
@@ -19,6 +19,6 @@
         String              locale,
         String              type,
         Map<String, String> attr,
-        AsyncCallback<Transform2D> callback);
+        AsyncCallback<ChartInfo> callback);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Tue Jun 07 13:07:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Tue Jun 07 13:26:24 2011 +0000
@@ -17,11 +17,15 @@
 import com.smartgwt.client.widgets.events.ResizedHandler;
 
 import de.intevation.flys.client.shared.Transform2D;
+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.shared.model.OutputMode;
 import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.event.OutputParameterChangeEvent;
 import de.intevation.flys.client.client.event.OutputParameterChangeHandler;
+import de.intevation.flys.client.client.event.PanEvent;
+import de.intevation.flys.client.client.event.PanHandler;
 import de.intevation.flys.client.client.event.ZoomEvent;
 import de.intevation.flys.client.client.event.ZoomHandler;
 import de.intevation.flys.client.client.services.ChartInfoService;
@@ -35,7 +39,8 @@
  */
 public class ChartOutputTab
 extends      OutputTab
-implements   ResizedHandler, OutputParameterChangeHandler, ZoomHandler
+implements   ResizedHandler, OutputParameterChangeHandler, ZoomHandler,
+             PanHandler
 {
     public static final int DEFAULT_CHART_WIDTH  = 600;
     public static final int DEFAULT_CHART_HEIGHT = 500;
@@ -46,6 +51,11 @@
     /** The service that is used to fetch chart information.*/
     protected ChartInfoServiceAsync info = GWT.create(ChartInfoService.class);
 
+
+    /** The ChartInfo object that provides information about the current
+     * chart.*/
+    protected ChartInfo chartInfo;
+
     /** The transformer used to transform image pixels into chart coordinates.*/
     protected Transform2D transformer;
 
@@ -163,12 +173,44 @@
     }
 
 
+    public void onPan(PanEvent event) {
+        int[] start = event.getStartPos();
+        int[] end   = event.getEndPos();
+
+        double[] startPos = transformer.transform(start[0], start[1]);
+        double[] endPos   = transformer.transform(end[0], end[1]);
+
+        double diffX = startPos[0] - endPos[0];
+        double diffY = startPos[1] - endPos[1];
+
+        panTo(diffX, diffY);
+    }
+
+
+    /**
+     * This method pans to chart with a given factor.
+     */
+    public void panTo(double diffX, double diffY) {
+        Axis xAxis = chartInfo.getXAxis(0);
+        Axis yAxis = chartInfo.getYAxis(0);
+
+        xrange[0] = xAxis.getFrom() + diffX;
+        xrange[1] = xAxis.getTo() + diffX;
+        yrange[0] = yAxis.getFrom() + diffY;
+        yrange[1] = yAxis.getTo() + diffY;
+
+        updateTransformer();
+        updateChartPanel();
+    }
+
+
     public void resetRanges() {
         xrange[0] = 0;
         xrange[1] = 0;
         yrange[0] = 0;
         yrange[1] = 0;
 
+        updateTransformer();
         updateChartPanel();
     }
 
@@ -191,6 +233,7 @@
         yrange[0] -= yadd;
         yrange[1] += yadd;
 
+        updateTransformer();
         updateChartPanel();
     }
 
@@ -209,13 +252,13 @@
             locale,
             mode.getName(),
             getChartAttributes(),
-            new AsyncCallback<Transform2D>() {
+            new AsyncCallback<ChartInfo>() {
                 public void onFailure(Throwable caught) {
                     GWT.log("ERROR: " + caught.getMessage());
                 }
 
-                public void onSuccess(Transform2D transformer) {
-                    setTransformer(transformer);
+                public void onSuccess(ChartInfo chartInfo) {
+                    setChartInfo(chartInfo);
                 }
             });
     }
@@ -248,6 +291,17 @@
     }
 
 
+    public ChartInfo getChartInfo() {
+        return chartInfo;
+    }
+
+
+    protected void setChartInfo(ChartInfo chartInfo) {
+        this.chartInfo = chartInfo;
+        setTransformer(chartInfo.getTransformer());
+    }
+
+
     /**
      * Returns the Transform2D object used to transform image coordinates into
      * chart coordinates.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java	Tue Jun 07 13:07:27 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java	Tue Jun 07 13:26:24 2011 +0000
@@ -44,6 +44,8 @@
 
     protected ImgButton zoomOut;
 
+    protected PanControl panControl;
+
 
 
     public ChartToolbar(CollectionView view, ChartOutputTab chartTab) {
@@ -57,6 +59,7 @@
         zoombox         = new ZoomboxControl(chartTab, MSG.zoom_in());
         zoomToMaxExtent = new ImgButton();
         zoomOut         = new ImgButton();
+        panControl      = new PanControl(chartTab, MSG.pan());
 
         datacage.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent event) {
@@ -97,6 +100,18 @@
         });
 
         zoombox.addZoomHandler(chartTab);
+        zoombox.addClickHandler(new ClickHandler() {
+            public void onClick(ClickEvent event) {
+                panControl.deselect();
+            }
+        });
+
+        panControl.addPanHandler(chartTab);
+        panControl.addClickHandler(new ClickHandler() {
+            public void onClick(ClickEvent event) {
+                zoombox.deselect();
+            }
+        });
 
         initLayout();
     }
@@ -128,6 +143,7 @@
         addMember(zoomToMaxExtent);
         addMember(zoomOut);
         addMember(zoombox);
+        addMember(panControl);
         addMember(spacer);
         addMember(position);
     }
--- 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,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Axis.java	Tue Jun 07 13:26:24 2011 +0000
@@ -0,0 +1,42 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class Axis implements Serializable {
+
+    protected int pos;
+
+    protected double from;
+    protected double to;
+
+
+    public Axis() {
+    }
+
+
+    public Axis(int pos, double from, double to) {
+        this.pos  = pos;
+        this.from = from;
+        this.to   = to;
+    }
+
+
+    public int getPos() {
+        return pos;
+    }
+
+
+    public double getFrom() {
+        return from;
+    }
+
+
+    public double getTo() {
+        return to;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartInfo.java	Tue Jun 07 13:26:24 2011 +0000
@@ -0,0 +1,62 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+
+import de.intevation.flys.client.shared.Transform2D;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class ChartInfo implements Serializable {
+
+    protected Axis[] xAxes;
+    protected Axis[] yAxes;
+
+    protected Transform2D transformer;
+
+
+    public ChartInfo() {
+    }
+
+
+    public ChartInfo(Axis[] xAxes, Axis[] yAxes, Transform2D transformer) {
+        this.xAxes       = xAxes;
+        this.yAxes       = yAxes;
+        this.transformer = transformer;
+    }
+
+
+    public Transform2D getTransformer() {
+        return transformer;
+    }
+
+
+    public int getXAxisCount() {
+        return xAxes.length;
+    }
+
+
+    public int getYAxisCount() {
+        return yAxes.length;
+    }
+
+
+    public Axis getXAxis(int pos) {
+        if (pos >= 0 && pos < xAxes.length) {
+            return xAxes[pos];
+        }
+
+        return null;
+    }
+
+
+    public Axis getYAxis(int pos) {
+        if (pos >= 0 && pos < yAxes.length) {
+            return yAxes[pos];
+        }
+
+        return null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org