April 26th, 2010
authorAlvaro Sanchez-Leon <alvsan09@gmail.com>
Mon, 26 Apr 2010 15:00:15 +0000 (15:00 +0000)
committerAlvaro Sanchez-Leon <alvsan09@gmail.com>
Mon, 26 Apr 2010 15:00:15 +0000 (15:00 +0000)
[Bug 310200] [TMF] Time Analysis Viewer widget improvements and bug fixes

org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/ITimeAnalysisViewer.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/Messages.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/TmfTimeAnalysisProvider.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/TmfTimeAnalysisViewer.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/messages.properties
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/widgets/ITimeDataProvider.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/widgets/TimeScaleCtrl.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/widgets/TmfTimeStatesCtrl.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/widgets/TmfTimeTipHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/widgets/TraceColorScheme.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/timeAnalysis/widgets/Utils.java

index d0d32d6628f96c9ddf6abceae626ef0628b4e9f2..d1bb5ada04a38185eb0af1ae1d498d5637f09bb6 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2009 Ericsson\r
+ * Copyright (c) 2009, 2010 Ericsson\r
  * \r
  * All rights reserved. This program and the accompanying materials are\r
  * made available under the terms of the Eclipse Public License v1.0 which\r
@@ -162,4 +162,6 @@ public interface ITimeAnalysisViewer extends ITmfViewer {
         */\r
        public void waitCursor(boolean waitInd);\r
 \r
+    public void setFocus();\r
+\r
 }
\ No newline at end of file
index c02a98638108f087b5c2a3d79bad9f9f950d14b5..32e1dd3ff7c7646e339ebac50ee98dea6025900b 100644 (file)
@@ -1,5 +1,5 @@
 /********************************************************************** \r
- * Copyright (c) 2005, 2008, 2009  IBM Corporation, Intel Corporation, Ericsson\r
+ * Copyright (c) 2005, 2008, 2009, 2010  IBM Corporation, Intel Corporation, Ericsson\r
  * \r
  * All rights reserved.   This program and the accompanying materials \r
  * are made available under the terms of the Eclipse Public License v1.0 \r
@@ -26,6 +26,7 @@ public class Messages {
        public static String _TRACE_CLASS_NAME;\r
        public static String _TRACE_GROUP_NAME;\r
        public static String _TRACE_START_TIME;\r
+       public static String _TRACE_EVENT_TIME;\r
        public static String _TRACE_DATE;\r
        public static String _TRACE_STOP_TIME;\r
        public static String _TRACE_STATE;\r
@@ -34,7 +35,7 @@ public class Messages {
        public static String _TRACE_FILTER_DESC;\r
        // misc\r
        public static String _Timescale;\r
-       public static String _DURATION;\r
+    public static String _DURATION;\r
        public static String _UNDEFINED_GROUP;\r
        public static String _TRACE_GROUP_LABEL;\r
        public static String _EDIT_PROFILING_OPTIONS;\r
index 4f4a49d84089d88526cada9006e95d33b3bc178a..ce95945b1445dba0864eb1f7610296b7fe8f755c 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2009 Ericsson\r
+ * Copyright (c) 2009, 2010 Ericsson\r
  * \r
  * All rights reserved. This program and the accompanying materials are\r
  * made available under the terms of the Eclipse Public License v1.0 which\r
@@ -15,8 +15,6 @@ package org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis;
 import java.util.List;\r
 import java.util.Map;\r
 \r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.TimeEvent;\r
@@ -25,7 +23,6 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.GC;\r
 import org.eclipse.swt.graphics.Image;\r
 import org.eclipse.swt.graphics.Rectangle;\r
-import org.eclipse.ui.plugin.AbstractUIPlugin;\r
 \r
 public abstract class TmfTimeAnalysisProvider {\r
     \r
@@ -55,31 +52,31 @@ public abstract class TmfTimeAnalysisProvider {
                }\r
        }\r
 \r
-       static private String _externalPath[] = {\r
-                       "icons/full/obj16/thread_obj.gif", // running thread\r
-                       "icons/full/obj16/threads_obj.gif", // suspended\r
-                       "icons/full/obj16/threadt_obj.gif", // stopped\r
-                       "icons/full/obj16/stckframe_running_obj.gif", // running stack frame\r
-                       "icons/full/obj16/stckframe_obj.gif", // stack frame\r
-       };\r
-\r
-       static private String _externalPlugin[] = { "org.eclipse.debug.ui",\r
-                       "org.eclipse.debug.ui", "org.eclipse.debug.ui",\r
-                       "org.eclipse.debug.ui", "org.eclipse.debug.ui", };\r
-\r
-       static private Image getImage(int idx) {\r
-               if (idx < 0 || idx >= IMG_NUM)\r
-                       SWT.error(SWT.ERROR_INVALID_ARGUMENT);\r
-               String key = "trace.img." + idx;\r
-               Image img = TmfUiPlugin.getDefault().getImageRegistry().get(key);\r
-               if (null == img) {\r
-                       ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(\r
-                                       _externalPlugin[idx], _externalPath[idx]);\r
-                       TmfUiPlugin.getDefault().getImageRegistry().put(key, desc);\r
-                       img = TmfUiPlugin.getDefault().getImageRegistry().get(key);\r
-               }\r
-               return img;\r
-       }\r
+       // static private String _externalPath[] = {\r
+       // "icons/full/obj16/thread_obj.gif", // running thread\r
+       // "icons/full/obj16/threads_obj.gif", // suspended\r
+       // "icons/full/obj16/threadt_obj.gif", // stopped\r
+       // "icons/full/obj16/stckframe_running_obj.gif", // running stack frame\r
+       // "icons/full/obj16/stckframe_obj.gif", // stack frame\r
+       // };\r
+       //\r
+       // static private String _externalPlugin[] = { "org.eclipse.debug.ui",\r
+       // "org.eclipse.debug.ui", "org.eclipse.debug.ui",\r
+       // "org.eclipse.debug.ui", "org.eclipse.debug.ui", };\r
+       //\r
+       // static private Image getImage(int idx) {\r
+       // if (idx < 0 || idx >= IMG_NUM)\r
+       // SWT.error(SWT.ERROR_INVALID_ARGUMENT);\r
+       // String key = "trace.img." + idx;\r
+       // Image img = TmfUiPlugin.getDefault().getImageRegistry().get(key);\r
+       // if (null == img) {\r
+       // ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(\r
+       // _externalPlugin[idx], _externalPath[idx]);\r
+       // TmfUiPlugin.getDefault().getImageRegistry().put(key, desc);\r
+       // img = TmfUiPlugin.getDefault().getImageRegistry().get(key);\r
+       // }\r
+       // return img;\r
+       // }\r
 \r
        public void drawState(TraceColorScheme colors, ITimeEvent event,\r
                        Rectangle rect, GC gc, boolean selected, boolean rectBound,\r
@@ -308,6 +305,7 @@ public abstract class TmfTimeAnalysisProvider {
         * @return\r
         */\r
        public Image getItemImage(Object obj) {\r
+           /*\r
                if (obj instanceof ITmfTimeAnalysisEntry) {\r
                        List<TimeEvent> list = ((ITmfTimeAnalysisEntry) obj).getTraceEvents();\r
                        if (null != list && list.size() > 0)\r
@@ -320,6 +318,7 @@ public abstract class TmfTimeAnalysisProvider {
                if (obj instanceof TimeEvent) {\r
                        return getImage(IMG_THREAD_RUNNING);\r
                }\r
+               */\r
                return null;\r
        }\r
 \r
index 5cf3b8d8cff610df045fc59c9eb9f04f426b1678..c829edf569ba8cb1c0b6c25b0d2a11c515bcf952 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************\r
- * Copyright (c) 2007, 2008, 2009 Intel Corporation, Ericsson\r
+ * Copyright (c) 2007, 2008, 2009, 2010 Intel Corporation, Ericsson\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
  * which accompanies this distribution, and is available at\r
@@ -40,6 +40,7 @@ import org.eclipse.swt.events.ControlEvent;
 import org.eclipse.swt.events.SelectionEvent;\r
 import org.eclipse.swt.events.SelectionListener;\r
 import org.eclipse.swt.graphics.Rectangle;\r
+import org.eclipse.swt.layout.GridLayout;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Control;\r
 \r
@@ -76,7 +77,7 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
        // Calender Time format, using Epoch reference or Relative time\r
        // format(default\r
        private boolean calendarTimeFormat = false;\r
-       private int timeScaleBoderWidth = 4;\r
+       private int borderWidth = 4;\r
        private int timeScaleHeight = 22;\r
 \r
        /** ctor */\r
@@ -171,10 +172,17 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
                _colors = new TraceColorScheme();\r
                _dataViewer = new Composite(parent, SWT.NULL);\r
                _dataViewer.setLayoutData(GridUtil.createFill());\r
+               GridLayout gl = new GridLayout();\r
+               gl.marginHeight = borderWidth;\r
+               gl.marginWidth = 0;\r
+               gl.verticalSpacing = 0;\r
+               gl.horizontalSpacing = 0;\r
+               _dataViewer.setLayout(gl);\r
 \r
                _timeScaleCtrl = new TimeScaleCtrl(_dataViewer, _colors);\r
                _timeScaleCtrl.setTimeProvider(this);\r
-               _timeScaleCtrl.setLayoutData(GridUtil.createFill());\r
+               _timeScaleCtrl.setLayoutData(GridUtil.createHorizontalFill());\r
+               _timeScaleCtrl.setHeight(timeScaleHeight);\r
 \r
                _stateCtrl = new TmfTimeStatesCtrl(_dataViewer, _colors, _utilImplm);\r
 \r
@@ -206,13 +214,6 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
                if (r.isEmpty())\r
                        return;\r
 \r
-               // System.out.println("Client Area:" + r);\r
-               // timeScaleBoderWidth = 8;\r
-               // timeScaleHeight = 22;\r
-               _timeScaleCtrl.setBounds(r.x, r.y + timeScaleBoderWidth, r.width,\r
-                               timeScaleHeight);\r
-               _stateCtrl.setBounds(r.x, r.y + timeScaleBoderWidth + timeScaleHeight,\r
-                               r.width, r.height - timeScaleBoderWidth - timeScaleHeight);\r
                int width = r.width;\r
                if (_nameWidth > width - _minNameWidth)\r
                        _nameWidth = width - _minNameWidth;\r
@@ -220,31 +221,33 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
                        _nameWidth = _minNameWidth;\r
        }\r
 \r
