changeset 2923:43e0f6d96206

FixA: Make the km chart helper panel more useful. flys-client/trunk@4788 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 25 Jun 2012 17:33:27 +0000
parents 71db63f67d31
children 60c375173263
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java
diffstat 2 files changed, 54 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Jun 25 13:50:22 2012 +0000
+++ b/flys-client/ChangeLog	Mon Jun 25 17:33:27 2012 +0000
@@ -1,3 +1,8 @@
+2012-06-25	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java:
+	  Removed some stupid programming. Make the chart km more useful.
+
 2012-06-25	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java	Mon Jun 25 13:50:22 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java	Mon Jun 25 17:33:27 2012 +0000
@@ -74,6 +74,7 @@
     protected Tab chart;
     protected VLayout chartContainer;
     protected Img chartImg;
+    protected TextItem kmText;
 
     public FixationPanel() {
         chartImg = new Img();
@@ -152,10 +153,15 @@
                     fixInfo = info;
                     htmlOverview = info.getHTML();
                     FixAnalysisArtifact art = (FixAnalysisArtifact)artifact;
-                    art.getFilter().setRiver(info.getRiver());
-                    art.getFilter().setCurrentKm(1d);
-                    art.getFilter().setFromKm(info.getFrom());
-                    art.getFilter().setToKm(info.getTo());
+                    FixFilter filter = art.getFilter();
+                    filter.setRiver(info.getRiver());
+                    if (filter.getCurrentKm() == -Double.MAX_VALUE) {
+                        filter.setCurrentKm(info.getFrom());
+                        filter.setToKm(info.getTo());
+                    }
+                    if (kmText != null) {
+                        kmText.setValue(filter.getCurrentKm());
+                    }
                     eventPane.setContents(htmlOverview);
                     updateChartTab(fixInfo.getFrom());
                     events.setPane(eventPane);
@@ -172,43 +178,42 @@
 
     protected Canvas createChartHelper() {
 
-
         DynamicForm form = new DynamicForm();
         Button lower = new Button("<<");
         lower.setWidth(30);
         Button upper = new Button(">>");
         upper.setWidth(30);
-        final TextItem currentkm = new TextItem();
-        currentkm.setWidth(60);
-        currentkm.setShowTitle(false);
-        currentkm.setValidators(new IsFloatValidator());
+        kmText = new TextItem();
+        kmText.setWidth(60);
+        kmText.setShowTitle(false);
+        kmText.setValidators(new IsFloatValidator());
 
-        form.setFields(currentkm);
+        form.setFields(kmText);
         form.setWidth(60);
         lower.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent ce) {
-                updateChartTabLow();
+                FixFilter filter = updateChartTabLow();
                 FixAnalysisArtifact art = (FixAnalysisArtifact) artifact;
-                currentkm.setValue(art.getFilter().getCurrentKm());
+                kmText.setValue(filter.getCurrentKm());
             }
         });
 
         upper.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent ce) {
-                updateChartTabUp();
+                FixFilter filter = updateChartTabUp();
                 FixAnalysisArtifact art = (FixAnalysisArtifact) artifact;
-                currentkm.setValue(art.getFilter().getCurrentKm());
+                kmText.setValue(filter.getCurrentKm());
             }
         });
 
-        currentkm.addChangedHandler(new ChangedHandler() {
+        kmText.addChangedHandler(new ChangedHandler() {
             public void onChanged(ChangedEvent ce) {
                 //TODO: get current value.
                 if(ce.getForm().validate() && ce.getItem().getValue() != null) {
                     try {
-                        String s = ce.getItem().getValue().toString();
-                        Double d = new Double(s);
-                        updateChartTab(d.doubleValue());
+                        double d = Double.parseDouble(
+                            ce.getItem().getValue().toString());
+                        updateChartTab(d);
                     }
                     catch(NumberFormatException nfe) {
                         // Do nothing.
@@ -231,10 +236,18 @@
         String locale    = config.getLocale ();
 
         FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact;
-        if (km < 0) {
-            km = 0;
+
+        if (fixInfo != null) {
+            if (km < fixInfo.getFrom()) km = fixInfo.getFrom();
+            if (km > fixInfo.getTo())   km = fixInfo.getTo();
         }
-        art.getFilter().setCurrentKm(km);
+
+        FixFilter filter = art.getFilter();
+
+        if (km < filter.getFromKm()) km = filter.getFromKm();
+        if (km > filter.getToKm())   km = filter.getToKm();
+
+        filter.setCurrentKm(km);
 
         int hWidth = helperContainer.getWidth() - 12;
         int hHeight = helperContainer.getHeight() - 62;
@@ -249,7 +262,7 @@
         String imgUrl = GWT.getModuleBaseURL();
         imgUrl += "fixings-km-chart";
         imgUrl += "?locale=" + locale;
-        imgUrl += "&filter=" + art.getFilter().getChartFilter(hWidth, hHeight);
+        imgUrl += "&filter=" + filter.getChartFilter(hWidth, hHeight);
 
         if (chartContainer.hasMember(chartImg)) {
             chartImg.setWidth(hWidth);
@@ -263,29 +276,33 @@
     }
 
 
-    protected void updateChartTabLow() {
+    protected FixFilter updateChartTabLow() {
         FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact;
 
-        double curr = art.getFilter().getCurrentKm();
-        if (curr > art.getFilter().getFromKm()) {
+        FixFilter filter = art.getFilter();
+
+        double curr = filter.getCurrentKm();
+        if (curr > filter.getFromKm()) {
             double newVal = (curr - 0.1) * 10;
             long round = Math.round(newVal);
             updateChartTab(((double)round) / 10);
         }
-        return;
+        return filter;
     }
 
 
-    protected void updateChartTabUp() {
+    protected FixFilter updateChartTabUp() {
         FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact;
 
-        double curr = art.getFilter().getCurrentKm();
-        if (curr < art.getFilter().getToKm()) {
+        FixFilter filter = art.getFilter();
+
+        double curr = filter.getCurrentKm();
+        if (curr < filter.getToKm()) {
             double newVal = (curr + 0.1) * 10;
             long round = Math.round(newVal);
             updateChartTab(((double)round) / 10);
         }
-        return;
+        return filter;
     }
 
 
@@ -311,12 +328,7 @@
     }
 
     private static FixationPanel getInstance(String uuid) {
-        for (int i = 0; i < instances.size(); i++) {
-            if (instances.get(uuid) != null) {
-                return instances.get(uuid);
-            }
-        }
-        return null;
+        return instances.get(uuid);
     }
 
     public abstract Canvas createWidget(DataList data);
@@ -338,7 +350,7 @@
 
         public FixFilter() {
             this.river = "";
-            this.fromKm = -1d;
+            this.fromKm = -Double.MAX_VALUE;
             this.toKm = -1;
             this.currentKm = -1;
             this.fromClass = -1;

http://dive4elements.wald.intevation.org