tmf: Simple warning fixes in tmf.core and tests
[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 /**
35 * Implementation of the scale for the time graph view.
36 *
37 * This goes above the "gantt chart" area.
38 *
39 * @version 1.0
40 * @author Alvaro Sanchez-Leon
41 * @author Patrick Tasse
42 */
43 public class TimeGraphScale extends TimeGraphBaseControl implements
44 MouseListener, MouseMoveListener {
45
46 /**
47 * Standard constructor
48 *
49 * @param parent
50 * The parent composite object
51 * @param colors
52 * The color scheme to use
53 */
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);
58 }
59
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
66
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);
71
72 private static final Calendar GREGORIAN_CALENDAR = GregorianCalendar.getInstance();
73
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);
82 private int _height;
83
84 /**
85 * Assign the time provider for this scale
86 *
87 * @param timeProvider
88 * The provider to use
89 */
90 public void setTimeProvider(ITimeDataProvider timeProvider) {
91 _timeProvider = timeProvider;
92 }
93
94 private long _timeDelta;
95
96 @Override
97 public Point computeSize(int wHint, int hHint, boolean changed) {
98 return super.computeSize(wHint, _height, changed);
99 }
100
101 /**
102 * Set the height of the scale
103 *
104 * @param height
105 * The height to use
106 */
107 public void setHeight(int height) {
108 this._height = height;
109 }
110
111 private void calcTimeDelta(int width, double pixelsPerNanoSec) {
112 double minDelta = (double) ((pixelsPerNanoSec == 0) ? YEAR_IN_NS : width / pixelsPerNanoSec);
113 long unit = 1;
114 if (_timeProvider != null && _timeProvider.isCalendarFormat()) {
115 if (minDelta > 6 * MONTH_IN_NS) {
116 unit = YEAR_IN_NS;
117 } else if (minDelta > 3 * MONTH_IN_NS) {
118 unit = 6 * MONTH_IN_NS;
119 } else if (minDelta > 10 * DAY_IN_NS) {
120 unit = MONTH_IN_NS;
121 } else if (minDelta > 12 * HOUR_IN_NS) {
122 unit = DAY_IN_NS;
123 } else if (minDelta > 3 * HOUR_IN_NS) {
124 unit = 6 * HOUR_IN_NS;
125 } else if (minDelta > 30 * MIN_IN_NS) {
126 unit = HOUR_IN_NS;
127 } else if (minDelta > 10 * MIN_IN_NS) {
128 unit = 15 * MIN_IN_NS;
129 } else if (minDelta > 30 * SEC_IN_NS) {
130 unit = MIN_IN_NS;
131 } else if (minDelta > 20 * SEC_IN_NS) {
132 unit = 30 * SEC_IN_NS;
133 } else if (minDelta <= 1) {
134 _timeDelta = 1;
135 return;
136 }
137 }
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;
149 } else {
150 _timeDelta = 10 * (long) Math.pow(10, pow10) * unit;
151 }
152 }
153
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();
167
168 TimeDraw getTimeDraw(long timeDelta) {
169 TimeDraw timeDraw;
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;
187 } else {
188 timeDraw = TIMEDRAW_ABS_NANOSEC;
189 }
190 return timeDraw;
191 }
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;
198 } else {
199 timeDraw = TIMEDRAW_NANOSEC;
200 }
201 return timeDraw;
202 }
203
204 @Override
205 void paint(Rectangle rect, PaintEvent e) {
206
207 if (_isInUpdate || null == _timeProvider) {
208 return;
209 }
210
211 GC gc = e.gc;
212 gc.fillRectangle(rect);
213
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();
219
220 gc.setBackground(_colors.getColor(TimeGraphColorScheme.TOOL_BACKGROUND));
221 gc.setForeground(_colors.getColor(TimeGraphColorScheme.TOOL_FOREGROUND));
222 Utils.init(_rect0, rect);
223
224 // draw top left area
225 _rect0.width = leftSpace;
226 _rect0.x += 4;
227 _rect0.width -= 4;
228 Rectangle absHeaderRect = new Rectangle(_rect0.x, _rect0.y, _rect0.width, _rect0.height);
229 _rect0.x -= 4;
230 _rect0.width += 4;
231
232 // prepare and draw right rect of the timescale
233 _rect0.x += leftSpace;
234 _rect0.width = rect.width - leftSpace;
235
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);
239 _rect0.height--;
240 gc.fillRectangle(_rect0);
241
242 if (time1 <= time0 || timeSpace < 2) {
243 return;
244 }
245
246 int numDigits = calculateDigits(time0, time1);
247
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);
252
253 TimeDraw timeDraw = getTimeDraw(_timeDelta);
254
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);
261 }
262 }
263
264 if (_rect0.isEmpty()) {
265 return;
266 }
267
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
273 + _rect0.height);
274 gc.setForeground(_colors.getColor(TimeGraphColorScheme.TOOL_FOREGROUND));
275 }
276
277 // draw time scale ticks
278 _rect0.y = rect.y;
279 _rect0.height = rect.height - 4;
280 _rect0.width = labelWidth;
281
282 long time;
283 if (_timeProvider != null && _timeProvider.isCalendarFormat()) {
284 time = floorToCalendar(time0, _timeDelta);
285 } else {
286 time = (long) (Math.ceil((double) time0 / _timeDelta) * _timeDelta);
287 }
288
289 int y = _rect0.y + _rect0.height;
290
291 if (_timeProvider != null && _timeProvider.isCalendarFormat()) {
292 timeDraw.drawAbsHeader(gc, time, absHeaderRect);
293 }
294
295 while (true) {
296 x = rect.x + leftSpace + (int) (Math.floor((time - time0) * pixelsPerNanoSec));
297 if (x >= rect.x + leftSpace + rect.width - _rect0.width) {
298 break;
299 }
300 if (x >= rect.x + leftSpace) {
301 gc.drawLine(x, y, x, y + 4);
302 _rect0.x = x;
303 if (x + _rect0.width <= rect.x + rect.width) {
304 timeDraw.draw(gc, time, _rect0);
305 }
306 }
307 if (pixelsPerNanoSec == 0 || time > Long.MAX_VALUE - _timeDelta || _timeDelta == 0) {
308 break;
309 }
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;
329 } else {
330 time += _timeDelta;
331 }
332 } else {
333 time += _timeDelta;
334 }
335 }
336 }
337
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;
364 } else {
365 long offset = GREGORIAN_CALENDAR.getTimeZone().getOffset(time / 1000000L) * 1000000L;
366 time += offset;
367 time = (time / timeDelta) * timeDelta;
368 time -= offset;
369 }
370 return time;
371 }
372
373 private int calculateDigits(long time0, long time1) {
374 int numDigits = 5;
375 long timeRange = time1 - time0;
376
377 if (_timeProvider.isCalendarFormat()) {
378 // Calculate the number of digits to represent the minutes provided
379 // 11:222
380 // HH:mm:ss
381 numDigits += 8;
382 if (timeRange < 10000) {
383 // HH:11:222:333:444__
384 numDigits += 10;
385 } else if (timeRange < 10000000) {
386 // HH:11:222:333__
387 numDigits += 6;
388 }
389 } else {
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);
393 // 11:222
394 if (strMinutes != null) {
395 numDigits += strMinutes.length();
396 } else {
397 numDigits += 2;
398 }
399 if (timeRange < 10000) {
400 // 11:222:333:444__
401 numDigits += 8;
402 } else if (timeRange < 10000000) {
403 // 11:222:333__
404 numDigits += 4;
405 }
406 }
407
408 return numDigits;
409 }
410
411 @Override
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) {
417 setCapture(true);
418 _dragState = 1;
419 } else if (3 == e.button) {
420 _dragState = 3;
421 }
422 if (x < 0) {
423 x = 0;
424 } else if (x > getSize().x - _timeProvider.getNameSpace()) {
425 x = getSize().x - _timeProvider.getNameSpace();
426 }
427 _dragX = _dragX0 = x;
428 _time0bak = _timeProvider.getTime0();
429 _time1bak = _timeProvider.getTime1();
430 }
431 }
432
433 @Override
434 public void mouseUp(MouseEvent e) {
435 if (e.button == 1 && _dragState == 1) {
436 setCapture(false);
437 _dragState = 0;
438
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());
442 }
443 } else if (e.button == 3 && _dragState == 3 && null != _timeProvider) {
444 _dragState = 0;
445 if (_dragX0 == _dragX || _timeProvider.getTime0() == _timeProvider.getTime1()) {
446 return;
447 }
448 int timeSpace = _timeProvider.getTimeSpace();
449 int leftSpace = _timeProvider.getNameSpace();
450 int x = Math.max(0, e.x - leftSpace);
451 if (timeSpace > 0) {
452 _dragX = x;
453 if (_dragX0 > _dragX) { // drag right to left
454 _dragX = _dragX0;
455 _dragX0 = x;
456 }
457 long time0 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / timeSpace));
458 long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX / timeSpace));
459
460 _timeProvider.setStartFinishTimeNotify(time0, time1);
461 _time0bak = _timeProvider.getTime0();
462 _time1bak = _timeProvider.getTime1();
463 }
464 }
465 }
466
467 @Override
468 public void mouseMove(MouseEvent e) {
469 if (_dragX0 < 0 || _dragState == 0 || _timeProvider == null) {
470 return;
471 }
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) {
478 _dragX = x;
479 if (_timeProvider.getTime0() == _timeProvider.getTime1()) {
480 return;
481 }
482 long interval = (long) ((_time1bak - _time0bak) * ((double) _dragX0 / _dragX));
483 if (interval == Long.MAX_VALUE) {
484 _timeProvider.setStartFinishTime(_time0bak, Long.MAX_VALUE);
485 } else {
486 long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / _dragX));
487 _timeProvider.setStartFinishTime(_time0bak, time1);
488 }
489 }
490 } else if (3 == _dragState) {
491 if (x < 0) {
492 _dragX = 0;
493 } else if (x > timeSpace) {
494 _dragX = timeSpace;
495 } else {
496 _dragX = x;
497 }
498 redraw();
499 }
500 }
501
502 @Override
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();
508 }
509 }
510 }
511
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$
526
527 static String pad(long n) {
528 String s = S;
529 if (n < 10) {
530 s = S00;
531 } else if (n < 100) {
532 s = S0;
533 }
534 return s + n;
535 }
536
537 public abstract void draw(GC gc, long time, Rectangle rect);
538
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
542 }
543
544 public abstract String hint();
545 }
546
547 class TimeDrawSec extends TimeDraw {
548 static String _hint = "sec"; //$NON-NLS-1$
549
550 @Override
551 public void draw(GC gc, long time, Rectangle rect) {
552 time /= 1000000000;
553 Utils.drawText(gc, time + "", rect, true); //$NON-NLS-1$
554 }
555
556 @Override
557 public String hint() {
558 return _hint;
559 }
560 }
561
562 class TimeDrawMillisec extends TimeDraw {
563 static String _hint = "s:ms"; //$NON-NLS-1$
564
565 @Override
566 public void draw(GC gc, long time, Rectangle rect) {
567 time /= 1000000;
568 long ms = time % 1000;
569 time /= 1000;
570 Utils.drawText(gc, time + pad(ms), rect, true);
571 }
572
573 @Override
574 public String hint() {
575 return _hint;
576 }
577 }
578
579 class TimeDrawMicrosec extends TimeDraw {
580 static String _hint = "s:ms:mcs"; //$NON-NLS-1$
581
582 @Override
583 public void draw(GC gc, long time, Rectangle rect) {
584 time /= 1000;
585 long mcs = time % 1000;
586 time /= 1000;
587 long ms = time % 1000;
588 time /= 1000;
589 Utils.drawText(gc, time + pad(ms) + pad(mcs), rect, true);
590 }
591
592 @Override
593 public String hint() {
594 return _hint;
595 }
596 }
597
598 class TimeDrawNanosec extends TimeDraw {
599 static String _hint = "s:ms:mcs:ns"; //$NON-NLS-1$
600
601 @Override
602 public void draw(GC gc, long time, Rectangle rect) {
603 long ns = time % 1000;
604 time /= 1000;
605 long mcs = time % 1000;
606 time /= 1000;
607 long ms = time % 1000;
608 time /= 1000;
609 Utils.drawText(gc, time + pad(ms) + pad(mcs) + pad(ns), rect, true);
610 }
611
612 @Override
613 public String hint() {
614 return _hint;
615 }
616 }
617
618 class TimeDrawAbsYear extends TimeDraw {
619 static String _hint = "YYYY"; //$NON-NLS-1$
620
621 @Override
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);
625 }
626
627 @Override
628 public String hint() {
629 return _hint;
630 }
631 }
632
633 class TimeDrawAbsMonth extends TimeDraw {
634 static String _hint = "YYYY Mmm"; //$NON-NLS-1$
635
636 @Override
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);
640 }
641
642 @Override
643 public String hint() {
644 return _hint;
645 }
646 }
647
648 class TimeDrawAbsDay extends TimeDraw {
649 static String _hint = "Mmm dd"; //$NON-NLS-1$
650
651 @Override
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);
655 }
656
657 @Override
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);
664 }
665 }
666
667 @Override
668 public String hint() {
669 return _hint;
670 }
671 }
672
673 class TimeDrawAbsHrs extends TimeDraw {
674 static String _hint = "Mmm dd HH:mm"; //$NON-NLS-1$
675
676 @Override
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);
680 }
681
682 @Override
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);
689 }
690 }
691
692 @Override
693 public String hint() {
694 return _hint;
695 }
696 }
697
698 class TimeDrawAbsMin extends TimeDraw {
699 static String _hint = "HH:mm"; //$NON-NLS-1$
700
701 @Override
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);
705 }
706
707 @Override
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);
714 }
715 }
716
717
718 @Override
719 public String hint() {
720 return _hint;
721 }
722 }
723
724 class TimeDrawAbsSec extends TimeDraw {
725 static String _hint = "HH:mm:ss"; //$NON-NLS-1$
726
727 @Override
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);
731 }
732
733 @Override
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);
740 }
741 }
742
743 @Override
744 public String hint() {
745 return _hint;
746 }
747 }
748
749 class TimeDrawAbsMillisec extends TimeDraw {
750 static String _hint = "HH:ss:ms"; //$NON-NLS-1$
751
752 @Override
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);
756
757 Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
758 }
759
760 @Override
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);
767 }
768 }
769
770 @Override
771 public String hint() {
772 return _hint;
773 }
774 }
775
776 class TimeDrawAbsMicroSec extends TimeDraw {
777 static String _hint = "HH:ss:ms:mcs"; //$NON-NLS-1$
778
779 @Override
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$
784 }
785
786 @Override
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);
793 }
794 }
795
796 @Override
797 public String hint() {
798 return _hint;
799 }
800 }
801
802 class TimeDrawAbsNanoSec extends TimeDraw {
803 static String _hint = "HH:ss:ms:mcs:ns"; //$NON-NLS-1$
804
805 @Override
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$
810 }
811
812 @Override
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);
819 }
820 }
821
822 @Override
823 public String hint() {
824 return _hint;
825 }
826 }
This page took 0.049753 seconds and 5 git commands to generate.