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