diff flys-client/src/main/java/de/intevation/flys/client/client/widgets/DischargeTablesChart.java @ 4218:6ae99d996f79

flys/issue903: Display the discharge tables of the selected gauge as chart in historical discharge calculation. There is a new class 'DischargeTablesChart' which is a Canvas and displays the chart using the new service 'DischargeTablesServiceImpl'.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 23 Oct 2012 12:01:19 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/widgets/DischargeTablesChart.java	Tue Oct 23 12:01:19 2012 +0200
@@ -0,0 +1,90 @@
+package de.intevation.flys.client.client.widgets;
+
+import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Img;
+import com.smartgwt.client.widgets.events.ResizedEvent;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+
+import de.intevation.flys.client.shared.model.Artifact;
+import de.intevation.flys.client.shared.model.ArtifactDescription;
+
+
+public class DischargeTablesChart extends Canvas implements ResizedHandler {
+
+    protected Artifact artifact;
+
+    protected Img img;
+
+    public DischargeTablesChart() {
+        super();
+    }
+
+    public DischargeTablesChart(Artifact artifact) {
+        super();
+        this.artifact = artifact;
+        init();
+    }
+
+    private void init() {
+        addChild(createImage());
+        addResizedHandler(this);
+        setSize("100%", "100%");
+    }
+
+    protected Img createImage() {
+        img = new Img(getUrl());
+        img.setSize("100%", "100%");
+
+        return img;
+    }
+
+    protected String getUrl() {
+        String url = GWT.getModuleBaseURL();
+        url += "dischargetablesoverview";
+        url += "?gauge=" + getGauge();
+        url += "&format=png";
+
+        String[] timerange = getTimerange();
+        url += "&lower=" + timerange[0];
+        url += "&upper=" + timerange[1];
+
+        int width = 600;
+        int height = 400;
+        if (img != null) {
+            width = img.getWidth();
+            height = img.getHeight();
+        }
+
+        url += "&width=" + String.valueOf(width);
+        url += "&height=" + String.valueOf(height);
+
+        // add time millis to 'deactivate' caching
+        url += "&timemillis" + System.currentTimeMillis();
+
+        GWT.log("DischargeTablesService URL = '" + url + "'");
+        return url;
+    }
+
+    protected String getGauge() {
+        ArtifactDescription desc = artifact.getArtifactDescription();
+        return desc.getReferenceGauge();
+    }
+
+    protected String[] getTimerange() {
+        ArtifactDescription desc = artifact.getArtifactDescription();
+        String yearStr = desc.getDataValueAsString("year_range");
+
+        if (yearStr != null && yearStr.length() > 0) {
+            return yearStr.split(";");
+        }
+
+        return new String[2];
+    }
+
+    @Override
+    public void onResized(ResizedEvent event) {
+        GWT.log("resized discharge tables overview chart");
+        img.setSrc(getUrl());
+    }
+}

http://dive4elements.wald.intevation.org