changeset 2477:936e3e6cd9b9

Issue 502. Create label to show coordinates for each y axis in the chart. flys-client/trunk@4220 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 12 Apr 2012 09:49:41 +0000 (2012-04-12)
parents e8c4f8f2220e
children 6462a02022ab
files flys-client/ChangeLog 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/MousePositionPanel.java flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartInfo.java
diffstat 4 files changed, 102 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Apr 11 13:24:53 2012 +0000
+++ b/flys-client/ChangeLog	Thu Apr 12 09:49:41 2012 +0000
@@ -1,3 +1,17 @@
+2012-04-12  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Issue 502.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java:
+	  Dynamically create a label for each y axis in the chart.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java:
+	  Added getter for transformer count.
+	  Update chart info on output parameter changed.
+
+	* src/main/java/de/intevation/flys/client/shared/model/ChartInfo.java:
+	  Added getter for transformer count.
+
 2012-04-11  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Wed Apr 11 13:24:53 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Thu Apr 12 09:49:41 2012 +0000
@@ -199,6 +199,7 @@
      * @param event The OutputParameterChangeEvent.
      */
     public void onOutputParameterChanged(OutputParameterChangeEvent event) {
+        updateChartInfo();
         updateChartPanel();
     }
 
@@ -522,6 +523,20 @@
 
 
     /**
+     * Returns the Transform2D count
+     *
+     * @return the Transformer2D count
+     */
+    public int getTransformerCount() {
+        if (chartInfo == null) {
+            return 0;
+        }
+
+        return chartInfo.getTransformerCount();
+    }
+
+
+    /**
      * Creates a new chart panel with default size.
      *
      * @return the created chart panel.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java	Wed Apr 11 13:24:53 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java	Thu Apr 12 09:49:41 2012 +0000
@@ -1,5 +1,9 @@
 package de.intevation.flys.client.client.ui.chart;
 
+import java.util.ArrayList;
+
+import com.google.gwt.core.client.GWT;
+
 import com.google.gwt.i18n.client.NumberFormat;
 
 import com.smartgwt.client.widgets.Canvas;
@@ -20,18 +24,14 @@
 
     protected NumberFormat nf;
 
-    protected Label x;
-    protected Label y;
-
+    protected HLayout xLayout;
+    protected ArrayList<HLayout> yLayouts;
 
     public MousePositionPanel(ChartOutputTab chartTab) {
         super();
 
         this.chartTab = chartTab;
 
-        x = new Label();
-        y = new Label();
-
         nf = NumberFormat.getDecimalFormat();
 
         chartTab.getChartPanel().addMouseMoveHandler(this);
@@ -47,46 +47,8 @@
     protected void initLayout() {
         setMembersMargin(5);
 
-        Label xDesc = new Label("Position: X = ");
-        Label yDesc  = new Label("Y = ");
-
-        HLayout xLayout = new HLayout();
-        xLayout.setWidth(125);
-        xLayout.addMember(xDesc);
-        xLayout.addMember(x);
-
-        HLayout yLayout = new HLayout();
-        yLayout.setWidth(70);
-        yLayout.addMember(yDesc);
-        yLayout.addMember(y);
-
-        xDesc.setWidth(70);
-        x.setWidth(55);
-        yDesc.setWidth(20);
-        y.setWidth(50);
-
-        addMember(xLayout);
-        addMember(yLayout);
-    }
-
-
-    /**
-     * /Updates the X value displayed in the <i>x</i> label.
-     *
-     * @param x the new x value.
-     */
-    public void setX(String x) {
-        this.x.setContents(x);
-    }
-
-
-    /**
-     * /Updates the Y value displayed in the <i>y</i> label.
-     *
-     * @param y the new y value.
-     */
-    public void setY(String y) {
-        this.y.setContents(y);
+        xLayout = null;
+        yLayouts = new ArrayList<HLayout>();
     }
 
 
@@ -108,11 +70,7 @@
      * @param y The y part of the pixel.
      */
     public void updateMousePosition(double x, double y) {
-        Transform2D transformer = chartTab.getTransformer();
-
-        if (transformer == null) {
-            return;
-        }
+        int transformerCount = chartTab.getTransformerCount();
 
         Canvas chart = chartTab.getChartPanel();
         int xOffset = chart.getPageLeft();
@@ -121,12 +79,66 @@
         x = x - xOffset;
         y = y - yOffset;
 
-        double[] xy    = transformer.transform(x,y);
-        String[] xyStr = transformer.format(new Number[] {
-            new Double(xy[0]), new Double(xy[1]) });
+        // Create Layout for x coordinates.
+        if (xLayout == null){
+            Label xDesc  = new Label("Position: X = ");
+            Label xLabel = new Label();
+            xLayout      = new HLayout();
+            xLayout.setWidth(125);
+            xLayout.addMember(xDesc);
+            xLayout.addMember(xLabel);
+            xDesc.setWidth(70);
+            xLabel.setWidth(55);
+            addMember(xLayout);
+        }
 
-        setX(xyStr[0]);
-        setY(xyStr[1]);
+        ArrayList<String> yCoordinates = new ArrayList<String>();
+        String xCoordinate = "";
+        for (int i = 0; i < transformerCount; i++) {
+            HLayout yLayout = null;
+            // If no layout exists for this y axis, create one.
+            // else use the existing one.
+            if (yLayouts.size() <= i) {
+                Label yDesc     = new Label("Y" + (i+1) + " = ");
+                Label yLabel    = new Label();
+                yLayout = new HLayout();
+                yLayout.setWidth(80);
+                yLayout.addMember(yDesc);
+                yLayout.addMember(yLabel);
+                yDesc.setWidth(30);
+                yLabel.setWidth(50);
+                addMember(yLayout);
+                yLayouts.add(i, yLayout);
+            }
+            else {
+                yLayout = yLayouts.get(i);
+            }
+
+            Transform2D transformer = chartTab.getTransformer(i);
+
+            if (transformer == null) {
+                return;
+            }
+
+            // Get the label for the coordinates.
+            Canvas xLabel = xLayout.getMember(1);
+            Canvas yLabel = yLayout.getMember(1);
+
+            double[] xy    = transformer.transform(x,y);
+            String[] xyStr = transformer.format(new Number[] {
+                new Double(xy[0]), new Double(xy[1]) });
+            // Set the coordinates.
+            xLabel.setContents(xyStr[0]);
+            yLabel.setContents(xyStr[1]);
+        }
+
+        // Remove y coordinates.
+        if (yLayouts.size() > transformerCount) {
+            for (int i = yLayouts.size() - 1; i >= transformerCount; i--) {
+                removeMember(yLayouts.get(i));
+                yLayouts.remove(i);
+            }
+        }
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartInfo.java	Wed Apr 11 13:24:53 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ChartInfo.java	Thu Apr 12 09:49:41 2012 +0000
@@ -38,6 +38,11 @@
     }
 
 
+    public int getTransformerCount() {
+        return transformer.length;
+    }
+
+
     public int getXAxisCount() {
         return xAxes.length;
     }

http://dive4elements.wald.intevation.org