1 | /* |
---|
2 | * $Id: AxisTransform.java,v 1.11 2003/08/22 23:02:31 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.sgt; |
---|
14 | |
---|
15 | import java.beans.PropertyChangeListener; |
---|
16 | import java.beans.PropertyChangeSupport; |
---|
17 | |
---|
18 | import gov.noaa.pmel.util.GeoDate; |
---|
19 | import gov.noaa.pmel.util.Range2D; |
---|
20 | import gov.noaa.pmel.util.TimeRange; |
---|
21 | import gov.noaa.pmel.util.SoTValue; |
---|
22 | import gov.noaa.pmel.util.SoTRange; |
---|
23 | |
---|
24 | /** |
---|
25 | * Abstract base class for cartesian axis transforms. Adds additional |
---|
26 | * functionality to <code>Transform</code> necessary for use with |
---|
27 | * axes. |
---|
28 | * |
---|
29 | * @author Donald Denbo |
---|
30 | * @version $Revision: 1.11 $, $Date: 2003/08/22 23:02:31 $ |
---|
31 | * @since 1.0 |
---|
32 | */ |
---|
33 | public abstract class AxisTransform implements Transform { |
---|
34 | protected PropertyChangeSupport changes_ = new PropertyChangeSupport(this); |
---|
35 | // serialVersion ref 1.9.2.2 |
---|
36 | private static final long serialVersionUID = -1577305732337537031L; |
---|
37 | protected double p1_; |
---|
38 | protected double p2_; |
---|
39 | protected double u1_; |
---|
40 | protected double u2_; |
---|
41 | protected long t1_; |
---|
42 | protected long t2_; |
---|
43 | protected boolean space_; |
---|
44 | protected String ident_; |
---|
45 | /** |
---|
46 | * Default constructor. Creates a transform with arguments |
---|
47 | * <code>AxisTransform(0.0, 1.0, 0.0, 1.0)</code>. |
---|
48 | **/ |
---|
49 | public AxisTransform() { |
---|
50 | this(0.0, 1.0, 0.0, 1.0); |
---|
51 | } |
---|
52 | /** |
---|
53 | * <code>AxisTransform</code> space constructor. |
---|
54 | * This constructor is used to define |
---|
55 | * transforms that use double values. |
---|
56 | * |
---|
57 | * @param p1 minimum value, physical coordinates |
---|
58 | * @param p2 maximum value, physical coordinates |
---|
59 | * @param u1 minimum value, user coordinates |
---|
60 | * @param u2 maximum value, user coordinates |
---|
61 | * @see LinearTransform |
---|
62 | **/ |
---|
63 | public AxisTransform(double p1,double p2,double u1,double u2) { |
---|
64 | this.p1_ = p1; |
---|
65 | this.p2_ = p2; |
---|
66 | this.u1_ = u1; |
---|
67 | this.u2_ = u2; |
---|
68 | space_ = true; |
---|
69 | computeTransform(); |
---|
70 | ident_ = "space transform"; |
---|
71 | } |
---|
72 | /** |
---|
73 | * <code>AxisTransform</code> space constructor. |
---|
74 | * This constructor is used to define |
---|
75 | * transforms that use <Range2D> values. |
---|
76 | * |
---|
77 | * @param pr physical coordinate range |
---|
78 | * @param ur user coordinate range |
---|
79 | * @see Range2D |
---|
80 | * @see LinearTransform |
---|
81 | **/ |
---|
82 | public AxisTransform(Range2D pr,Range2D ur) { |
---|
83 | this(pr.start, pr.end, ur.start, ur.end); |
---|
84 | } |
---|
85 | /** |
---|
86 | * <code>AxisTransform</code> time constructor. |
---|
87 | * This constructor is used to define |
---|
88 | * transforms that use <code>GeoDate</code> values. |
---|
89 | * |
---|
90 | * @param p1 minimum value, physical coordinates |
---|
91 | * @param p2 maximum value, physical coordinates |
---|
92 | * @param t1 minimum time |
---|
93 | * @param t2 maximum time |
---|
94 | * @see GeoDate |
---|
95 | * @see LinearTransform |
---|
96 | **/ |
---|
97 | public AxisTransform(double p1,double p2,GeoDate t1,GeoDate t2) { |
---|
98 | p1_ = p1; |
---|
99 | p2_ = p2; |
---|
100 | t1_ = t1.getTime(); |
---|
101 | t2_ = t2.getTime(); |
---|
102 | space_ = false; |
---|
103 | computeTransform(); |
---|
104 | ident_ = "time transform"; |
---|
105 | } |
---|
106 | /** |
---|
107 | * <code>AxisTransform</code> time constructor. |
---|
108 | * This constructor is used to define |
---|
109 | * transforms that use <code>long</code> values to represent |
---|
110 | * number of milliseconds since 1970-01-01. |
---|
111 | * |
---|
112 | * @since 3.0 |
---|
113 | * @param p1 minimum value, physical coordinates |
---|
114 | * @param p2 maximum value, physical coordinates |
---|
115 | * @param t1 minimum time |
---|
116 | * @param t2 maximum time |
---|
117 | * @see LinearTransform |
---|
118 | **/ |
---|
119 | public AxisTransform(double p1, double p2, long t1, long t2) { |
---|
120 | p1_ = p1; |
---|
121 | p2_ = p2; |
---|
122 | t1_ = t1; |
---|
123 | t2_ = t2; |
---|
124 | space_ = false; |
---|
125 | computeTransform(); |
---|
126 | ident_ = "time transform"; |
---|
127 | } |
---|
128 | /** |
---|
129 | * <code>AxisTransform</code> time constructor. |
---|
130 | * This constructor is used to define |
---|
131 | * transforms that use <TimeRange> values. |
---|
132 | * |
---|
133 | * @param pr physical coordinates range |
---|
134 | * @param tr time range |
---|
135 | * @see Range2D |
---|
136 | * @see TimeRange |
---|
137 | * @see GeoDate |
---|
138 | * @see LinearTransform |
---|
139 | **/ |
---|
140 | public AxisTransform(Range2D pr, TimeRange tr) { |
---|
141 | this(pr.start, pr.end, tr.start, tr.end); |
---|
142 | } |
---|
143 | /** |
---|
144 | * <code>AxisTransform</code> SoT constructor. This constructor |
---|
145 | * uses the <code>SoTRange</code> class enabling the construction of |
---|
146 | * a Time or Space transform. |
---|
147 | * |
---|
148 | * @since 2.0 |
---|
149 | */ |
---|
150 | public AxisTransform(Range2D pr, SoTRange str) { |
---|
151 | if(str.isTime()) { |
---|
152 | t1_ = str.getStart().getLongTime(); |
---|
153 | t2_ = str.getEnd().getLongTime(); |
---|
154 | space_ = false; |
---|
155 | } else { |
---|
156 | u1_ = ((SoTRange.Double)str).start; |
---|
157 | u2_ = ((SoTRange.Double)str).end; |
---|
158 | space_ = true; |
---|
159 | } |
---|
160 | setRangeP(pr); |
---|
161 | computeTransform(); |
---|
162 | } |
---|
163 | /** |
---|
164 | * Set physical coordinate range. |
---|
165 | * <BR><B>Property Change:</B> <code>rangeP</code>. |
---|
166 | * |
---|
167 | * @param p1 minimum value, physical coordinates |
---|
168 | * @param p2 maximum value, physical coordinates |
---|
169 | * @see LinearTransform |
---|
170 | **/ |
---|
171 | public void setRangeP(double p1,double p2) { |
---|
172 | if(p1_ != p1 || p2_ != p2) { |
---|
173 | Range2D tempOld = new Range2D(p1_, p2_); |
---|
174 | this.p1_ = p1; |
---|
175 | this.p2_ = p2; |
---|
176 | computeTransform(); |
---|
177 | changes_.firePropertyChange("rangeP", |
---|
178 | tempOld, |
---|
179 | new Range2D(p1_, p2_)); |
---|
180 | } |
---|
181 | } |
---|
182 | /** |
---|
183 | * Set transform identifier. |
---|
184 | * |
---|
185 | * @param id transform identifier |
---|
186 | **/ |
---|
187 | public void setId(String id) { |
---|
188 | ident_ = id; |
---|
189 | } |
---|
190 | /** |
---|
191 | * Get transform identifier. |
---|
192 | * |
---|
193 | * @return identifier |
---|
194 | **/ |
---|
195 | public String getId() { |
---|
196 | return ident_; |
---|
197 | } |
---|
198 | /** |
---|
199 | * Set physical coordinate range. |
---|
200 | * |
---|
201 | * @param prange physcial coordinate range |
---|
202 | * @see Range2D |
---|
203 | * @see LinearTransform |
---|
204 | **/ |
---|
205 | public void setRangeP(Range2D prange) { |
---|
206 | setRangeP(prange.start, prange.end); |
---|
207 | } |
---|
208 | /** |
---|
209 | * Get the physical coordinate range. |
---|
210 | * |
---|
211 | * @return physcial coordinate range |
---|
212 | * @see Range2D |
---|
213 | **/ |
---|
214 | public Range2D getRangeP() { |
---|
215 | return new Range2D(p1_, p2_); |
---|
216 | } |
---|
217 | /** |
---|
218 | * Set the user coordinate range for space values. |
---|
219 | * <BR><B>Property Change:</B> <code>rangeU</code>. |
---|
220 | * |
---|
221 | * @param u1 minimum value, user coordinates |
---|
222 | * @param u2 maximum value, user coordinates |
---|
223 | * @see LinearTransform |
---|
224 | **/ |
---|
225 | public void setRangeU(double u1,double u2) { |
---|
226 | if(u1_ != u1 || u2_ != u2) { |
---|
227 | Range2D tempOld = new Range2D(u1_, u2_); |
---|
228 | this.u1_ = u1; |
---|
229 | this.u2_ = u2; |
---|
230 | space_ = true; |
---|
231 | computeTransform(); |
---|
232 | changes_.firePropertyChange("rangeU", |
---|
233 | tempOld, |
---|
234 | new Range2D(u1_, u2_)); |
---|
235 | } |
---|
236 | } |
---|
237 | /** |
---|
238 | * Set the user coordinate range for <code>Range2D</code> values. |
---|
239 | * |
---|
240 | * @param urange user coordinate range |
---|
241 | * @see Range2D |
---|
242 | * @see LinearTransform |
---|
243 | **/ |
---|
244 | public void setRangeU(Range2D urange) { |
---|
245 | setRangeU(urange.start, urange.end); |
---|
246 | } |
---|
247 | /** |
---|
248 | * Get the user coordinate range for double values. |
---|
249 | * |
---|
250 | * @return user range |
---|
251 | * @see Range2D |
---|
252 | **/ |
---|
253 | public Range2D getRangeU() { |
---|
254 | return new Range2D(u1_, u2_); |
---|
255 | } |
---|
256 | /** |
---|
257 | * Set the user coordinate range for <code>GeoDate</code> values. |
---|
258 | * <BR><B>Property Change:</B> <code>rangeU</code>. |
---|
259 | * |
---|
260 | * @param t1 minimum time |
---|
261 | * @param t2 maximum time |
---|
262 | * @see GeoDate |
---|
263 | * @see LinearTransform |
---|
264 | **/ |
---|
265 | public void setRangeU(GeoDate gt1, GeoDate gt2) { |
---|
266 | setRangeU(gt1.getTime(), gt2.getTime()); |
---|
267 | } |
---|
268 | /** |
---|
269 | * |
---|
270 | * @since 3.0 |
---|
271 | */ |
---|
272 | public void setRangeU(long t1, long t2) { |
---|
273 | if(!(t1_ == t1) || !(t2_ == t2)) { |
---|
274 | SoTRange tempOld = new SoTRange.Time(t1_, t2_); |
---|
275 | t1_ = t1; |
---|
276 | t2_ = t2; |
---|
277 | space_ = false; |
---|
278 | computeTransform(); |
---|
279 | changes_.firePropertyChange("rangeU", |
---|
280 | tempOld, |
---|
281 | new SoTRange.Time(t1_, t2_)); |
---|
282 | } |
---|
283 | } |
---|
284 | /** |
---|
285 | * Set the user coordinate range for <code>TimeRange</code> value. |
---|
286 | * |
---|
287 | * @param trange time range |
---|
288 | * @see TimeRange |
---|
289 | * @see LinearTransform |
---|
290 | **/ |
---|
291 | public void setRangeU(TimeRange trange) { |
---|
292 | setRangeU(trange.start, trange.end); |
---|
293 | } |
---|
294 | /** |
---|
295 | * Get the user coordinate range for <code>GeoDate</code> values. |
---|
296 | * |
---|
297 | * @return time range |
---|
298 | * @see TimeRange |
---|
299 | **/ |
---|
300 | public TimeRange getTimeRangeU() { |
---|
301 | return new TimeRange(new GeoDate(t1_), new GeoDate(t2_)); |
---|
302 | } |
---|
303 | /** |
---|
304 | * Set the user range with a <code>SoTRange</code> object. |
---|
305 | * @since 2.0 |
---|
306 | */ |
---|
307 | public void setRangeU(SoTRange str) { |
---|
308 | if(str.isTime()) { |
---|
309 | setRangeU(str.getStart().getLongTime(), |
---|
310 | str.getEnd().getLongTime()); |
---|
311 | } else { |
---|
312 | setRangeU(((SoTRange.Double)str).start, |
---|
313 | ((SoTRange.Double)str).end); |
---|
314 | } |
---|
315 | } |
---|
316 | /** |
---|
317 | * Get the user range as a <code>SoTRange</code> object. |
---|
318 | * @since 2.0 |
---|
319 | */ |
---|
320 | public SoTRange getSoTRangeU() { |
---|
321 | if(space_) { |
---|
322 | return new SoTRange.Double(u1_, u2_); |
---|
323 | } else { |
---|
324 | return new SoTRange.Time(t1_, t2_); |
---|
325 | } |
---|
326 | } |
---|
327 | /** |
---|
328 | * Test if transform has user double values. |
---|
329 | * |
---|
330 | * @return true if user coordinates are double values |
---|
331 | **/ |
---|
332 | public boolean isSpace() { |
---|
333 | return space_; |
---|
334 | } |
---|
335 | /** |
---|
336 | * Test if transform has user <code>GeoDate</code> values. |
---|
337 | * |
---|
338 | * @return true if user coordinates are <code>GeoDate</code> values. |
---|
339 | * @see GeoDate |
---|
340 | **/ |
---|
341 | public boolean isTime() { |
---|
342 | return !space_; |
---|
343 | } |
---|
344 | abstract double getTransP(GeoDate t); |
---|
345 | /** |
---|
346 | * @since 3.0 |
---|
347 | */ |
---|
348 | abstract double getTransP(long t); |
---|
349 | abstract GeoDate getTimeTransU(double p); |
---|
350 | /** |
---|
351 | * @since 3.0 |
---|
352 | */ |
---|
353 | abstract long getLongTimeTransU(double p); |
---|
354 | abstract void computeTransform(); |
---|
355 | abstract AxisTransform copy(); |
---|
356 | |
---|
357 | /** |
---|
358 | * Get physical value as a function of <code>SoTValue</code>. |
---|
359 | * @since 2.0 |
---|
360 | */ |
---|
361 | public abstract double getTransP(SoTValue value); |
---|
362 | /** |
---|
363 | * Get user transform value as a <code>SoTValue</code> |
---|
364 | * @since 2.0 |
---|
365 | */ |
---|
366 | public abstract SoTValue getSoTTransU(double value); |
---|
367 | /** |
---|
368 | * Add listener to changes in <code>LinearTransform</code> |
---|
369 | * properties. |
---|
370 | * @since 2.0 |
---|
371 | */ |
---|
372 | public void addPropertyChangeListener(PropertyChangeListener listener) { |
---|
373 | changes_.addPropertyChangeListener(listener); |
---|
374 | } |
---|
375 | /** |
---|
376 | * Remove listener from list. |
---|
377 | * @since 2.0 |
---|
378 | */ |
---|
379 | public void removePropertyChangeListener(PropertyChangeListener listener) { |
---|
380 | changes_.removePropertyChangeListener(listener); |
---|
381 | } |
---|
382 | } |
---|