Bug 378401: Implementation of time graph widget.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / widgets / TimeGraphScale.java
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
7 *
8 * Contributors:
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
13 *
14 *****************************************************************************/
15
16 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
17
18 import java.text.SimpleDateFormat;
19 import java.util.Calendar;
20 import java.util.Date;
21 import java.util.GregorianCalendar;
22
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;
33
34 public class TimeGraphScale extends TimeGraphBaseControl implements MouseListener, MouseMoveListener {
35
36 public TimeGraphScale(Composite parent, TimeGraphColorScheme colors) {
37 super(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS
38 | SWT.DOUBLE_BUFFERED);
39 addMouseListener(this);
40 addMouseMoveListener(this);
41 }
42
43 private static final long SEC_IN_NS = 1000000000;
44 private static final long MIN_IN_NS = 60 * SEC_IN_NS;
45 private static final long HOUR_IN_NS = 60 * MIN_IN_NS;
46 private static final long DAY_IN_NS = 24 * HOUR_IN_NS;
47 private static final long MONTH_IN_NS = 31 * DAY_IN_NS; // upper limit
48 private static final long YEAR_IN_NS = 366 * DAY_IN_NS; // upper limit
49
50 private static final double LOG10_1 = Math.log10(1);
51 private static final double LOG10_2 = Math.log10(2);
52 private static final double LOG10_3 = Math.log10(3);
53 private static final double LOG10_5 = Math.log10(5);
54
55 private static final Calendar GREGORIAN_CALENDAR = GregorianCalendar.getInstance();
56
57 private ITimeDataProvider _timeProvider;
58 private int _dragState = 0;
59 private int _dragX0 = 0;
60 private int _dragX = 0;
61 private long _time0bak;
62 private long _time1bak;
63 private boolean _isInUpdate;
64 private Rectangle _rect0 = new Rectangle(0, 0, 0, 0);
65 private int _height;
66
67 public void setTimeProvider(ITimeDataProvider timeProvider) {
68 _timeProvider = timeProvider;
69 }
70
71 private long _timeDelta;
72
73 @Override
74 public Point computeSize(int wHint, int hHint, boolean changed) {
75 return super.computeSize(wHint, _height, changed);
76 }
77
78 public void setHeight(int height) {
79 this._height = height;
80 }
81
82 private void calcTimeDelta(int width, double pixelsPerNanoSec) {
83 double minDelta = (double) ((pixelsPerNanoSec == 0) ? YEAR_IN_NS : width / pixelsPerNanoSec);
84 long unit = 1;
85 if (_timeProvider != null && _timeProvider.isCalendarFormat()) {
86 if (minDelta > 6 * MONTH_IN_NS) {
87 unit = YEAR_IN_NS;
88 } else if (minDelta > 3 * MONTH_IN_NS) {
89 unit = 6 * MONTH_IN_NS;
90 } else if (minDelta > 10 * DAY_IN_NS) {
91 unit = MONTH_IN_NS;
92 } else if (minDelta > 12 * HOUR_IN_NS) {
93 unit = DAY_IN_NS;
94 } else if (minDelta > 3 * HOUR_IN_NS) {
95 unit = 6 * HOUR_IN_NS;
96 } else if (minDelta > 30 * MIN_IN_NS) {
97 unit = HOUR_IN_NS;
98 } else if (minDelta > 10 * MIN_IN_NS) {
99 unit = 15 * MIN_IN_NS;
100 } else if (minDelta > 30 * SEC_IN_NS) {
101 unit = MIN_IN_NS;
102 } else if (minDelta > 20 * SEC_IN_NS) {
103 unit = 30 * SEC_IN_NS;
104 } else if (minDelta <= 1) {
105 _timeDelta = 1;
106 return;
107 }
108 }
109 double log = Math.log10((double) minDelta / unit);
110 long pow10 = (long) log;
111 double remainder = log - pow10;
112 if (remainder < LOG10_1) {
113 _timeDelta = (long) Math.pow(10, pow10) * unit;
114 } else if (remainder < LOG10_2) {
115 _timeDelta = 2 * (long) Math.pow(10, pow10) * unit;
116 } else if (remainder < LOG10_3 && unit >= HOUR_IN_NS && unit < YEAR_IN_NS) {
117 _timeDelta = 3 * (long) Math.pow(10, pow10) * unit;
118 } else if (remainder < LOG10_5) {
119 _timeDelta = 5 * (long) Math.pow(10, pow10) * unit;
120 } else {
121 _timeDelta = 10 * (long) Math.pow(10, pow10) * unit;
122 }
123 }
124
125 private static TimeDraw TIMEDRAW_NANOSEC = new TimeDrawNanosec();
126 private static TimeDraw TIMEDRAW_MICROSEC = new TimeDrawMicrosec();
127 private static TimeDraw TIMEDRAW_MILLISEC = new TimeDrawMillisec();
128 private static TimeDraw TIMEDRAW_SEC = new TimeDrawSec();
129 private static TimeDraw TIMEDRAW_ABS_NANOSEC = new TimeDrawAbsNanoSec();
130 private static TimeDraw TIMEDRAW_ABS_MICROSEC = new TimeDrawAbsMicroSec();
131 private static TimeDraw TIMEDRAW_ABS_MILLISEC = new TimeDrawAbsMillisec();
132 private static TimeDraw TIMEDRAW_ABS_SEC = new TimeDrawAbsSec();
133 private static TimeDraw TIMEDRAW_ABS_MIN = new TimeDrawAbsMin();
134 private static TimeDraw TIMEDRAW_ABS_HRS = new TimeDrawAbsHrs();
135 private static TimeDraw TIMEDRAW_ABS_DAY = new TimeDrawAbsDay();
136 private static TimeDraw TIMEDRAW_ABS_MONTH = new TimeDrawAbsMonth();
137 private static TimeDraw TIMEDRAW_ABS_YEAR = new TimeDrawAbsYear();
138
139 TimeDraw getTimeDraw(long timeDelta) {
140 TimeDraw timeDraw;
141 if (_timeProvider != null && _timeProvider.isCalendarFormat()) {
142 if (timeDelta >= YEAR_IN_NS)
143 timeDraw = TIMEDRAW_ABS_YEAR;
144 else if (timeDelta >= MONTH_IN_NS)
145 timeDraw = TIMEDRAW_ABS_MONTH;
146 else if (timeDelta >= DAY_IN_NS)
147 timeDraw = TIMEDRAW_ABS_DAY;
148 else if (timeDelta >= HOUR_IN_NS)
149 timeDraw = TIMEDRAW_ABS_HRS;
150 else if (timeDelta >= MIN_IN_NS)
151 timeDraw = TIMEDRAW_ABS_MIN;
152 else if (timeDelta >= SEC_IN_NS)
153 timeDraw = TIMEDRAW_ABS_SEC;
154 else if (timeDelta >= 1000000)
155 timeDraw = TIMEDRAW_ABS_MILLISEC;
156 else if (timeDelta >= 1000)
157 timeDraw = TIMEDRAW_ABS_MICROSEC;
158 else
159 timeDraw = TIMEDRAW_ABS_NANOSEC;
160 return timeDraw;
161 }
162 if (timeDelta >= 1000000000)
163 timeDraw = TIMEDRAW_SEC;
164 else if (timeDelta >= 1000000)
165 timeDraw = TIMEDRAW_MILLISEC;
166 else if (timeDelta >= 1000)
167 timeDraw = TIMEDRAW_MICROSEC;
168 else
169 timeDraw = TIMEDRAW_NANOSEC;
170 return timeDraw;
171 }
172
173 @Override
174 void paint(Rectangle rect, PaintEvent e) {
175
176 if (_isInUpdate || null == _timeProvider)
177 return;
178
179 GC gc = e.gc;
180 gc.fillRectangle(rect);
181
182 long time0 = _timeProvider.getTime0();
183 long time1 = _timeProvider.getTime1();
184 long selectedTime = _timeProvider.getSelectedTime();
185 int leftSpace = _timeProvider.getNameSpace();
186 int timeSpace = _timeProvider.getTimeSpace();
187
188 gc.setBackground(_colors.getColor(TimeGraphColorScheme.TOOL_BACKGROUND));
189 gc.setForeground(_colors.getColor(TimeGraphColorScheme.TOOL_FOREGROUND));
190 Utils.init(_rect0, rect);
191
192 // draw top left area
193 _rect0.width = leftSpace;
194 _rect0.x += 4;
195 _rect0.width -= 4;
196 Rectangle absHeaderRect = new Rectangle(_rect0.x, _rect0.y, _rect0.width, _rect0.height);
197 _rect0.x -= 4;
198 _rect0.width += 4;
199
200 // prepare and draw right rect of the timescale
201 _rect0.x += leftSpace;
202 _rect0.width = rect.width - leftSpace;
203
204 // draw bottom border and erase all other area
205 gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1,
206 rect.y + rect.height - 1);
207 _rect0.height--;
208 gc.fillRectangle(_rect0);
209
210 if (time1 <= time0 || timeSpace < 2) {
211 return;
212 }
213
214 int numDigits = calculateDigits(time0, time1);
215
216 int labelWidth = gc.getCharWidth('0') * numDigits;
217 double pixelsPerNanoSec = (timeSpace <= RIGHT_MARGIN) ? 0 :
218 (double) (timeSpace - RIGHT_MARGIN) / (time1 - time0);
219 calcTimeDelta(labelWidth, pixelsPerNanoSec);
220
221 TimeDraw timeDraw = getTimeDraw(_timeDelta);
222
223 // draw zoom rectangle
224 if (3 == _dragState && null != _timeProvider) {
225 if (_dragX0 < _dragX) {
226 gc.drawRectangle(leftSpace + _dragX0, rect.y, _dragX - _dragX0 - 1, rect.height - 8);
227 } else if (_dragX0 > _dragX) {
228 gc.drawRectangle(leftSpace + _dragX, rect.y, _dragX0 - _dragX - 1, rect.height - 8);
229 }
230 }
231
232 if (_rect0.isEmpty())
233 return;
234
235 // draw selected time
236 int x = _rect0.x + (int) ((double)(selectedTime - time0) * pixelsPerNanoSec);
237 if (x >= _rect0.x && x < _rect0.x + _rect0.width) {
238 gc.setForeground(_colors.getColor(TimeGraphColorScheme.SELECTED_TIME));
239 gc.drawLine(x, _rect0.y + _rect0.height - 6, x, _rect0.y
240 + _rect0.height);
241 gc.setForeground(_colors.getColor(TimeGraphColorScheme.TOOL_FOREGROUND));
242 }
243
244 // draw time scale ticks
245 _rect0.y = rect.y;
246 _rect0.height = rect.height - 4;
247 _rect0.width = labelWidth;
248
249 long time;
250 if (_timeProvider != null && _timeProvider.isCalendarFormat()) {
251 time = floorToCalendar(time0, _timeDelta);
252 } else {
253 time = (long) (Math.ceil((double) time0 / _timeDelta) * _timeDelta);
254 }
255
256 // long t = (long) (time * 1000000000);
257 int y = _rect0.y + _rect0.height;
258
259 if (_timeProvider != null && _timeProvider.isCalendarFormat()) {
260 timeDraw.drawAbsHeader(gc, time, absHeaderRect);
261 }
262
263 while (true) {
264 x = rect.x + leftSpace + (int) (Math.floor((time - time0) * pixelsPerNanoSec));
265 gc.drawLine(x, y, x, y + 4);
266 if (x >= rect.x + leftSpace + rect.width - _rect0.width) {
267 break;
268 }
269 if (x >= rect.x + leftSpace) {
270 _rect0.x = x;
271 if (x + _rect0.width <= rect.x + rect.width)
272 timeDraw.draw(gc, time, _rect0);
273 }
274 if (pixelsPerNanoSec == 0 || time > Long.MAX_VALUE - _timeDelta || _timeDelta == 0) {
275 break;
276 }
277 time += _timeDelta;
278 if (_timeProvider != null && _timeProvider.isCalendarFormat()) {
279 if (_timeDelta >= YEAR_IN_NS) {
280 GREGORIAN_CALENDAR.setTime(new Date(time / 1000000));
281 GREGORIAN_CALENDAR.set(Calendar.MONTH, 0); // January 1st of year
282 GREGORIAN_CALENDAR.set(Calendar.DAY_OF_MONTH, 1);
283 time = GREGORIAN_CALENDAR.getTimeInMillis() * 1000000;
284 } else if (_timeDelta >= MONTH_IN_NS) {
285 GREGORIAN_CALENDAR.setTime(new Date(time / 1000000));
286 GREGORIAN_CALENDAR.set(Calendar.DAY_OF_MONTH, 1); // 1st of month
287 time = GREGORIAN_CALENDAR.getTimeInMillis() * 1000000;
288 }
289 }
290 }
291 }
292
293 private long floorToCalendar(long time, long timeDelta) {
294 if (_timeDelta >= YEAR_IN_NS) {
295 GREGORIAN_CALENDAR.setTime(new Date(time / 1000000));
296 int year = GREGORIAN_CALENDAR.get(Calendar.YEAR);
297 int yearDelta = (int) (timeDelta / YEAR_IN_NS);
298 year = (year / yearDelta) * yearDelta;
299 GREGORIAN_CALENDAR.set(Calendar.YEAR, year);
300 GREGORIAN_CALENDAR.set(Calendar.MONTH, 0); // January 1st of year
301 GREGORIAN_CALENDAR.set(Calendar.DAY_OF_MONTH, 1);
302 GREGORIAN_CALENDAR.set(Calendar.HOUR_OF_DAY, 0);
303 GREGORIAN_CALENDAR.set(Calendar.MINUTE, 0);
304 GREGORIAN_CALENDAR.set(Calendar.SECOND, 0);
305 GREGORIAN_CALENDAR.set(Calendar.MILLISECOND, 0);
306 time = GREGORIAN_CALENDAR.getTimeInMillis() * 1000000;
307 } else if (_timeDelta >= MONTH_IN_NS) {
308 GREGORIAN_CALENDAR.setTime(new Date(time / 1000000));
309 int month = GREGORIAN_CALENDAR.get(Calendar.MONTH);
310 int monthDelta = (int) (timeDelta / MONTH_IN_NS);
311 month = (month / monthDelta) * monthDelta;
312 GREGORIAN_CALENDAR.set(Calendar.MONTH, month);
313 GREGORIAN_CALENDAR.set(Calendar.DAY_OF_MONTH, 1); // 1st of month
314 GREGORIAN_CALENDAR.set(Calendar.HOUR_OF_DAY, 0);
315 GREGORIAN_CALENDAR.set(Calendar.MINUTE, 0);
316 GREGORIAN_CALENDAR.set(Calendar.SECOND, 0);
317 GREGORIAN_CALENDAR.set(Calendar.MILLISECOND, 0);
318 time = GREGORIAN_CALENDAR.getTimeInMillis() * 1000000;
319 } else {
320 time = (time / timeDelta) * timeDelta;
321 }
322 return time;
323 }
324
325 private int calculateDigits(long time0, long time1) {
326 int numDigits = 5;
327 long timeRange = time1 - time0;
328
329 if (_timeProvider.isCalendarFormat()) {
330 // Calculate the number of digits to represent the minutes provided
331 // 11:222
332 // HH:mm:ss
333 numDigits += 8;
334 if (timeRange < 10000) {
335 // HH:11:222:333:444__
336 numDigits += 10;
337 } else if (timeRange < 10000000) {
338 // HH:11:222:333__
339 numDigits += 6;
340 }
341 } else {
342 // Calculate the number of digits to represent the minutes provided
343 long min = (long) ((time1 * 1E-9) / 60); // to sec then to minutes
344 String strMinutes = String.valueOf(min);
345 // 11:222
346 if (strMinutes != null) {
347 numDigits += strMinutes.length();
348 } else {
349 numDigits += 2;
350 }
351 if (timeRange < 10000) {
352 // 11:222:333:444__
353 numDigits += 8;
354 } else if (timeRange < 10000000) {
355 // 11:222:333__
356 numDigits += 4;
357 }
358 }
359
360 return numDigits;
361 }
362
363 @Override
364 public void mouseDown(MouseEvent e) {
365 getParent().setFocus();
366 if (_dragState == 0 && null != _timeProvider) {
367 int x = e.x - _timeProvider.getNameSpace();
368 if (1 == e.button && x > 0) {
369 setCapture(true);
370 _dragState = 1;
371 } else if (3 == e.button) {
372 _dragState = 3;
373 }
374 if (x < 0) {
375 x = 0;
376 } else if (x > getSize().x - _timeProvider.getNameSpace()) {
377 x = getSize().x - _timeProvider.getNameSpace();
378 }
379 _dragX = _dragX0 = x;
380 _time0bak = _timeProvider.getTime0();
381 _time1bak = _timeProvider.getTime1();
382 }
383 }
384
385 @Override
386 public void mouseUp(MouseEvent e) {
387 if (e.button == 1 && _dragState == 1) {
388 setCapture(false);
389 _dragState = 0;
390
391 // Notify time provider to check the need for listener notification
392 if (_dragX != _dragX0 && _timeProvider.getTime0() != _timeProvider.getTime1()) {
393 _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1());
394 }
395 } else if (e.button == 3 && _dragState == 3 && null != _timeProvider) {
396 _dragState = 0;
397 if (_dragX0 == _dragX || _timeProvider.getTime0() == _timeProvider.getTime1()) {
398 return;
399 }
400 int timeSpace = _timeProvider.getTimeSpace();
401 int leftSpace = _timeProvider.getNameSpace();
402 int x = e.x - leftSpace;
403 if (timeSpace > 0) {
404 _dragX = x;
405 if (_dragX0 > _dragX) { // drag right to left
406 _dragX = _dragX0;
407 _dragX0 = x;
408 }
409 long time0 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / timeSpace));
410 long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX / timeSpace));
411
412 _timeProvider.setStartFinishTimeNotify(time0, time1);
413 _time0bak = _timeProvider.getTime0();
414 _time1bak = _timeProvider.getTime1();
415 }
416 }
417 }
418
419 @Override
420 public void mouseMove(MouseEvent e) {
421 if (_dragX0 < 0 || _dragState == 0 || _timeProvider == null) {
422 return;
423 }
424 Point size = getSize();
425 int leftSpace = _timeProvider.getNameSpace();
426 int timeSpace = _timeProvider.getTimeSpace();
427 int x = e.x - leftSpace;
428 if (1 == _dragState) {
429 if (x > 0 && size.x > leftSpace && _dragX != x) {
430 _dragX = x;
431 if (_timeProvider.getTime0() == _timeProvider.getTime1()) {
432 return;
433 }
434 long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / _dragX));
435 _timeProvider.setStartFinishTime(_time0bak, time1);
436 }
437 } else if (3 == _dragState) {
438 if (x < 0) {
439 _dragX = 0;
440 } else if (x > timeSpace) {
441 _dragX = timeSpace;
442 } else {
443 _dragX = x;
444 }
445 redraw();
446 }
447 }
448
449 @Override
450 public void mouseDoubleClick(MouseEvent e) {
451 if (null != _timeProvider && _timeProvider.getTime0() != _timeProvider.getTime1()) {
452 _timeProvider.resetStartFinishTime();
453 _time0bak = _timeProvider.getTime0();
454 _time1bak = _timeProvider.getTime1();
455 }
456 }
457 }
458
459 abstract class TimeDraw {
460 static String S = ":" ; //$NON-NLS-1$
461 static String S0 = ":0" ; //$NON-NLS-1$
462 static String S00 = ":00"; //$NON-NLS-1$
463 protected static final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$
464 protected static final SimpleDateFormat stimeformatheader = new SimpleDateFormat("yyyy MMM dd"); //$NON-NLS-1$
465 protected static final SimpleDateFormat sminformat = new SimpleDateFormat("HH:mm"); //$NON-NLS-1$
466 protected static final SimpleDateFormat sminformatheader = new SimpleDateFormat("yyyy MMM dd"); //$NON-NLS-1$
467 protected static final SimpleDateFormat shrsformat = new SimpleDateFormat("MMM dd HH:mm"); //$NON-NLS-1$
468 protected static final SimpleDateFormat shrsformatheader = new SimpleDateFormat("yyyy"); //$NON-NLS-1$
469 protected static final SimpleDateFormat sdayformat = new SimpleDateFormat("MMM dd"); //$NON-NLS-1$
470 protected static final SimpleDateFormat sdayformatheader = new SimpleDateFormat("yyyy"); //$NON-NLS-1$
471 protected static final SimpleDateFormat smonthformat = new SimpleDateFormat("yyyy MMM"); //$NON-NLS-1$
472 protected static final SimpleDateFormat syearformat = new SimpleDateFormat("yyyy"); //$NON-NLS-1$
473
474 static String pad(long n) {
475 String s = S;
476 if (n < 10)
477 s = S00;
478 else if (n < 100)
479 s = S0;
480 return s + n;
481 }
482
483 public abstract void draw(GC gc, long time, Rectangle rect);
484
485 public void drawAbsHeader(GC gc, long time, Rectangle absHeaderRect) {
486 // Override to draw absolute time header
487 // This is for the time information not shown in the draw of each tick
488 }
489
490 public abstract String hint();
491 }
492
493 class TimeDrawSec extends TimeDraw {
494 static String _hint = "sec"; //$NON-NLS-1$
495
496 @Override
497 public void draw(GC gc, long time, Rectangle rect) {
498 time /= 1000000000;
499 Utils.drawText(gc, time + "", rect, true); //$NON-NLS-1$
500 }
501
502 @Override
503 public String hint() {
504 return _hint;
505 }
506 }
507
508 class TimeDrawMillisec extends TimeDraw {
509 static String _hint = "s:ms"; //$NON-NLS-1$
510
511 @Override
512 public void draw(GC gc, long time, Rectangle rect) {
513 time /= 1000000;
514 long ms = time % 1000;
515 time /= 1000;
516 Utils.drawText(gc, time + pad(ms), rect, true);
517 }
518
519 @Override
520 public String hint() {
521 return _hint;
522 }
523 }
524
525 class TimeDrawMicrosec extends TimeDraw {
526 static String _hint = "s:ms:mcs"; //$NON-NLS-1$
527
528 @Override
529 public void draw(GC gc, long time, Rectangle rect) {
530 time /= 1000;
531 long mcs = time % 1000;
532 time /= 1000;
533 long ms = time % 1000;
534 time /= 1000;
535 Utils.drawText(gc, time + pad(ms) + pad(mcs), rect, true);
536 }
537
538 @Override
539 public String hint() {
540 return _hint;
541 }
542 }
543
544 class TimeDrawNanosec extends TimeDraw {
545 static String _hint = "s:ms:mcs:ns"; //$NON-NLS-1$
546
547 @Override
548 public void draw(GC gc, long time, Rectangle rect) {
549 long ns = time % 1000;
550 time /= 1000;
551 long mcs = time % 1000;
552 time /= 1000;
553 long ms = time % 1000;
554 time /= 1000;
555 Utils.drawText(gc, time + pad(ms) + pad(mcs) + pad(ns), rect, true);
556 }
557
558 @Override
559 public String hint() {
560 return _hint;
561 }
562 }
563
564 class TimeDrawAbsYear extends TimeDraw {
565 static String _hint = "YYYY"; //$NON-NLS-1$
566
567 @Override
568 public void draw(GC gc, long time, Rectangle rect) {
569 String stime = syearformat.format(new Date((long) (time / 1000000)));
570 Utils.drawText(gc, stime, rect, true);
571 }
572
573 @Override
574 public String hint() {
575 return _hint;
576 }
577 }
578
579 class TimeDrawAbsMonth extends TimeDraw {
580 static String _hint = "YYYY Mmm"; //$NON-NLS-1$
581
582 @Override
583 public void draw(GC gc, long time, Rectangle rect) {
584 String stime = smonthformat.format(new Date((long) (time / 1000000)));
585 Utils.drawText(gc, stime, rect, true);
586 }
587
588 @Override
589 public String hint() {
590 return _hint;
591 }
592 }
593
594 class TimeDrawAbsDay extends TimeDraw {
595 static String _hint = "Mmm dd"; //$NON-NLS-1$
596
597 @Override
598 public void draw(GC gc, long time, Rectangle rect) {
599 String stime = sdayformat.format(new Date((long) (time / 1000000)));
600 Utils.drawText(gc, stime, rect, true);
601 }
602
603 @Override
604 public void drawAbsHeader(GC gc, long time, Rectangle rect) {
605 String header = sdayformatheader.format(new Date((long) (time / 1000000)));
606 int headerwidth = gc.stringExtent(header).x + 4;
607 if (headerwidth <= rect.width) {
608 rect.x += (rect.width - headerwidth);
609 Utils.drawText(gc, header, rect, true);
610 }
611 }
612
613 @Override
614 public String hint() {
615 return _hint;
616 }
617 }
618
619 class TimeDrawAbsHrs extends TimeDraw {
620 static String _hint = "Mmm dd HH:mm"; //$NON-NLS-1$
621
622 @Override
623 public void draw(GC gc, long time, Rectangle rect) {
624 String stime = shrsformat.format(new Date((long) (time / 1000000)));
625 Utils.drawText(gc, stime, rect, true);
626 }
627
628 @Override
629 public void drawAbsHeader(GC gc, long time, Rectangle rect) {
630 String header = shrsformatheader.format(new Date((long) (time / 1000000)));
631 int headerwidth = gc.stringExtent(header).x + 4;
632 if (headerwidth <= rect.width) {
633 rect.x += (rect.width - headerwidth);
634 Utils.drawText(gc, header, rect, true);
635 }
636 }
637
638 @Override
639 public String hint() {
640 return _hint;
641 }
642 }
643
644 class TimeDrawAbsMin extends TimeDraw {
645 static String _hint = "HH:mm"; //$NON-NLS-1$
646
647 @Override
648 public void draw(GC gc, long time, Rectangle rect) {
649 String stime = sminformat.format(new Date((long) (time / 1000000)));
650 Utils.drawText(gc, stime, rect, true);
651 }
652
653 @Override
654 public void drawAbsHeader(GC gc, long time, Rectangle rect) {
655 String header = sminformatheader.format(new Date((long) (time / 1000000)));
656 int headerwidth = gc.stringExtent(header).x + 4;
657 if (headerwidth <= rect.width) {
658 rect.x += (rect.width - headerwidth);
659 Utils.drawText(gc, header, rect, true);
660 }
661 }
662
663
664 @Override
665 public String hint() {
666 return _hint;
667 }
668 }
669
670 class TimeDrawAbsSec extends TimeDraw {
671 static String _hint = "HH:mm:ss"; //$NON-NLS-1$
672
673 @Override
674 public void draw(GC gc, long time, Rectangle rect) {
675 String stime = stimeformat.format(new Date((long) (time / 1000000)));
676 Utils.drawText(gc, stime, rect, true);
677 }
678
679 @Override
680 public void drawAbsHeader(GC gc, long time, Rectangle rect) {
681 String header = stimeformatheader.format(new Date((long) (time / 1000000)));
682 int headerwidth = gc.stringExtent(header).x + 4;
683 if (headerwidth <= rect.width) {
684 rect.x += (rect.width - headerwidth);
685 Utils.drawText(gc, header, rect, true);
686 }
687 }
688
689 @Override
690 public String hint() {
691 return _hint;
692 }
693 }
694
695 class TimeDrawAbsMillisec extends TimeDraw {
696 static String _hint = "HH:ss:ms"; //$NON-NLS-1$
697
698 @Override
699 public void draw(GC gc, long time, Rectangle rect) {
700 String stime = stimeformat.format(new Date((long) (time / 1000000)));
701 String ns = Utils.formatNs(time, Resolution.MILLISEC);
702
703 Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
704 }
705
706 @Override
707 public void drawAbsHeader(GC gc, long time, Rectangle rect) {
708 String header = stimeformatheader.format(new Date((long) (time / 1000000)));
709 int headerwidth = gc.stringExtent(header).x + 4;
710 if (headerwidth <= rect.width) {
711 rect.x += (rect.width - headerwidth);
712 Utils.drawText(gc, header, rect, true);
713 }
714 }
715
716 @Override
717 public String hint() {
718 return _hint;
719 }
720 }
721
722 class TimeDrawAbsMicroSec extends TimeDraw {
723 static String _hint = "HH:ss:ms:mcs"; //$NON-NLS-1$
724
725 @Override
726 public void draw(GC gc, long time, Rectangle rect) {
727 String stime = stimeformat.format(new Date((long) (time / 1000000)));
728 String micr = Utils.formatNs(time, Resolution.MICROSEC);
729 Utils.drawText(gc, stime + "." + micr, rect, true); //$NON-NLS-1$
730 }
731
732 @Override
733 public void drawAbsHeader(GC gc, long time, Rectangle rect) {
734 String header = stimeformatheader.format(new Date((long) (time / 1000000)));
735 int headerwidth = gc.stringExtent(header).x + 4;
736 if (headerwidth <= rect.width) {
737 rect.x += (rect.width - headerwidth);
738 Utils.drawText(gc, header, rect, true);
739 }
740 }
741
742 @Override
743 public String hint() {
744 return _hint;
745 }
746 }
747
748 class TimeDrawAbsNanoSec extends TimeDraw {
749 static String _hint = "HH:ss:ms:mcs:ns"; //$NON-NLS-1$
750
751 @Override
752 public void draw(GC gc, long time, Rectangle rect) {
753 String stime = stimeformat.format(new Date((long) (time / 1000000)));
754 String ns = Utils.formatNs(time, Resolution.NANOSEC);
755 Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
756 }
757
758 @Override
759 public void drawAbsHeader(GC gc, long time, Rectangle rect) {
760 String header = stimeformatheader.format(new Date((long) (time / 1000000)));
761 int headerwidth = gc.stringExtent(header).x + 4;
762 if (headerwidth <= rect.width) {
763 rect.x += (rect.width - headerwidth);
764 Utils.drawText(gc, header, rect, true);
765 }
766 }
767
768 @Override
769 public String hint() {
770 return _hint;
771 }
772 }
This page took 0.057007 seconds and 6 git commands to generate.