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