Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tasse2014-11-14 20:03:05 +0000
committerPatrick Tasse2014-12-16 22:21:59 +0000
commit1e68f9c2eccc1a8d12535abb720275f56a1ac086 (patch)
treec65e173349a4c8d73e79b3763afd9a449f154eec
parent7f8b6611ead970c83c8cde5b5d00caa05eea6127 (diff)
downloadorg.eclipse.linuxtools-1e68f9c2eccc1a8d12535abb720275f56a1ac086.tar.gz
org.eclipse.linuxtools-1e68f9c2eccc1a8d12535abb720275f56a1ac086.tar.xz
org.eclipse.linuxtools-1e68f9c2eccc1a8d12535abb720275f56a1ac086.zip
tmf: Bug 422341: Mouse wheel on horizontal scroll bar a bit too small
- Remove the built-in horizontal scroll bar from the time graph control - Add method to programatically scroll left or right in time graph control - Scroll horizontally instead of zooming on mouse scroll over horizontal scroll bar, zoom on Ctrl+mouse scroll (Windows) - Add a horizontal slider to the time graph viewer - Scroll horizontally and ignore the slider's internal selection event on mouse scroll, zoom on Ctrl+mouse scroll (Linux) Change-Id: I5db4cc25306d5bb62efe6790d2dd516ded28a020 Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com> Reviewed-on: https://git.eclipse.org/r/36522 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java77
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java127
2 files changed, 120 insertions, 84 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java
index 9b7bb9a4f2..d4396b342b 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java
@@ -57,6 +57,8 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Slider;
@@ -79,6 +81,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
private static final long RECENTERING_MARGIN_FACTOR = 50;
private static final String HIDE_ARROWS_KEY = "hide.arrows"; //$NON-NLS-1$
private static final long DEFAULT_FREQUENCY = 1000000000L;
+ private static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1;
private long fMinTimeInterval;
private ITimeGraphEntry fSelectedEntry;
@@ -100,6 +103,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
private TimeGraphControl fTimeGraphCtrl;
private TimeGraphScale fTimeScaleCtrl;
+ private Slider fHorizontalScrollBar;
private Slider fVerticalScrollBar;
private TimeGraphColorScheme fColorScheme;
private Object fInputElement;
@@ -206,7 +210,6 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
if (fTimeGraphCtrl != null) {
setTimeRange(input);
- fVerticalScrollBar.setEnabled(true);
setTopIndex(0);
fSelectionBegin = 0;
fSelectionEnd = 0;
@@ -245,7 +248,6 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
public void refresh() {
ITimeGraphEntry[] input = fTimeGraphContentProvider.getElements(fInputElement);
setTimeRange(input);
- fVerticalScrollBar.setEnabled(true);
refreshAllData(input);
}
@@ -369,14 +371,13 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
setTopIndex(fVerticalScrollBar.getSelection());
}
});
- fVerticalScrollBar.setEnabled(false);
fTimeGraphCtrl = createTimeGraphControl(fDataViewer, fColorScheme);
fTimeGraphCtrl.setTimeProvider(this);
fTimeGraphCtrl.setTimeGraphScale(fTimeScaleCtrl);
fTimeGraphCtrl.addSelectionListener(this);
- fTimeGraphCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
+ fTimeGraphCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
fTimeGraphCtrl.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseScrolled(MouseEvent e) {
@@ -395,9 +396,48 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
}
});
+ fHorizontalScrollBar = new Slider(fDataViewer, SWT.HORIZONTAL | SWT.NO_FOCUS);
+ fHorizontalScrollBar.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
+ fHorizontalScrollBar.addListener(SWT.MouseWheel, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ if ((event.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
+ getTimeGraphControl().zoom(event.count > 0);
+ } else {
+ getTimeGraphControl().horizontalScroll(event.count > 0);
+ }
+ // don't handle the immediately following SWT.Selection event
+ event.doit = false;
+ }
+ });
+ fHorizontalScrollBar.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ int start = fHorizontalScrollBar.getSelection();
+ long time0 = getTime0();
+ long time1 = getTime1();
+ long timeMin = getMinTime();
+ long timeMax = getMaxTime();
+ long delta = timeMax - timeMin;
+
+ long range = time1 - time0;
+ time0 = timeMin + Math.round(delta * ((double) start / H_SCROLLBAR_MAX));
+ time1 = time0 + range;
+
+ // TODO: Follow-up with Bug 310310
+ // In Linux SWT.DRAG is the only value received
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310310
+ if (event.detail == SWT.DRAG) {
+ setStartFinishTime(time0, time1);
+ } else {
+ setStartFinishTimeNotify(time0, time1);
+ }
+ }
+ });
+
Composite filler = new Composite(fDataViewer, SWT.NONE);
GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false);
- gd.heightHint = fTimeGraphCtrl.getHorizontalBar().getSize().y;
+ gd.heightHint = fHorizontalScrollBar.getSize().y;
filler.setLayoutData(gd);
filler.setLayout(new FillLayout());
@@ -409,6 +449,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
});
resizeControls();
fDataViewer.update();
+ adjustHorizontalScrollBar();
adjustVerticalScrollBar();
return fDataViewer;
}
@@ -454,6 +495,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
if (fNameWidth < fMinNameWidth) {
fNameWidth = fMinNameWidth;
}
+ adjustHorizontalScrollBar();
adjustVerticalScrollBar();
}
@@ -612,7 +654,6 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
if (fNameWidth < MIN_NAME_WIDTH) {
fNameWidth = MIN_NAME_WIDTH;
}
- fTimeGraphCtrl.adjustScrolls();
fTimeGraphCtrl.redraw();
fTimeScaleCtrl.redraw();
}
@@ -690,7 +731,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
}
fTimeRangeFixed = true;
- fTimeGraphCtrl.adjustScrolls();
+ adjustHorizontalScrollBar();
fTimeGraphCtrl.redraw();
fTimeScaleCtrl.redraw();
}
@@ -715,7 +756,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
fTime0Bound = 0;
fTime1Bound = 0;
}
- fTimeGraphCtrl.adjustScrolls();
+ adjustHorizontalScrollBar();
}
@Override
@@ -786,7 +827,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
if (fTime1 - fTime0 < fMinTimeInterval) {
fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
}
- fTimeGraphCtrl.adjustScrolls();
+ adjustHorizontalScrollBar();
fTimeGraphCtrl.redraw();
fTimeScaleCtrl.redraw();
@@ -1283,6 +1324,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
*
* @return The scroll bar
*/
+ @Deprecated
public ScrollBar getHorizontalBar() {
return fTimeGraphCtrl.getHorizontalBar();
}
@@ -1686,6 +1728,23 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
return fFollowArrowBwdAction;
}
+ private void adjustHorizontalScrollBar() {
+ long time0 = getTime0();
+ long time1 = getTime1();
+ long timeMin = getMinTime();
+ long timeMax = getMaxTime();
+ long delta = timeMax - timeMin;
+ int timePos = 0;
+ int thumb = H_SCROLLBAR_MAX;
+ if (delta != 0) {
+ // Thumb size (page size)
+ thumb = Math.max(1, (int) (H_SCROLLBAR_MAX * ((double) (time1 - time0) / delta)));
+ // At the beginning of visible window
+ timePos = (int) (H_SCROLLBAR_MAX * ((double) (time0 - timeMin) / delta));
+ }
+ fHorizontalScrollBar.setValues(timePos, 0, H_SCROLLBAR_MAX, thumb, Math.max(1, thumb / 2), Math.max(2, thumb));
+ }
+
private void adjustVerticalScrollBar() {
int topIndex = fTimeGraphCtrl.getTopIndex();
int countPerPage = fTimeGraphCtrl.countPerPage();
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java
index 28be4b3d87..5d988950ab 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java
@@ -79,7 +79,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.ScrollBar;
/**
* Time graph control implementation
@@ -94,6 +93,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
MenuDetectListener, ITmfTimeGraphDrawingHelper, ITimeGraphColorListener, Listener {
/** Max scrollbar size */
+ @Deprecated
public static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1;
/** Constant indicating that all levels of the time graph should be expanded
@@ -208,7 +208,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
*/
public TimeGraphControl(Composite parent, TimeGraphColorScheme colors) {
- super(parent, colors, SWT.NO_BACKGROUND | SWT.H_SCROLL | SWT.DOUBLE_BUFFERED);
+ super(parent, colors, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
fItemData = new ItemData();
@@ -222,11 +222,6 @@ public class TimeGraphControl extends TimeGraphBaseControl
addControlListener(this);
addMenuDetectListener(this);
addListener(SWT.MouseWheel, this);
- ScrollBar scrollHor = getHorizontalBar();
-
- if (scrollHor != null) {
- scrollHor.addSelectionListener(this);
- }
}
@Override
@@ -474,35 +469,8 @@ public class TimeGraphControl extends TimeGraphBaseControl
/**
* Adjust the scoll bars
*/
+ @Deprecated
public void adjustScrolls() {
- if (null == fTimeProvider) {
- getHorizontalBar().setValues(0, 1, 1, 1, 1, 1);
- return;
- }
-
- // HORIZONTAL BAR
- // Visible window
- long time0 = fTimeProvider.getTime0();
- long time1 = fTimeProvider.getTime1();
- // Time boundaries
- long timeMin = fTimeProvider.getMinTime();
- long timeMax = fTimeProvider.getMaxTime();
-
- long delta = timeMax - timeMin;
-
- int timePos = 0;
- int thumb = H_SCROLLBAR_MAX;
-
- if (delta != 0) {
- // Thumb size (page size)
- thumb = Math.max(1, (int) (H_SCROLLBAR_MAX * ((double) (time1 - time0) / delta)));
- // At the beginning of visible window
- timePos = (int) (H_SCROLLBAR_MAX * ((double) (time0 - timeMin) / delta));
- }
-
- // position, minimum, maximum, thumb size, increment (half page)t, page
- // increment size (full page)
- getHorizontalBar().setValues(timePos, 0, H_SCROLLBAR_MAX, thumb, Math.max(1, thumb / 2), Math.max(2, thumb));
}
boolean ensureVisibleItem(int idx, boolean redraw) {
@@ -899,6 +867,34 @@ public class TimeGraphControl extends TimeGraphBaseControl
}
/**
+ * Scroll left or right by one half window size
+ *
+ * @param left
+ * true to scroll left, false to scroll right
+ *
+ * @since 3.2
+ */
+ public void horizontalScroll(boolean left) {
+ long time0 = fTimeProvider.getTime0();
+ long time1 = fTimeProvider.getTime1();
+ long timeMin = fTimeProvider.getMinTime();
+ long timeMax = fTimeProvider.getMaxTime();
+ long range = time1 - time0;
+ if (range <= 0) {
+ return;
+ }
+ long increment = Math.max(1, range / 2);
+ if (left) {
+ time0 = Math.max(time0 - increment, timeMin);
+ time1 = time0 + range;
+ } else {
+ time1 = Math.min(time1 + increment, timeMax);
+ time0 = time1 - range;
+ }
+ fTimeProvider.setStartFinishTimeNotify(time0, time1);
+ }
+
+ /**
* Zoom based on mouse cursor location with mouse scrolling
*
* @param zoomIn true to zoom in, false to zoom out
@@ -1190,7 +1186,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
}
long time0 = fTimeProvider.getTime0();
long time1 = fTimeProvider.getTime1();
- int width = getCtrlSize().x;
+ int width = getSize().x;
int nameSpace = fTimeProvider.getNameSpace();
double pixelsPerNanoSec = (width - nameSpace <= RIGHT_MARGIN) ? 0 : (double) (width - nameSpace - RIGHT_MARGIN) / (time1 - time0);
int x = getBounds().x + nameSpace + (int) ((time - time0) * pixelsPerNanoSec);
@@ -1206,7 +1202,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
return -1;
}
long hitTime = -1;
- Point size = getCtrlSize();
+ Point size = getSize();
long time0 = fTimeProvider.getTime0();
long time1 = fTimeProvider.getTime1();
int nameWidth = fTimeProvider.getNameSpace();
@@ -1266,7 +1262,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
* @return The count
*/
public int countPerPage() {
- int height = getCtrlSize().y;
+ int height = getSize().y;
int count = 0;
int ySum = 0;
for (int idx = fTopIndex; idx < fItemData.fExpandedItems.length; idx++) {
@@ -1317,14 +1313,6 @@ public class TimeGraphControl extends TimeGraphBaseControl
return elements.toArray(new ITimeGraphEntry[0]);
}
- Point getCtrlSize() {
- Point size = getSize();
- if (getHorizontalBar().isVisible()) {
- size.y -= getHorizontalBar().getSize().y;
- }
- return size;
- }
-
Rectangle getNameRect(Rectangle bound, int idx, int nameWidth) {
Rectangle rect = getStatesRect(bound, idx, nameWidth);
rect.x = bound.x;
@@ -2095,7 +2083,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
if (null == fTimeProvider) {
return;
}
- Point size = getCtrlSize();
+ Point size = getSize();
if (DRAG_TRACE_ITEM == fDragState) {
int nameWidth = fTimeProvider.getNameSpace();
if (e.x > nameWidth && size.x > nameWidth && fDragX != e.x) {
@@ -2164,7 +2152,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
public void mouseDown(MouseEvent e) {
if (fDragState != DRAG_NONE || null == fTimeProvider ||
fTimeProvider.getTime0() == fTimeProvider.getTime1() ||
- getCtrlSize().x - fTimeProvider.getNameSpace() <= 0) {
+ getSize().x - fTimeProvider.getNameSpace() <= 0) {
return;
}
int idx;
@@ -2249,7 +2237,7 @@ public class TimeGraphControl extends TimeGraphBaseControl
}
} else if (3 == e.button) {
setCapture(true);
- fDragX = Math.min(Math.max(e.x, fTimeProvider.getNameSpace()), getCtrlSize().x - RIGHT_MARGIN);
+ fDragX = Math.min(Math.max(e.x, fTimeProvider.getNameSpace()), getSize().x - RIGHT_MARGIN);
fDragX0 = fDragX;
fDragTime0 = getTimeAtX(fDragX0);
fDragState = DRAG_ZOOM;
@@ -2335,16 +2323,24 @@ public class TimeGraphControl extends TimeGraphBaseControl
return;
}
boolean zoomScroll = false;
+ boolean horizontalScroll = false;
Point p = getParent().toControl(getDisplay().getCursorLocation());
Point parentSize = getParent().getSize();
if (p.x >= 0 && p.x < parentSize.x && p.y >= 0 && p.y < parentSize.y) {
// over the parent control
- if (e.x > getCtrlSize().x) {
+ if (e.x > getSize().x) {
// over the vertical scroll bar
zoomScroll = false;
- } else if (e.y < 0 || e.y >= getCtrlSize().y) {
- // over the time scale or horizontal scroll bar
+ } else if (e.y < 0) {
+ // over the time scale
zoomScroll = true;
+ } else if (e.y >= getSize().y) {
+ // over the horizontal scroll bar
+ if ((e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
+ zoomScroll = true;
+ } else {
+ horizontalScroll = true;
+ }
} else {
if (e.x < fTimeProvider.getNameSpace()) {
// over the name space
@@ -2367,6 +2363,8 @@ public class TimeGraphControl extends TimeGraphBaseControl
} else if (e.count < 0) {
zoom(false);
}
+ } else if (horizontalScroll) {
+ horizontalScroll(e.count > 0);
} else {
setTopIndex(getTopIndex() - e.count);
}
@@ -2393,35 +2391,14 @@ public class TimeGraphControl extends TimeGraphBaseControl
adjustScrolls();
}
+ @Deprecated
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
+ @Deprecated
@Override
public void widgetSelected(SelectionEvent e) {
- if (e.widget == getVerticalBar()) {
- setTopIndex(getVerticalBar().getSelection());
- } else if (e.widget == getHorizontalBar() && null != fTimeProvider) {
- int start = getHorizontalBar().getSelection();
- long time0 = fTimeProvider.getTime0();
- long time1 = fTimeProvider.getTime1();
- long timeMin = fTimeProvider.getMinTime();
- long timeMax = fTimeProvider.getMaxTime();
- long delta = timeMax - timeMin;
-
- long range = time1 - time0;
- time0 = timeMin + Math.round(delta * ((double) start / H_SCROLLBAR_MAX));
- time1 = time0 + range;
-
- // TODO: Follow-up with Bug 310310
- // In Linux SWT.DRAG is the only value received
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310310
- if (e.detail == SWT.DRAG) {
- fTimeProvider.setStartFinishTime(time0, time1);
- } else {
- fTimeProvider.setStartFinishTimeNotify(time0, time1);
- }
- }
}
@Override

Back to the top