lttng/tmf: add a "unit-less" representation of time in timechart
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / widgets / TimeGraphScale.java
index 6ae35f25b3e70cdba16446ef76745ca96ea67175..49023be1d5bc7bc08c6b5359ab8f3ed1e5a5ef9a 100644 (file)
 
 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
 
+import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.MouseListener;
@@ -166,30 +168,38 @@ public class TimeGraphScale extends TimeGraphBaseControl implements
     private static TimeDraw TIMEDRAW_ABS_DAY = new TimeDrawAbsDay();
     private static TimeDraw TIMEDRAW_ABS_MONTH = new TimeDrawAbsMonth();
     private static TimeDraw TIMEDRAW_ABS_YEAR = new TimeDrawAbsYear();
+    private static TimeDraw TIMEDRAW_NUMBER = new TimeDrawNumber();
 
     TimeDraw getTimeDraw(long timeDelta) {
         TimeDraw timeDraw;
-        if (_timeProvider != null && _timeProvider.isCalendarFormat()) {
-            if (timeDelta >= YEAR_IN_NS) {
-                timeDraw = TIMEDRAW_ABS_YEAR;
-            } else if (timeDelta >= MONTH_IN_NS) {
-                timeDraw = TIMEDRAW_ABS_MONTH;
-            } else if (timeDelta >= DAY_IN_NS) {
-                timeDraw = TIMEDRAW_ABS_DAY;
-            } else if (timeDelta >= HOUR_IN_NS) {
-                timeDraw = TIMEDRAW_ABS_HRS;
-            } else if (timeDelta >= MIN_IN_NS) {
-                timeDraw = TIMEDRAW_ABS_MIN;
-            } else if (timeDelta >= SEC_IN_NS) {
-                timeDraw = TIMEDRAW_ABS_SEC;
-            } else if (timeDelta >= 1000000) {
-                timeDraw = TIMEDRAW_ABS_MILLISEC;
-            } else if (timeDelta >= 1000) {
-                timeDraw = TIMEDRAW_ABS_MICROSEC;
-            } else {
-                timeDraw = TIMEDRAW_ABS_NANOSEC;
+        if (_timeProvider != null) {
+
+            if (_timeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
+                if (timeDelta >= YEAR_IN_NS) {
+                    timeDraw = TIMEDRAW_ABS_YEAR;
+                } else if (timeDelta >= MONTH_IN_NS) {
+                    timeDraw = TIMEDRAW_ABS_MONTH;
+                } else if (timeDelta >= DAY_IN_NS) {
+                    timeDraw = TIMEDRAW_ABS_DAY;
+                } else if (timeDelta >= HOUR_IN_NS) {
+                    timeDraw = TIMEDRAW_ABS_HRS;
+                } else if (timeDelta >= MIN_IN_NS) {
+                    timeDraw = TIMEDRAW_ABS_MIN;
+                } else if (timeDelta >= SEC_IN_NS) {
+                    timeDraw = TIMEDRAW_ABS_SEC;
+                } else if (timeDelta >= 1000000) {
+                    timeDraw = TIMEDRAW_ABS_MILLISEC;
+                } else if (timeDelta >= 1000) {
+                    timeDraw = TIMEDRAW_ABS_MICROSEC;
+                } else {
+                    timeDraw = TIMEDRAW_ABS_NANOSEC;
+                }
+                return timeDraw;
+            } else if (_timeProvider.getTimeFormat() == TimeFormat.NUMBER) {
+                timeDraw = TIMEDRAW_NUMBER;
+                return timeDraw;
             }
-            return timeDraw;
+
         }
         if (timeDelta >= 1000000000) {
             timeDraw = TIMEDRAW_SEC;
@@ -842,3 +852,28 @@ class TimeDrawAbsNanoSec extends TimeDraw {
         return _hint;
     }
 }
+
+
+class TimeDrawNumber extends TimeDraw {
+
+    @Override
+    public void draw(GC gc, long time, Rectangle rect) {
+        String stime = NumberFormat.getInstance().format(time);
+        Utils.drawText(gc, stime, rect, true);
+    }
+
+    @Override
+    public void drawAbsHeader(GC gc, long time, Rectangle rect) {
+        String header = NumberFormat.getInstance().format(time);
+        int headerwidth = gc.stringExtent(header).x + 4;
+        if (headerwidth <= rect.width) {
+            rect.x += (rect.width - headerwidth);
+            Utils.drawText(gc, header, rect, true);
+        }
+    }
+
+    @Override
+    public String hint() {
+        return "cycle"; //$NON-NLS-1$
+    }
+}
This page took 0.025307 seconds and 5 git commands to generate.