-       /** Tries to set most convinient time range for display. */\r
+       /** Tries to set most convenient time range for display. */\r
        void setTimeRange(Object traces[]) {\r
                _endTime = 0;\r
                _beginTime = -1;\r
                ITimeEvent event;\r
                for (int i = 0; i < traces.length; i++) {\r
-                       ITmfTimeAnalysisEntry thread = (ITmfTimeAnalysisEntry) traces[i];\r
-                       long lastEventTime = thread.getStopTime();\r
-                       if (lastEventTime > thread.getStartTime()) {\r
-                               if (lastEventTime > _endTime)\r
-                                       _endTime = lastEventTime;\r
+                       ITmfTimeAnalysisEntry entry = (ITmfTimeAnalysisEntry) traces[i];\r
+                       if (entry.getStopTime() >= entry.getStartTime() && entry.getStopTime() > 0) {\r
+                           if (_beginTime < 0 || entry.getStartTime() < _beginTime) {\r
+                               _beginTime = entry.getStartTime();\r
+                           }\r
+                           if (entry.getStopTime() > _endTime) {\r
+                               _endTime = entry.getStopTime();\r
+                           }\r
                        }\r
-                       List<TimeEvent> list = thread.getTraceEvents();\r
+                       List<TimeEvent> list = entry.getTraceEvents();\r
                        int len = list.size();\r
                        if (len > 0) {\r
+                event = (ITimeEvent) list.get(0);\r
+                if (_beginTime < 0 || event.getTime() < _beginTime) {\r
+                    _beginTime = event.getTime();\r
+                }\r
                                event = (ITimeEvent) list.get(list.size() - 1);\r
-                               lastEventTime = event.getTime();\r
-                               if (lastEventTime > _endTime) {\r
-                                       _endTime = lastEventTime;\r
-                                       long duration = event.getDuration();\r
-                                       _endTime += duration > 0 ? duration : 1000000;\r
+                               long eventEndTime = event.getTime() + (event.getDuration() > 0 ? event.getDuration() : 0);\r
+                               if (eventEndTime > _endTime) {\r
+                                       _endTime = eventEndTime;\r
                                }\r
-                               event = (ITimeEvent) list.get(0);\r
-                               if (_beginTime < 0 || _beginTime > event.getTime())\r
-                                       _beginTime = event.getTime();\r
                        }\r
                }\r
 \r
@@ -253,7 +256,8 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
        }\r
 \r
        void setTimeBounds() {\r
-               _time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);\r
+               //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);\r
+           _time0_ = _beginTime;\r
                if (_time0_ < 0)\r
                        _time0_ = 0;\r
                // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;\r
@@ -284,8 +288,8 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
        void updateInternalData(ITmfTimeAnalysisEntry[] traces, long start, long end) {\r
                if (null == traces)\r
                        traces = new ITmfTimeAnalysisEntry[0];\r
-               if (end < 1 || start < 1) {\r
-                       // End or start time are unspecified and need to be determined from\r
+               if ((start == 0 && end == 0) || start < 0 || end < 0) {\r
+                       // Start and end time are unspecified and need to be determined from\r
                        // individual processes\r
                        setTimeRange(traces);\r
                } else {\r
@@ -301,8 +305,11 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
         */\r
        private void refreshAllData(ITmfTimeAnalysisEntry[] traces) {\r
                setTimeBounds();\r
-               if (_selectedTime < 0 || _selectedTime > _endTime)\r
-                       _selectedTime = _endTime;\r
+               if (_selectedTime < _beginTime) {\r
+                   _selectedTime = _beginTime;\r
+               } else if (_selectedTime > _endTime) {\r
+            _selectedTime = _endTime;\r
+               }\r
                _stateCtrl.refreshData(traces);\r
                filterOutNotification();\r
        }\r
@@ -381,18 +388,6 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
                return _time0_;\r
        }\r
 \r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see\r
-        * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider\r
-        * #mouseUp()\r
-        */\r
-       public void mouseUp() {\r
-               // refresh listeners with the new selected time if changed\r
-               notifyStartFinishTimeSelectionListeners(_time0, _time1);\r
-       }\r
-\r
        /*\r
         * (non-Javadoc)\r
         * \r
@@ -451,9 +446,9 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
                                _time0 += dt;\r
                                _time1 += dt;\r
                        }\r
-                       if (_time0 < 0) {\r
-                               _time1 -= _time0;\r
-                               _time0 = 0;\r
+                       if (_time0 < _time0_) {\r
+                               _time1 += _time0_ - _time0;\r
+                               _time0 = _time0_;\r
                        } else if (_time1 > _time1_) {\r
                                _time0 -= _time1 - _time1_;\r
                                _time1 = _time1_;\r
@@ -699,12 +694,14 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
        }\r
 \r
        public int getBorderWidth() {\r
-               return timeScaleBoderWidth;\r
+               return borderWidth;\r
        }\r
 \r
        public void setBorderWidth(int borderWidth) {\r
                if (borderWidth > -1) {\r
-                       this.timeScaleBoderWidth = borderWidth;\r
+            this.borderWidth = borderWidth;\r
+            GridLayout gl = (GridLayout)_dataViewer.getLayout();\r
+            gl.marginHeight = borderWidth;\r
                }\r
        }\r
 \r
@@ -715,6 +712,7 @@ public class TmfTimeAnalysisViewer implements ITimeAnalysisViewer, ITimeDataProv
        public void setHeaderHeight(int headerHeight) {\r
                if (headerHeight > -1) {\r
                        this.timeScaleHeight = headerHeight;\r
+                       _timeScaleCtrl.setHeight(headerHeight);\r
                }\r
        }\r
 \r
index 3d3413fbad0e8632fefdf033d233d70e6c5c7f39..7dac086b5a41699ab431db7d25d668fa44ac2ea7 100644 (file)
@@ -1,5 +1,5 @@
 #*******************************************************************************\r
-# Copyright (c) 2009 Ericsson\r
+# Copyright (c) 2009, 2010 Ericsson\r
 # \r
 # All rights reserved. This program and the accompanying materials are\r
 # made available under the terms of the Eclipse Public License v1.0 which\r
@@ -20,6 +20,7 @@ _TRACE_NAME = Process Name
 _TRACE_CLASS_NAME = Class Name\r
 _TRACE_GROUP_NAME = Group Name\r
 _TRACE_START_TIME = Start Time\r
+_TRACE_EVENT_TIME = Event Time\r
 _TRACE_STOP_TIME = Stop Time\r
 _DURATION = Duration\r
 _TRACE_STATE = State\r
index 2060aa11c4084f00210ac07d92d3f4e25030af0d..7cab4dd51b90dae73e89ccbbbd8273c15b0536c3 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************\r
- * Copyright (c) 2007, Intel Corporation.\r
+ * Copyright (c) 2007, 2010 Intel Corporation.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
  * which accompanies this distribution, and is available at\r
@@ -8,7 +8,7 @@
  * Contributors:\r
  *    Intel Corporation - Initial API and implementation\r
  *    Ruslan A. Scherbakov, Intel - Initial API and implementation\r
- *    Alvaro Sanchex-Leon - Udpated for TMF\r
+ *    Alvaro Sanchex-Leon - Updated for TMF\r
  *\r
  * $Id: ITimeDataProvider.java,v 1.2 2007/02/27 18:37:36 ewchan Exp $ \r
  *****************************************************************************/\r
@@ -33,13 +33,6 @@ public interface ITimeDataProvider {
 \r
        long getMinTimeInterval();\r
 \r
-       /**\r
-        * Receive Notification when any of the buttons of the mouse switch back to\r
-        * up position, this method may trigger time update notification to\r
-        * listeners\r
-        */\r
-       void mouseUp();\r
-\r
        /**\r
         * Updates the time range and notify registered listeners\r
         * \r
index 1e3a44b40fba45253083cc95fe0ce1bb6a95e464..7e7ff670637de73bf3a0665e696de366fd04e779 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************\r
- * Copyright (c) 2007, 2008 Intel Corporation and others.\r
+ * Copyright (c) 2007, 2008, 2010 Intel Corporation and others.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
  * which accompanies this distribution, and is available at\r
 package org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets;\r
 \r
 import java.text.SimpleDateFormat;\r
+import java.util.Calendar;\r
 import java.util.Date;\r
+import java.util.GregorianCalendar;\r
+import java.util.TimeZone;\r
 \r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.Messages;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.Utils.Resolution;\r
@@ -40,6 +43,20 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener,
                addMouseMoveListener(this);\r
        }\r
 \r
+    private static final long SEC_IN_NS = 1000000000;\r
+    private static final long MIN_IN_NS = 60 * SEC_IN_NS;\r
+    private static final long HOUR_IN_NS = 60 * MIN_IN_NS;\r
+    private static final long DAY_IN_NS = 24 * HOUR_IN_NS;\r
+    private static final long MONTH_IN_NS = 31 * DAY_IN_NS; // upper limit\r
+    private static final long YEAR_IN_NS = 366 * DAY_IN_NS; // upper limit\r
+    \r
+    private static final double LOG10_1 = Math.log10(1);\r
+    private static final double LOG10_2 = Math.log10(2);\r
+    private static final double LOG10_3 = Math.log10(3);\r
+    private static final double LOG10_5 = Math.log10(5);\r
+    \r
+    private static final Calendar GREGORIAN_CALENDAR = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));\r
+    \r
        private ITimeDataProvider _timeProvider;\r
        private int _dragState = 0;\r
        private int _dragX0 = 0;\r
@@ -48,68 +65,108 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener,
        private long _time1bak;\r
        private boolean _isInUpdate;\r
        private Rectangle _rect0 = new Rectangle(0, 0, 0, 0);\r
+    private int _height;\r
 \r
        public void setTimeProvider(ITimeDataProvider timeProvider) {\r
                _timeProvider = timeProvider;\r
        }\r
 \r
-       private double _timeDeltaD;\r
        private long _timeDelta;\r
 \r
-       private void calcTimeDelta(int width, double K) {\r
-               long D[] = { 1, 2, 5, };\r
-               long pow = 1;\r
-               double powD = 1;\r
-               long td = pow;\r
-               double tdD = powD;\r
-               double dx = tdD * K;\r
-               int i = 0;\r
-               while (dx < width) {\r
-                       td = D[i] * pow;\r
-                       tdD = D[i] * powD;\r
-                       dx = tdD * K;\r
-                       i++;\r
-                       if (i == 3) {\r
-                               i = 0;\r
-                               pow *= 10;\r
-                               powD *= 10;\r
-                       }\r
-               }\r
-               _timeDeltaD = tdD;\r
-               _timeDelta = td;\r
-//             Trace.debug("Width: " + width + " K: " + K + " Time Delta: "\r
-//                             + _timeDelta);\r
-       }\r
-\r
-       static private TimeDraw _tds[] = new TimeDraw[] { new TimeDrawSec(),\r
-                       new TimeDrawMillisec(), new TimeDrawMicrosec(),\r
-                       new TimeDrawNanosec(), new TimeDrawAbsSec(),\r
-                       new TimeDrawAbsMillisec(), new TimeDrawAbsMicroSec(),\r
-                       new TimeDrawAbsNanoSec() };\r
+       @Override\r
+    public Point computeSize(int wHint, int hHint, boolean changed) {\r
+        return super.computeSize(wHint, _height, changed);\r
+    }\r
+\r
+    public void setHeight(int height) {\r
+        this._height = height;\r
+    }\r
+    \r
+    private void calcTimeDelta(int width, double pixelsPerNanoSec) {\r
+        double minDelta = (double) ((pixelsPerNanoSec ==0) ? YEAR_IN_NS : width / pixelsPerNanoSec);\r
+        long unit = 1;\r
+        if (_timeProvider != null && _timeProvider.isCalendarFormat()) {\r
+            if (minDelta > 6 * MONTH_IN_NS) {\r
+                unit = YEAR_IN_NS;\r
+            } else if (minDelta > 3 * MONTH_IN_NS) {\r
+                unit = 6 * MONTH_IN_NS;\r
+            } else if (minDelta > 10 * DAY_IN_NS) {\r
+                unit = MONTH_IN_NS;\r
+            } else if (minDelta > 12 * HOUR_IN_NS) {\r
+                unit = DAY_IN_NS;\r
+            } else if (minDelta > 3 * HOUR_IN_NS) {\r
+                unit = 6 * HOUR_IN_NS;\r
+            } else if (minDelta > 30 * MIN_IN_NS) {\r
+                unit = HOUR_IN_NS;\r
+            } else if (minDelta > 10 * MIN_IN_NS) {\r
+                unit = 15 * MIN_IN_NS;\r
+            } else if (minDelta > 30 * SEC_IN_NS) {\r
+                unit = MIN_IN_NS;\r
+            } else if (minDelta > 20 * SEC_IN_NS) {\r
+                unit = 30 * SEC_IN_NS;\r
+            }\r
+        }\r
+        double log = Math.log10((double) minDelta / unit);\r
+        long pow10 = (long) log;\r
+        double remainder = log - pow10;\r
+        if (remainder < LOG10_1) {\r
+            _timeDelta = (long) Math.pow(10, pow10) * unit;\r
+        } else if (remainder < LOG10_2) {\r
+            _timeDelta = 2 * (long) Math.pow(10, pow10) * unit;\r
+        } else if (remainder < LOG10_3 && unit >= HOUR_IN_NS && unit < YEAR_IN_NS) {\r
+            _timeDelta = 3 * (long) Math.pow(10, pow10) * unit;\r
+        } else if (remainder < LOG10_5) {\r
+            _timeDelta = 5 * (long) Math.pow(10, pow10) * unit;\r
+        } else {\r
+            _timeDelta = 10 * (long) Math.pow(10, pow10) * unit;\r
+        }\r
+    }\r
+\r
+    private static TimeDraw TIMEDRAW_NANOSEC = new TimeDrawNanosec();\r
+    private static TimeDraw TIMEDRAW_MICROSEC = new TimeDrawMicrosec();\r
+    private static TimeDraw TIMEDRAW_MILLISEC = new TimeDrawMillisec();\r
+    private static TimeDraw TIMEDRAW_SEC = new TimeDrawSec();\r
+    private static TimeDraw TIMEDRAW_ABS_NANOSEC = new TimeDrawAbsNanoSec();\r
+    private static TimeDraw TIMEDRAW_ABS_MICROSEC = new TimeDrawAbsMicroSec();\r
+    private static TimeDraw TIMEDRAW_ABS_MILLISEC = new TimeDrawAbsMillisec();\r
+    private static TimeDraw TIMEDRAW_ABS_SEC = new TimeDrawAbsSec();\r
+    private static TimeDraw TIMEDRAW_ABS_MIN = new TimeDrawAbsMin();\r
+    private static TimeDraw TIMEDRAW_ABS_HRS = new TimeDrawAbsHrs();\r
+    private static TimeDraw TIMEDRAW_ABS_DAY = new TimeDrawAbsDay();\r
+    private static TimeDraw TIMEDRAW_ABS_MONTH = new TimeDrawAbsMonth();\r
+    private static TimeDraw TIMEDRAW_ABS_YEAR = new TimeDrawAbsYear();\r
 \r
        TimeDraw getTimeDraw(long timeDelta) {\r
                TimeDraw timeDraw;\r
-               if (_timeProvider != null) {\r
-                       if (_timeProvider.isCalendarFormat()) {\r
-                               if (timeDelta >= 1000000000)\r
-                                       timeDraw = _tds[4];\r
-                               else if (timeDelta >= 1000000)\r
-                                       timeDraw = _tds[5];\r
-                               else if (timeDelta >= 1000)\r
-                                       timeDraw = _tds[6];\r
-                               else\r
-                                       timeDraw = _tds[7];\r
-                               return timeDraw;\r
-                       }\r
+               if (_timeProvider != null && _timeProvider.isCalendarFormat()) {\r
+            if (timeDelta >= YEAR_IN_NS)\r
+                timeDraw = TIMEDRAW_ABS_YEAR;\r
+            else if (timeDelta >= MONTH_IN_NS)\r
+                timeDraw = TIMEDRAW_ABS_MONTH;\r
+            else if (timeDelta >= DAY_IN_NS)\r
+                timeDraw = TIMEDRAW_ABS_DAY;\r
+            else if (timeDelta >= HOUR_IN_NS)\r
+                timeDraw = TIMEDRAW_ABS_HRS;\r
+            else if (timeDelta >= MIN_IN_NS)\r
+                timeDraw = TIMEDRAW_ABS_MIN;\r
+            else if (timeDelta >= SEC_IN_NS)\r
+                timeDraw = TIMEDRAW_ABS_SEC;\r
+                       else if (timeDelta >= 1000000)\r
+                               timeDraw = TIMEDRAW_ABS_MILLISEC;\r
+                       else if (timeDelta >= 1000)\r
+                               timeDraw = TIMEDRAW_ABS_MICROSEC;\r
+                       else\r
+                               timeDraw = TIMEDRAW_ABS_NANOSEC;\r
+                       return timeDraw;\r
                }\r
                if (timeDelta >= 1000000000)\r
-                       timeDraw = _tds[0];\r
+                       timeDraw = TIMEDRAW_SEC;\r
                else if (timeDelta >= 1000000)\r
-                       timeDraw = _tds[1];\r
+                       timeDraw = TIMEDRAW_MILLISEC;\r
                else if (timeDelta >= 1000)\r
-                       timeDraw = _tds[2];\r
+                       timeDraw = TIMEDRAW_MICROSEC;\r
                else\r
-                       timeDraw = _tds[3];\r
+                       timeDraw = TIMEDRAW_NANOSEC;\r
                return timeDraw;\r
        }\r
 \r
@@ -120,67 +177,71 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener,
                        return;\r
 \r
                GC gc = e.gc;\r
+               gc.fillRectangle(rect);\r
+               \r
                if (null == _timeProvider) {\r
-                       gc.fillRectangle(rect);\r
                        return;\r
                }\r
 \r
-               gc.setBackground(_colors.getColor(TraceColorScheme.TOOL_BACKGROUND));\r
-               gc.setForeground(_colors.getColor(TraceColorScheme.TOOL_FOREGROUND));\r
                long time0 = _timeProvider.getTime0();\r
                long time1 = _timeProvider.getTime1();\r
                long selectedTime = _timeProvider.getSelectedTime();\r
                int leftSpace = _timeProvider.getNameSpace();\r
                int timeSpace = _timeProvider.getTimeSpace();\r
-\r
-               if (time1 <= time0 || timeSpace < 2) {\r
-                       gc.fillRectangle(rect);\r
-                       return;\r
-               }\r
-\r
-               int numDigits = calculateDigits(time0, time1);\r
-\r
+               \r
+               gc.setBackground(_colors.getColor(TraceColorScheme.TOOL_BACKGROUND));\r
+               gc.setForeground(_colors.getColor(TraceColorScheme.TOOL_FOREGROUND));\r
                Utils.init(_rect0, rect);\r
-               int labelWidth = gc.getCharWidth('0') * numDigits;\r
-               double K = 1;\r
-               if (rect.width - leftSpace > 0) {\r
-                       K = (double) timeSpace / (time1 - time0);\r
-                       calcTimeDelta(labelWidth, K);\r
-               }\r
                \r
-               TimeDraw timeDraw = getTimeDraw(_timeDelta);\r
-\r
                // draw top left area\r
                _rect0.width = leftSpace;\r
-               gc.fillRectangle(_rect0);\r
                _rect0.x += 4;\r
                _rect0.width -= 4;\r
                if (_rect0.width > 0) {\r
-// TODO: Check if we really need that piece of code...                 \r
-//                     if (false && rect.width - leftSpace > 0)\r
-//                             Utils.drawText(gc, Messages._Timescale + ": "\r
-//                                             + timeDraw.hint(), _rect0, true);\r
-//                     else\r
-                               Utils.drawText(gc, Messages._Timescale + ":", _rect0, true);\r
+                   Utils.drawText(gc, Messages._Timescale + ":", _rect0, true);\r
                }\r
+               int messageWidth = gc.stringExtent(Messages._Timescale + ":").x + 4;\r
+               Rectangle absHeaderRect = new Rectangle(_rect0.x + messageWidth, _rect0.y, _rect0.width - messageWidth, _rect0.height);\r
                _rect0.x -= 4;\r
                _rect0.width += 4;\r
-\r
+               \r
                // prepare and draw right rect of the timescale\r
                _rect0.x += leftSpace;\r
                _rect0.width = rect.width - leftSpace;\r
-\r
+               \r
                // draw bottom border and erase all other area\r
                gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1,\r
-                               rect.y + rect.height - 1);\r
+                       rect.y + rect.height - 1);\r
                _rect0.height--;\r
                gc.fillRectangle(_rect0);\r
+               \r
+               if (time1 <= time0 || timeSpace < 2) {\r
+                   return;\r
+               }\r
+               \r
+               int numDigits = calculateDigits(time0, time1);\r
+               \r
+               int labelWidth = gc.getCharWidth('0') * numDigits;\r
+               double pixelsPerNanoSec = (timeSpace <= 2) ? 0 :\r
+                   (double) (timeSpace - 2) / (time1 - time0); // 2 pixels less to make sure end time is visible\r
+               calcTimeDelta(labelWidth, pixelsPerNanoSec);\r
+               \r
+               TimeDraw timeDraw = getTimeDraw(_timeDelta);\r
+\r
+               // draw zoom rectangle\r
+        if (3 == _dragState && null != _timeProvider) {\r
+            if (_dragX0 < _dragX) {\r
+                gc.drawRectangle(leftSpace + _dragX0, rect.y, _dragX - _dragX0 - 1, rect.height - 8);\r
+            } else if (_dragX0 > _dragX) {\r
+                gc.drawRectangle(leftSpace + _dragX, rect.y, _dragX0 - _dragX - 1, rect.height - 8);\r
+            }\r
+        }\r
 \r
                if (_rect0.isEmpty())\r
                        return;\r
 \r
                // draw selected time\r
-               int x = _rect0.x + (int) ((selectedTime - time0) * K);\r
+               int x = _rect0.x + (int) ((double)(selectedTime - time0) * pixelsPerNanoSec);\r
                if (x >= _rect0.x && x < _rect0.x + _rect0.width) {\r
                        gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME));\r
                        gc.drawLine(x, _rect0.y + _rect0.height - 6, x, _rect0.y\r
@@ -194,12 +255,23 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener,
                _rect0.y = rect.y;\r
                _rect0.height = rect.height - 4;\r
                _rect0.width = labelWidth;\r
-               long time = (long) (Math.floor(time0 / _timeDeltaD) * _timeDeltaD);\r
+               \r
+               long time;\r
+        if (_timeProvider != null && _timeProvider.isCalendarFormat()) {\r
+            time = floorToCalendar(time0, _timeDelta);\r
+        } else {\r
+            time = (long) (Math.ceil((double) time0 / _timeDelta) * _timeDelta);\r
+        }\r
+               \r
                // long t = (long) (time * 1000000000);\r
-               long t = time;\r
                int y = _rect0.y + _rect0.height;\r
+\r
+        if (_timeProvider != null && _timeProvider.isCalendarFormat()) {\r
+            timeDraw.drawAbsHeader(gc, time, absHeaderRect);\r
+        }\r
+               \r
                while (true) {\r
-                       x = rect.x + leftSpace + (int) ((time - time0) * K);\r
+                       x = rect.x + leftSpace + (int) (Math.floor((time - time0) * pixelsPerNanoSec));\r
                        if (x >= rect.x + leftSpace + rect.width - _rect0.width) {\r
                                break;\r
                        }\r
@@ -207,13 +279,59 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener,
                                gc.drawLine(x, y, x, y + 4);\r
                                _rect0.x = x;\r
                                if (x + _rect0.width <= rect.x + rect.width)\r
-                                       timeDraw.draw(gc, t, _rect0);\r
+                                       timeDraw.draw(gc, time, _rect0);\r
+                       }\r
+                       if (pixelsPerNanoSec == 0 || time > Long.MAX_VALUE - _timeDelta) {\r
+                           break;\r
                        }\r
-                       time += _timeDeltaD;\r
-                       t += _timeDelta;\r
+                       time += _timeDelta;\r
+            if (_timeProvider != null && _timeProvider.isCalendarFormat()) {\r
+                if (_timeDelta >= YEAR_IN_NS) {\r
+                    GREGORIAN_CALENDAR.setTime(new Date(time / 1000000));\r
+                    GREGORIAN_CALENDAR.set(Calendar.MONTH, 0); // January 1st of year\r
+                    GREGORIAN_CALENDAR.set(Calendar.DAY_OF_MONTH, 1);\r
+                    time = GREGORIAN_CALENDAR.getTimeInMillis() * 1000000;\r
+                } else if (_timeDelta >= MONTH_IN_NS) {\r
+                    GREGORIAN_CALENDAR.setTime(new Date(time / 1000000));\r
+                    GREGORIAN_CALENDAR.set(Calendar.DAY_OF_MONTH, 1); // 1st of month\r
+                    time = GREGORIAN_CALENDAR.getTimeInMillis() * 1000000;\r
+                }\r
+            }\r
                }\r
        }\r
 \r
+       private long floorToCalendar(long time, long timeDelta) {\r
+        if (_timeDelta >= YEAR_IN_NS) {\r
+            GREGORIAN_CALENDAR.setTime(new Date(time / 1000000));\r
+            int year = GREGORIAN_CALENDAR.get(Calendar.YEAR);\r
+            int yearDelta = (int) (timeDelta / YEAR_IN_NS);\r
+            year = (year / yearDelta) * yearDelta;\r
+            GREGORIAN_CALENDAR.set(Calendar.YEAR, year);\r
+            GREGORIAN_CALENDAR.set(Calendar.MONTH, 0); // January 1st of year\r
+            GREGORIAN_CALENDAR.set(Calendar.DAY_OF_MONTH, 1);\r
+            GREGORIAN_CALENDAR.set(Calendar.HOUR_OF_DAY, 0);\r
+            GREGORIAN_CALENDAR.set(Calendar.MINUTE, 0);\r
+            GREGORIAN_CALENDAR.set(Calendar.SECOND, 0);\r
+            GREGORIAN_CALENDAR.set(Calendar.MILLISECOND, 0);\r
+            time = GREGORIAN_CALENDAR.getTimeInMillis() * 1000000;\r
+        } else if (_timeDelta >= MONTH_IN_NS) {\r
+            GREGORIAN_CALENDAR.setTime(new Date(time / 1000000));\r
+            int month = GREGORIAN_CALENDAR.get(Calendar.MONTH);\r
+            int monthDelta = (int) (timeDelta / MONTH_IN_NS);\r
+            month = (month / monthDelta) * monthDelta;\r
+            GREGORIAN_CALENDAR.set(Calendar.MONTH, month);\r
+            GREGORIAN_CALENDAR.set(Calendar.DAY_OF_MONTH, 1); // 1st of month\r
+            GREGORIAN_CALENDAR.set(Calendar.HOUR_OF_DAY, 0);\r
+            GREGORIAN_CALENDAR.set(Calendar.MINUTE, 0);\r
+            GREGORIAN_CALENDAR.set(Calendar.SECOND, 0);\r
+            GREGORIAN_CALENDAR.set(Calendar.MILLISECOND, 0);\r
+            time = GREGORIAN_CALENDAR.getTimeInMillis() * 1000000;\r
+        } else {\r
+            time = (time / timeDelta) * timeDelta;\r
+        }\r
+        return time;\r
+       }\r
+       \r
        private int calculateDigits(long time0, long time1) {\r
                int numDigits = 5;\r
                long timeRange = time1 - time0;\r
@@ -222,7 +340,7 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener,
                        // Calculate the number of digits to represent the minutes provided\r
                        // 11:222\r
                        // HH:mm:ss\r
-                       numDigits += 5;\r
+                       numDigits += 8;\r
                        if (timeRange < 10000) {\r
                                // HH:11:222:333:444__\r
                                numDigits += 10;\r
@@ -254,65 +372,87 @@ public class TimeScaleCtrl extends TraceCtrl implements MouseListener,
        }\r
 \r
        public void mouseDown(MouseEvent e) {\r
-               if (1 == e.button && null != _timeProvider) {\r
-                       setCapture(true);\r
-                       _dragState = 1;\r
-               }\r
-               // Window adjustment allowed using mouse button three.\r
-               _dragX = _dragX0 = e.x - _timeProvider.getNameSpace();\r
-               _time0bak = _timeProvider.getTime0();\r
-               _time1bak = _timeProvider.getTime1();\r
+           if (_dragState == 0 && null != _timeProvider) {\r
+               if (1 == e.button) {\r
+                   setCapture(true);\r
+                   _dragState = 1;\r
+               } else if (3 == e.button) {\r
+                   _dragState = 3;\r
+               }\r
+               int x = e.x - _timeProvider.getNameSpace();\r
+               if (x < 0) {\r
+                   x = 0;\r
+               } else if (x > getSize().x - _timeProvider.getNameSpace()) {\r
+                   x = getSize().x - _timeProvider.getNameSpace();\r
+               }\r
+               _dragX = _dragX0 = x;\r
+               _time0bak = _timeProvider.getTime0();\r
+               _time1bak = _timeProvider.getTime1();\r
+           }\r
        }\r
 \r
        public void mouseUp(MouseEvent e) {\r
-               if (1 == _dragState) {\r
+               if (e.button == 1 && _dragState == 1) {\r
                        setCapture(false);\r
                        _dragState = 0;\r
-               }\r
-\r
-               if (3 == e.button && null != _timeProvider) {\r
-                       if (_dragX0 < 0) {\r
+               } else if (e.button == 3 && _dragState == 3 && null != _timeProvider) {\r
+                   _dragState = 0;\r
+                       if (_dragX0 == _dragX) {\r
                                return;\r
                        }\r
-                       Point size = getSize();\r
-\r
+                       int timeSpace = _timeProvider.getTimeSpace();\r
                        int leftSpace = _timeProvider.getNameSpace();\r
                        int x = e.x - leftSpace;\r
-                       if (x > 0 && size.x > leftSpace && _dragX != x) {\r
+                       if (timeSpace > 0) {\r
                                _dragX = x;\r
-                               long time0 = _time0bak + ((_time1bak - _time0bak) * _dragX0)\r
-                                               / (size.x - leftSpace);\r
-                               long time1 = _time0bak + ((_time1bak - _time0bak) * _dragX)\r
-                                               / (size.x - leftSpace);\r
+                               if (_dragX0 > _dragX) { // drag right to left\r
+                                   _dragX = _dragX0;\r
+                                   _dragX0 = x;\r
+                               }\r
+                               long time0 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / timeSpace));\r
+                               long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX / timeSpace));\r
 \r
                                _timeProvider.setStartFinishTime(time0, time1);\r
+                   _time0bak = _timeProvider.getTime0();\r
+                   _time1bak = _timeProvider.getTime1();\r
                        }\r
                }\r
 \r
                // Notify time provider to check the need for listener notification\r
-               _timeProvider.mouseUp();\r
+               _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1());\r
        }\r
 \r
        public void mouseMove(MouseEvent e) {\r
-               if (_dragX0 < 0) {\r
+               if (_dragX0 < 0 || _dragState == 0) {\r
                        return;\r
                }\r
                Point size = getSize();\r
+               int leftSpace = _timeProvider.getNameSpace();\r
+               int timeSpace = _timeProvider.getTimeSpace();\r
+               int x = e.x - leftSpace;\r
                if (1 == _dragState && null != _timeProvider) {\r
-                       int leftSpace = _timeProvider.getNameSpace();\r
-                       int x = e.x - leftSpace;\r
                        if (x > 0 && size.x > leftSpace && _dragX != x) {\r
                                _dragX = x;\r
-                               long time1 = _time0bak + ((_time1bak - _time0bak) * _dragX0)\r
-                                               / _dragX;\r
+                               long time1 = _time0bak + (long) ((_time1bak - _time0bak) * ((double) _dragX0 / _dragX));\r
                                _timeProvider.setStartFinishTime(_time0bak, time1);\r
                        }\r
+               } else if (3 == _dragState && null != _timeProvider) {\r
+                   if (x < 0) {\r
+                       _dragX = 0;\r
+                   } else if (x > timeSpace) {\r
+                       _dragX = timeSpace;\r
+                   } else {\r
+                _dragX = x;\r
+            }\r
+                   redraw();\r
                }\r
        }\r
 \r
        public void mouseDoubleClick(MouseEvent e) {\r
                if (null != _timeProvider) {\r
                        _timeProvider.resetStartFinishTime();\r
+            _time0bak = _timeProvider.getTime0();\r
+            _time1bak = _timeProvider.getTime1();\r
                }\r
        }\r
 }\r
@@ -321,7 +461,28 @@ abstract class TimeDraw {
        static String S = ":";\r
        static String S0 = ":0";\r
        static String S00 = ":00";\r
-       protected SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss");\r
+    protected static final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss");\r
+    protected static final SimpleDateFormat stimeformatheader = new SimpleDateFormat("yyyy MMM dd");\r
+    protected static final SimpleDateFormat sminformat = new SimpleDateFormat("HH:mm");\r
+    protected static final SimpleDateFormat sminformatheader = new SimpleDateFormat("yyyy MMM dd");\r
+    protected static final SimpleDateFormat shrsformat = new SimpleDateFormat("MMM dd HH:mm");\r
+    protected static final SimpleDateFormat shrsformatheader = new SimpleDateFormat("yyyy");\r
+    protected static final SimpleDateFormat sdayformat = new SimpleDateFormat("MMM dd");\r
+    protected static final SimpleDateFormat sdayformatheader = new SimpleDateFormat("yyyy");\r
+    protected static final SimpleDateFormat smonthformat = new SimpleDateFormat("yyyy MMM");\r
+    protected static final SimpleDateFormat syearformat = new SimpleDateFormat("yyyy");\r
+    static {\r
+        stimeformat.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+        stimeformatheader.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+        sminformat.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+        sminformatheader.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+        shrsformat.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+        shrsformatheader.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+        sdayformat.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+        sdayformatheader.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+        smonthformat.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+        syearformat.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+    }\r
        \r
        static String pad(long n) {\r
                String s = S;\r
@@ -332,8 +493,13 @@ abstract class TimeDraw {
                return s + n;\r
        }\r
 \r
-       public abstract void draw(GC gc, long time, Rectangle rect);\r
+    public abstract void draw(GC gc, long time, Rectangle rect);\r
 \r
+    public void drawAbsHeader(GC gc, long time, Rectangle absHeaderRect) {\r
+        // Override to draw absolute time header\r
+        // This is for the time information not shown in the draw of each tick\r
+    }\r
+    \r
        public abstract String hint();\r
 }\r
 \r
@@ -408,19 +574,135 @@ class TimeDrawNanosec extends TimeDraw {
        }\r
 }\r
 \r
-class TimeDrawAbsSec extends TimeDraw {\r
-       static String _hint = "HH:mm:ss";\r
+class TimeDrawAbsYear extends TimeDraw {\r
+    static String _hint = "YYYY";\r
 \r
-       @Override\r
-       public void draw(GC gc, long time, Rectangle rect) {\r
-               String stime = stimeformat.format(new Date((long) (time * 1E-6)));\r
-               Utils.drawText(gc, stime, rect, true);\r
-       }\r
+    @Override\r
+    public void draw(GC gc, long time, Rectangle rect) {\r
+        String stime = syearformat.format(new Date((long) (time / 1000000)));\r
+        Utils.drawText(gc, stime, rect, true);\r
+    }\r
 \r
-       @Override\r
-       public String hint() {\r
-               return _hint;\r
-       }\r
+    @Override\r
+    public String hint() {\r
+        return _hint;\r
+    }\r
+}\r
+\r
+class TimeDrawAbsMonth extends TimeDraw {\r
+    static String _hint = "YYYY Mmm";\r
+\r
+    @Override\r
+    public void draw(GC gc, long time, Rectangle rect) {\r
+        String stime = smonthformat.format(new Date((long) (time / 1000000)));\r
+        Utils.drawText(gc, stime, rect, true);\r
+    }\r
+\r
+    @Override\r
+    public String hint() {\r
+        return _hint;\r
+    }\r
+}\r
+\r
+class TimeDrawAbsDay extends TimeDraw {\r
+    static String _hint = "Mmm dd";\r
+\r
+    @Override\r
+    public void draw(GC gc, long time, Rectangle rect) {\r
+        String stime = sdayformat.format(new Date((long) (time / 1000000)));\r
+        Utils.drawText(gc, stime, rect, true);\r
+    }\r
+\r
+    @Override\r
+    public void drawAbsHeader(GC gc, long time, Rectangle rect) {\r
+        String header = sdayformatheader.format(new Date((long) (time / 1000000)));\r
+        int headerwidth = gc.stringExtent(header).x + 4;\r
+        if (headerwidth <= rect.width) {\r
+            rect.x += (rect.width - headerwidth);\r
+            Utils.drawText(gc, header, rect, true);\r
+        }\r
+    }\r
+    \r
+    @Override\r
+    public String hint() {\r
+        return _hint;\r
+    }\r
+}\r
+\r
+class TimeDrawAbsHrs extends TimeDraw {\r
+    static String _hint = "Mmm dd HH:mm";\r
+\r
+    @Override\r
+    public void draw(GC gc, long time, Rectangle rect) {\r
+        String stime = shrsformat.format(new Date((long) (time / 1000000)));\r
+        Utils.drawText(gc, stime, rect, true);\r
+    }\r
+\r
+    @Override\r
+    public void drawAbsHeader(GC gc, long time, Rectangle rect) {\r
+        String header = shrsformatheader.format(new Date((long) (time / 1000000)));\r
+        int headerwidth = gc.stringExtent(header).x + 4;\r
+        if (headerwidth <= rect.width) {\r
+            rect.x += (rect.width - headerwidth);\r
+            Utils.drawText(gc, header, rect, true);\r
+        }\r
+    }\r
+    \r
+    @Override\r
+    public String hint() {\r
+        return _hint;\r
+    }\r
+}\r
+\r
+class TimeDrawAbsMin extends TimeDraw {\r
+    static String _hint = "HH:mm";\r
+\r
+    @Override\r
+    public void draw(GC gc, long time, Rectangle rect) {\r
+        String stime = sminformat.format(new Date((long) (time / 1000000)));\r
+        Utils.drawText(gc, stime, rect, true);\r
+    }\r
+\r
+    @Override\r
+    public void drawAbsHeader(GC gc, long time, Rectangle rect) {\r
+        String header = sminformatheader.format(new Date((long) (time / 1000000)));\r
+        int headerwidth = gc.stringExtent(header).x + 4;\r
+        if (headerwidth <= rect.width) {\r
+            rect.x += (rect.width - headerwidth);\r
+            Utils.drawText(gc, header, rect, true);\r
+        }\r
+    }\r
+    \r
+    \r
+    @Override\r
+    public String hint() {\r
+        return _hint;\r
+    }\r
+}\r
+\r
+class TimeDrawAbsSec extends TimeDraw {\r
+    static String _hint = "HH:mm:ss";\r
+\r
+    @Override\r
+    public void draw(GC gc, long time, Rectangle rect) {\r
+        String stime = stimeformat.format(new Date((long) (time / 1000000)));\r
+        Utils.drawText(gc, stime, rect, true);\r
+    }\r
+\r
+    @Override\r
+    public void drawAbsHeader(GC gc, long time, Rectangle rect) {\r
+        String header = stimeformatheader.format(new Date((long) (time / 1000000)));\r
+        int headerwidth = gc.stringExtent(header).x + 4;\r
+        if (headerwidth <= rect.width) {\r
+            rect.x += (rect.width - headerwidth);\r
+            Utils.drawText(gc, header, rect, true);\r
+        }\r
+    }\r
+    \r
+    @Override\r
+    public String hint() {\r
+        return _hint;\r
+    }\r
 }\r
 \r
 class TimeDrawAbsMillisec extends TimeDraw {\r
@@ -428,12 +710,22 @@ class TimeDrawAbsMillisec extends TimeDraw {
 \r
        @Override\r
        public void draw(GC gc, long time, Rectangle rect) {\r
-               String stime = stimeformat.format(new Date((long) (time * 1E-6)));\r
+               String stime = stimeformat.format(new Date((long) (time / 1000000)));\r
                String ns = Utils.formatNs(time, Resolution.MILLISEC);\r
 \r
                Utils.drawText(gc, stime + " " + ns, rect, true);\r
        }\r
 \r
+    @Override\r
+    public void drawAbsHeader(GC gc, long time, Rectangle rect) {\r
+        String header = stimeformatheader.format(new Date((long) (time / 1000000)));\r
+        int headerwidth = gc.stringExtent(header).x + 4;\r
+        if (headerwidth <= rect.width) {\r
+            rect.x += (rect.width - headerwidth);\r
+            Utils.drawText(gc, header, rect, true);\r
+        }\r
+    }\r
+    \r
        @Override\r
        public String hint() {\r
                return _hint;\r
@@ -445,11 +737,21 @@ class TimeDrawAbsMicroSec extends TimeDraw {
 \r
        @Override\r
        public void draw(GC gc, long time, Rectangle rect) {\r
-               String stime = stimeformat.format(new Date((long) (time * 1E-6)));\r
+               String stime = stimeformat.format(new Date((long) (time / 1000000)));\r
                String micr = Utils.formatNs(time, Resolution.MICROSEC);\r
                Utils.drawText(gc, stime + " " + micr, rect, true);\r
        }\r
 \r
+    @Override\r
+    public void drawAbsHeader(GC gc, long time, Rectangle rect) {\r
+        String header = stimeformatheader.format(new Date((long) (time / 1000000)));\r
+        int headerwidth = gc.stringExtent(header).x + 4;\r
+        if (headerwidth <= rect.width) {\r
+            rect.x += (rect.width - headerwidth);\r
+            Utils.drawText(gc, header, rect, true);\r
+        }\r
+    }\r
+    \r
        @Override\r
        public String hint() {\r
                return _hint;\r
@@ -461,11 +763,21 @@ class TimeDrawAbsNanoSec extends TimeDraw {
 \r
        @Override\r
        public void draw(GC gc, long time, Rectangle rect) {\r
-               String stime = stimeformat.format(new Date((long) (time * 1E-6)));\r
+               String stime = stimeformat.format(new Date((long) (time / 1000000)));\r
                String ns = Utils.formatNs(time, Resolution.NANOSEC);\r
                Utils.drawText(gc, stime + " " + ns, rect, true);\r
        }\r
 \r
+    @Override\r
+    public void drawAbsHeader(GC gc, long time, Rectangle rect) {\r
+        String header = stimeformatheader.format(new Date((long) (time / 1000000)));\r
+        int headerwidth = gc.stringExtent(header).x + 4;\r
+        if (headerwidth <= rect.width) {\r
+            rect.x += (rect.width - headerwidth);\r
+            Utils.drawText(gc, header, rect, true);\r
+        }\r
+    }\r
+    \r
        @Override\r
        public String hint() {\r
                return _hint;\r
index 47ebf35ac762b2603677b61587ce13ca6c3abaf6..3dcfe82ad713eb373dfb70d1a7169c06aafd89c8 100644 (file)
@@ -54,6 +54,8 @@ import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.Point;\r
 import org.eclipse.swt.graphics.Rectangle;\r
 import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Event;\r
+import org.eclipse.swt.widgets.Listener;\r
 import org.eclipse.swt.widgets.ScrollBar;\r
 \r
 /**\r
@@ -68,7 +70,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
        public static final boolean DEFAULT_DRAW_THREAD_JOIN = true;\r
        public static final boolean DEFAULT_DRAW_THREAD_WAIT = true;\r
        public static final boolean DEFAULT_DRAW_THREAD_RELEASE = true;\r
-       public static final Integer H_SCROLLBAR_MAX = Integer.MAX_VALUE;\r
+       public static int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1;\r
 \r
        private final double zoomCoeff = 1.5;\r
 \r
@@ -77,7 +79,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
        private boolean _isDragCursor3 = false;\r
        private boolean _isWaitCursor = true;\r
        private boolean _mouseHover = false;\r
-       private int _itemHeightDefault = 18;\r
+       private int _itemHeightDefault = 19;\r
        private int _itemHeight = _itemHeightDefault;\r
        private int _topItem = 0;\r
        private int _dragState = 0;\r
@@ -85,8 +87,6 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
        private int _dragX0 = 0;\r
        private int _dragX = 0;\r
        private int _idealNameWidth = 0;\r
-       // TODO: 050409\r
-       // private double _timeStep = 0.001;\r
        // private double _timeStep = 10000000;\r
        private long _time0bak;\r
        private long _time1bak;\r
@@ -108,6 +108,8 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
        private int _borderWidth = 0;\r
        private int _headerHeight = 0;\r
 \r
+       private Listener mouseScrollFilterListener;\r
+\r
        public TmfTimeStatesCtrl(Composite parent, TraceColorScheme colors,\r
                        TmfTimeAnalysisProvider rutilImp) {\r
 \r
@@ -135,6 +137,13 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                if (scrollHor != null) {\r
                        scrollHor.addSelectionListener(this);\r
                }\r
+               mouseScrollFilterListener = new Listener() {\r
+                       // This filter is used to prevent scrolling of the view when the\r
+                       // mouse wheel is used to zoom\r
+                       public void handleEvent(Event event) {\r
+                               event.doit = false;\r
+                       }\r
+               };\r
 \r
                _dragCursor3 = new Cursor(super.getDisplay(), SWT.CURSOR_SIZEWE);\r
                _WaitCursor = new Cursor(super.getDisplay(), SWT.CURSOR_WAIT);\r
@@ -239,14 +248,11 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                long delta = timeMax - timeMin;\r
 \r
                int timePos = 0;\r
-               int thumb = 0;\r
+               int thumb = H_SCROLLBAR_MAX;\r
 \r
                if (delta != 0) {\r
                        // Thumb size (page size)\r
-                       thumb = Math\r
-                                       .max(\r
-                                                       1,\r
-                                                       (int) (H_SCROLLBAR_MAX * ((double) (time1 - time0) / delta)));\r
+                       thumb = Math.max(1, (int) (H_SCROLLBAR_MAX * ((double) (time1 - time0) / delta)));\r
                        // At the beginning of visible window\r
                        timePos = (int) (H_SCROLLBAR_MAX * ((double) (time0 - timeMin) / delta));\r
                }\r
@@ -378,12 +384,12 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                if (null == _timeProvider)\r
                        return;\r
                ITmfTimeAnalysisEntry trace = getSelectedTrace();\r
-               if (trace == _timeProvider)\r
+               if (trace == _timeProvider || trace == null)\r
                        return;\r
                long selectedTime = _timeProvider.getSelectedTime();\r
                long endTime = _timeProvider.getEndTime();\r
                ITimeEvent nextEvent;\r
-               if (-1 == n && selectedTime >= endTime)\r
+               if (-1 == n && selectedTime > endTime)\r
                        nextEvent = Utils.findEvent(trace, selectedTime, 0);\r
                else\r
                        nextEvent = Utils.findEvent(trace, selectedTime, n);\r
@@ -414,6 +420,38 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                selectTrace(-1);\r
        }\r
 \r
+       /**\r
+        * Zooming based on mouse cursor location with mouse scrolling\r
+        * \r
+        * @param zoomIn\r
+        */\r
+       public void zoom(boolean zoomIn) {\r
+               int globalX = getDisplay().getCursorLocation().x;\r
+               Point p = toControl(globalX, 0);\r
+               int nameSpace = _timeProvider.getNameSpace();\r
+               int timeSpace = _timeProvider.getTimeSpace();\r
+               int xPos = Math.max(nameSpace, Math.min(nameSpace + timeSpace, p.x));\r
+               long time0 = _timeProvider.getTime0();\r
+               long time1 = _timeProvider.getTime1();\r
+               long interval = time1 - time0;\r
+               if (interval == 0) {\r
+                       interval = 1;\r
+               } // to allow getting out of single point interval\r
+               long newInterval;\r
+               if (zoomIn) {\r
+                       newInterval = Math.max(Math.round((double) interval * 0.8), _timeProvider.getMinTimeInterval());\r
+               } else {\r
+                       newInterval = Math.round((double) interval * 1.25);\r
+               }\r
+               long center = time0 + Math.round(((double) (xPos - nameSpace) / timeSpace * interval));\r
+               long newTime0 = center - Math.round((double) newInterval * (center - time0) / interval);\r
+               long newTime1 = newTime0 + newInterval;\r
+               _timeProvider.setStartFinishTime(newTime0, newTime1);\r
+       }\r
+\r
+       /**\r
+        * zoom in using single click\r
+        */\r
        public void zoomIn() {\r
                long _time0 = _timeProvider.getTime0();\r
                long _time1 = _timeProvider.getTime1();\r
@@ -447,6 +485,9 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                _timeProvider.setStartFinishTimeNotify(time0, time1);\r
        }\r
 \r
+       /**\r
+        * zoom out using single click\r
+        */\r
        public void zoomOut() {\r
                long _time0 = _timeProvider.getTime0();\r
                long _time1 = _timeProvider.getTime1();\r
@@ -586,7 +627,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                int nameWidth = _timeProvider.getNameSpace();\r
                x -= nameWidth;\r
                if (x >= 0 && size.x >= nameWidth) {\r
-                       hitTime = time0 + ((time1 - time0) * x) / (size.x - nameWidth);\r
+                       hitTime = time0 + (long) ((time1 - time0) * ((double) (x + 1) / (size.x - nameWidth - 1))) - 1;\r
                }\r
                return hitTime;\r
        }\r
@@ -733,9 +774,10 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                        return;\r
 \r
                int xr = bound.x + nameWidth;\r
-               double K = (double) (bound.width - xr) / (time1 - time0);\r
+               double pixelsPerNanoSec = (bound.width - xr <= 2) ? 0\r
+                               : (double) (bound.width - xr - 2) / (time1 - time0); // 2 pixels less to make sure end time is visible\r
 \r
-               int x0 = xr + (int) ((e.getTime() - time0) * K);\r
+               int x0 = xr + (int) ((e.getTime() - time0) * pixelsPerNanoSec);\r
                if (x0 < xr)\r
                        return;\r
 \r
@@ -855,16 +897,14 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
 \r
        @Override\r
        void paint(Rectangle bound, PaintEvent e) {\r
-               // If no user preference defined for item height\r
-               if (_itemHeight == _itemHeightDefault) {\r
-                       _itemHeight = getFontHeight() + 6;\r
-               }\r
+               GC gc = e.gc;\r
+               gc.setBackground(_colors.getColor(TraceColorScheme.BACKGROUND));\r
+               drawBackground(gc, bound.x, bound.y, bound.width, bound.height);\r
 \r
                if (bound.width < 2 || bound.height < 2 || null == _timeProvider)\r
                        return;\r
 \r
                _idealNameWidth = 0;\r
-               GC gc = e.gc;\r
                int nameWidth = _timeProvider.getNameSpace();\r
                long time0 = _timeProvider.getTime0();\r
                long time1 = _timeProvider.getTime1();\r
@@ -894,15 +934,6 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                if (drawTracesInteraction)\r
                        drawTraceInteractions(bound, e.gc);\r
 \r
-               // fill free canvas area\r
-               _rect0.x = bound.x;\r
-               _rect0.y += _rect0.height;\r
-               _rect0.width = bound.width;\r
-               _rect0.height = bound.y + bound.height - _rect0.y;\r
-               if (_rect0.y < bound.y + bound.height) {\r
-                       gc.setBackground(_colors.getColor(TraceColorScheme.BACKGROUND));\r
-                       gc.fillRectangle(_rect0);\r
-               }\r
                // draw drag line, no line if name space is 0.\r
                if (3 == _dragState) {\r
                        gc.setForeground(_colors.getColor(TraceColorScheme.BLACK));\r
@@ -1024,7 +1055,8 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
 \r
                Utils.init(_rect1, rect);\r
                boolean selected = item._selected;\r
-               double K = (double) rect.width / (time1 - time0);\r
+               double pixelsPerNanoSec = (rect.width <= 2) ? 0\r
+                               : (double) (rect.width - 2) / (time1 - time0); // 2 pixels less to make sure end time is visible\r
                boolean group = item instanceof GroupItem;\r
 \r
                if (group) {\r
@@ -1043,8 +1075,8 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                ITimeEvent nextEvent = null;\r
                                long currEventTime = currEvent.getTime();\r
                                long nextEventTime = currEventTime;\r
-                               x0 = rect.x + (int) ((currEventTime - time0) * K);\r
-                               int xEnd = rect.x + (int) ((time1 - time0) * K);\r
+                               x0 = rect.x + (int) ((currEventTime - time0) * pixelsPerNanoSec);\r
+                               int xEnd = rect.x + (int) ((time1 - time0) * pixelsPerNanoSec);\r
                                int x1 = -1;\r
                                int idx = 1;\r
 \r
@@ -1068,7 +1100,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                                nextEvent = null;\r
                                                nextEventTime = endTime;\r
                                        }\r
-                                       x1 = rect.x + (int) ((nextEventTime - time0) * K);\r
+                                       x1 = rect.x + (int) ((nextEventTime - time0) * pixelsPerNanoSec);\r
                                        if (x1 >= rect.x) {\r
                                                _rect1.x = x0 >= rect.x ? x0 : rect.x;\r
                                                _rect1.width = (x1 <= xEnd ? x1 : xEnd) - _rect1.x;\r
@@ -1124,7 +1156,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                }\r
 \r
                // draw selected time\r
-               int x = rect.x + (int) ((selectedTime - time0) * K);\r
+               int x = rect.x + (int) ((selectedTime - time0) * pixelsPerNanoSec);\r
                if (x >= rect.x && x < rect.x + rect.width) {\r
                        gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME));\r
                        if (group)\r
@@ -1163,7 +1195,8 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                Utils.init(_rect1, rect);\r
                boolean selected = item._selected;\r
                // K pixels per second\r
-               double K = (double) rect.width / (time1 - time0);\r
+               double pixelsPerNanoSec = (rect.width <= 2) ? 0\r
+                               : (double) (rect.width - 2) / (time1 - time0); // 2 pixels less to make sure end time is visible\r
                // Trace.debug("Value of K: " + K + " width:" + rect.width + " time0: "\r
                // + time0 + " time1:" + time1 + " endTime: " + endTime);\r
 \r
@@ -1190,10 +1223,10 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                long currEventTime = currEvent.getTime();\r
                                long nextEventTime = currEventTime;\r
                                // x0 - Points to the beginning of the event being drawn\r
-                               double step = (double) ((currEventTime - time0) * K);\r
+                               double step = (double) ((currEventTime - time0) * pixelsPerNanoSec);\r
                                x0 = rect.x + step;\r
                                // xEnd - Points to the end of the events rectangle\r
-                               double xEnd = rect.x + (double) ((time1 - time0) * K);\r
+                               double xEnd = rect.x + (double) ((time1 - time0) * pixelsPerNanoSec);\r
                                double x1 = -1;\r
                                int idx = 1;\r
                                double xNext = 0;\r
@@ -1241,7 +1274,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                                // with space until next event\r
                                                _rect1.x += _rect1.width;\r
                                                x0 = x1;\r
-                                               xNext = rect.x + (double) ((nextEventTime - time0) * K);\r
+                                               xNext = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec);\r
                                        }\r
                                        // Fill space till next event\r
                                        fillSpace(rect, gc, selected, x0, xNext, xEnd);\r
@@ -1250,7 +1283,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                        currEvent = nextEvent;\r
                                        currEventTime = nextEventTime;\r
                                        // Move x0 to the beginning of next event\r
-                                       x0 = rect.x + (double) ((nextEventTime - time0) * K);\r
+                                       x0 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec);\r
                                        // Trace.debug("rect.x: " + rect.x + " + " +\r
                                        // "(nextEvenTime: "\r
                                        // + nextEventTime + "- time0: " + time0 + ") * K: "\r
@@ -1296,7 +1329,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                }\r
 \r
                // draw selected time\r
-               int x = rect.x + (int) ((selectedTime - time0) * K);\r
+               int x = rect.x + (int) ((selectedTime - time0) * pixelsPerNanoSec);\r
                if (x >= rect.x && x < rect.x + rect.width) {\r
                        gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME));\r
                        if (group)\r
@@ -1337,7 +1370,8 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                Utils.init(_rect1, rect);\r
                boolean selected = item._selected;\r
                // K pixels per second\r
-               double K = (double) rect.width / (time1 - time0);\r
+               double pixelsPerNanoSec = (rect.width <= 2) ? 0\r
+                               : (double) (rect.width - 2) / (time1 - time0); // 2 pixels lesser to make sure end time is visible\r
                // Trace.debug("Value of K: " + K + " width:" + rect.width + " time0: "\r
                // + time0 + " time1:" + time1 + " endTime: " + endTime);\r
 \r
@@ -1346,9 +1380,6 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                if (group) {\r
                        // gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus));\r
                        // gc.fillRectangle(rect);\r
-                       // if (Trace.isDEBUG()) {\r
-                       // Trace.debug("\n\t\t\tGroup: " + ((GroupItem) item)._name);\r
-                       // }\r
                } else if (item instanceof TraceItem) {\r
                        ITmfTimeAnalysisEntry trace = ((TraceItem) item)._trace;\r
 \r
@@ -1356,12 +1387,19 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                        List<TimeEvent> list = trace.getTraceEvents();\r
                        // Iterator it = list.iterator();\r
                        int count = list.size();\r
-                       ITimeEvent lastEvent = null;\r
+                       // ITimeEvent lastEvent = null;\r
                        // if (Trace.isDEBUG()) {\r
                        // Trace.debug("\n\t\t\tTrace: " + trace.getName()\r
                        // + utilImpl.getTraceClassName(trace));\r
                        // }\r
                        // Trace.debug("count is: " + count);\r
+                       // Drawing rectangle is smaller than reserved space\r
+                       _rect1.y += 3;\r
+                       _rect1.height -= 6;\r
+\r
+                       // Clean up to empty line to draw on top\r
+                       int xEnd = rect.x + rect.width;\r
+                       fillSpace(rect, gc, selected, _rect1.x, xEnd, xEnd);\r
                        if (count > 0) {\r
                                ITimeEvent currEvent = list.get(0);\r
                                ITimeEvent nextEvent = null;\r
@@ -1370,22 +1408,15 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                // initial value\r
                                long nextEventTime = currEventTime;\r
                                // x0 - Points to the beginning of the event being drawn\r
-                               double step = (double) ((currEventTime - time0) * K);\r
+                               double step = (double) ((currEventTime - time0) * pixelsPerNanoSec);\r
                                x0 = rect.x + step;\r
                                // xEnd - Points to the end of the events rectangle\r
-                               double xEnd = rect.x + (double) ((time1 - time0) * K);\r
                                double x1 = -1;\r
                                int idx = 1;\r
                                double xNext = 0;\r
 \r
-                               // Drawing rectangle is smaller than reserved space\r
-                               _rect1.y += 3;\r
-                               _rect1.height -= 6;\r
-\r
-                               // Clean up to empty line to draw on top\r
-                               fillSpace(rect, gc, selected, _rect1.x, xEnd, xEnd);\r
                                // draw event states\r
-                               while (x0 <= xEnd && null != currEvent) {\r
+                               while (/* x0 <= xEnd &&*/ null != currEvent) {\r
                                        boolean stopped = false;// currEvent instanceof\r
                                        // refresh current event duration as the loop moves\r
                                        currEventDuration = currEvent.getDuration();\r
@@ -1406,14 +1437,15 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                        }\r
 \r
                                        // Calculate position to next event\r
-                                       xNext = rect.x + (double) ((nextEventTime - time0) * K);\r
+                                       xNext = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec);\r
 \r
                                        // Calculate end position of current event\r
                                        if (currEventDuration < 0) {\r
-                                               x1 = rect.x + (double) ((nextEventTime - time0) * K);\r
+                                               x1 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec);\r
+                                       } else if (currEventDuration == 0) {\r
+                                               x1 = x0;\r
                                        } else {\r
-                                               x1 = currEventDuration == 0 ? (x0 + 2)\r
-                                                               : (x0 + (double) ((currEventDuration) * K));\r
+                                               x1 = x0 + (double) ((currEventDuration) * pixelsPerNanoSec);\r
                                        }\r
 \r
                                        // If event end position x1 further away than start position\r
@@ -1422,12 +1454,17 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                        // Trace.debug("Next Event Pos: " + xNext\r
                                        // + " End Of Current at: " + x1 + " Event Duration: "\r
                                        // + currEventDuration);\r
-                                       x1 = x1 > xNext ? xNext : x1;\r
+                                       if (currEventDuration != 0) {\r
+                                               x1 = x1 > xNext ? xNext : x1;\r
+                                       }\r
                                        // if event end boundary is within time range\r
                                        if (x1 >= rect.x && x0 <= xEnd) {\r
-                                               // Fill with space until x0\r
-                                               x0 = (double) (x0 >= rect.x ? x0 : rect.x);\r
-                                               _rect1.width = (int) ((x1 <= xEnd ? x1 : xEnd) - x0);\r
+                                               if (currEventDuration != 0) {\r
+                                                       x0 = (double) (x0 >= rect.x ? x0 : rect.x);\r
+                                               } else {\r
+                                                       x1 = x0 + 2; // make punctual events 2 pixels wide\r
+                                               }\r
+                                               _rect1.width = (int) Math.round((x1 <= xEnd ? x1 : xEnd) - x0);\r
                                                _rect1.x = (int) x0;\r
                                                boolean timeSelected = currEventTime <= selectedTime\r
                                                                && selectedTime < nextEventTime;\r
@@ -1444,13 +1481,13 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                        }\r
 \r
                                        // Fill space till next event\r
-                                       fillSpace(rect, gc, selected, x0, xNext, xEnd);\r
+                                       // fillSpace(rect, gc, selected, x0, xNext, xEnd);\r
 \r
-                                       lastEvent = currEvent;\r
+                                       // lastEvent = currEvent;\r
                                        currEvent = nextEvent;\r
                                        currEventTime = nextEventTime;\r
                                        // Move x0 to the beginning of next event\r
-                                       x0 = rect.x + (double) ((nextEventTime - time0) * K);\r
+                                       x0 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec);\r
                                        // Trace.debug("rect.x: " + rect.x + " + " +\r
                                        // "(nextEvenTime: "\r
                                        // + nextEventTime + "- time0: " + time0 + ") * K: "\r
@@ -1458,26 +1495,6 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                }\r
                        }\r
 \r
