tmf: Bug 476390: Support SHIFT+left click to update the selection range
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Wed, 2 Sep 2015 01:20:32 +0000 (21:20 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 23 Sep 2015 10:40:04 +0000 (06:40 -0400)
Change-Id: Ie11006e88c325c77b16d5d7bdb3765944b54e0f6
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/55050
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/TmfMouseSelectionProvider.java

index 2919cff8022398f108c8b90df771d50c8290d222..594fa44e1314c90cdf29a3741ec28b5f8d72bfe7 100644 (file)
@@ -37,6 +37,8 @@ public class TmfMouseSelectionProvider extends TmfBaseProvider implements MouseL
     private long fEndTime;
     /** Flag indicating that an update is ongoing */
     private boolean fIsInternalUpdate;
+    /** Flag indicating that the begin marker is dragged */
+    private boolean fDragBeginMarker;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -81,9 +83,25 @@ public class TmfMouseSelectionProvider extends TmfBaseProvider implements MouseL
     @Override
     public void mouseDown(MouseEvent e) {
         if ((getChartViewer().getWindowDuration() != 0) && (e.button == 1)) {
-            IAxis xAxis = getChart().getAxisSet().getXAxis(0);
-            fBeginTime = limitXDataCoordinate(xAxis.getDataCoordinate(e.x));
-            fEndTime = fBeginTime;
+            fDragBeginMarker = false;
+            if (((e.stateMask & SWT.SHIFT) != SWT.SHIFT) || (fEndTime == fBeginTime)) {
+                IAxis xAxis = getChart().getAxisSet().getXAxis(0);
+                fBeginTime = limitXDataCoordinate(xAxis.getDataCoordinate(e.x));
+                fEndTime = fBeginTime;
+            } else {
+                long selectionBegin = fBeginTime;
+                long selectionEnd = fEndTime;
+                IAxis xAxis = getChart().getAxisSet().getXAxis(0);
+                long time = limitXDataCoordinate(xAxis.getDataCoordinate(e.x));
+                if (Math.abs(time - selectionBegin) < Math.abs(time - selectionEnd)) {
+                    fDragBeginMarker = true;
+                    fBeginTime = time;
+                    fEndTime = selectionEnd;
+                } else {
+                    fBeginTime = selectionBegin;
+                    fEndTime = time;
+                }
+            }
             fIsInternalUpdate = true;
         }
     }
@@ -111,7 +129,11 @@ public class TmfMouseSelectionProvider extends TmfBaseProvider implements MouseL
     public void mouseMove(MouseEvent e) {
         if (fIsInternalUpdate) {
             IAxis xAxis = getChart().getAxisSet().getXAxis(0);
-            fEndTime = limitXDataCoordinate(xAxis.getDataCoordinate(e.x));
+            if (fDragBeginMarker) {
+                fBeginTime = limitXDataCoordinate(xAxis.getDataCoordinate(e.x));
+            } else {
+                fEndTime = limitXDataCoordinate(xAxis.getDataCoordinate(e.x));
+            }
             getChart().redraw();
         }
     }
This page took 0.025749 seconds and 5 git commands to generate.