diff flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java @ 538:75df57220104

Adapted the MousePositionPanel to use the Transform2D object for computing the chart coordinates from image coordinates. flys-client/trunk@2036 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 01 Jun 2011 09:03:18 +0000
parents e08777967bad
children ed29599e06e5
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Wed Jun 01 08:50:40 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Wed Jun 01 09:03:18 2011 +0000
@@ -3,10 +3,10 @@
 import java.util.Date;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Img;
-import com.smartgwt.client.widgets.Label;
 
 import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
@@ -14,11 +14,14 @@
 import com.smartgwt.client.widgets.events.ResizedEvent;
 import com.smartgwt.client.widgets.events.ResizedHandler;
 
+import de.intevation.flys.client.shared.Transform2D;
 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.services.ChartInfoService;
+import de.intevation.flys.client.client.services.ChartInfoServiceAsync;
 import de.intevation.flys.client.client.ui.CollectionView;
 import de.intevation.flys.client.client.ui.OutputTab;
 
@@ -37,6 +40,16 @@
 
 
 
+    /** The service that is used to fetch chart information.*/
+    protected ChartInfoServiceAsync info = GWT.create(ChartInfoService.class);
+
+    /** The transformer used to transform image pixels into chart coordinates.*/
+    protected Transform2D transformer;
+
+    /** The collection view.*/
+    protected CollectionView view;
+
+
     /** The canvas that wraps the chart toolbar.*/
     protected Canvas tbarPanel;
 
@@ -62,6 +75,7 @@
     ){
         super(title, collection, mode);
 
+        view      = collectionView;
         left      = new Canvas();
         right     = new Canvas();
         tbarPanel = new ChartToolbar(collectionView, this);
@@ -105,6 +119,7 @@
      */
     public void onResized(ResizedEvent event) {
         updateChartPanel();
+        updateTransformer();
     }
 
 
@@ -119,6 +134,35 @@
     }
 
 
+    /**
+     * Updates the Transform2D object using the chart info service.
+     */
+    public void updateTransformer() {
+        Canvas chart = getChartPanel();
+
+        Config config = Config.getInstance();
+        String url    = config.getServerUrl();
+        String locale = config.getLocale();
+
+        info.getChartInfo(
+            view.getCollection(),
+            url,
+            locale,
+            mode.getName(),
+            chart.getWidth(),
+            chart.getHeight(),
+            new AsyncCallback<Transform2D>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("ERROR: " + caught.getMessage());
+                }
+
+                public void onSuccess(Transform2D transformer) {
+                    setTransformer(transformer);
+                }
+            });
+    }
+
+
     public void updateChartPanel() {
         Canvas[] children = right.getChildren();
         for (Canvas child: children) {
@@ -130,7 +174,36 @@
 
 
     public Canvas getChartPanel() {
-        return right;
+        Canvas[] children = right.getChildren();
+
+        if (children == null || children.length == 0) {
+            GWT.log("=> No chart image in the panel.");
+            return right;
+        }
+
+        return children[0];
+    }
+
+
+    /**
+     * Returns the Transform2D object used to transform image coordinates into
+     * chart coordinates.
+     *
+     * @return the Transform2D object.
+     */
+    public Transform2D getTransformer() {
+        return transformer;
+    }
+
+
+    /**
+     * Set a new Transform2D object for the chart. This should be the case, only
+     * if the chart image size has changed.
+     *
+     * @param transformer The new Transform2D object.
+     */
+    protected void setTransformer(Transform2D transformer) {
+        this.transformer = transformer;
     }
 
 
@@ -149,15 +222,6 @@
     }
 
 
-    protected Canvas createThemeControlPanel() {
-        Label label = new Label("Themensteuerung");
-        label.setHeight(25);
-        label.setMargin(5);
-
-        return label;
-    }
-
-
     /**
      * Builds the chart image and returns it.
      *

http://dive4elements.wald.intevation.org