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