Bug 378401: Implementation of time graph widget.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / widgets / TimeGraphControl.java
index 3b8f81c5d2bc83fb9421dc102f99fa622bf8b431..ec7a8bc3a4a3fcaecb4a1000d0e3599c9f24539a 100644 (file)
@@ -106,6 +106,43 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
     protected LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());\r
     protected Color[] fEventColorMap = null;\r
 \r
+    private MouseScrollNotifier fMouseScrollNotifier;\r
+    private Object fMouseScrollNotifierLock = new Object();\r
+    private class MouseScrollNotifier extends Thread {\r
+        private final static long DELAY = 400L;\r
+        private final static long POLLING_INTERVAL = 10L;\r
+        private long fLastScrollTime = Long.MAX_VALUE;\r
+\r
+        @Override\r
+        public void run() {\r
+            while ((System.currentTimeMillis() - fLastScrollTime) < DELAY) {\r
+                try {\r
+                    Thread.sleep(POLLING_INTERVAL);\r
+                } catch (Exception e) {\r
+                    return;\r
+                }\r
+            }\r
+            if (!isInterrupted()) {\r
+                Display.getDefault().asyncExec(new Runnable() {\r
+                    @Override\r
+                    public void run() {\r
+                        if (isDisposed()) {\r
+                            return;\r
+                        }\r
+                        _timeProvider.notifyStartFinishTime();\r
+                    }\r
+                });\r
+            }\r
+            synchronized (fMouseScrollNotifierLock) {\r
+                fMouseScrollNotifier = null;\r
+            }\r
+        }\r
+\r
+        public void mouseScrolled() {\r
+            fLastScrollTime = System.currentTimeMillis();\r
+        }\r
+    }\r
+\r
     public TimeGraphControl(Composite parent, TimeGraphColorScheme colors) {\r
 \r
         super(parent, colors, SWT.NO_BACKGROUND | SWT.H_SCROLL | SWT.DOUBLE_BUFFERED);\r
@@ -538,6 +575,13 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
         long newTime0 = center - Math.round((double) newInterval * (center - time0) / interval);\r
         long newTime1 = newTime0 + newInterval;\r
         _timeProvider.setStartFinishTime(newTime0, newTime1);\r
+        synchronized (fMouseScrollNotifierLock) {\r
+            if (fMouseScrollNotifier == null) {\r
+                fMouseScrollNotifier = new MouseScrollNotifier();\r
+                fMouseScrollNotifier.start();\r
+            }\r
+            fMouseScrollNotifier.mouseScrolled();\r
+        }\r
     }\r
 \r
     /**\r
@@ -1277,10 +1321,6 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe
                 redraw();\r
             }\r
             _mouseOverSplitLine = mouseOverSplitLine;\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.notifyStartFinishTime();\r
         }\r
         updateCursor(e.x, e.y);\r
     }\r
This page took 0.025294 seconds and 5 git commands to generate.