source: ether_megapoli/trunk/service/implementation/gov2/noaa/pmel/sgt/MonthYearAxis.java @ 192

Last change on this file since 192 was 192, checked in by vmipsl, 13 years ago

Servlet _ Contour en cours _ package gov2

File size: 3.5 KB
Line 
1/*
2 * $Id: MonthYearAxis.java,v 1.5 2000/12/19 01:00:38 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
13package  gov.noaa.pmel.sgt;
14
15import gov.noaa.pmel.util.GeoDate;
16import gov.noaa.pmel.util.TimeRange;
17import gov.noaa.pmel.util.IllegalTimeValue;
18
19/**
20 * Draws time axes using the month/year style.
21 *
22 * <pre>
23 *            |..........|..........|..........|..........|
24 *                 mar         apr        may      jun
25 *                               1980
26 * </pre>
27 *
28 * @author Donald Denbo
29 * @version $Revision: 1.5 $, $Date: 2000/12/19 01:00:38 $
30 * @see Axis
31 * @see TimeAxis
32 */
33class MonthYearAxis implements TimeAxisStyle {
34  static final int YEAR_TEST__ = 31;
35  static final String defaultMinorLabelFormat__ = "MMM";
36  static final String defaultMajorLabelFormat__ = "yyyy";
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.MONTHS;
42  /**
43   * MonthYearAxis constructor.
44   *
45   * @param id axis identifier
46   **/
47  public MonthYearAxis() {
48  }
49  public double computeLocation(double prev,double now) {
50    return (prev + now)*0.5;
51  }
52  public void computeDefaults(GeoDate delta) {
53    if(delta.getTime()/GeoDate.MSECS_IN_DAY > 240) {
54      defaultMinorLabelInterval_ = 2;
55    } else {
56      defaultMinorLabelInterval_ = 1;
57    }
58  }
59  public int getMinorValue(GeoDate time) {
60    return time.getGMTMonth();
61  }
62  public int getMajorValue(GeoDate time) {
63    return time.getGMTYear();
64  }
65  public boolean isRoomForMajorLabel(GeoDate delta) {
66    return delta.getTime()/GeoDate.MSECS_IN_DAY > YEAR_TEST__;
67  }
68  public boolean isStartOfMinor(GeoDate time) {
69    return time.getGMTMonth() == 1;
70  }
71  public String getDefaultMinorLabelFormat() {
72    return defaultMinorLabelFormat__;
73  }
74  public String getDefaultMajorLabelFormat() {
75    return defaultMajorLabelFormat__;
76  }
77  public int getDefaultNumSmallTics() {
78    return defaultNumSmallTics__;
79  }
80  public int getDefaultMinorLabelInterval() {
81    return defaultMinorLabelInterval_;
82  }
83  public int getDefaultMajorLabelInterval() {
84    return defaultMajorLabelInterval_;
85  }
86  public GeoDate getStartTime(TimeRange tRange) {
87    boolean time_increasing;
88    GeoDate time = null;
89    time_increasing = tRange.end.after(tRange.start);
90    try {
91      if(time_increasing) {
92        time = new GeoDate(tRange.start.getGMTMonth(), 1,
93                           tRange.start.getGMTYear(), 0, 0, 0, 0);
94        if(!time.equals(tRange.start)) time.increment(1.0, GeoDate.MONTHS);
95      } else {
96        time = new GeoDate(tRange.end.getGMTMonth(), 1,
97                           tRange.end.getGMTYear(), 0, 0, 0, 0);
98        if(!time.equals(tRange.end)) time.increment(1.0, GeoDate.MONTHS);
99      }
100    } catch (IllegalTimeValue e) {}
101    return time;
102  }
103  public double getIncrementValue() {
104    return incrementValue__;
105  }
106  public int getIncrementUnits() {
107    return incrementUnits__;
108  }
109  public String toString() {
110    return "MonthYearAxis";
111  }
112}
Note: See TracBrowser for help on using the repository browser.