changeset 3362:bea50e45f0d3

FixA: Input fields for chart navigation now use the correct i18n number formats. flys-client/trunk@5049 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 19 Jul 2012 07:39:50 +0000
parents 89df168f289c
children 8d38a1e097c2
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java
diffstat 3 files changed, 71 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jul 18 17:30:44 2012 +0000
+++ b/flys-client/ChangeLog	Thu Jul 19 07:39:50 2012 +0000
@@ -1,3 +1,9 @@
+2012-07-18  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java:
+	  Input fields for chart navigation now use the correct i18n number formats.
+
 2012-07-18	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java	Wed Jul 18 17:30:44 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java	Thu Jul 19 07:39:50 2012 +0000
@@ -4,6 +4,7 @@
 import java.util.HashMap;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.NumberFormat;
 
 import com.smartgwt.client.types.Alignment;
 
@@ -80,7 +81,6 @@
         currentkm = new TextItem();
         currentkm.setWidth(60);
         currentkm.setShowTitle(false);
-        currentkm.setValidators(new IsFloatValidator());
 
         form.setFields(currentkm);
         form.setWidth(60);
@@ -97,11 +97,23 @@
         collectionView.setMinKm(fix.getFilter().getFromKm());
         collectionView.setMaxKm(fix.getFilter().getToKm());
 
+        NumberFormat nf = NumberFormat.getDecimalFormat();
         if (collectionView.getCurrentKm() == -1d) {
-            currentkm.setValue(fix.getFilter().getFromKm());
+            try {
+                double d = Double.valueOf(fix.getFilter().getFromKm());
+                currentkm.setValue(nf.format(d));
+            } catch (NumberFormatException e) {
+                currentkm.setValue(fix.getFilter().getFromKm());
+            }
             collectionView.setCurrentKm(fix.getFilter().getFromKm());
         }
         else {
+            try {
+                double d = Double.valueOf(fix.getFilter().getFromKm());
+                currentkm.setValue(nf.format(d));
+            } catch (NumberFormatException e) {
+                currentkm.setValue(fix.getFilter().getFromKm());
+            }
             currentkm.setValue(collectionView.getCurrentKm());
         }
 
@@ -109,7 +121,13 @@
             public void onClick(ClickEvent ce) {
                 tbarPanel.deselectControls();
                 updateChartDown();
-                currentkm.setValue(collectionView.getCurrentKm());
+                try {
+                    NumberFormat nf = NumberFormat.getDecimalFormat();
+                    double d = Double.valueOf(collectionView.getCurrentKm());
+                    currentkm.setValue(nf.format(d));
+                } catch (NumberFormatException e) {
+                    currentkm.setValue(collectionView.getCurrentKm());
+                }
             }
         });
 
@@ -117,7 +135,13 @@
             public void onClick(ClickEvent ce) {
                 tbarPanel.deselectControls();
                 updateChartUp();
-                currentkm.setValue(collectionView.getCurrentKm());
+                try {
+                    NumberFormat nf = NumberFormat.getDecimalFormat();
+                    double d = Double.valueOf(collectionView.getCurrentKm());
+                    currentkm.setValue(nf.format(d));
+                } catch (NumberFormatException e) {
+                    currentkm.setValue(collectionView.getCurrentKm());
+                }
             }
         });
 
@@ -126,11 +150,18 @@
                 if (!kpe.getKeyName().equals("Enter")) {
                     return;
                 }
-                if(kpe.getForm().validate() && kpe.getItem().getValue() != null) {
+                if(kpe.getItem().getValue() != null) {
                     tbarPanel.deselectControls();
                     try {
                         String s = kpe.getItem().getValue().toString();
-                        Double d = new Double(s);
+                        double d;
+                        try {
+                            NumberFormat nf = NumberFormat.getDecimalFormat();
+                            d = nf.parse(s);
+                            currentkm.setValue(nf.format(d));
+                        } catch (NumberFormatException e) {
+                            d = -1d;
+                        }
                         if (d <= collectionView.getMaxKm() &&
                             d >= collectionView.getMinKm()) {
                             collectionView.setCurrentKm(d);
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java	Wed Jul 18 17:30:44 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java	Thu Jul 19 07:39:50 2012 +0000
@@ -10,6 +10,7 @@
 import com.google.gwt.json.client.JSONNumber;
 import com.google.gwt.json.client.JSONString;
 import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.i18n.client.NumberFormat;
 
 import com.smartgwt.client.util.SC;
 
@@ -156,12 +157,19 @@
                     FixAnalysisArtifact art = (FixAnalysisArtifact)artifact;
                     FixFilter filter = art.getFilter();
                     filter.setRiver(info.getRiver());
-                    if (filter.getCurrentKm() == -Double.MAX_VALUE) {
+                    if (filter.getCurrentKm() == -Double.MAX_VALUE ||
+                        filter.getCurrentKm() == -1d) {
                         filter.setCurrentKm(info.getFrom());
                         filter.setToKm(info.getTo());
                     }
                     if (kmText != null) {
-                        kmText.setValue(filter.getCurrentKm());
+                        NumberFormat nf = NumberFormat.getDecimalFormat();
+                        try {
+                            double d = Double.valueOf(filter.getCurrentKm());
+                            kmText.setValue(nf.format(d));
+                        } catch (NumberFormatException e) {
+                            kmText.setValue(filter.getCurrentKm());
+                        }
                     }
                     eventPane.setContents(htmlOverview);
                     updateChartTab(fixInfo.getFrom());
@@ -186,33 +194,43 @@
         kmText = new TextItem();
         kmText.setWidth(60);
         kmText.setShowTitle(false);
-        kmText.setValidators(new IsFloatValidator());
+
 
         form.setFields(kmText);
         form.setWidth(60);
         lower.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent ce) {
                 FixFilter filter = updateChartTabLow();
-                FixAnalysisArtifact art = (FixAnalysisArtifact) artifact;
-                kmText.setValue(filter.getCurrentKm());
+                NumberFormat nf = NumberFormat.getDecimalFormat();
+                try {
+                    double d = Double.valueOf(filter.getCurrentKm());
+                    kmText.setValue(nf.format(d));
+                } catch (NumberFormatException e) {
+                    kmText.setValue(filter.getCurrentKm());
+                }
             }
         });
 
         upper.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent ce) {
                 FixFilter filter = updateChartTabUp();
-                FixAnalysisArtifact art = (FixAnalysisArtifact) artifact;
-                kmText.setValue(filter.getCurrentKm());
+                NumberFormat nf = NumberFormat.getDecimalFormat();
+                try {
+                    double d = Double.valueOf(filter.getCurrentKm());
+                    kmText.setValue(nf.format(d));
+                } catch (NumberFormatException e) {
+                    kmText.setValue(filter.getCurrentKm());
+                }
             }
         });
 
         kmText.addChangedHandler(new ChangedHandler() {
             public void onChanged(ChangedEvent ce) {
                 //TODO: get current value.
-                if(ce.getForm().validate() && ce.getItem().getValue() != null) {
+                if(ce.getItem().getValue() != null) {
+                    NumberFormat nf = NumberFormat.getDecimalFormat();
                     try {
-                        double d = Double.parseDouble(
-                            ce.getItem().getValue().toString());
+                        double d = nf.parse(ce.getItem().getValue().toString());
                         updateChartTab(d);
                     }
                     catch(NumberFormatException nfe) {

http://dive4elements.wald.intevation.org