changeset 1598:ef745bc6bed9

Distinguish between numbers and dates while parsing chart info documents; the MousePosition panel now displays the position on date axes correctly. flys-client/trunk@3931 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 06 Feb 2012 14:43:27 +0000
parents 8bbaa0d173cf
children 4ba6f1fb3a03
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/Transform2D.java
diffstat 4 files changed, 107 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Feb 06 13:27:05 2012 +0000
+++ b/flys-client/ChangeLog	Mon Feb 06 14:43:27 2012 +0000
@@ -1,3 +1,18 @@
+2012-02-06  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/Transform2D.java: A
+	  Transform2D object now knows about the type of x and y axis and implements
+	  a method format() that returns an 2dim string array with formatted values
+	  for x and y axis.
+
+	* src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java:
+	  Read x and y axis type for transformation matrix and create new
+	  Transform2D instances with these information. This allows the Transform2D
+	  object to format date values as well.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java:
+	  Don't format x and y values itself - let Transform2D do this.
+
 2012-02-06  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/Axis.java: Axis is an
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java	Mon Feb 06 13:27:05 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java	Mon Feb 06 14:43:27 2012 +0000
@@ -75,8 +75,8 @@
      *
      * @param x the new x value.
      */
-    public void setX(double x) {
-        this.x.setContents(nf.format(x));
+    public void setX(String x) {
+        this.x.setContents(x);
     }
 
 
@@ -85,8 +85,8 @@
      *
      * @param y the new y value.
      */
-    public void setY(double y) {
-        this.y.setContents(nf.format(y));
+    public void setY(String y) {
+        this.y.setContents(y);
     }
 
 
@@ -121,10 +121,12 @@
         x = x - xOffset;
         y = y - yOffset;
 
-        double[] xy = transformer.transform(x,y);
+        double[] xy    = transformer.transform(x,y);
+        String[] xyStr = transformer.format(new Number[] {
+            new Double(xy[0]), new Double(xy[1]) });
 
-        setX(xy[0]);
-        setY(xy[1]);
+        setX(xyStr[0]);
+        setY(xyStr[1]);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java	Mon Feb 06 13:27:05 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java	Mon Feb 06 14:43:27 2012 +0000
@@ -229,7 +229,7 @@
         List<Transform2D> transformer = new ArrayList<Transform2D>(num);
 
         for (int i = 0; i < num; i++) {
-            Transform2D t = createTransformer(matrix.item(i));
+            Transform2D t = createTransformer((Element) matrix.item(i));
 
             if (t == null) {
                 logger.warn("Broken transformation matrix at pos: " + i);
@@ -243,26 +243,30 @@
     }
 
 
-    protected Transform2D createTransformer(Node matrix) {
-        String sx = XMLUtils.xpathString(
-            matrix, "@art:sx", ArtifactNamespaceContext.INSTANCE);
+    protected Transform2D createTransformer(Element matrix) {
+        String ns = ArtifactNamespaceContext.NAMESPACE_URI;
 
-        String sy = XMLUtils.xpathString(
-            matrix, "@art:sy", ArtifactNamespaceContext.INSTANCE);
+        String sx    = matrix.getAttributeNS(ns, "sx");
+        String sy    = matrix.getAttributeNS(ns, "sy");
+        String tx    = matrix.getAttributeNS(ns, "tx");
+        String ty    = matrix.getAttributeNS(ns, "ty");
+        String xType = matrix.getAttributeNS(ns, "xtype");
+        String yType = matrix.getAttributeNS(ns, "ytype");
 
-        String tx = XMLUtils.xpathString(
-            matrix, "@art:tx", ArtifactNamespaceContext.INSTANCE);
-
-        String ty = XMLUtils.xpathString(
-            matrix, "@art:ty", ArtifactNamespaceContext.INSTANCE);
+        xType = xType == null || xType.length() == 0 ? "number" : xType;
+        yType = yType == null || yType.length() == 0 ? "number" : yType;
 
         if (sx != null && sy != null && tx != null && ty != null) {
             try {
+                logger.debug("Create new Transform2D with x format: " + xType);
+                logger.debug("Create new Transform2D with y format: " + yType);
+
                 return new Transform2D(
                     Double.parseDouble(sx),
                     Double.parseDouble(sy),
                     Double.parseDouble(tx),
-                    Double.parseDouble(ty));
+                    Double.parseDouble(ty),
+                    xType, yType);
             }
             catch (NumberFormatException nfe) {
                 logger.warn("Error while parsing matrix values.");
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/Transform2D.java	Mon Feb 06 13:27:05 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/Transform2D.java	Mon Feb 06 14:43:27 2012 +0000
@@ -1,8 +1,12 @@
 package de.intevation.flys.client.shared;
 
 import java.io.Serializable;
+import java.util.Date;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
+import com.google.gwt.i18n.client.NumberFormat;
 
 
 /**
@@ -13,6 +17,9 @@
  */
 public class Transform2D implements Serializable {
 
+    protected String xType;
+    protected String yType;
+
     protected double sx;
     protected double sy;
 
@@ -33,6 +40,19 @@
      * @param ty The translation factor for the y axis.
      */
     public Transform2D(double sx, double sy, double tx, double ty) {
+        this(sx, sy, tx, ty, "number", "number");
+    }
+
+
+    public Transform2D(
+        double sx, double sy,
+        double tx, double ty,
+        String xType,
+        String yType
+    ) {
+        this.xType = xType;
+        this.yType = yType;
+
         this.sx  = sx;
         this.sy  = sy;
         this.tx  = tx;
@@ -52,6 +72,53 @@
     }
 
 
+    public String[] format(Number[] xy) {
+        String x = null;
+        String y = null;
+
+        if (xType.equals("date")) {
+            x = formatDate(xy[0].longValue());
+        }
+        else {
+            x = formatNumber(xy[0].doubleValue());
+        }
+
+        if (yType.equals("date")) {
+            y = formatDate(xy[1].longValue());
+        }
+        else {
+            y = formatNumber(xy[1].doubleValue());
+        }
+
+        return new String[] { x, y };
+    }
+
+
+    protected String formatDate(long time) {
+        Date date = new Date(time);
+        DateTimeFormat df = getDateTimeFormat();
+
+        return df.format(date);
+    }
+
+
+    protected String formatNumber(double number) {
+        NumberFormat nf = getNumberFormat();
+
+        return nf.format(number);
+    }
+
+
+    public DateTimeFormat getDateTimeFormat() {
+        return DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT);
+    }
+
+
+    public NumberFormat getNumberFormat() {
+        return NumberFormat.getDecimalFormat();
+    }
+
+
     public void dumpGWT() {
         GWT.log("SX = " + sx);
         GWT.log("SY = " + sy);

http://dive4elements.wald.intevation.org