Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
1597:8bbaa0d173cf | 1598:ef745bc6bed9 |
---|---|
1 package de.intevation.flys.client.shared; | 1 package de.intevation.flys.client.shared; |
2 | 2 |
3 import java.io.Serializable; | 3 import java.io.Serializable; |
4 import java.util.Date; | |
4 | 5 |
5 import com.google.gwt.core.client.GWT; | 6 import com.google.gwt.core.client.GWT; |
7 import com.google.gwt.i18n.client.DateTimeFormat; | |
8 import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; | |
9 import com.google.gwt.i18n.client.NumberFormat; | |
6 | 10 |
7 | 11 |
8 /** | 12 /** |
9 * This object supports a linear transformation to transform xy coordinates into | 13 * This object supports a linear transformation to transform xy coordinates into |
10 * an other coordinate system based on scale and translation values. | 14 * an other coordinate system based on scale and translation values. |
11 * | 15 * |
12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 16 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
13 */ | 17 */ |
14 public class Transform2D implements Serializable { | 18 public class Transform2D implements Serializable { |
19 | |
20 protected String xType; | |
21 protected String yType; | |
15 | 22 |
16 protected double sx; | 23 protected double sx; |
17 protected double sy; | 24 protected double sy; |
18 | 25 |
19 protected double tx; | 26 protected double tx; |
31 * @param sy The scale factor for the y axis. | 38 * @param sy The scale factor for the y axis. |
32 * @param tx The translation factor for the x axis. | 39 * @param tx The translation factor for the x axis. |
33 * @param ty The translation factor for the y axis. | 40 * @param ty The translation factor for the y axis. |
34 */ | 41 */ |
35 public Transform2D(double sx, double sy, double tx, double ty) { | 42 public Transform2D(double sx, double sy, double tx, double ty) { |
43 this(sx, sy, tx, ty, "number", "number"); | |
44 } | |
45 | |
46 | |
47 public Transform2D( | |
48 double sx, double sy, | |
49 double tx, double ty, | |
50 String xType, | |
51 String yType | |
52 ) { | |
53 this.xType = xType; | |
54 this.yType = yType; | |
55 | |
36 this.sx = sx; | 56 this.sx = sx; |
37 this.sy = sy; | 57 this.sy = sy; |
38 this.tx = tx; | 58 this.tx = tx; |
39 this.ty = ty; | 59 this.ty = ty; |
40 } | 60 } |
50 | 70 |
51 return new double[] { resX, resY }; | 71 return new double[] { resX, resY }; |
52 } | 72 } |
53 | 73 |
54 | 74 |
75 public String[] format(Number[] xy) { | |
76 String x = null; | |
77 String y = null; | |
78 | |
79 if (xType.equals("date")) { | |
80 x = formatDate(xy[0].longValue()); | |
81 } | |
82 else { | |
83 x = formatNumber(xy[0].doubleValue()); | |
84 } | |
85 | |
86 if (yType.equals("date")) { | |
87 y = formatDate(xy[1].longValue()); | |
88 } | |
89 else { | |
90 y = formatNumber(xy[1].doubleValue()); | |
91 } | |
92 | |
93 return new String[] { x, y }; | |
94 } | |
95 | |
96 | |
97 protected String formatDate(long time) { | |
98 Date date = new Date(time); | |
99 DateTimeFormat df = getDateTimeFormat(); | |
100 | |
101 return df.format(date); | |
102 } | |
103 | |
104 | |
105 protected String formatNumber(double number) { | |
106 NumberFormat nf = getNumberFormat(); | |
107 | |
108 return nf.format(number); | |
109 } | |
110 | |
111 | |
112 public DateTimeFormat getDateTimeFormat() { | |
113 return DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT); | |
114 } | |
115 | |
116 | |
117 public NumberFormat getNumberFormat() { | |
118 return NumberFormat.getDecimalFormat(); | |
119 } | |
120 | |
121 | |
55 public void dumpGWT() { | 122 public void dumpGWT() { |
56 GWT.log("SX = " + sx); | 123 GWT.log("SX = " + sx); |
57 GWT.log("SY = " + sy); | 124 GWT.log("SY = " + sy); |
58 GWT.log("TX = " + tx); | 125 GWT.log("TX = " + tx); |
59 GWT.log("TY = " + ty); | 126 GWT.log("TY = " + ty); |