changeset 2934:a5ebe2e2c772

issue457 flys-client/trunk@4860 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 03 Jul 2012 12:13:36 +0000 (2012-07-03)
parents d87730b89afa
children 6cf983dd4f8a
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java
diffstat 2 files changed, 27 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Jul 02 09:49:22 2012 +0000
+++ b/flys-client/ChangeLog	Tue Jul 03 12:13:36 2012 +0000
@@ -1,3 +1,10 @@
+2012-07-03	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Fix issue457.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java:
+	  Store and consider direction (up, down) when using the km spinner.
+
 2012-07-02	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java	Mon Jul 02 09:49:22 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java	Tue Jul 03 12:13:36 2012 +0000
@@ -282,23 +282,33 @@
      * the last one is taken.
      * @param in possible return values.
      * @param to the value to be as close to as possible.
+     * @param up if true, prefer numerically higher values in case of two
+     *           values with equal distance to \param to.
      * @return value from in that is closest to to, -1 if none.
      */
-    public static double closest(Double[] in, double to) {
+    public static double closest(Double[] in, double to, boolean up) {
         if (in == null || in.length == 0) {
             return -1;
         }
         if (in[0] == to) {
             return to;
         }
+        for (int i = 0; i < in.length; i++) {
+            GWT.log ("Close? " + in[i]);
+        }
+        
         double minDiff = Math.abs(to - in[0]);
         double bestMatch = in[0];
         for (int i = 1; i < in.length; i++) {
             if (in[i] == to) {
                 return to;
             }
+            if ((in[i] < to && up)
+                || (in[i] > to && !up)) {
+                continue;
+            }
             double diff = Math.abs(to - in[i]);
-            if (diff < minDiff) {
+            if (diff <= minDiff) {
                 minDiff = diff;
                 bestMatch = in[i];
             }
@@ -403,9 +413,12 @@
      * @param item        The SpinnerItem which was manipulated.
      * @param enteredKm   The double-parsed value that has been entered.
      * @param facetRecord The underlying datastores record.
+     * @param up          If true, numerically higher values are preferred if
+     *                    two values in \param in are in the same distance to
+     *                    \param to.
      */
     public void spinnerValueEntered(final SpinnerItem item,
-        final double enteredKm, final FacetRecord facetRecord
+        final double enteredKm, final FacetRecord facetRecord, final boolean up
     ) {
         disable();
         Config config       = Config.getInstance();
@@ -441,7 +454,7 @@
                 public void onSuccess(Map<Integer, Double[]> obj) {
                     Double[] kms = obj.get(dbid);
                     double closest =
-                        CrossSectionChartThemePanel.closest(kms, enteredKm);
+                        CrossSectionChartThemePanel.closest(kms, enteredKm, up);
                     GWT.log("Got single km close to " + enteredKm + " for " + dbid + ", it is "
                         + closest);
 
@@ -474,38 +487,6 @@
 
 
     /**
-     * Create the handler for ChangeEvents on the Spinner in the
-     * facets that control km of cross section.
-     *
-     * @param facetRecord The FacetRecord (~row in table) where this
-     *                    handler is added to (to a child, to be exact).
-     */
-    // TODO obsolete?
-    public final ChangedHandler createSpinnerHandler(
-        final FacetRecord facetRecord)
-    {
-        ChangedHandler handler = new ChangedHandler()
-            {
-                @Override
-                public void onChanged(final ChangedEvent ce) {
-                    if (ce.getValue() == null) {
-                        return;
-                    }
-                    String value = ce.getValue().toString();
-
-                    // Now, query the value with the kmService.
-                    final double selected_km =
-                        Double.parseDouble(value);
-                    final SpinnerItem item = (SpinnerItem) ce.getItem();
-
-                    spinnerValueEntered(item, selected_km, facetRecord);
-                }
-            };
-        return handler;
-    }
-
-
-    /**
      * Create a "kilometer spinner" for CrossSection Facets.
      * @param facetRecord The respective Facet/Theme.
      * @return label, intialized SpinnerItem.
@@ -551,7 +532,7 @@
             minusButton.setHeight(height);
             minusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
                 public void onClick(ClickEvent evt) {
-                    spinnerValueEntered(null, currentValue - 0.1d, _facetRecord);
+                    spinnerValueEntered(null, currentValue - 0.1d, _facetRecord, false);
                 }
             });
 
@@ -607,7 +588,7 @@
                         try {
                             spinnerValueEntered(null,
                                 Double.parseDouble(kmField.getValue().toString()),
-                                _facetRecord);
+                                _facetRecord, true);
                         }
                         catch(NumberFormatException nfe) {
                             GWT.log("entered string cannot be parsed to double.");
@@ -637,7 +618,7 @@
             plusButton.setHeight(height);
             plusButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
                 public void onClick(ClickEvent evt) {
-                    spinnerValueEntered(null, currentValue + 0.1d, _facetRecord);
+                    spinnerValueEntered(null, currentValue + 0.1d, _facetRecord, true);
                 }
             });
             this.addMember(minusButton);

http://dive4elements.wald.intevation.org