changeset 3373:86e69788c946

Added a new UIProvider that allows the input of a time period; the helper panel displays the field campaigns of MINFO's SQ relation. flys-client/trunk@5085 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 20 Jul 2012 10:17:25 +0000
parents cb84e717e54d
children 27e455487d66
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQCampaignChart.java flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQMultiPeriodPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQPeriodPanel.java
diffstat 5 files changed, 136 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Jul 20 09:37:27 2012 +0000
+++ b/flys-client/ChangeLog	Fri Jul 20 10:17:25 2012 +0000
@@ -1,3 +1,20 @@
+2012-07-20  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/sq/SQCampaignChart.java:
+	  New subclass of VLayout that displays a chart with field campaigns. The
+	  code is copied from SQMultiPeriodPanel.
+
+	* src/main/java/de/intevation/flys/client/client/ui/sq/SQMultiPeriodPanel.java:
+	  Moved the code to display the field campaign charts into SQCampaignChart
+	  class.
+
+	* src/main/java/de/intevation/flys/client/client/ui/sq/SQPeriodPanel.java:
+	  New UIProvider that allows the input of a time period; the helper panel
+	  displays a chart with field campaigns.
+
+	* src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java:
+	  Registered SQPeriodPanel as new UIProvider.
+
 2012-07-20  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Fri Jul 20 09:37:27 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Fri Jul 20 10:17:25 2012 +0000
@@ -1,7 +1,5 @@
 package de.intevation.flys.client.client.ui;
 
-import de.intevation.flys.client.shared.model.User;
-
 import de.intevation.flys.client.client.ui.fixation.FixEventSelect;
 import de.intevation.flys.client.client.ui.fixation.FixFunctionSelect;
 import de.intevation.flys.client.client.ui.fixation.FixGaugeSelectPanel;
@@ -10,6 +8,8 @@
 import de.intevation.flys.client.client.ui.fixation.FixPeriodPanel;
 import de.intevation.flys.client.client.ui.fixation.FixQSelectPanel;
 import de.intevation.flys.client.client.ui.sq.SQMultiPeriodPanel;