-                       // fill space after last event\r
-                       int xEnd = rect.x + rect.width;\r
-                       if (x0 < xEnd) {\r
-                               // Trace.debug("Space after last event, x0: " + x0 + ", xEnd: "\r
-                               // + xEnd);\r
-                               _rect1.x = (int) (x0 >= rect.x ? x0 : rect.x);\r
-                               _rect1.width = xEnd - _rect1.x;\r
-                               gc.setBackground(_colors\r
-                                               .getBkColor(selected, _isInFocus, false));\r
-                               gc.fillRectangle(_rect1);\r
-                               // draw middle line\r
-                               gc.setForeground(_colors.getColor(utilImpl\r
-                                               .getEventColorVal(lastEvent)));\r
-                               int midy = _rect1.y + _rect1.height / 2;\r
-                               int lw = gc.getLineWidth();\r
-                               gc.setLineWidth(2);\r
-                               gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy);\r
-                               gc.setLineWidth(lw);\r
-                       }\r
-\r
                        // draw focus area\r
                        Utils.init(_rect1, rect);\r
                        gc.setForeground(_colors.getBkColor(selected, _isInFocus, false));\r
@@ -1496,7 +1513,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                }\r
 \r
                // draw selected time\r
-               int x = rect.x + (int) ((selectedTime - time0) * K);\r
+               int x = rect.x + (int) ((double) (selectedTime - time0) * pixelsPerNanoSec);\r
                if (x >= rect.x && x < rect.x + rect.width) {\r
                        gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME));\r
                        if (group)\r
