1 /*****************************************************************************
2 * Copyright (c) 2007, 2008 Intel Corporation, 2010, 2012 Ericsson.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Intel Corporation - Initial API and implementation
10 * Ruslan A. Scherbakov, Intel - Initial API and implementation
11 * Alvaro Sanchez-Leon - Updated for TMF
12 * Patrick Tasse - Refactoring
14 *****************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
;
18 import java
.text
.SimpleDateFormat
;
19 import java
.util
.Calendar
;
20 import java
.util
.Date
;
21 import java
.util
.GregorianCalendar
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.Resolution
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.events
.MouseEvent
;
26 import org
.eclipse
.swt
.events
.MouseListener
;
27 import org
.eclipse
.swt
.events
.MouseMoveListener
;
28 import org
.eclipse
.swt
.events
.PaintEvent
;
29 import org
.eclipse
.swt
.graphics
.GC
;
30 import org
.eclipse
.swt
.graphics
.Point
;
31 import org
.eclipse
.swt
.graphics
.Rectangle
;
32 import org
.eclipse
.swt
.widgets
.Composite
;
35 * Implementation of the scale for the time graph view.
37 * This goes above the "gantt chart" area.
40 * @author Alvaro Sanchez-Leon
41 * @author Patrick Tasse
43 public class TimeGraphScale
extends TimeGraphBaseControl
implements
44 MouseListener
, MouseMoveListener
{
47 * Standard constructor
50 * The parent composite object
52 * The color scheme to use
54 public TimeGraphScale(Composite parent
, TimeGraphColorScheme colors
) {
55 super(parent
, colors
, SWT
.NO_BACKGROUND
| SWT
.NO_FOCUS
| SWT
.DOUBLE_BUFFERED
);
56 addMouseListener(this);
57 addMouseMoveListener(this);
60 private static final long SEC_IN_NS
= 1000000000;
61 private static final long MIN_IN_NS
= 60 * SEC_IN_NS
;
62 private static final long HOUR_IN_NS
= 60 * MIN_IN_NS
;
63 private static final long DAY_IN_NS
= 24 * HOUR_IN_NS
;
64 private static final long MONTH_IN_NS
= 31 * DAY_IN_NS
; // upper limit
65 private static final long YEAR_IN_NS
= 366 * DAY_IN_NS
; // upper limit
67 private static final double LOG10_1
= Math
.log10(1);
68 private static final double LOG10_2
= Math
.log10(2);
69 private static final double LOG10_3
= Math
.log10(3);
70 private static final double LOG10_5
= Math
.log10(5);
72 private static final Calendar GREGORIAN_CALENDAR
= GregorianCalendar
.getInstance();
74 private ITimeDataProvider _timeProvider
;
75 private int _dragState
= 0;
76 private int _dragX0
= 0;
77 private int _dragX
= 0;
78 private long _time0bak
;
79 private long _time1bak
;
80 private boolean _isInUpdate
;
81 private final Rectangle _rect0
= new Rectangle(0, 0, 0, 0);
85 * Assign the time provider for this scale
90 public void setTimeProvider(ITimeDataProvider timeProvider
) {
91 _timeProvider
= timeProvider
;
94 private long _timeDelta
;
97 public Point
computeSize(int wHint
, int hHint
, boolean changed
) {
98 return super.computeSize(wHint
, _height
, changed
);
102 * Set the height of the scale
107 public void setHeight(int height
) {
108 this._height
= height
;
111 private void calcTimeDelta(int width
, double pixelsPerNanoSec
) {
112 double minDelta
= (double) ((pixelsPerNanoSec
== 0) ? YEAR_IN_NS
: width
/ pixelsPerNanoSec
);
114 if (_timeProvider
!= null && _timeProvider
.isCalendarFormat()) {
115 if (minDelta
> 6 * MONTH_IN_NS
) {
117 } else if (minDelta
> 3 * MONTH_IN_NS
) {
118 unit
= 6 * MONTH_IN_NS
;
119 } else if (minDelta
> 10 * DAY_IN_NS
) {
121 } else if (minDelta
> 12 * HOUR_IN_NS
) {
123 } else if (minDelta
> 3 * HOUR_IN_NS
) {
124 unit
= 6 * HOUR_IN_NS
;
125 } else if (minDelta
> 30 * MIN_IN_NS
) {
127 } else if (minDelta
> 10 * MIN_IN_NS
) {
128 unit
= 15 * MIN_IN_NS
;
129 } else if (minDelta
> 30 * SEC_IN_NS
) {
131 } else if (minDelta
> 20 * SEC_IN_NS
) {
132 unit
= 30 * SEC_IN_NS
;
133 } else if (minDelta
<= 1) {
138 double log
= Math
.log10((double) minDelta
/ unit
);
139 long pow10
= (long) log
;
140 double remainder
= log
- pow10
;
141 if (remainder
< LOG10_1
) {
142 _timeDelta
= (long) Math
.pow(10, pow10
) * unit
;
143 } else if (remainder
< LOG10_2
) {
144 _timeDelta
= 2 * (long) Math
.pow(10, pow10
) * unit
;
145 } else if (remainder
< LOG10_3
&& unit
>= HOUR_IN_NS
&& unit
< YEAR_IN_NS
) {
146 _timeDelta
= 3 * (long) Math
.pow(10, pow10
) * unit
;
147 } else if (remainder
< LOG10_5
) {
148 _timeDelta
= 5 * (long) Math
.pow(10, pow10
) * unit
;
150 _timeDelta
= 10 * (long) Math
.pow(10, pow10
) * unit
;
154 private static TimeDraw TIMEDRAW_NANOSEC
= new TimeDrawNanosec();
155 private static TimeDraw TIMEDRAW_MICROSEC
= new TimeDrawMicrosec();
156 private static TimeDraw TIMEDRAW_MILLISEC
= new TimeDrawMillisec();
157 private static TimeDraw TIMEDRAW_SEC
= new TimeDrawSec();
158 private static TimeDraw TIMEDRAW_ABS_NANOSEC
= new TimeDrawAbsNanoSec();
159 private static TimeDraw TIMEDRAW_ABS_MICROSEC
= new TimeDrawAbsMicroSec();
160 private static TimeDraw TIMEDRAW_ABS_MILLISEC
= new TimeDrawAbsMillisec();
161 private static TimeDraw TIMEDRAW_ABS_SEC
= new TimeDrawAbsSec();
162 private static TimeDraw TIMEDRAW_ABS_MIN
= new TimeDrawAbsMin();
163 private static TimeDraw TIMEDRAW_ABS_HRS
= new TimeDrawAbsHrs();
164 private static TimeDraw TIMEDRAW_ABS_DAY
= new TimeDrawAbsDay();
165 private static TimeDraw TIMEDRAW_ABS_MONTH
= new TimeDrawAbsMonth();
166 private static TimeDraw TIMEDRAW_ABS_YEAR
= new TimeDrawAbsYear();
168 TimeDraw
getTimeDraw(long timeDelta
) {
170 if (_timeProvider
!= null && _timeProvider
.isCalendarFormat()) {
171 if (timeDelta
>= YEAR_IN_NS
) {
172 timeDraw
= TIMEDRAW_ABS_YEAR
;
173 } else if (timeDelta
>= MONTH_IN_NS
) {
174 timeDraw
= TIMEDRAW_ABS_MONTH
;
175 } else if (timeDelta
>= DAY_IN_NS
) {
176 timeDraw
= TIMEDRAW_ABS_DAY
;
177 } else if (timeDelta
>= HOUR_IN_NS
) {
178 timeDraw
= TIMEDRAW_ABS_HRS
;
179 } else if (timeDelta
>= MIN_IN_NS
) {
180 timeDraw
= TIMEDRAW_ABS_MIN
;
181 } else if (timeDelta
>= SEC_IN_NS
) {
182 timeDraw
= TIMEDRAW_ABS_SEC
;
183 } else if (timeDelta
>= 1000000) {
184 timeDraw
= TIMEDRAW_ABS_MILLISEC
;
185 } else if (timeDelta
>= 1000) {
186 timeDraw
= TIMEDRAW_ABS_MICROSEC
;
188 timeDraw
= TIMEDRAW_ABS_NANOSEC
;
192 if (timeDelta
>= 1000000000) {
193 timeDraw
= TIMEDRAW_SEC
;
194 } else if (timeDelta
>= 1000000) {
195 timeDraw
= TIMEDRAW_MILLISEC
;
196 } else if (timeDelta
>= 1000) {
197 timeDraw
= TIMEDRAW_MICROSEC
;
199 timeDraw
= TIMEDRAW_NANOSEC
;
205 void paint(Rectangle rect
, PaintEvent e
) {
207 if (_isInUpdate
|| null == _timeProvider
) {
212 gc
.fillRectangle(rect
);
214 long time0
= _timeProvider
.getTime0();
215 long time1
= _timeProvider
.getTime1();
216 long selectedTime
= _timeProvider
.getSelectedTime();
217 int leftSpace
= _timeProvider
.getNameSpace();
218 int timeSpace
= _timeProvider
.getTimeSpace();
220 gc
.setBackground(_colors
.getColor(TimeGraphColorScheme
.TOOL_BACKGROUND
));
221 gc
.setForeground(_colors
.getColor(TimeGraphColorScheme
.TOOL_FOREGROUND
));
222 Utils
.init(_rect0
, rect
);
224 // draw top left area
225 _rect0
.width
= leftSpace
;
228 Rectangle absHeaderRect
= new Rectangle(_rect0
.x
, _rect0
.y
, _rect0
.width
, _rect0
.height
);
232 // prepare and draw right rect of the timescale
233 _rect0
.x
+= leftSpace
;
234 _rect0
.width
= rect
.width
- leftSpace
;
236 // draw bottom border and erase all other area
237 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
- 1, rect
.x
+ rect
.width
- 1,
238 rect
.y
+ rect
.height
- 1);
240 gc
.fillRectangle(_rect0
);
242 if (time1
<= time0
|| timeSpace
< 2) {
246 int numDigits
= calculateDigits(time0
, time1
);
248 int labelWidth
= gc
.getCharWidth('0') * numDigits
;
249 double pixelsPerNanoSec
= (timeSpace
<= RIGHT_MARGIN
) ?
0 :
250 (double) (timeSpace
- RIGHT_MARGIN
) / (time1
- time0
);
251 calcTimeDelta(labelWidth
, pixelsPerNanoSec
);
253 TimeDraw timeDraw
= getTimeDraw(_timeDelta
);
255 // draw zoom rectangle
256 if (3 == _dragState
&& null != _timeProvider
) {
257 if (_dragX0
< _dragX
) {
258 gc
.drawRectangle(leftSpace
+ _dragX0
, rect
.y
, _dragX
- _dragX0
- 1, rect
.height
- 8);
259 } else if (_dragX0
> _dragX
) {
260 gc
.drawRectangle(leftSpace
+ _dragX
, rect
.y
, _dragX0
- _dragX
- 1, rect
.height
- 8);
264 if (_rect0
.isEmpty()) {
268 // draw selected time
269 int x
= _rect0
.x
+ (int) ((double)(selectedTime
- time0
) * pixelsPerNanoSec
);
270 if (x
>= _rect0
.x
&& x
< _rect0
.x
+ _rect0
.width
) {
271 gc
.setForeground(_colors
.getColor(TimeGraphColorScheme
.SELECTED_TIME
));
272 gc
.drawLine(x
, _rect0
.y
+ _rect0
.height
- 6, x
, _rect0
.y
274 gc
.setForeground(_colors
.getColor(TimeGraphColorScheme
.TOOL_FOREGROUND
));
277 // draw time scale ticks
279 _rect0
.height
= rect
.height
- 4;
280 _rect0
.width
= labelWidth
;
283 if (_timeProvider
!= null && _timeProvider
.isCalendarFormat()) {
284 time
= floorToCalendar(time0
, _timeDelta
);
286 time
= (long) (Math
.ceil((double) time0
/ _timeDelta
) * _timeDelta
);
289 int y
= _rect0
.y
+ _rect0
.height
;
291 if (_timeProvider
!= null && _timeProvider
.isCalendarFormat()) {
292 timeDraw
.drawAbsHeader(gc
, time
, absHeaderRect
);
296 x
= rect
.x
+ leftSpace
+ (int) (Math
.floor((time
- time0
) * pixelsPerNanoSec
));
297 if (x
>= rect
.x
+ leftSpace
+ rect
.width
- _rect0
.width
) {
300 if (x
>= rect
.x
+ leftSpace
) {
301 gc
.drawLine(x
, y
, x
, y
+ 4);
303 if (x
+ _rect0
.width
<= rect
.x
+ rect
.width
) {
304 timeDraw
.draw(gc
, time
, _rect0
);
307 if (pixelsPerNanoSec
== 0 || time
> Long
.MAX_VALUE
- _timeDelta
|| _timeDelta
== 0) {
310 if (_timeProvider
!= null && _timeProvider
.isCalendarFormat()) {
311 if (_timeDelta
>= YEAR_IN_NS
) {
312 long millis
= time
/ 1000000L;
313 GREGORIAN_CALENDAR
.setTime(new Date(millis
));
314 GREGORIAN_CALENDAR
.add(Calendar
.YEAR
, (int) (_timeDelta
/ YEAR_IN_NS
));
315 millis
= GREGORIAN_CALENDAR
.getTimeInMillis();
316 time
= millis
* 1000000L;
317 } else if (_timeDelta
>= MONTH_IN_NS
) {
318 long millis
= time
/ 1000000L;
319 GREGORIAN_CALENDAR
.setTime(new Date(millis
));
320 GREGORIAN_CALENDAR
.add(Calendar
.MONTH
, (int) (_timeDelta
/ MONTH_IN_NS
));
321 millis
= GREGORIAN_CALENDAR
.getTimeInMillis();
322 time
= millis
* 1000000L;
323 } else if (_timeDelta
>= DAY_IN_NS
) {
324 long millis
= time
/ 1000000L;
325 GREGORIAN_CALENDAR
.setTime(new Date(millis
));
326 GREGORIAN_CALENDAR
.add(Calendar
.DAY_OF_MONTH
, (int) (_timeDelta
/ DAY_IN_NS
));
327 millis
= GREGORIAN_CALENDAR
.getTimeInMillis();
328 time
= millis
* 1000000L;
338 private long floorToCalendar(long time
, long timeDelta
) {
339 if (_timeDelta
>= YEAR_IN_NS
) {
340 GREGORIAN_CALENDAR
.setTime(new Date(time
/ 1000000));
341 int year
= GREGORIAN_CALENDAR
.get(Calendar
.YEAR
);
342 int yearDelta
= (int) (timeDelta
/ YEAR_IN_NS
);
343 year
= (year
/ yearDelta
) * yearDelta
;
344 GREGORIAN_CALENDAR
.set(Calendar
.YEAR
, year
);
345 GREGORIAN_CALENDAR
.set(Calendar
.MONTH
, 0); // January 1st of year
346 GREGORIAN_CALENDAR
.set(Calendar
.DAY_OF_MONTH
, 1);
347 GREGORIAN_CALENDAR
.set(Calendar
.HOUR_OF_DAY
, 0);
348 GREGORIAN_CALENDAR
.set(Calendar
.MINUTE
, 0);
349 GREGORIAN_CALENDAR
.set(Calendar
.SECOND
, 0);
350 GREGORIAN_CALENDAR
.set(Calendar
.MILLISECOND
, 0);
351 time
= GREGORIAN_CALENDAR
.getTimeInMillis() * 1000000;
352 } else if (_timeDelta
>= MONTH_IN_NS
) {
353 GREGORIAN_CALENDAR
.setTime(new Date(time
/ 1000000));
354 int month
= GREGORIAN_CALENDAR
.get(Calendar
.MONTH
);
355 int monthDelta
= (int) (timeDelta
/ MONTH_IN_NS
);
356 month
= (month
/ monthDelta
) * monthDelta
;
357 GREGORIAN_CALENDAR
.set(Calendar
.MONTH
, month
);
358 GREGORIAN_CALENDAR
.set(Calendar
.DAY_OF_MONTH
, 1); // 1st of month
359 GREGORIAN_CALENDAR
.set(Calendar
.HOUR_OF_DAY
, 0);
360 GREGORIAN_CALENDAR
.set(Calendar
.MINUTE
, 0);
361 GREGORIAN_CALENDAR
.set(Calendar
.SECOND
, 0);
362 GREGORIAN_CALENDAR
.set(Calendar
.MILLISECOND
, 0);
363 time
= GREGORIAN_CALENDAR
.getTimeInMillis() * 1000000;
365 long offset
= GREGORIAN_CALENDAR
.getTimeZone().getOffset(time
/ 1000000L) * 1000000L;
367 time
= (time
/ timeDelta
) * timeDelta
;
373 private int calculateDigits(long time0
, long time1
) {
375 long timeRange
= time1
- time0
;
377 if (_timeProvider
.isCalendarFormat()) {
378 // Calculate the number of digits to represent the minutes provided
382 if (timeRange
< 10000) {
383 // HH:11:222:333:444__
385 } else if (timeRange
< 10000000) {
390 // Calculate the number of digits to represent the minutes provided
391 long min
= (long) ((time1
* 1E-9) / 60); // to sec then to minutes
392 String strMinutes
= String
.valueOf(min
);
394 if (strMinutes
!= null) {
395 numDigits
+= strMinutes
.length();
399 if (timeRange
< 10000) {
402 } else if (timeRange
< 10000000) {
412 public void mouseDown(MouseEvent e
) {
413 getParent().setFocus();
414 if (_dragState
== 0 && null != _timeProvider
) {
415 int x
= e
.x
- _timeProvider
.getNameSpace();
416 if (1 == e
.button
&& x
> 0) {
419 } else if (3 == e
.button
) {
424 } else if (x
> getSize().x
- _timeProvider
.getNameSpace()) {
425 x
= getSize().x
- _timeProvider
.getNameSpace();
427 _dragX
= _dragX0
= x
;
428 _time0bak
= _timeProvider
.getTime0();
429 _time1bak
= _timeProvider
.getTime1();
434 public void mouseUp(MouseEvent e
) {
435 if (e
.button
== 1 && _dragState
== 1) {
439 // Notify time provider to check the need for listener notification
440 if (_dragX
!= _dragX0
&& _timeProvider
.getTime0() != _timeProvider
.getTime1()) {
441 _timeProvider
.setStartFinishTimeNotify(_timeProvider
.getTime0(), _timeProvider
.getTime1());
443 } else if (e
.button
== 3 && _dragState
== 3 && null != _timeProvider
) {
445 if (_dragX0
== _dragX
|| _timeProvider
.getTime0() == _timeProvider
.getTime1()) {
448 int timeSpace
= _timeProvider
.getTimeSpace();
449 int leftSpace
= _timeProvider
.getNameSpace();
450 int x
= Math
.max(0, e
.x
- leftSpace
);
453 if (_dragX0
> _dragX
) { // drag right to left
457 long time0
= _time0bak
+ (long) ((_time1bak
- _time0bak
) * ((double) _dragX0
/ timeSpace
));
458 long time1
= _time0bak
+ (long) ((_time1bak
- _time0bak
) * ((double) _dragX
/ timeSpace
));
460 _timeProvider
.setStartFinishTimeNotify(time0
, time1
);
461 _time0bak
= _timeProvider
.getTime0();
462 _time1bak
= _timeProvider
.getTime1();
468 public void mouseMove(MouseEvent e
) {
469 if (_dragX0
< 0 || _dragState
== 0 || _timeProvider
== null) {
472 Point size
= getSize();
473 int leftSpace
= _timeProvider
.getNameSpace();
474 int timeSpace
= _timeProvider
.getTimeSpace();
475 int x
= e
.x
- leftSpace
;
476 if (1 == _dragState
) {
477 if (x
> 0 && size
.x
> leftSpace
&& _dragX
!= x
) {
479 if (_timeProvider
.getTime0() == _timeProvider
.getTime1()) {
482 long interval
= (long) ((_time1bak
- _time0bak
) * ((double) _dragX0
/ _dragX
));
483 if (interval
== Long
.MAX_VALUE
) {
484 _timeProvider
.setStartFinishTime(_time0bak
, Long
.MAX_VALUE
);
486 long time1
= _time0bak
+ (long) ((_time1bak
- _time0bak
) * ((double) _dragX0
/ _dragX
));
487 _timeProvider
.setStartFinishTime(_time0bak
, time1
);
490 } else if (3 == _dragState
) {
493 } else if (x
> timeSpace
) {
503 public void mouseDoubleClick(MouseEvent e
) {
504 if (null != _timeProvider
&& _timeProvider
.getTime0() != _timeProvider
.getTime1()) {
505 _timeProvider
.resetStartFinishTime();
506 _time0bak
= _timeProvider
.getTime0();
507 _time1bak
= _timeProvider
.getTime1();
512 abstract class TimeDraw
{
513 static String S
= ":" ; //$NON-NLS-1$
514 static String S0
= ":0" ; //$NON-NLS-1$
515 static String S00
= ":00"; //$NON-NLS-1$
516 protected static final SimpleDateFormat stimeformat
= new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$
517 protected static final SimpleDateFormat stimeformatheader
= new SimpleDateFormat("yyyy MMM dd"); //$NON-NLS-1$
518 protected static final SimpleDateFormat sminformat
= new SimpleDateFormat("HH:mm"); //$NON-NLS-1$
519 protected static final SimpleDateFormat sminformatheader
= new SimpleDateFormat("yyyy MMM dd"); //$NON-NLS-1$
520 protected static final SimpleDateFormat shrsformat
= new SimpleDateFormat("MMM dd HH:mm"); //$NON-NLS-1$
521 protected static final SimpleDateFormat shrsformatheader
= new SimpleDateFormat("yyyy"); //$NON-NLS-1$
522 protected static final SimpleDateFormat sdayformat
= new SimpleDateFormat("MMM dd"); //$NON-NLS-1$
523 protected static final SimpleDateFormat sdayformatheader
= new SimpleDateFormat("yyyy"); //$NON-NLS-1$
524 protected static final SimpleDateFormat smonthformat
= new SimpleDateFormat("yyyy MMM"); //$NON-NLS-1$
525 protected static final SimpleDateFormat syearformat
= new SimpleDateFormat("yyyy"); //$NON-NLS-1$
527 static String
pad(long n
) {
531 } else if (n
< 100) {
537 public abstract void draw(GC gc
, long time
, Rectangle rect
);
539 public void drawAbsHeader(GC gc
, long time
, Rectangle absHeaderRect
) {
540 // Override to draw absolute time header
541 // This is for the time information not shown in the draw of each tick
544 public abstract String
hint();
547 class TimeDrawSec
extends TimeDraw
{
548 static String _hint
= "sec"; //$NON-NLS-1$
551 public void draw(GC gc
, long time
, Rectangle rect
) {
553 Utils
.drawText(gc
, time
+ "", rect
, true); //$NON-NLS-1$
557 public String
hint() {
562 class TimeDrawMillisec
extends TimeDraw
{
563 static String _hint
= "s:ms"; //$NON-NLS-1$
566 public void draw(GC gc
, long time
, Rectangle rect
) {
568 long ms
= time
% 1000;
570 Utils
.drawText(gc
, time
+ pad(ms
), rect
, true);
574 public String
hint() {
579 class TimeDrawMicrosec
extends TimeDraw
{
580 static String _hint
= "s:ms:mcs"; //$NON-NLS-1$
583 public void draw(GC gc
, long time
, Rectangle rect
) {
585 long mcs
= time
% 1000;
587 long ms
= time
% 1000;
589 Utils
.drawText(gc
, time
+ pad(ms
) + pad(mcs
), rect
, true);
593 public String
hint() {
598 class TimeDrawNanosec
extends TimeDraw
{
599 static String _hint
= "s:ms:mcs:ns"; //$NON-NLS-1$
602 public void draw(GC gc
, long time
, Rectangle rect
) {
603 long ns
= time
% 1000;
605 long mcs
= time
% 1000;
607 long ms
= time
% 1000;
609 Utils
.drawText(gc
, time
+ pad(ms
) + pad(mcs
) + pad(ns
), rect
, true);
613 public String
hint() {
618 class TimeDrawAbsYear
extends TimeDraw
{
619 static String _hint
= "YYYY"; //$NON-NLS-1$
622 public void draw(GC gc
, long time
, Rectangle rect
) {
623 String stime
= syearformat
.format(new Date((long) (time
/ 1000000)));
624 Utils
.drawText(gc
, stime
, rect
, true);
628 public String
hint() {
633 class TimeDrawAbsMonth
extends TimeDraw
{
634 static String _hint
= "YYYY Mmm"; //$NON-NLS-1$
637 public void draw(GC gc
, long time
, Rectangle rect
) {
638 String stime
= smonthformat
.format(new Date((long) (time
/ 1000000)));
639 Utils
.drawText(gc
, stime
, rect
, true);
643 public String
hint() {
648 class TimeDrawAbsDay
extends TimeDraw
{
649 static String _hint
= "Mmm dd"; //$NON-NLS-1$
652 public void draw(GC gc
, long time
, Rectangle rect
) {
653 String stime
= sdayformat
.format(new Date((long) (time
/ 1000000)));
654 Utils
.drawText(gc
, stime
, rect
, true);
658 public void drawAbsHeader(GC gc
, long time
, Rectangle rect
) {
659 String header
= sdayformatheader
.format(new Date((long) (time
/ 1000000)));
660 int headerwidth
= gc
.stringExtent(header
).x
+ 4;
661 if (headerwidth
<= rect
.width
) {
662 rect
.x
+= (rect
.width
- headerwidth
);
663 Utils
.drawText(gc
, header
, rect
, true);
668 public String
hint() {
673 class TimeDrawAbsHrs
extends TimeDraw
{
674 static String _hint
= "Mmm dd HH:mm"; //$NON-NLS-1$
677 public void draw(GC gc
, long time
, Rectangle rect
) {
678 String stime
= shrsformat
.format(new Date((long) (time
/ 1000000)));
679 Utils
.drawText(gc
, stime
, rect
, true);
683 public void drawAbsHeader(GC gc
, long time
, Rectangle rect
) {
684 String header
= shrsformatheader
.format(new Date((long) (time
/ 1000000)));
685 int headerwidth
= gc
.stringExtent(header
).x
+ 4;
686 if (headerwidth
<= rect
.width
) {
687 rect
.x
+= (rect
.width
- headerwidth
);
688 Utils
.drawText(gc
, header
, rect
, true);
693 public String
hint() {
698 class TimeDrawAbsMin
extends TimeDraw
{
699 static String _hint
= "HH:mm"; //$NON-NLS-1$
702 public void draw(GC gc
, long time
, Rectangle rect
) {
703 String stime
= sminformat
.format(new Date((long) (time
/ 1000000)));
704 Utils
.drawText(gc
, stime
, rect
, true);
708 public void drawAbsHeader(GC gc
, long time
, Rectangle rect
) {
709 String header
= sminformatheader
.format(new Date((long) (time
/ 1000000)));
710 int headerwidth
= gc
.stringExtent(header
).x
+ 4;
711 if (headerwidth
<= rect
.width
) {
712 rect
.x
+= (rect
.width
- headerwidth
);
713 Utils
.drawText(gc
, header
, rect
, true);
719 public String
hint() {
724 class TimeDrawAbsSec
extends TimeDraw
{
725 static String _hint
= "HH:mm:ss"; //$NON-NLS-1$
728 public void draw(GC gc
, long time
, Rectangle rect
) {
729 String stime
= stimeformat
.format(new Date((long) (time
/ 1000000)));
730 Utils
.drawText(gc
, stime
, rect
, true);
734 public void drawAbsHeader(GC gc
, long time
, Rectangle rect
) {
735 String header
= stimeformatheader
.format(new Date((long) (time
/ 1000000)));
736 int headerwidth
= gc
.stringExtent(header
).x
+ 4;
737 if (headerwidth
<= rect
.width
) {
738 rect
.x
+= (rect
.width
- headerwidth
);
739 Utils
.drawText(gc
, header
, rect
, true);
744 public String
hint() {
749 class TimeDrawAbsMillisec
extends TimeDraw
{
750 static String _hint
= "HH:ss:ms"; //$NON-NLS-1$
753 public void draw(GC gc
, long time
, Rectangle rect
) {
754 String stime
= stimeformat
.format(new Date((long) (time
/ 1000000)));
755 String ns
= Utils
.formatNs(time
, Resolution
.MILLISEC
);
757 Utils
.drawText(gc
, stime
+ "." + ns
, rect
, true); //$NON-NLS-1$
761 public void drawAbsHeader(GC gc
, long time
, Rectangle rect
) {
762 String header
= stimeformatheader
.format(new Date((long) (time
/ 1000000)));
763 int headerwidth
= gc
.stringExtent(header
).x
+ 4;
764 if (headerwidth
<= rect
.width
) {
765 rect
.x
+= (rect
.width
- headerwidth
);
766 Utils
.drawText(gc
, header
, rect
, true);
771 public String
hint() {
776 class TimeDrawAbsMicroSec
extends TimeDraw
{
777 static String _hint
= "HH:ss:ms:mcs"; //$NON-NLS-1$
780 public void draw(GC gc
, long time
, Rectangle rect
) {
781 String stime
= stimeformat
.format(new Date((long) (time
/ 1000000)));
782 String micr
= Utils
.formatNs(time
, Resolution
.MICROSEC
);
783 Utils
.drawText(gc
, stime
+ "." + micr
, rect
, true); //$NON-NLS-1$
787 public void drawAbsHeader(GC gc
, long time
, Rectangle rect
) {
788 String header
= stimeformatheader
.format(new Date((long) (time
/ 1000000)));
789 int headerwidth
= gc
.stringExtent(header
).x
+ 4;
790 if (headerwidth
<= rect
.width
) {
791 rect
.x
+= (rect
.width
- headerwidth
);
792 Utils
.drawText(gc
, header
, rect
, true);
797 public String
hint() {
802 class TimeDrawAbsNanoSec
extends TimeDraw
{
803 static String _hint
= "HH:ss:ms:mcs:ns"; //$NON-NLS-1$
806 public void draw(GC gc
, long time
, Rectangle rect
) {
807 String stime
= stimeformat
.format(new Date((long) (time
/ 1000000)));
808 String ns
= Utils
.formatNs(time
, Resolution
.NANOSEC
);
809 Utils
.drawText(gc
, stime
+ "." + ns
, rect
, true); //$NON-NLS-1$
813 public void drawAbsHeader(GC gc
, long time
, Rectangle rect
) {
814 String header
= stimeformatheader
.format(new Date((long) (time
/ 1000000)));
815 int headerwidth
= gc
.stringExtent(header
).x
+ 4;
816 if (headerwidth
<= rect
.width
) {
817 rect
.x
+= (rect
.width
- headerwidth
);
818 Utils
.drawText(gc
, header
, rect
, true);
823 public String
hint() {