source: ether_megapoli/trunk/service/implementation/gov2/noaa/pmel/sgt/TimeAxis.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: 23.8 KB
Line 
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
13package  gov.noaa.pmel.sgt;
14
15import gov.noaa.pmel.util.TimeRange;
16import gov.noaa.pmel.util.TimePoint;
17import gov.noaa.pmel.util.GeoDate;
18import gov.noaa.pmel.util.Point2D;
19import gov.noaa.pmel.util.Debug;
20import gov.noaa.pmel.util.SoTValue;
21import gov.noaa.pmel.util.SoTPoint;
22import gov.noaa.pmel.util.SoTRange;
23
24import java.util.Enumeration;
25import java.util.Vector;
26import java.awt.Graphics;
27import java.awt.Rectangle;
28import 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 */
41public 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    if(orientation_ == Axis.HORIZONTAL) {
276      label = new SGLabel("major", time.toString(majorLabelFormat_),
277                          new Point2D.Double(val, ymajor_));
278      label.setOrientation(SGLabel.HORIZONTAL);
279    } else {
280      label = new SGLabel("major", time.toString(majorLabelFormat_),
281                          new Point2D.Double(xmajor_, val));
282      label.setOrientation(SGLabel.VERTICAL);
283    }
284    label.setAlign(vertalign_, SGLabel.CENTER);
285    label.setFont(labelFont_);
286    label.setColor(labelColor_);
287    label.setHeightP(MAJOR_LABEL_RATIO__*labelHeight_);
288    label.setLayer(graph_.getLayer());
289    try {
290      label.draw(g);
291    } catch (LayerNotFoundException e) {}
292    g.setColor(saved);
293  }
294  //
295  /**
296   * Default contructor.
297   **/
298  public TimeAxis(int style) {
299    this("", style);
300  }
301  /**
302   * TimeAxis constructor.
303   *
304   * @param id axis identifier
305   **/
306  public TimeAxis(String id,int style) {
307    super(id);
308    minorLabelInterval_ = 2;
309    majorLabelInterval_ = 1;
310    numSmallTics_ = 0;
311    space_ = false;
312    axisStyle_ = style;
313    //
314    if(axisStyle_ == AUTO || axisStyle_ == MONTH_YEAR) {
315      txt_ = (TimeAxisStyle)new MonthYearAxis();
316    } else if(axisStyle_ == YEAR_DECADE) {
317      txt_ = (TimeAxisStyle)new YearDecadeAxis();
318    } else if(axisStyle_ == DAY_MONTH) {
319      txt_ = (TimeAxisStyle)new DayMonthAxis();
320    } else if(axisStyle_ == HOUR_DAY) {
321      txt_ = (TimeAxisStyle)new HourDayAxis();
322    } else {
323      txt_ = (TimeAxisStyle)new MinuteHourAxis();
324    }
325    minorLabelFormat_ = txt_.getDefaultMinorLabelFormat();
326    majorLabelFormat_ = txt_.getDefaultMajorLabelFormat();
327    minorLabelInterval_ = txt_.getDefaultMinorLabelInterval();
328    majorLabelInterval_ = txt_.getDefaultMajorLabelInterval();
329    numSmallTics_ = txt_.getDefaultNumSmallTics();
330//
331    largeTicHeight_ = defaultLargeTicHeight__;
332    smallTicHeight_ = defaultSmallTicHeight__;
333    ticPosition_ = defaultTicPosition__;
334    labelPosition_ = defaultLabelPosition__;
335    labelHeight_ = defaultLabelHeight__;
336    tRange_ = null;
337    tLocation_ = null;
338  }
339  public Axis copy() {
340    TimeAxis newAxis;
341    try {
342      newAxis = (TimeAxis)clone();
343    } catch (CloneNotSupportedException e) {
344      newAxis = new TimeAxis(getStyle());
345    }
346    //
347    // remove registered axes and transforms
348    //
349    newAxis.registeredAxes_ = new Vector(2,2);
350    newAxis.registeredTransforms_ = new Vector(2,2);
351    //
352    return newAxis;
353  }
354  /**
355   * Set the minor and major label formats.
356   *
357   * @param minor minor label format
358   * @param major major label format
359   **/
360  public void setLabelFormat(String minor,String major) {
361    if(minorLabelFormat_ == null ||
362       majorLabelFormat_ == null ||
363      !minorLabelFormat_.equals(minor) ||
364      !majorLabelFormat_.equals(major)) {
365
366      minorLabelFormat_ = minor;
367      majorLabelFormat_ = major;
368      modified("TimeAxis: setLabelFormat()");
369    }
370  }
371  /**
372   * Set the minor label format.
373   *
374   * @param minor minor label format
375   **/
376  public void setMinorLabelFormat(String minor) {
377    if(minorLabelFormat_ == null || !minorLabelFormat_.equals(minor)) {
378      minorLabelFormat_ = minor;
379      modified("TimeAxis: setMinorLabelFormat()");
380    }
381  }
382  /**
383   * Set the major label format.
384   *
385   * @param major major label format
386   **/
387  public void setMajorLabelFormat(String major) {
388    if(majorLabelFormat_ == null || !majorLabelFormat_.equals(major)) {
389      majorLabelFormat_ = major;
390      modified("TimeAxis: setMajorLabelFormat()");
391    }
392  }
393  /**
394   * Get the minor label format.
395   *
396   * @return minor label format
397   **/
398  public String getMinorLabelFormat() {
399    return minorLabelFormat_;
400  }
401  /**
402   * Get the major label format.
403   *
404   * @return major label format
405   **/
406  public String getMajorLabelFormat() {
407    return majorLabelFormat_;
408  }
409  /**
410   * Set the minor and major label intervals.
411   *
412   * @param minor minor label interval
413   * @param major major label interval
414   **/
415  public void setLabelInterval(int minor,int major) {
416    if(minorLabelInterval_ != minor || majorLabelInterval_ != major) {
417      minorLabelInterval_ = minor;
418      majorLabelInterval_ = major;
419      modified("TimeAxis: setLabelInterval()");
420    }
421  }
422  /**
423   * Set the minor label interval.
424   *
425   * @param minor minor label interval
426   **/
427  public void setMinorLabelInterval(int minor) {
428    if(minorLabelInterval_ != minor) {
429      minorLabelInterval_ = minor;
430      modified("TimeAxis: setMinorLabelInterval()");
431    }
432  }
433  /**
434   * Set the major label interval.
435   *
436   * @param major major label interval
437   **/
438  public void setMajorLabelInterval(int major) {
439    if(majorLabelInterval_ != major) {
440      majorLabelInterval_ = major;
441      modified("TimeAxis: setMajorLabelInterval()");
442    }
443  }
444  /**
445   * Get the minor label interval.
446   *
447   * @return minor label interval
448   **/
449  public int getMinorLabelInterval() {
450    return minorLabelInterval_;
451  }
452  /**
453   * Get the major label interval.
454   *
455   * @return major label interval
456   **/
457  public int getMajorLabelInterval() {
458    return majorLabelInterval_;
459  }
460  /**
461   * Set the time axis style.
462   *
463   * @param style new time axis style
464   */
465  public void setStyle(int style) {
466    if(axisStyle_ != style) {
467      axisStyle_ = style;
468      if(axisStyle_ == AUTO && tRange_ != null) {
469        setAuto();
470      }
471      modified("TimeAxis: setStyle()");
472    }
473  }
474  /**
475   * Get the time axis style.
476   *
477   * @return time axis style
478   */
479  public int getStyle() {
480    return axisStyle_;
481  }
482  /**
483   * Set the user range to draw the axis.  Registered Axes and Transforms
484   * will be updated.
485   *
486   * @param tr TimeRange of axis.
487   **/
488  public void setRangeU(TimeRange tr) {
489    if(tRange_ == null || !tRange_.equals(tr)) {
490      tRange_ = tr;
491      if(axisStyle_ == AUTO) {
492        setAuto();
493      }
494      updateRegisteredAxes();
495      updateRegisteredTransforms();
496      modified("TimeAxis: setRangeU()");
497    }
498  }
499  /**
500   * Get the time range of the axis.
501   *
502   * @return TimeRange of axis
503   **/
504  public TimeRange getTimeRangeU() {
505    return tRange_;
506  }
507  public void setRangeU(SoTRange tr) {
508    setRangeU(new TimeRange(tr.getStart().getLongTime(),
509                            tr.getEnd().getLongTime(),
510                            tr.getDelta().getLongTime()));
511  }
512  public SoTRange getSoTRangeU() {
513    return new SoTRange.Time(tRange_);
514  }
515  /**
516   * Set the origin in user units of the axis.
517   *
518   * @param tp origin of axis in user units
519   **/
520  public void setLocationU(TimePoint tp) {
521    if(tLocation_ == null || !tLocation_.equals(tp)) {
522      tLocation_ = tp;
523      modified("TimeAxis: setLocationU()");
524    }
525  }
526  public void setLocationU(SoTPoint tp) {
527    double x;
528    long t;
529    if(tp.isXTime()) {
530      t = tp.getX().getLongTime();
531      x = ((SoTValue.Double)tp.getY()).getValue();
532    } else {
533      t = tp.getY().getLongTime();
534      x = ((SoTValue.Double)tp.getX()).getValue();
535    }
536    setLocationU(new TimePoint(x, new GeoDate(t)));
537  }
538  /**
539   * Returns origin as a <code>SoTPoint</code>.
540   */
541  public SoTPoint getSoTLocationU() {
542    if(orientation_ == HORIZONTAL) {
543      return new SoTPoint(tLocation_.t, tLocation_.x);
544    } else {
545      return new SoTPoint(tLocation_.x, tLocation_.t);
546    }
547  }
548  /**
549   * Get the origin in user units.
550   *
551   * @return origin in user units
552   **/
553  public TimePoint getLocationU() {
554    return tLocation_;
555  }
556  //
557  public Rectangle getBounds() {
558    double xp, yp, ymin, ymax, xmin, xmax;
559    int xd, yd, width, height, x, y;
560    if(orientation_ == Axis.HORIZONTAL) {
561      //
562      yp = graph_.getYUtoP(tLocation_.x);
563
564      setupDraw(yp);
565
566      xd = graph_.getXUtoD(tRange_.start);
567      width = graph_.getXUtoD(tRange_.end) - xd;
568      x = xd;
569      ymax = yp;
570      ymin = yp;
571      if(labelPosition_ == POSITIVE_SIDE) {
572        ymax = ymajor_ + MAJOR_LABEL_RATIO__*labelHeight_;
573        if(ticPosition_ == BOTH_SIDES || ticPosition_ == NEGATIVE_SIDE) {
574          ymin = ymin - 1.3*largeTicHeight_;
575        }
576      } else {
577        ymin = ymajor_ - MAJOR_LABEL_RATIO__*labelHeight_;
578        if(ticPosition_ == BOTH_SIDES || ticPosition_ == POSITIVE_SIDE) {
579          ymax = ymax + 1.3*largeTicHeight_;
580        }
581      }
582      y = graph_.getLayer().getYPtoD(ymax);
583      height = graph_.getLayer().getYPtoD(ymin) - y;
584    } else {
585      xp = graph_.getXUtoP(tLocation_.x);
586
587      setupDraw(xp);
588      yd = graph_.getYUtoD(tRange_.start);
589      y = graph_.getYUtoD(tRange_.end);
590      height = yd - y;
591      xmin = xp;
592      xmax = xp;
593      if(labelPosition_ == POSITIVE_SIDE) {
594        xmax = xmajor_ + MAJOR_LABEL_RATIO__*labelHeight_;
595        if(ticPosition_ == BOTH_SIDES || ticPosition_ == NEGATIVE_SIDE) {
596          xmin = xmin - 1.3*largeTicHeight_;
597        }
598      } else {
599        xmin = xmajor_ - MAJOR_LABEL_RATIO__*labelHeight_;
600        if(ticPosition_ == BOTH_SIDES || ticPosition_ == POSITIVE_SIDE) {
601          xmax = xmax + 1.3*largeTicHeight_;
602        }
603      }
604      x = graph_.getLayer().getXPtoD(xmin);
605      width = graph_.getLayer().getXPtoD(xp) - x;
606    }
607    return new Rectangle(x, y, width, height);
608  }
609  public void setBounds(Rectangle r) {
610    setBounds(r.x, r.y, r.width, r.height);
611  }
612  public void setBounds(int x, int y, int width, int height) {
613  }
614  public void modified(String mess) {
615    //    if(Debug.EVENT) System.out.println("TimeAxis: modified()");
616    if(graph_ != null)
617      graph_.modified(mess);
618  }
619  //
620  void draw(Graphics g) {
621    int xloc, yloc, xend, yend;
622    int vertalign;
623    int minor_val, minor_val_old;
624    int major_val, major_val_old;
625    double xp, yp;
626    double xp_minor_old, yp_minor_old;
627    double x, y;
628    double xp_major_old, yp_major_old;
629    boolean draw_minor, draw_major;
630    boolean time_increasing;
631    GeoDate time = new GeoDate();
632    GeoDate minor_time_old;
633    GeoDate major_time_old;
634    GeoDate time_end = new GeoDate();
635    SGLabel label;
636    if(!visible_) return;
637    //
638    if(lineColor_ == null) {
639      g.setColor(graph_.getLayer().getPane().getComponent().getForeground());
640    } else {
641      g.setColor(lineColor_);
642    }
643    //
644    draw_minor = minorLabelInterval_ != 0 && labelPosition_ != NO_LABEL;
645    draw_major = majorLabelInterval_ != 0 && labelPosition_ != NO_LABEL;
646    //
647    time_increasing = tRange_.end.after(tRange_.start);
648    //
649    time = txt_.getStartTime(tRange_);
650    if(time_increasing) {
651      time_end = new GeoDate(tRange_.end);
652    } else {
653      time_end = new GeoDate(tRange_.start);
654    }
655    //
656    if(orientation_ == Axis.HORIZONTAL) {
657      yloc = graph_.getYUtoD(tLocation_.x);
658      xloc = graph_.getXUtoD(tRange_.start);
659      xend = graph_.getXUtoD(tRange_.end);
660      g.drawLine(xloc, yloc, xend, yloc);
661      //
662      yp = graph_.getYUtoP(tLocation_.x);
663      xp = graph_.getXUtoP(time);
664
665      setupDraw(yp);
666
667      if(txt_.isStartOfMinor(time)) {
668        drawThickXTic(g, xp, yp, 1.3f*largeTicHeight_);
669      } else {
670        drawXTic(g, xp, yp, largeTicHeight_);
671      }
672      major_val = txt_.getMajorValue(time);
673      major_val_old = major_val;
674      minor_val_old = txt_.getMinorValue(time);
675      xp_major_old = xp;
676      xp_minor_old = xp;
677      minor_time_old = new GeoDate(time);
678      major_time_old = new GeoDate(time);
679      time.increment(txt_.getIncrementValue(), txt_.getIncrementUnits());
680      //
681      while (time.before(time_end)) {
682        xp = graph_.getXUtoP(time);
683        minor_val = txt_.getMinorValue(time);
684        if(txt_.isStartOfMinor(time)) {
685          drawThickXTic(g, xp, yp, 1.3f*largeTicHeight_);
686        } else {
687          drawXTic(g, xp, yp, largeTicHeight_);
688        }
689        if(draw_minor && minor_val_old%minorLabelInterval_ == 0) {
690          x = txt_.computeLocation(xp_minor_old, xp);
691          drawMinorLabel(g, x, minor_time_old);
692        }
693        major_val = txt_.getMajorValue(time);
694        if(major_val != major_val_old) {
695          if(draw_major && major_val_old%majorLabelInterval_ == 0) {
696            x = (xp_major_old + xp)*0.5;
697            drawMajorLabel(g, x, major_time_old);
698          }
699          xp_major_old = xp;
700          major_val_old = major_val;
701          major_time_old = new GeoDate(time);
702        }
703        xp_minor_old = xp;
704        minor_val_old = minor_val;
705        minor_time_old = new GeoDate(time);
706        time.increment(txt_.getIncrementValue(), txt_.getIncrementUnits());
707      } // end of while
708      if(draw_major && major_val_old%majorLabelInterval_ == 0) {
709        GeoDate delta = time_end.subtract(major_time_old);
710        if(txt_.isRoomForMajorLabel(delta)) {
711          xp = graph_.getXUtoP(time_end);
712          x = (xp_major_old + xp)*0.5;
713          drawMajorLabel(g, x, major_time_old);
714        }
715      }
716    } else {          // vertical axis
717      xloc = graph_.getXUtoD(tLocation_.x);
718      yloc = graph_.getYUtoD(tRange_.start);
719      yend = graph_.getYUtoD(tRange_.end);
720      g.drawLine(xloc, yloc, xloc, yend);
721      //
722      xp = graph_.getXUtoP(tLocation_.x);
723      yp = graph_.getYUtoP(time);
724
725      setupDraw(xp);
726
727      if(txt_.isStartOfMinor(time)) {
728        drawThickYTic(g, xp, yp, 1.3f*largeTicHeight_);
729      } else {
730        drawYTic(g, xp, yp, largeTicHeight_);
731      }
732      major_val = txt_.getMajorValue(time);
733      major_val_old = major_val;
734      minor_val_old = txt_.getMinorValue(time);
735      yp_major_old = yp;
736      yp_minor_old = yp;
737      minor_time_old = new GeoDate(time);
738      major_time_old = new GeoDate(time);
739      time.increment(txt_.getIncrementValue(), txt_.getIncrementUnits());
740      //
741      while (time.before(time_end)) {
742        yp = graph_.getYUtoP(time);
743        minor_val = txt_.getMinorValue(time);
744        if(txt_.isStartOfMinor(time)) {
745          drawThickYTic(g, xp, yp, 1.3f*largeTicHeight_);
746        } else {
747          drawYTic(g, xp, yp, largeTicHeight_);
748        }
749        if(draw_minor && minor_val_old%minorLabelInterval_ == 0) {
750          y = txt_.computeLocation(yp_minor_old, yp);
751          drawMinorLabel(g, y, minor_time_old);
752        }
753        major_val = txt_.getMajorValue(time);
754        if(major_val != major_val_old) {
755          if(draw_major && major_val_old%majorLabelInterval_ == 0) {
756            y = (yp_major_old + yp)*0.5;
757            drawMajorLabel(g, y, major_time_old);
758          }
759          yp_major_old = yp;
760          major_val_old = major_val;
761          major_time_old = new GeoDate(time);
762        }
763        yp_minor_old = yp;
764        minor_val_old = minor_val;
765        minor_time_old = new GeoDate(time);
766        time.increment(txt_.getIncrementValue(), txt_.getIncrementUnits());
767      } // end of while
768      if(draw_major && major_val_old%majorLabelInterval_ == 0) {
769        GeoDate delta = time_end.subtract(major_time_old);
770        if(txt_.isRoomForMajorLabel(delta)) {
771          yp = graph_.getYUtoP(time_end);
772          y = (yp_major_old + yp)*0.5;
773          drawMajorLabel(g, y, major_time_old);
774        }
775      }
776    }
777  }
778  public void setTitle(SGLabel title) {
779  // Time axes don't use title_
780    title_ = null;
781  }
782}
783
Note: See TracBrowser for help on using the repository browser.