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