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