@@ -1597,6 +1614,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
        public void focusGained(FocusEvent e) {\r
                _isInFocus = true;\r
                redraw();\r
+               getDisplay().addFilter(SWT.MouseWheel, mouseScrollFilterListener);\r
        }\r
 \r
        public void focusLost(FocusEvent e) {\r
@@ -1606,6 +1624,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                        _dragState = 0;\r
                }\r
                redraw();\r
+               getDisplay().removeFilter(SWT.MouseWheel, mouseScrollFilterListener);\r
        }\r
 \r
        public boolean isInFocus() {\r
@@ -1621,9 +1640,9 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                        int x = e.x - nameWidth;\r
                        if (x > 0 && size.x > nameWidth && _dragX != x) {\r
                                _dragX = x;\r
-                               double K = (double) (size.x - nameWidth)\r
-                                               / (_time1bak - _time0bak);\r
-                               long timeDelta = (long) ((_dragX - _dragX0) / K);\r
+                               double pixelsPerNanoSec = (size.x - nameWidth <= 2) ? 0\r
+                                               : (double) (size.x - nameWidth - 2) / (_time1bak - _time0bak); // 2 pixels less to make sure end time is visible\r
+                               long timeDelta = (long) ((pixelsPerNanoSec == 0) ? 0 : ((_dragX - _dragX0) / pixelsPerNanoSec));\r
                                long time1 = _time1bak - timeDelta;\r
                                long maxTime = _timeProvider.getMaxTime();\r
                                if (time1 > maxTime)\r
@@ -1643,6 +1662,10 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                        if (_mouseHover != mouseHover)\r
                                redraw();\r
                        _mouseHover = mouseHover;\r
+                       // Make sure any time changes are notified to the application e.g.\r
+                       // getting back from the horizontal scroll bar or zoomed using the\r
+                       // mouse wheel\r
+                       _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1());\r
                }\r
                updateCursor(e.x, e.y);\r
        }\r