+import de.intevation.flys.client.client.ui.sq.SQPeriodPanel;
+import de.intevation.flys.client.shared.model.User;
 
 /**
  * Depending on the provider the state declared, return a UIProvider.
@@ -123,6 +123,9 @@
         else if (uiProvider.equals("periods_select")) {
             return new SQMultiPeriodPanel();
         }
+        else if (uiProvider.equals("sq.period.select")) {
+            return new SQPeriodPanel();
+        }
         else if (uiProvider.equals("outliers_input")) {
             return new DoubleInputPanel();
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQCampaignChart.java	Fri Jul 20 10:17:25 2012 +0000
@@ -0,0 +1,79 @@
+package de.intevation.flys.client.client.ui.sq;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.json.client.JSONNumber;
+import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONString;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.widgets.Img;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.shared.model.Artifact;
+
+
+public class SQCampaignChart extends VLayout {
+
+    private final Artifact artifact;
+
+    protected Img chartImg;
+
+    public SQCampaignChart(Artifact artifact, ResizedHandler resizeHandler) {
+        super();
+
+        this.artifact = artifact;
+        this.chartImg = new Img();
+
+        addResizedHandler(resizeHandler);
+        setAlign(Alignment.CENTER);
+    }
+
+    public void update() {
+        Config config = Config.getInstance();
+        String locale = config.getLocale();
+
+        int hWidth = getWidth() - 12;
+        int hHeight = getHeight() - 12;
+
+        if ((int) (hHeight * 4f / 3) < hWidth) {
+            hWidth = (int) (hHeight * 4f / 3);
+        }
+        else {
+            hHeight = (int) (hWidth * 3f / 4);
+        }
+
+        String river = artifact.getArtifactDescription().getRiver();
+
+        JSONObject jfix = new JSONObject();
+        JSONObject jfilter = new JSONObject();
+        JSONObject jrName = new JSONObject();
+        JSONString jrValue = new JSONString(river);
+        JSONObject jextent = new JSONObject();
+        JSONNumber jwidth = new JSONNumber(hWidth);
+        JSONNumber jheight = new JSONNumber(hHeight);
+
+        jrName.put("name", jrValue);
+        jfilter.put("river", jrName);
+        jextent.put("width", jwidth);
+        jextent.put("height", jheight);
+        jfilter.put("extent", jextent);
+        jfix.put("sq", jfilter);
+        String filter = jfix.toString();
+
+        String imgUrl = GWT.getModuleBaseURL();
+        imgUrl += "sq-km-chart";
+        imgUrl += "?locale=" + locale;
+        imgUrl += "&filter=" + filter;
+
+        if (chartImg != null && hasMember(chartImg)) {
+            chartImg.setWidth(hWidth);
+            chartImg.setHeight(hHeight);
+            chartImg.setSrc(imgUrl);
+        }
+        else {
+            chartImg = new Img(imgUrl, hWidth, hHeight);
+            addMember(chartImg);
+        }
+    }
+}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQMultiPeriodPanel.java	Fri Jul 20 09:37:27 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQMultiPeriodPanel.java	Fri Jul 20 10:17:25 2012 +0000
@@ -1,100 +1,32 @@
 package de.intevation.flys.client.client.ui.sq;
 
-import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.json.client.JSONNumber;
-import com.google.gwt.json.client.JSONString;
-
-import com.google.gwt.core.client.GWT;
-
-import com.smartgwt.client.types.Alignment;
-
-import com.smartgwt.client.widgets.Img;
 import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.events.ResizedEvent;
 import com.smartgwt.client.widgets.events.ResizedHandler;
-import com.smartgwt.client.widgets.events.ResizedEvent;
 
 import de.intevation.flys.client.client.ui.MultiPeriodPanel;
 
-import de.intevation.flys.client.client.Config;
+
 /**
  * This UIProvider creates helper panel for sq relation.
  *
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class SQMultiPeriodPanel
-extends      MultiPeriodPanel
-implements   ResizedHandler
-{
-    protected VLayout chartContainer;
-
-    protected Img chartImg;
+public class SQMultiPeriodPanel extends MultiPeriodPanel implements
+    ResizedHandler {
+    protected SQCampaignChart chartContainer;
 
     public SQMultiPeriodPanel() {
-        chartImg = new Img();
     }
 
-
+    @Override
     protected Canvas createHelper() {
-        Config config    = Config.getInstance();
-        String locale    = config.getLocale ();
-
-        chartContainer = new VLayout();
-        chartContainer.addResizedHandler(this);
-        chartContainer.setAlign(Alignment.CENTER);
-
+        chartContainer = new SQCampaignChart(artifact, this);
         return chartContainer;
     }
 
-
-    protected void updateChart() {
-        Config config    = Config.getInstance();
-        String locale    = config.getLocale ();
-
-        int hWidth = chartContainer.getWidth() - 12;
-        int hHeight = chartContainer.getHeight() - 12;
-
-        if ((int)(hHeight *4f/3) < hWidth) {
-            hWidth = (int)(hHeight * 4f/3);
-        }
-        else {
-            hHeight = (int)(hWidth *3f/4);
-        }
-        String river = artifact.getArtifactDescription().getRiver();
-
-        JSONObject jfix = new JSONObject();
-        JSONObject jfilter = new JSONObject();
-        JSONObject jrName = new JSONObject();
-        JSONString jrValue = new JSONString(river);
-        JSONObject jextent = new JSONObject();
-        JSONNumber jwidth = new JSONNumber(hWidth);
-        JSONNumber jheight = new JSONNumber(hHeight);
-
-        jrName.put("name", jrValue);
-        jfilter.put("river", jrName);
-        jextent.put("width", jwidth);
-        jextent.put("height", jheight);
-        jfilter.put("extent", jextent);
-        jfix.put("sq", jfilter);
-        String filter = jfix.toString();
-
-        String imgUrl = GWT.getModuleBaseURL();
-        imgUrl += "sq-km-chart";
-        imgUrl += "?locale=" + locale;
-        imgUrl += "&filter=" + filter;
-        if (chartContainer.hasMember(chartImg)) {
-            chartImg.setWidth(hWidth);
-            chartImg.setHeight(hHeight);
-            chartImg.setSrc(imgUrl);
-        }
-        else {
-            chartImg = new Img(imgUrl, hWidth, hHeight);
-            chartContainer.addMember(chartImg);
-        }
-    }
-
-
+    @Override
     public void onResized(ResizedEvent re) {
-        updateChart();
+        chartContainer.update();
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/sq/SQPeriodPanel.java	Fri Jul 20 10:17:25 2012 +0000
@@ -0,0 +1,26 @@
+package de.intevation.flys.client.client.ui.sq;
+
+import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.events.ResizedEvent;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+
+import de.intevation.flys.client.client.ui.PeriodPanel;
+
+public class SQPeriodPanel extends PeriodPanel implements ResizedHandler {
+
+    private SQCampaignChart chartLayout;
+
+    @Override
+    protected Canvas createHelper() {
+        GWT.log("Create new SQCampaignChart as Helper Widget");
+        chartLayout = new SQCampaignChart(artifact, this);
+        return chartLayout;
+    }
+
+
+    @Override
+    public void onResized(ResizedEvent re) {
+        chartLayout.update();
+    }
+}

http://dive4elements.wald.intevation.org