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