@@ -1751,6 +1774,8 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                }\r
                                selectItem(idx, false);\r
                                fireSelectionChanged();\r
+                       } else {\r
+                               selectItem(idx, false); // clear selection\r
                        }\r
                }\r
        }\r
@@ -1768,7 +1793,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                }\r
 \r
                // Notify time provider to check the need for listener notification\r
-               _timeProvider.mouseUp();\r
+               _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1());\r
        }\r
 \r
        public void controlMoved(ControlEvent e) {\r
@@ -1788,7 +1813,7 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
                                _topItem = 0;\r
                        redraw();\r
                } else if (e.widget == getHorizontalBar() && null != _timeProvider) {\r
-                       int startTime = getHorizontalBar().getSelection();\r
+                       int start = getHorizontalBar().getSelection();\r
                        long time0 = _timeProvider.getTime0();\r
                        long time1 = _timeProvider.getTime1();\r
                        long timeMin = _timeProvider.getMinTime();\r
@@ -1797,25 +1822,23 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
 \r
                        long range = time1 - time0;\r
                        // _timeRangeFixed = true;\r
-                       time0 = timeMin\r
-                                       + (long) ((double) ((startTime * delta) / H_SCROLLBAR_MAX));\r
+                       time0 = timeMin + (long) (delta * ((double) start / H_SCROLLBAR_MAX));\r
                        time1 = time0 + range;\r
-                       // Trace.debug("\nstartTime:" + startTime + " time0:" + time0\r
-                       // + " time1:" + time1 + " Delta:" + delta);\r
-                       _timeProvider.setStartFinishTimeNotify(time0, time1);\r
+\r
+                       // TODO: Follow-up with Bug 310310\r
+                       // In Linux SWT.DRAG is the only value received\r
+                       // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310310\r
+                       if (e.detail == SWT.DRAG) {\r
+                               _timeProvider.setStartFinishTime(time0, time1);\r
+                       } else {\r
+                               _timeProvider.setStartFinishTimeNotify(time0, time1);\r
+                       }\r
                }\r
        }\r
 \r
        public void mouseEnter(MouseEvent e) {\r
        }\r
 \r
