Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/shared/Transform2D.java @ 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 | ea2191b1299d |
children |
line wrap: on
line diff
--- 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);