1 | /* |
---|
2 | * $Id: TimeAxis.java,v 1.15 2003/08/22 23:02:32 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 gov.noaa.pmel.util.TimeRange; |
---|
16 | import gov.noaa.pmel.util.TimePoint; |
---|
17 | import gov.noaa.pmel.util.GeoDate; |
---|
18 | import gov.noaa.pmel.util.Point2D; |
---|
19 | import gov.noaa.pmel.util.Debug; |
---|
20 | import gov.noaa.pmel.util.SoTValue; |
---|
21 | import gov.noaa.pmel.util.SoTPoint; |
---|
22 | import gov.noaa.pmel.util.SoTRange; |
---|
23 | |
---|
24 | import java.util.Enumeration; |
---|
25 | import java.util.Vector; |
---|
26 | import java.awt.Graphics; |
---|
27 | import java.awt.Rectangle; |
---|
28 | import java.awt.Color; |
---|
29 | // jdk1.2 |
---|
30 | //import java.awt.geom.Point2D; |
---|
31 | |
---|
32 | /** |
---|
33 | * Base class for time axes. A time axis is an axis whose user units |
---|
34 | * are GeoDate objects. |
---|
35 | * |
---|
36 | * @author Donald Denbo |
---|
37 | * @version $Revision: 1.15 $, $Date: 2003/08/22 23:02:32 $ |
---|
38 | * @since 1.0 |
---|
39 | * @see Axis |
---|
40 | */ |
---|
41 | public class TimeAxis extends Axis implements Cloneable{ |
---|
42 | // |
---|
43 | protected TimeRange tRange_; |
---|
44 | protected TimePoint tLocation_; |
---|
45 | // |
---|
46 | protected String minorLabelFormat_; |
---|
47 | protected int minorLabelInterval_; |
---|
48 | protected String majorLabelFormat_; |
---|
49 | protected int majorLabelInterval_; |
---|
50 | // |
---|
51 | protected double yminor_; |
---|
52 | // |
---|
53 | protected double ymajor_; |
---|
54 | protected double xminor_; |
---|
55 | protected double xmajor_; |
---|
56 | protected int vertalign_; |
---|
57 | // |
---|
58 | /**@shapeType AggregationLink |
---|
59 | @associates <b>TimeAxisStyle</b> |
---|
60 | * @supplierCardinality 1 |
---|
61 | * @byValue */ |
---|
62 | protected TimeAxisStyle txt_; |
---|
63 | protected int axisStyle_; |
---|
64 | static final double TIC_RATIO__ = 1.3; |
---|
65 | static final double TIC_GAP__ = 0.05; |
---|
66 | static final double LABEL_RATIO__ = 1.0; |
---|
67 | static final double MAJOR_LABEL_RATIO__ = 1.25; |
---|
68 | |
---|
69 | static final double defaultLargeTicHeight__ = 0.1; |
---|
70 | static final double defaultSmallTicHeight__ = 0.05; |
---|
71 | static final int defaultTicPosition__ = Axis.NEGATIVE_SIDE; |
---|
72 | static final int defaultLabelPosition__ = Axis.NEGATIVE_SIDE; |
---|
73 | static final double defaultLabelHeight__ = 0.15; |
---|
74 | /** |
---|
75 | * Automatically select the time axis style |
---|
76 | */ |
---|
77 | public static final int AUTO = 0; |
---|
78 | /** |
---|
79 | * Use the YearDecadeAxis style. |
---|
80 | * <pre> |
---|
81 | * |..........|..........|..........|..........| |
---|
82 | * 84 85 86 87 |
---|
83 | * 1980 |
---|
84 | * </pre> |
---|
85 | */ |
---|
86 | public static final int YEAR_DECADE = 1; |
---|
87 | /** |
---|
88 | * Use the MonthYearAxis style. |
---|
89 | * <pre> |
---|
90 | * |..........|..........|..........|..........| |
---|
91 | * Mar Apr May Jun |
---|
92 | * 1980 |
---|
93 | * </pre> |
---|
94 | */ |
---|
95 | public static final int MONTH_YEAR = 2; |
---|
96 | /** |
---|
97 | * Use the DayMonthAxis style. |
---|
98 | * <pre> |
---|
99 | * |..........|..........|..........|..........| |
---|
100 | * 3 4 5 6 |
---|
101 | * 1993-04 |
---|
102 | * </pre> |
---|
103 | */ |
---|
104 | public static final int DAY_MONTH = 3; |
---|
105 | /** |
---|
106 | * Use the HourDayAxis style. |
---|
107 | * <pre> |
---|
108 | * |..........|..........|..........|..........| |
---|
109 | * 03 04 05 06 07 |
---|
110 | * 1987-06-07 |
---|
111 | * </pre> |
---|
112 | */ |
---|
113 | public static final int HOUR_DAY = 4; |
---|
114 | /** |
---|
115 | * Use the MinuteHourAxis style. |
---|
116 | * <pre> |
---|
117 | * |..........|..........|..........|..........| |
---|
118 | * 15 30 45 00 15 |
---|
119 | * 1987-06-07 13 |
---|
120 | * </pre> |
---|
121 | */ |
---|
122 | public static final int MINUTE_HOUR = 5; |
---|
123 | |
---|
124 | private void setAuto() { |
---|
125 | TimeAxisStyle newStyle = null; |
---|
126 | |
---|
127 | GeoDate delta = tRange_.end.subtract(tRange_.start); |
---|
128 | double days = ((double)Math.abs(delta.getTime()))/((double)GeoDate.MSECS_IN_DAY); |
---|
129 | if(Debug.TAXIS) { |
---|
130 | System.out.println("setAuto: days = " + days); |
---|
131 | } |
---|
132 | if(days > 1000.0) { |
---|
133 | if(!(txt_ instanceof YearDecadeAxis)) { |
---|
134 | newStyle = (TimeAxisStyle)new YearDecadeAxis(); |
---|
135 | } |
---|
136 | } else if(days > 91.0) { |
---|
137 | if(!(txt_ instanceof MonthYearAxis)) { |
---|
138 | newStyle = (TimeAxisStyle)new MonthYearAxis(); |
---|
139 | } |
---|
140 | } else if(days > 5.0) { |
---|
141 | if(!(txt_ instanceof DayMonthAxis)) { |
---|
142 | newStyle = (TimeAxisStyle)new DayMonthAxis(); |
---|
143 | } |
---|
144 | } else if((days > 0.1666667)) { // 6 hours |
---|
145 | if(!(txt_ instanceof HourDayAxis)) { |
---|
146 | newStyle = (TimeAxisStyle)new HourDayAxis(); |
---|
147 | } |
---|
148 | } else { |
---|
149 | if(!(txt_ instanceof MinuteHourAxis)) { |
---|
150 | newStyle = (TimeAxisStyle)new MinuteHourAxis(); |
---|
151 | } |
---|
152 | } |
---|
153 | if(newStyle != null) { |
---|
154 | txt_ = newStyle; |
---|
155 | // } else { |
---|
156 | // return; |
---|
157 | } |
---|
158 | txt_.computeDefaults(delta); |
---|
159 | |
---|
160 | minorLabelFormat_ = txt_.getDefaultMinorLabelFormat(); |
---|
161 | majorLabelFormat_ = txt_.getDefaultMajorLabelFormat(); |
---|
162 | minorLabelInterval_ = txt_.getDefaultMinorLabelInterval(); |
---|
163 | majorLabelInterval_ = txt_.getDefaultMajorLabelInterval(); |
---|
164 | numSmallTics_ = txt_.getDefaultNumSmallTics(); |
---|
165 | // largeTicHeight_ = txt_.getDefaultLargeTicHeight(); |
---|
166 | // smallTicHeight_ = txt_.getDefaultSmallTicHeight(); |
---|
167 | // ticPosition_ = txt_.getDefaultTicPosition(); |
---|
168 | // labelPosition_ = txt_.getDefaultLabelPosition(); |
---|
169 | // labelHeight_ = txt_.getDefaultLabelHeight(); |
---|
170 | if(Debug.TAXIS) { |
---|
171 | System.out.println(" style, ticPosition, labelPostiion = " + |
---|
172 | txt_.toString() + ", " + ticPosition_ + ", " + labelPosition_); |
---|
173 | System.out.println(" minorFormat, majorFormat, minorInterval, majorInterval = " + |
---|
174 | minorLabelFormat_ + ", " + majorLabelFormat_ + ", " + |
---|
175 | minorLabelInterval_ + ", " + majorLabelInterval_); |
---|
176 | System.out.println(" smallTics, largeHgt, smallHgt, labelHgt = " + |
---|
177 | numSmallTics_ + ", " + largeTicHeight_ + ", " + smallTicHeight_ + ", " + labelHeight_); |
---|
178 | } |
---|
179 | } |
---|
180 | protected void updateRegisteredTransforms() { |
---|
181 | if(!registeredTransforms_.isEmpty()) { |
---|
182 | AxisTransform trns; |
---|
183 | for(Enumeration it = registeredTransforms_.elements(); |
---|
184 | it.hasMoreElements();) { |
---|
185 | trns = (AxisTransform)it.nextElement(); |
---|
186 | trns.setRangeP(pRange_); |
---|
187 | trns.setRangeU(tRange_); |
---|
188 | } |
---|
189 | } |
---|
190 | } |
---|
191 | // |
---|
192 | protected void updateRegisteredAxes() { |
---|
193 | if(!registeredAxes_.isEmpty()) { |
---|
194 | TimeAxis ax; |
---|
195 | for(Enumeration it = registeredAxes_.elements(); |
---|
196 | it.hasMoreElements();) { |
---|
197 | ax = (TimeAxis)it.nextElement(); |
---|
198 | ax.setRangeU(tRange_); |
---|
199 | ax.setRangeP(pRange_); |
---|
200 | } |
---|
201 | } |
---|
202 | } |
---|
203 | protected void setupDraw(double val) { |
---|
204 | if(orientation_ == Axis.HORIZONTAL) { |
---|
205 | if(labelPosition_ == POSITIVE_SIDE) { |
---|
206 | vertalign_ = SGLabel.BOTTOM; |
---|
207 | if(minorLabelInterval_ == 0) { |
---|
208 | yminor_ = val; |
---|
209 | } else if(ticPosition_ == BOTH_SIDES || ticPosition_ == POSITIVE_SIDE) { |
---|
210 | yminor_ = val + TIC_RATIO__*largeTicHeight_; |
---|
211 | } else { |
---|
212 | yminor_ = val + TIC_GAP__; |
---|
213 | } |
---|
214 | ymajor_ = yminor_ + LABEL_RATIO__*labelHeight_; |
---|
215 | } else { |
---|
216 | vertalign_ = SGLabel.TOP; |
---|
217 | if(minorLabelInterval_ == 0) { |
---|
218 | yminor_ = val; |
---|
219 | } else if(ticPosition_ == BOTH_SIDES || ticPosition_ == NEGATIVE_SIDE) { |
---|
220 | yminor_ = val - TIC_RATIO__*largeTicHeight_; |
---|
221 | } else { |
---|
222 | yminor_ = val - TIC_GAP__; |
---|
223 | } |
---|
224 | ymajor_ = yminor_ - LABEL_RATIO__*labelHeight_; |
---|
225 | } |
---|
226 | } else { |
---|
227 | if(labelPosition_ == NEGATIVE_SIDE) { |
---|
228 | vertalign_ = SGLabel.BOTTOM; |
---|
229 | if(minorLabelInterval_ == 0) { |
---|
230 | xminor_ = val; |
---|
231 | } else if(ticPosition_ == BOTH_SIDES || ticPosition_ == NEGATIVE_SIDE) { |
---|
232 | xminor_ = val - TIC_RATIO__*largeTicHeight_; |
---|
233 | } else { |
---|
234 | xminor_ = val - TIC_GAP__; |
---|
235 | } |
---|
236 | xmajor_ = xminor_ - LABEL_RATIO__*labelHeight_; |
---|
237 | } else { |
---|
238 | vertalign_ = SGLabel.TOP; |
---|
239 | if(minorLabelInterval_ == 0) { |
---|
240 | xminor_ = val; |
---|
241 | } else if(ticPosition_ == BOTH_SIDES || ticPosition_ == POSITIVE_SIDE) { |
---|
242 | xminor_ = val + TIC_RATIO__*largeTicHeight_; |
---|
243 | } else { |
---|
244 | xminor_ = val + TIC_GAP__; |
---|
245 | } |
---|
246 | xmajor_ = xminor_ + LABEL_RATIO__*labelHeight_; |
---|
247 | } |
---|
248 | } |
---|
249 | } |
---|
250 | protected void drawMinorLabel(Graphics g,double val,GeoDate time) { |
---|
251 | SGLabel label; |
---|
252 | Color saved = g.getColor(); |
---|
253 | if(orientation_ == Axis.HORIZONTAL) { |
---|
254 | label = new SGLabel("minor", time.toString(minorLabelFormat_), |
---|
255 | new Point2D.Double(val, yminor_)); |
---|
256 | label.setOrientation(SGLabel.HORIZONTAL); |
---|
257 | } else { |
---|
258 | label = new SGLabel("minor", time.toString(minorLabelFormat_), |
---|
259 | new Point2D.Double(xminor_, val)); |
---|
260 | label.setOrientation(SGLabel.VERTICAL); |
---|
261 | } |
---|
262 | label.setAlign(vertalign_, SGLabel.CENTER); |
---|
263 | label.setFont(labelFont_); |
---|
264 | label.setColor(labelColor_); |
---|
265 | label.setHeightP(labelHeight_); |
---|
266 | label.setLayer(graph_.getLayer()); |
---|
267 | try { |
---|
268 | label.draw(g); |
---|
269 | } catch (LayerNotFoundException e) {} |
---|
270 | g.setColor(saved); |
---|
271 | } |
---|
272 | protected void drawMajorLabel(Graphics g,double val,GeoDate time) { |
---|
273 | Color saved = g.getColor(); |
---|
274 | SGLabel label; |
---|
275 | // VMIPSL |
---|
276 | String labelStr = time.toString( majorLabelFormat_ ); |
---|
277 | if( title_ != null ) |
---|
278 | labelStr += title_.getText(); |
---|
279 | if(orientation_ == Axis.HORIZONTAL) { |
---|
280 | label = new SGLabel("major", labelStr, |
---|
281 | new Point2D.Double(val, ymajor_)); |
---|
282 | label.setOrientation(SGLabel.HORIZONTAL); |
---|
283 | } else { |
---|
284 | label = new SGLabel("major", labelStr, |
---|
285 | new Point2D.Double(xmajor_, val)); |
---|
286 | label.setOrientation(SGLabel.VERTICAL); |
---|
287 | } |
---|
288 | label.setAlign(vertalign_, SGLabel.CENTER); |
---|
289 | label.setFont(labelFont_); |
---|
290 | label.setColor(labelColor_); |
---|
291 | label.setHeightP(MAJOR_LABEL_RATIO__*labelHeight_); |
---|
292 | label.setLayer(graph_.getLayer()); |
---|
293 | try { |
---|
294 | label.draw(g); |
---|
295 | } catch (LayerNotFoundException e) {} |
---|
296 | g.setColor(saved); |
---|
297 | } |
---|
298 | // |
---|
299 | /** |
---|
300 | * Default contructor. |
---|
301 | **/ |
---|
302 | public TimeAxis(int style) { |
---|
303 | this("", style); |
---|
304 | } |
---|
305 | /** |
---|
306 | * TimeAxis constructor. |
---|
307 | * |
---|
308 | * @param id axis identifier |
---|
309 | **/ |
---|
310 | public TimeAxis(String id,int style) { |
---|
311 | super(id); |
---|
312 | minorLabelInterval_ = 2; |
---|
313 | majorLabelInterval_ = 1; |
---|
314 | numSmallTics_ = 0; |
---|
315 | space_ = false; |
---|
316 | axisStyle_ = style; |
---|
317 | // |
---|
318 | if(axisStyle_ == AUTO || axisStyle_ == MONTH_YEAR) { |
---|
319 | txt_ = (TimeAxisStyle)new MonthYearAxis(); |
---|
320 | } else if(axisStyle_ == YEAR_DECADE) { |
---|
321 | txt_ = (TimeAxisStyle)new YearDecadeAxis(); |
---|
322 | } else if(axisStyle_ == DAY_MONTH) { |
---|
323 | txt_ = (TimeAxisStyle)new DayMonthAxis(); |
---|
324 | } else if(axisStyle_ == HOUR_DAY) { |
---|
325 | txt_ = (TimeAxisStyle)new HourDayAxis(); |
---|
326 | } else { |
---|
327 | txt_ = (TimeAxisStyle)new MinuteHourAxis(); |
---|
328 | } |
---|
329 | minorLabelFormat_ = txt_.getDefaultMinorLabelFormat(); |
---|
330 | majorLabelFormat_ = txt_.getDefaultMajorLabelFormat(); |
---|
331 | minorLabelInterval_ = txt_.getDefaultMinorLabelInterval(); |
---|
332 | majorLabelInterval_ = txt_.getDefaultMajorLabelInterval(); |
---|
333 | numSmallTics_ = txt_.getDefaultNumSmallTics(); |
---|
334 | // |
---|
335 | largeTicHeight_ = defaultLargeTicHeight__; |
---|
336 | smallTicHeight_ = defaultSmallTicHeight__; |
---|
337 | ticPosition_ = defaultTicPosition__; |
---|
338 | labelPosition_ = defaultLabelPosition__; |
---|
339 | labelHeight_ = defaultLabelHeight__; |
---|
340 | tRange_ = null; |
---|
341 | tLocation_ = null; |
---|
342 | } |
---|
343 | public Axis copy() { |
---|
344 | TimeAxis newAxis; |
---|
345 | try { |
---|
346 | newAxis = (TimeAxis)clone(); |
---|
347 | } catch (CloneNotSupportedException e) { |
---|
348 | newAxis = new TimeAxis(getStyle()); |
---|
349 | } |
---|
350 | // |
---|
351 | // remove registered axes and transforms |
---|
352 | // |
---|
353 | newAxis.registeredAxes_ = new Vector(2,2); |
---|
354 | newAxis.registeredTransforms_ = new Vector(2,2); |
---|
355 | // |
---|
356 | return newAxis; |
---|
357 | } |
---|
358 | /** |
---|
359 | * Set the minor and major label formats. |
---|
360 | * |
---|
361 | * @param minor minor label format |
---|
362 | * @param major major label format |
---|
363 | **/ |
---|
364 | public void setLabelFormat(String minor,String major) { |
---|
365 | if(minorLabelFormat_ == null || |
---|
366 | majorLabelFormat_ == null || |
---|
367 | !minorLabelFormat_.equals(minor) || |
---|
368 | !majorLabelFormat_.equals(major)) { |
---|
369 | |
---|
370 | minorLabelFormat_ = minor; |
---|
371 | majorLabelFormat_ = major; |
---|
372 | modified("TimeAxis: setLabelFormat()"); |
---|
373 | } |
---|
374 | } |
---|
375 | /** |
---|
376 | * Set the minor label format. |
---|
377 | * |
---|
378 | * @param minor minor label format |
---|
379 | **/ |
---|
380 | public void setMinorLabelFormat(String minor) { |
---|
381 | if(minorLabelFormat_ == null || !minorLabelFormat_.equals(minor)) { |
---|
382 | minorLabelFormat_ = minor; |
---|
383 | modified("TimeAxis: setMinorLabelFormat()"); |
---|
384 | } |
---|
385 | } |
---|
386 | /** |
---|
387 | * Set the major label format. |
---|
388 | * |
---|
389 | * @param major major label format |
---|
390 | **/ |
---|
391 | public void setMajorLabelFormat(String major) { |
---|
392 | if(majorLabelFormat_ == null || !majorLabelFormat_.equals(major)) { |
---|
393 | majorLabelFormat_ = major; |
---|
394 | modified("TimeAxis: setMajorLabelFormat()"); |
---|
395 | } |
---|
396 | } |
---|
397 | /** |
---|
398 | * Get the minor label format. |
---|
399 | * |
---|
400 | * @return minor label format |
---|
401 | **/ |
---|
402 | public String getMinorLabelFormat() { |
---|
403 | return minorLabelFormat_; |
---|
404 | } |
---|
405 | /** |
---|
406 | * Get the major label format. |
---|
407 | * |
---|
408 | * @return major label format |
---|
409 | **/ |
---|
410 | public String getMajorLabelFormat() { |
---|
411 | return majorLabelFormat_; |
---|
412 | } |
---|
413 | /** |
---|
414 | * Set the minor and major label intervals. |
---|
415 | * |
---|
416 | * @param minor minor label interval |
---|
417 | * @param major major label interval |
---|
418 | **/ |
---|
419 | public void setLabelInterval(int minor,int major) { |
---|
420 | if(minorLabelInterval_ != minor || majorLabelInterval_ != major) { |
---|
421 | minorLabelInterval_ = minor; |
---|
422 | majorLabelInterval_ = major; |
---|
423 | modified("TimeAxis: setLabelInterval()"); |
---|
424 | } |
---|
425 | } |
---|
426 | /** |
---|
427 | * Set the minor label interval. |
---|
428 | * |
---|
429 | * @param minor minor label interval |
---|
430 | **/ |
---|
431 | public void setMinorLabelInterval(int minor) { |
---|
432 | if(minorLabelInterval_ != minor) { |
---|
433 | minorLabelInterval_ = minor; |
---|
434 | modified("TimeAxis: setMinorLabelInterval()"); |
---|
435 | } |
---|
436 | } |
---|
437 | /** |
---|
438 | * Set the major label interval. |
---|
439 | * |
---|
440 | * @param major major label interval |
---|
441 | **/ |
---|
442 | public void setMajorLabelInterval(int major) { |
---|
443 | if(majorLabelInterval_ != major) { |
---|
444 | majorLabelInterval_ = major; |
---|
445 | modified("TimeAxis: setMajorLabelInterval()"); |
---|
446 | } |
---|
447 | } |
---|
448 | /** |
---|
449 | * Get the minor label interval. |
---|
450 | * |
---|
451 | * @return minor label interval |
---|
452 | **/ |
---|
453 | public int getMinorLabelInterval() { |
---|
454 | return minorLabelInterval_; |
---|
455 | } |
---|
456 | /** |
---|
457 | * Get the major label interval. |
---|
458 | * |
---|
459 | * @return major label interval |
---|
460 | **/ |
---|
461 | public int getMajorLabelInterval() { |
---|
462 | return majorLabelInterval_; |
---|
463 | } |
---|
464 | /** |
---|
465 | * Set the time axis style. |
---|
466 | * |
---|
467 | * @param style new time axis style |
---|
468 | */ |
---|
469 | public void setStyle(int style) { |
---|
470 | if(axisStyle_ != style) { |
---|
471 | axisStyle_ = style; |
---|
472 | if(axisStyle_ == AUTO && tRange_ != null) { |
---|
473 | setAuto(); |
---|
474 | } |
---|
475 | modified("TimeAxis: setStyle()"); |
---|
476 | } |
---|
477 | } |
---|
478 | /** |
---|
479 | * Get the time axis style. |
---|
480 | * |
---|
481 | * @return time axis style |
---|
482 | */ |
---|
483 | public int getStyle() { |
---|
484 | return axisStyle_; |
---|
485 | } |
---|
486 | /** |
---|
487 | * Set the user range to draw the axis. Registered Axes and Transforms |
---|
488 | * will be updated. |
---|
489 | * |
---|
490 | * @param tr TimeRange of axis. |
---|
491 | **/ |
---|
492 | public void setRangeU(TimeRange tr) { |
---|
493 | if(tRange_ == null || !tRange_.equals(tr)) { |
---|
494 | tRange_ = tr; |
---|
495 | if(axisStyle_ == AUTO) { |
---|
496 | setAuto(); |
---|
497 | } |
---|
498 | updateRegisteredAxes(); |
---|
499 | updateRegisteredTransforms(); |
---|
500 | modified("TimeAxis: setRangeU()"); |
---|
501 | } |
---|
502 | } |
---|
503 | /** |
---|
504 | * Get the time range of the axis. |
---|
505 | * |
---|
506 | * @return TimeRange of axis |
---|
507 | **/ |
---|
508 | public TimeRange getTimeRangeU() { |
---|
509 | return tRange_; |
---|
510 | } |
---|
511 | public void setRangeU(SoTRange tr) { |
---|
512 | setRangeU(new TimeRange(tr.getStart().getLongTime(), |
---|
513 | tr.getEnd().getLongTime(), |
---|
514 | tr.getDelta().getLongTime())); |
---|
515 | } |
---|
516 | public SoTRange getSoTRangeU() { |
---|
517 | return new SoTRange.Time(tRange_); |
---|
518 | } |
---|
519 | /** |
---|
520 | * Set the origin in user units of the axis. |
---|
521 | * |
---|
522 | * @param tp origin of axis in user units |
---|
523 | **/ |
---|
524 | public void setLocationU(TimePoint tp) { |
---|
525 | if(tLocation_ == null || !tLocation_.equals(tp)) { |
---|
526 | tLocation_ = tp; |
---|
527 | modified("TimeAxis: setLocationU()"); |
---|
528 | } |
---|
529 | } |
---|
530 | public void setLocationU(SoTPoint tp) { |
---|
531 | double x; |
---|
532 | long t; |
---|
533 | if(tp.isXTime()) { |
---|
534 | t = tp.getX().getLongTime(); |
---|
535 | x = ((SoTValue.Double)tp.getY()).getValue(); |
---|
536 | } else { |
---|
537 | t = tp.getY().getLongTime(); |
---|
538 | x = ((SoTValue.Double)tp.getX()).getValue(); |
---|
539 | } |
---|
540 | setLocationU(new TimePoint(x, new GeoDate(t))); |
---|
541 | } |
---|
542 | /** |
---|
543 | * Returns origin as a <code>SoTPoint</code>. |
---|
544 | */ |
---|
545 | public SoTPoint getSoTLocationU() { |
---|
546 | if(orientation_ == HORIZONTAL) { |
---|
547 | return new SoTPoint(tLocation_.t, tLocation_.x); |
---|
548 | } else { |
---|
549 | return new SoTPoint(tLocation_.x, tLocation_.t); |
---|
550 | } |
---|
551 | } |
---|
552 | /** |
---|
553 | * Get the origin in user units. |
---|
554 | * |
---|
555 | * @return origin in user units |
---|
556 | **/ |
---|
557 | public TimePoint getLocationU() { |
---|
558 | return tLocation_; |
---|
559 | } |
---|
560 | // |
---|
561 | public Rectangle getBounds() { |
---|
562 | double xp, yp, ymin, ymax, xmin, xmax; |
---|
563 | int xd, yd, width, height, x, y; |
---|
564 | if(orientation_ == Axis.HORIZONTAL) { |
---|
565 | // |
---|
566 | yp = graph_.getYUtoP(tLocation_.x); |
---|
567 | |
---|
568 | setupDraw(yp); |
---|
569 | |
---|
570 | xd = graph_.getXUtoD(tRange_.start); |
---|
571 | width = graph_.getXUtoD(tRange_.end) - xd; |
---|
572 | x = xd; |
---|
573 | ymax = yp; |
---|
574 | ymin = yp; |
---|
575 | if(labelPosition_ == POSITIVE_SIDE) { |
---|
576 | ymax = ymajor_ + MAJOR_LABEL_RATIO__*labelHeight_; |
---|
577 | if(ticPosition_ == BOTH_SIDES || ticPosition_ == NEGATIVE_SIDE) { |
---|
578 | ymin = ymin - 1.3*largeTicHeight_; |
---|
579 | } |
---|
580 | } else { |
---|
581 | ymin = ymajor_ - MAJOR_LABEL_RATIO__*labelHeight_; |
---|
582 | if(ticPosition_ == BOTH_SIDES || ticPosition_ == POSITIVE_SIDE) { |
---|
583 | ymax = ymax + 1.3*largeTicHeight_; |
---|
584 | } |
---|
585 | } |
---|
586 | y = graph_.getLayer().getYPtoD(ymax); |
---|
587 | height = graph_.getLayer().getYPtoD(ymin) - y; |
---|
588 | } else { |
---|
589 | xp = graph_.getXUtoP(tLocation_.x); |
---|
590 | |
---|
591 | setupDraw(xp); |
---|
592 | yd = graph_.getYUtoD(tRange_.start); |
---|
593 | y = graph_.getYUtoD(tRange_.end); |
---|
594 | height = yd - y; |
---|
595 | xmin = xp; |
---|
596 | xmax = xp; |
---|
597 | if(labelPosition_ == POSITIVE_SIDE) { |
---|
598 | xmax = xmajor_ + MAJOR_LABEL_RATIO__*labelHeight_; |
---|
599 | if(ticPosition_ == BOTH_SIDES || ticPosition_ == NEGATIVE_SIDE) { |
---|
600 | xmin = xmin - 1.3*largeTicHeight_; |
---|
601 | } |
---|
602 | } else { |
---|
603 | xmin = xmajor_ - MAJOR_LABEL_RATIO__*labelHeight_; |
---|
604 | if(ticPosition_ == BOTH_SIDES || ticPosition_ == POSITIVE_SIDE) { |
---|
605 | xmax = xmax + 1.3*largeTicHeight_; |
---|
606 | } |
---|
607 | } |
---|
608 | x = graph_.getLayer().getXPtoD(xmin); |
---|
609 | width = graph_.getLayer().getXPtoD(xp) - x; |
---|
610 | } |
---|
611 | return new Rectangle(x, y, width, height); |
---|
612 | } |
---|
613 | public void setBounds(Rectangle r) { |
---|
614 | setBounds(r.x, r.y, r.width, r.height); |
---|
615 | } |
---|
616 | public void setBounds(int x, int y, int width, int height) { |
---|
617 | } |
---|
618 | public void modified(String mess) { |
---|
619 | // if(Debug.EVENT) System.out.println("TimeAxis: modified()"); |
---|
620 | if(graph_ != null) |
---|
621 | graph_.modified(mess); |
---|
622 | } |
---|
623 | // |
---|
624 | void draw(Graphics g) { |
---|
625 | int xloc, yloc, xend, yend; |
---|
626 | int vertalign; |
---|
627 | int minor_val, minor_val_old; |
---|
628 | int major_val, major_val_old; |
---|
629 | double xp, yp; |
---|
630 | double xp_minor_old, yp_minor_old; |
---|
631 | double x, y; |
---|
632 | double xp_major_old, yp_major_old; |
---|
633 | boolean draw_minor, draw_major; |
---|
634 | boolean time_increasing; |
---|
635 | GeoDate time = new GeoDate(); |
---|
636 | GeoDate minor_time_old; |
---|
637 | GeoDate major_time_old; |
---|
638 | GeoDate time_end = new GeoDate(); |
---|
639 | SGLabel label; |
---|
640 | if(!visible_) return; |
---|
641 | // |
---|
642 | if(lineColor_ == null) { |
---|
643 | g.setColor(graph_.getLayer().getPane().getComponent().getForeground()); |
---|
644 | } else { |
---|
645 | g.setColor(lineColor_); |
---|
646 | } |
---|
647 | // |
---|
648 | draw_minor = minorLabelInterval_ != 0 && labelPosition_ != NO_LABEL; |
---|
649 | draw_major = majorLabelInterval_ != 0 && labelPosition_ != NO_LABEL; |
---|
650 | // |
---|
651 | time_increasing = tRange_.end.after(tRange_.start); |
---|
652 | // |
---|
653 | time = txt_.getStartTime(tRange_); |
---|
654 | if(time_increasing) { |
---|
655 | time_end = new GeoDate(tRange_.end); |
---|
656 | } else { |
---|
657 | time_end = new GeoDate(tRange_.start); |
---|
658 | } |
---|
659 | // |
---|
660 | if(orientation_ == Axis.HORIZONTAL) { |
---|
661 | yloc = graph_.getYUtoD(tLocation_.x); |
---|
662 | xloc = graph_.getXUtoD(tRange_.start); |
---|
663 | xend = graph_.getXUtoD(tRange_.end); |
---|
664 | g.drawLine(xloc, yloc, xend, yloc); |
---|
665 | // |
---|
666 | yp = graph_.getYUtoP(tLocation_.x); |
---|
667 | xp = graph_.getXUtoP(time); |
---|
668 | |
---|
669 | setupDraw(yp); |
---|
670 | |
---|
671 | if(txt_.isStartOfMinor(time)) { |
---|
672 | drawThickXTic(g, xp, yp, 1.3f*largeTicHeight_); |
---|
673 | } else { |
---|
674 | drawXTic(g, xp, yp, largeTicHeight_); |
---|
675 | } |
---|
676 | major_val = txt_.getMajorValue(time); |
---|
677 | major_val_old = major_val; |
---|
678 | minor_val_old = txt_.getMinorValue(time); |
---|
679 | xp_major_old = xp; |
---|
680 | xp_minor_old = xp; |
---|
681 | minor_time_old = new GeoDate(time); |
---|
682 | major_time_old = new GeoDate(time); |
---|
683 | time.increment(txt_.getIncrementValue(), txt_.getIncrementUnits()); |
---|
684 | // |
---|
685 | while (time.before(time_end)) { |
---|
686 | xp = graph_.getXUtoP(time); |
---|
687 | minor_val = txt_.getMinorValue(time); |
---|
688 | if(txt_.isStartOfMinor(time)) { |
---|
689 | drawThickXTic(g, xp, yp, 1.3f*largeTicHeight_); |
---|
690 | } else { |
---|
691 | drawXTic(g, xp, yp, largeTicHeight_); |
---|
692 | } |
---|
693 | if(draw_minor && minor_val_old%minorLabelInterval_ == 0) { |
---|
694 | x = txt_.computeLocation(xp_minor_old, xp); |
---|
695 | drawMinorLabel(g, x, minor_time_old); |
---|
696 | } |
---|
697 | major_val = txt_.getMajorValue(time); |
---|
698 | if(major_val != major_val_old) { |
---|
699 | if(draw_major && major_val_old%majorLabelInterval_ == 0) { |
---|
700 | x = (xp_major_old + xp)*0.5; |
---|
701 | drawMajorLabel(g, x, major_time_old); |
---|
702 | } |
---|
703 | xp_major_old = xp; |
---|
704 | major_val_old = major_val; |
---|
705 | major_time_old = new GeoDate(time); |
---|
706 | } |
---|
707 | xp_minor_old = xp; |
---|
708 | minor_val_old = minor_val; |
---|
709 | minor_time_old = new GeoDate(time); |
---|
710 | time.increment(txt_.getIncrementValue(), txt_.getIncrementUnits()); |
---|
711 | } // end of while |
---|
712 | if(draw_major && major_val_old%majorLabelInterval_ == 0) { |
---|
713 | GeoDate delta = time_end.subtract(major_time_old); |
---|
714 | if(txt_.isRoomForMajorLabel(delta)) { |
---|
715 | xp = graph_.getXUtoP(time_end); |
---|
716 | x = (xp_major_old + xp)*0.5; |
---|
717 | drawMajorLabel(g, x, major_time_old); |
---|
718 | } |
---|
719 | } |
---|
720 | } else { // vertical axis |
---|
721 | xloc = graph_.getXUtoD(tLocation_.x); |
---|
722 | yloc = graph_.getYUtoD(tRange_.start); |
---|
723 | yend = graph_.getYUtoD(tRange_.end); |
---|
724 | g.drawLine(xloc, yloc, xloc, yend); |
---|
725 | // |
---|
726 | xp = graph_.getXUtoP(tLocation_.x); |
---|
727 | yp = graph_.getYUtoP(time); |
---|
728 | |
---|
729 | setupDraw(xp); |
---|
730 | |
---|
731 | if(txt_.isStartOfMinor(time)) { |
---|
732 | drawThickYTic(g, xp, yp, 1.3f*largeTicHeight_); |
---|
733 | } else { |
---|
734 | drawYTic(g, xp, yp, largeTicHeight_); |
---|
735 | } |
---|
736 | major_val = txt_.getMajorValue(time); |
---|
737 | major_val_old = major_val; |
---|
738 | minor_val_old = txt_.getMinorValue(time); |
---|
739 | yp_major_old = yp; |
---|
740 | yp_minor_old = yp; |
---|
741 | minor_time_old = new GeoDate(time); |
---|
742 | major_time_old = new GeoDate(time); |
---|
743 | time.increment(txt_.getIncrementValue(), txt_.getIncrementUnits()); |
---|
744 | // |
---|
745 | while (time.before(time_end)) { |
---|
746 | yp = graph_.getYUtoP(time); |
---|
747 | minor_val = txt_.getMinorValue(time); |
---|
748 | if(txt_.isStartOfMinor(time)) { |
---|
749 | drawThickYTic(g, xp, yp, 1.3f*largeTicHeight_); |
---|
750 | } else { |
---|
751 | drawYTic(g, xp, yp, largeTicHeight_); |
---|
752 | } |
---|
753 | if(draw_minor && minor_val_old%minorLabelInterval_ == 0) { |
---|
754 | y = txt_.computeLocation(yp_minor_old, yp); |
---|
755 | drawMinorLabel(g, y, minor_time_old); |
---|
756 | } |
---|
757 | major_val = txt_.getMajorValue(time); |
---|
758 | if(major_val != major_val_old) { |
---|
759 | if(draw_major && major_val_old%majorLabelInterval_ == 0) { |
---|
760 | y = (yp_major_old + yp)*0.5; |
---|
761 | drawMajorLabel(g, y, major_time_old); |
---|
762 | } |
---|
763 | yp_major_old = yp; |
---|
764 | major_val_old = major_val; |
---|
765 | major_time_old = new GeoDate(time); |
---|
766 | } |
---|
767 | yp_minor_old = yp; |
---|
768 | minor_val_old = minor_val; |
---|
769 | minor_time_old = new GeoDate(time); |
---|
770 | time.increment(txt_.getIncrementValue(), txt_.getIncrementUnits()); |
---|
771 | } // end of while |
---|
772 | if(draw_major && major_val_old%majorLabelInterval_ == 0) { |
---|
773 | GeoDate delta = time_end.subtract(major_time_old); |
---|
774 | if(txt_.isRoomForMajorLabel(delta)) { |
---|
775 | yp = graph_.getYUtoP(time_end); |
---|
776 | y = (yp_major_old + yp)*0.5; |
---|
777 | drawMajorLabel(g, y, major_time_old); |
---|
778 | } |
---|
779 | } |
---|
780 | } |
---|
781 | } |
---|
782 | |
---|
783 | public void setTitle( final SGLabel title ) |
---|
784 | { |
---|
785 | // Time axes don't use title_ |
---|
786 | // title_ = null; |
---|
787 | // VMIPSL |
---|
788 | if( title_ == null || !title_.equals( title ) ) |
---|
789 | { |
---|
790 | title_ = title; |
---|
791 | title_.setMoveable( false ); |
---|
792 | modified( "Axis: setTitle()" ); |
---|
793 | } |
---|
794 | } |
---|
795 | } |
---|
796 | |
---|