-       /*\r
-        * (non-Javadoc)\r
-        * \r
-        * @see\r
-        * org.eclipse.swt.events.MouseTrackListener#mouseExit(org.eclipse.swt.events\r
-        * .MouseEvent)\r
-        */\r
        public void mouseExit(MouseEvent e) {\r
                if (_mouseHover) {\r
                        _mouseHover = false;\r
@@ -1827,10 +1850,12 @@ public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,
        }\r
 \r
        public void mouseScrolled(MouseEvent e) {\r
+               if (!_isInFocus)\r
+                       return;\r
                if (e.count > 0) {\r
-                       zoomIn();\r
+                       zoom(true);\r
                } else if (e.count < 0) {\r
-                       zoomOut();\r
+                       zoom(false);\r
                }\r
        }\r
 \r
index bdd38c14162476ca6a29e2dbdcc76db9b4840c5a..eda2d7992b53c6cd0e4fedcbedc1f2cc310aac31 100644 (file)
@@ -17,8 +17,8 @@ package org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets;
 import java.util.Iterator;\r
 import java.util.Map;\r
 \r
-import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.Messages;\r
+import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer.TimeFormat;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;\r
@@ -131,19 +131,20 @@ public class TmfTimeTipHandler {
                                                addItem(message, eventAddOns.get(message));\r
                                        }\r
 \r
-                                       // start time\r
-                                       long startTime = threadEvent == null ? thrd.getStartTime()\r
-                                                       : threadEvent.getTime();\r
-\r
-                                       long duration = threadEvent == null ? -1 : threadEvent\r
-                                                       .getDuration();\r
-\r
-                                       if (duration < 0 && threadEvent != null\r
-                                                       && nextEvent != null) {\r
-                                               long stopTime = nextEvent.getTime();\r
-                                               duration = stopTime - startTime;\r
+                                       long eventStartTime = -1;\r
+                                       long eventDuration = -1;\r
+                                       long eventEndTime = -1;\r
+                                       \r
+                                       if (threadEvent != null) {\r
+                                           eventStartTime = threadEvent.getTime();\r
+                                           eventDuration = threadEvent.getDuration();\r
+                                           if (eventDuration < 0 && nextEvent != null) {\r
+                                               eventEndTime = nextEvent.getTime();\r
+                                               eventDuration = eventEndTime - eventStartTime;\r
+                                           } else {\r
+                                               eventEndTime = eventStartTime + eventDuration;\r
+                                           }\r
                                        }\r
-                                       long eventEndtime = startTime + duration;\r
 \r
 // TODO: Check if we need "format"                                     \r
 //                                     TimeFormat format = TimeFormat.RELATIVE;\r
@@ -152,19 +153,44 @@ public class TmfTimeTipHandler {
 //                                             format = TimeFormat.ABSOLUTE; // Absolute format\r
 //                                                                                                             // (calendar)\r
                                                // Add Date\r
-                                               addItem(Messages._TRACE_DATE, Utils\r
-                                                               .formatDate(startTime));\r
+                                               addItem(Messages._TRACE_DATE, eventStartTime > -1 ?\r
+                                                       Utils.formatDate(eventStartTime)\r
+                                                       : "?");\r
+                                               if (eventDuration > 0) {\r
+                            addItem(Messages._TRACE_START_TIME, eventStartTime > -1 ?\r
+                                    Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res)\r
+                                    : "?");\r
+                            \r
+                            addItem(Messages._TRACE_STOP_TIME, eventEndTime > -1 ?\r
+                                    Utils.formatTime(eventEndTime, TimeFormat.ABSOLUTE, res)\r
+                                    : "?");\r
+                                               } else {\r
+                            addItem(Messages._TRACE_EVENT_TIME, eventStartTime > -1 ?\r
+                                    Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res)\r
+                                    : "?");\r
+                                               }\r
+                                       } else {\r
+                                               if (eventDuration > 0) {\r
+                                               addItem(Messages._TRACE_START_TIME, eventStartTime > -1 ?\r
+                                                       Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res)\r
+                                                       : "?");\r
+                                           \r
+                                               addItem(Messages._TRACE_STOP_TIME, eventEndTime > -1 ?\r
+                                                       Utils.formatTime(eventEndTime, TimeFormat.RELATIVE, res)\r
+                                                       : "?");\r
+                                               } else {\r
+                            addItem(Messages._TRACE_EVENT_TIME, eventStartTime > -1 ?\r
+                                    Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res)\r
+                                    : "?");\r
+                                               }\r
                                        }\r
