1 | /* |
---|
2 | * $Id: HourDayAxis.java,v 1.8 2001/01/05 18:59:27 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.GeoDate; |
---|
16 | import gov.noaa.pmel.util.TimeRange; |
---|
17 | import gov.noaa.pmel.util.IllegalTimeValue; |
---|
18 | |
---|
19 | /** |
---|
20 | * Draws time axes using the hour/day style. |
---|
21 | * |
---|
22 | * <pre> |
---|
23 | * |..........|..........|..........|..........| |
---|
24 | * 3 4 5 6 |
---|
25 | * jun 7 |
---|
26 | * </pre> |
---|
27 | * |
---|
28 | * @author Donald Denbo |
---|
29 | * @version $Revision: 1.8 $, $Date: 2001/01/05 18:59:27 $ |
---|
30 | * @see Axis |
---|
31 | * @see TimeAxis |
---|
32 | */ |
---|
33 | class HourDayAxis implements TimeAxisStyle { |
---|
34 | static final int HOUR_TEST__ = 4; |
---|
35 | static final String defaultMinorLabelFormat__ = "HH"; |
---|
36 | static final String defaultMajorLabelFormat__ = "yyyy-MM-dd"; |
---|
37 | static final int defaultNumSmallTics__ = 0; |
---|
38 | int defaultMinorLabelInterval_ = 2; |
---|
39 | int defaultMajorLabelInterval_ = 1; |
---|
40 | static final double incrementValue__ = 1.0; |
---|
41 | static final int incrementUnits__ = GeoDate.HOURS; |
---|
42 | /** |
---|
43 | * HourDayAxis constructor. |
---|
44 | * |
---|
45 | * @param id axis identifier |
---|
46 | **/ |
---|
47 | public HourDayAxis() { |
---|
48 | } |
---|
49 | public double computeLocation(double prev,double now) { |
---|
50 | return prev; |
---|
51 | } |
---|
52 | public void computeDefaults(GeoDate delta) { |
---|
53 | long days = delta.getTime()/GeoDate.MSECS_IN_DAY; |
---|
54 | long msec = delta.getTime() % GeoDate.MSECS_IN_DAY; |
---|
55 | if(days > 2) { |
---|
56 | defaultMinorLabelInterval_ = 6; |
---|
57 | } else if((days > 0) || (msec > 43200000)) { |
---|
58 | defaultMinorLabelInterval_ = 2; |
---|
59 | } else { |
---|
60 | defaultMinorLabelInterval_ = 1; |
---|
61 | } |
---|
62 | } |
---|
63 | public int getMinorValue(GeoDate time) { |
---|
64 | return time.getGMTHours(); |
---|
65 | } |
---|
66 | public int getMajorValue(GeoDate time) { |
---|
67 | return time.getGMTDay(); |
---|
68 | } |
---|
69 | public boolean isRoomForMajorLabel(GeoDate delta) { |
---|
70 | return 24.0*(((double)delta.getTime())/((double)GeoDate.MSECS_IN_DAY)) > HOUR_TEST__; |
---|
71 | } |
---|
72 | public boolean isStartOfMinor(GeoDate time) { |
---|
73 | return time.getGMTHours() == 0; |
---|
74 | } |
---|
75 | public String getDefaultMinorLabelFormat() { |
---|
76 | return defaultMinorLabelFormat__; |
---|
77 | } |
---|
78 | public String getDefaultMajorLabelFormat() { |
---|
79 | return defaultMajorLabelFormat__; |
---|
80 | } |
---|
81 | public int getDefaultNumSmallTics() { |
---|
82 | return defaultNumSmallTics__; |
---|
83 | } |
---|
84 | public int getDefaultMinorLabelInterval() { |
---|
85 | return defaultMinorLabelInterval_; |
---|
86 | } |
---|
87 | public int getDefaultMajorLabelInterval() { |
---|
88 | return defaultMajorLabelInterval_; |
---|
89 | } |
---|
90 | public GeoDate getStartTime(TimeRange tRange) { |
---|
91 | boolean time_increasing; |
---|
92 | GeoDate time = null; |
---|
93 | time_increasing = tRange.end.after(tRange.start); |
---|
94 | try { |
---|
95 | if(time_increasing) { |
---|
96 | time = new GeoDate(tRange.start.getGMTMonth(), |
---|
97 | tRange.start.getGMTDay(), |
---|
98 | tRange.start.getGMTYear(), |
---|
99 | tRange.start.getGMTHours(), 0, 0, 0); |
---|
100 | if(!time.equals(tRange.start)) time.increment(1.0f, GeoDate.HOURS); |
---|
101 | } else { |
---|
102 | time = new GeoDate(tRange.end.getGMTMonth(), |
---|
103 | tRange.end.getGMTDay(), |
---|
104 | tRange.end.getGMTYear(), |
---|
105 | tRange.end.getGMTHours(), 0, 0, 0); |
---|
106 | if(!time.equals(tRange.end)) time.increment(1.0f, GeoDate.HOURS); |
---|
107 | } |
---|
108 | } catch (IllegalTimeValue e) {} |
---|
109 | return time; |
---|
110 | } |
---|
111 | public double getIncrementValue() { |
---|
112 | return incrementValue__; |
---|
113 | } |
---|
114 | public int getIncrementUnits() { |
---|
115 | return incrementUnits__; |
---|
116 | } |
---|
117 | public String toString() { |
---|
118 | return "HourDayAxis"; |
---|
119 | } |
---|
120 | } |
---|