tmf: add minimum margin for right mouse drag zoom
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Fri, 19 Aug 2016 13:55:12 +0000 (09:55 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Tue, 23 Aug 2016 18:25:29 +0000 (14:25 -0400)
This will prevent zooming when the right drag is less than 5 pixels.
For extensions that define a context sensitive menu for time events,
this will prevent zooming when the user accidentally moves the mouse
when wanting to get the context sensitive menu.

Change-Id: I198aaac1212f2f762e1dbe87d3fa3cb115a5d3a5
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/79370
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java

index 524f2edfe21ba9607915772a08d7c17fcd7693da..008f084455163080dba76d1d093fc231944e9d69 100644 (file)
@@ -111,6 +111,8 @@ public class TimeGraphControl extends TimeGraphBaseControl
     /** Constant indicating that all levels of the time graph should be expanded */
     public static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS;
 
+    private static final int DRAG_MARGIN = 5;
+
     private static final int DRAG_NONE = 0;
     private static final int DRAG_TRACE_ITEM = 1;
     private static final int DRAG_SPLIT_LINE = 2;
@@ -2801,9 +2803,9 @@ public class TimeGraphControl extends TimeGraphBaseControl
     @Override
     public void mouseUp(MouseEvent e) {
         if (fPendingMenuDetectEvent != null && e.button == 3) {
-            if ((fDragState == DRAG_ZOOM) && (fDragX0 == fDragX)) {
+            if ((fDragState == DRAG_ZOOM) && isInDragZoomMargin()) {
                 // Select entry and time event for single click
-                long time = getTimeAtX(e.x);
+                long time = getTimeAtX(fDragX0);
                 fTimeProvider.setSelectionRangeNotify(time, time, false);
                 int idx = getItemIndexAtY(e.y);
                 selectItem(idx, false);
@@ -2835,7 +2837,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
                 fTimeGraphScale.setDragRange(-1, -1);
             } else if (e.button == fDragButton && DRAG_ZOOM == fDragState) {
                 int nameWidth = fTimeProvider.getNameSpace();
-                if (Math.max(fDragX, fDragX0) > nameWidth && fDragX != fDragX0) {
+                if ((Math.max(fDragX, fDragX0) > nameWidth) && !isInDragZoomMargin()) {
                     long time0 = getTimeAtX(fDragX0);
                     long time1 = getTimeAtX(fDragX);
                     if (time0 < time1) {
@@ -3365,7 +3367,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
                 return;
             }
             fPendingMenuDetectEvent = null;
-            if ((p.x >= fTimeProvider.getNameSpace()) && (fDragState != DRAG_ZOOM || fDragX != fDragX0)) {
+            if ((p.x >= fTimeProvider.getNameSpace()) && (fDragState != DRAG_ZOOM || !isInDragZoomMargin())) {
                 return;
             }
         } else {
@@ -3430,4 +3432,8 @@ public class TimeGraphControl extends TimeGraphBaseControl
     public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() {
         return new TmfTimeViewAlignmentInfo(getShell(), toDisplay(0, 0), fTimeProvider.getNameSpace());
     }
+
+    private boolean isInDragZoomMargin() {
+        return (Math.abs(fDragX - fDragX0) < DRAG_MARGIN);
+    }
 }
This page took 0.026556 seconds and 5 git commands to generate.