-                                       addItem(Messages._TRACE_START_TIME, Utils.formatTime(\r
-                                                       startTime, TimeFormat.RELATIVE, res));\r
-\r
-                                       addItem(Messages._TRACE_STOP_TIME, Utils.formatTime(\r
-                                                       eventEndtime, TimeFormat.RELATIVE, res));\r
 \r
-                                       // Duration in relative format in any case\r
-                                       addItem(Messages._DURATION, duration > -1 ? Utils\r
-                                                       .formatTime(duration, TimeFormat.RELATIVE, res)\r
-                                                       : "?");\r
+                                       if (eventDuration > 0) {\r
+                                           // Duration in relative format in any case\r
+                                           addItem(Messages._DURATION, eventDuration > -1 ?\r
+                                                   Utils.formatTime(eventDuration, TimeFormat.RELATIVE, res)\r
+                                                   : "?");\r
+                                       }\r
 \r
                                } else if (item instanceof GroupItem) {\r
                                        addItem(Messages._TRACE_GROUP_NAME, item.toString());\r
index 962767fd76c2adaf76895d8ae1709c3c50254d0c..32c533ceb7c715e483b006f9ed79c7999e631e3a 100644 (file)
@@ -130,7 +130,9 @@ public class TraceColorScheme {
        static public final int GR_FOREGROUND_SEL_NOFOCUS = 76;\r
 \r
        static public final int LIGHT_LINE = 77;\r
-       static public final int BACKGROUND_NAME = 78;\r
+    static public final int BACKGROUND_NAME = 78;\r
+    static public final int BACKGROUND_NAME_SEL = 79;\r
+    static public final int BACKGROUND_NAME_SEL_NOFOCUS = 80;\r
 \r
        // Interraction's colors\r
        static public final int TI_START_THREAD = BLACK;\r
@@ -205,8 +207,7 @@ public class TraceColorScheme {
                        //\r
                        new RGB(100, 100, 100), // UNKNOWN\r
                        new RGB(174, 200, 124), // RUNNING\r
-                       new Mix(new SysCol(SWT.COLOR_BLUE), new SysCol(SWT.COLOR_GRAY), 1,\r
-                                       3), // SLEEPING\r
+                       new Mix(new SysCol(SWT.COLOR_BLUE), new SysCol(SWT.COLOR_GRAY), 1, 3), // SLEEPING\r
                        new RGB(210, 150, 60), // WAITING\r
                        new RGB(242, 225, 168), // BLOCKED\r
                        new Mix(new SysCol(SWT.COLOR_RED), new SysCol(SWT.COLOR_GRAY), 1, 3), // DEADLOCK\r
@@ -243,8 +244,8 @@ public class TraceColorScheme {
 \r
                        new SysCol(SWT.COLOR_LIST_BACKGROUND), // BACKGROUND\r
                        new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND\r
-                       new SysCol(SWT.COLOR_LIST_SELECTION), // BACKGROUND_SEL\r
-                       new SysCol(SWT.COLOR_LIST_SELECTION_TEXT), // FOREGROUND_SEL\r
+                       new RGB(232, 242, 254), // BACKGROUND_SEL\r
+                       new SysCol(SWT.COLOR_LIST_FOREGROUND), // FOREGROUND_SEL\r
                        new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // BACKGROUND_SEL_NOFOCUS\r
                        new SysCol(SWT.COLOR_WIDGET_FOREGROUND), // FOREGROUND_SEL_NOFOCUS\r
                        new SysCol(SWT.COLOR_WIDGET_BACKGROUND), // TOOL_BACKGROUND\r
@@ -299,8 +300,10 @@ public class TraceColorScheme {
 \r
                        new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(\r
                                        SWT.COLOR_LIST_BACKGROUND), 1, 3), // LIGHT_LINE\r
-                       new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(\r
-                                       SWT.COLOR_LIST_BACKGROUND), 1, 6), // BACKGROUND_NAME\r
+\r
+                       new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_LIST_BACKGROUND), 1, 6),   // BACKGROUND_NAME\r
+                   new Mix(new SysCol(SWT.COLOR_GRAY), new RGB(232, 242, 254), 1, 6),                  // BACKGROUND_NAME_SEL\r
+                   new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_WIDGET_BACKGROUND), 1, 6), // BACKGROUND_NAME_SEL_NOFOCUS\r
        };\r
 \r
        private Color _colors[];\r
@@ -330,13 +333,19 @@ public class TraceColorScheme {
        }\r
 \r
        public Color getBkColor(boolean selected, boolean focused, boolean name) {\r
-               if (selected && focused)\r
-                       return getColor(BACKGROUND_SEL);\r
-               if (selected)\r
-                       return getColor(BACKGROUND_SEL_NOFOCUS);\r
-               if (name)\r
-                       return getColor(BACKGROUND_NAME);\r
-               return getColor(BACKGROUND);\r
+           if (name) {\r
+               if (selected && focused)\r
+                   return getColor(BACKGROUND_NAME_SEL);\r
+               if (selected)\r
+                   return getColor(BACKGROUND_NAME_SEL_NOFOCUS);\r
+               return getColor(BACKGROUND_NAME);\r
+           } else {\r
+               if (selected && focused)\r
+                   return getColor(BACKGROUND_SEL);\r
+               if (selected)\r
+                   return getColor(BACKGROUND_SEL_NOFOCUS);\r
+               return getColor(BACKGROUND);\r
+           }\r
        }\r
 \r
        public Color getFgColor(boolean selected, boolean focused) {\r
index 730a3dc0f2ed5f2283313aebd39c973a468a10f2..80680e32fdc84d3fabca2a20c6e409ba83a794a4 100644 (file)
@@ -19,12 +19,13 @@ import java.text.SimpleDateFormat;
 import java.util.Date;\r
 import java.util.Iterator;\r
 import java.util.List;\r
+import java.util.TimeZone;\r
 import java.util.Vector;\r
 \r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer.TimeFormat;\r
-import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.TimeEvent;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;\r
+import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.TimeEvent;\r
 import org.eclipse.swt.graphics.Color;\r
 import org.eclipse.swt.graphics.Device;\r
 import org.eclipse.swt.graphics.GC;\r
@@ -47,8 +48,12 @@ public class Utils {
                SECONDS, MILLISEC, MICROSEC, NANOSEC\r
        };\r
 \r
-       static private SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss");\r
-       static private SimpleDateFormat sdateformat = new SimpleDateFormat("yyyy.MM.dd");\r
+       static private final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss");\r
+       static private final SimpleDateFormat sdateformat = new SimpleDateFormat("yyyy-MM-dd");\r
+       static {\r
+        stimeformat.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+        sdateformat.setTimeZone(TimeZone.getTimeZone("GMT"));\r
+       }\r
 \r
 //     static private String _externalPlugin[] = { "org.eclipse.debug.ui",\r
 //                     "org.eclipse.debug.ui", "org.eclipse.debug.ui",\r
@@ -335,64 +340,49 @@ public class Utils {
         * @param n\r
         * @return\r
         */\r
-       static ITimeEvent findEvent(ITmfTimeAnalysisEntry thread, long time, int n) {\r
-               if (null == thread)\r
-                       return null;\r
-               List<TimeEvent> list = thread.getTraceEvents();\r
-               Iterator<TimeEvent> it = list.iterator();\r
-               ITimeEvent event = null;\r
-               ITimeEvent prevEvent = null;\r
-               ITimeEvent nextEvent = null;\r
-               if (it.hasNext()) {\r
-                       event = (ITimeEvent) it.next();\r
-                       long currStartTime = event.getTime();\r
-                       long currEndTime = currStartTime + event.getDuration();\r
-\r
-                       if (time < currStartTime) {\r
-                               if (1 != n)\r
-                                       event = null;\r
-                               return event;\r
-                       }\r
-                       while (it.hasNext()) {\r
-                               currStartTime = event.getTime();\r
-                               currEndTime = currStartTime + event.getDuration();\r
-                               nextEvent = (ITimeEvent) it.next();\r
-\r
-                               long nextEventTime = nextEvent.getTime();\r
-                               currEndTime = currEndTime >= nextEventTime ? (nextEventTime - 1)\r
-                                               : currEndTime;\r
-\r
-//                             Trace.debug("currStartTime: " + currStartTime\r
-//                                             + " currEndTime: " + currEndTime + " nextEventTime: "\r
-//                                             + nextEventTime + " time: " + time);\r
-                               if (currStartTime <= time && time <= currEndTime) {\r
-                                       if (1 == n)\r
-                                               event = nextEvent;\r
-                                       else if (-1 == n)\r
-                                               event = prevEvent;\r
-                                       return event;\r
-                               }\r
-\r
-                               if (time > currEndTime && time < nextEventTime) {\r
-                                       //Located in a non Event area\r
-                                       if (2 == n || -1 == n) {\r
-                                               return event;\r
-                                       } else if (1 == n) {\r
-                                               return nextEvent;\r
-                                       }\r
-                                       return null;\r
-                               }\r
-\r
-                               prevEvent = event;\r
-                               event = nextEvent;\r
-                       }\r
-               }\r
-               if (1 == n)\r
-                       event = null;\r
-               else if (-1 == n)\r
-                       event = prevEvent;\r
-               return event;\r
-       }\r
+    static ITimeEvent findEvent(ITmfTimeAnalysisEntry thread, long time, int n) {\r
+        if (null == thread)\r
+            return null;\r
+        List<TimeEvent> list = thread.getTraceEvents();\r
+        Iterator<TimeEvent> it = list.iterator();\r
+        ITimeEvent nextEvent = null;\r
+        ITimeEvent currEvent = null;\r
+        ITimeEvent prevEvent = null;\r
+\r
+        while (it.hasNext()) {\r
+            nextEvent = (ITimeEvent) it.next();\r
+            long nextStartTime = nextEvent.getTime();\r
+            \r
+            if (nextStartTime > time) {\r
+                break;\r
+            }\r
+            \r
+            if (currEvent == null || currEvent.getTime() != nextStartTime) {\r
+                prevEvent = currEvent;\r
+                currEvent = nextEvent;\r
+            }\r
+        }\r
+        \r
+        if (n == -1) { //previous\r
+            if (currEvent != null && currEvent.getTime() + currEvent.getDuration() >= time) {\r
+                return prevEvent;\r
+            } else {\r
+                return currEvent;\r
+            }\r
+        } else if (n == 0) { //current\r
+            if (currEvent != null && currEvent.getTime() + currEvent.getDuration() >= time) {\r
+                return currEvent;\r
+            } else {\r
+                return null;\r
+            }\r
+        } else if (n == 1) { //next\r
+            return nextEvent;\r
+        } else if (n == 2) { //current or previous when in empty space\r
+            return currEvent;\r
+        }\r
+        \r
+        return null;\r
+    }\r
 \r
        // static public TRCPackage getPackage(Object element) {\r
        // if (element instanceof TRCPackage)\r
This page took 0.061109 seconds and 5 git commands to generate.