From 6a08b49e83fdadfde5d307fcfd4a52ad3df8359d Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Fri, 29 Jun 2012 14:42:05 -0400 Subject: [PATCH] Fix for bug 383935: Disappearing tool tip in time graph and other issues --- .../ui/widgets/timegraph/TimeGraphViewer.java | 4 +- .../timegraph/widgets/TimeGraphControl.java | 10 +- .../widgets/TimeGraphTooltipHandler.java | 122 ++++++++++++------ .../ui/widgets/timegraph/widgets/Utils.java | 5 +- 4 files changed, 87 insertions(+), 54 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java index c63b8ad83e..1c78b54ead 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphViewer.java @@ -370,7 +370,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { _time1 = _time1_; } if (_time1 - _time0 < _minTimeInterval) { - _time1 = _time0 + _minTimeInterval; + _time1 = Math.min(_time1_, _time0 + _minTimeInterval); } } @@ -622,7 +622,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener { } } if (_time1 - _time0 < _minTimeInterval) { - _time1 = _time0 + _minTimeInterval; + _time1 = Math.min(_time1_, _time0 + _minTimeInterval); } _stateCtrl.adjustScrolls(); _stateCtrl.redraw(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java index dd11e43218..bc782fba25 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java @@ -874,13 +874,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe x -= nameWidth; int timeWidth = size.x - nameWidth - RIGHT_MARGIN; if (x >= 0 && size.x >= nameWidth) { - if (time1 - time0 > timeWidth) { - // get the last possible time represented by the pixel position - // by taking the time of the next pixel position minus 1 nanosecond - hitTime = time0 + (long) ((time1 - time0) * ((double) (x + 1) / timeWidth)) - 1; - } else { - hitTime = time0 + Math.round((time1 - time0) * ((double) x / timeWidth)); - } + hitTime = time0 + Math.round((time1 - time0) * ((double) x / timeWidth)); } return hitTime; } @@ -1048,7 +1042,7 @@ public class TimeGraphControl extends TimeGraphBaseControl implements FocusListe long time1 = _timeProvider.getTime1(); long selectedTime = _timeProvider.getSelectedTime(); double pixelsPerNanoSec = (bounds.width - nameSpace <= RIGHT_MARGIN) ? 0 : (double) (bounds.width - nameSpace - RIGHT_MARGIN) / (time1 - time0); - int x = bounds.x + nameSpace + (int) ((selectedTime - time0) * pixelsPerNanoSec); + int x = bounds.x + nameSpace + (int) Math.round((selectedTime - time0) * pixelsPerNanoSec); if (x >= nameSpace && x < bounds.x + bounds.width) { gc.setForeground(_colors.getColor(TimeGraphColorScheme.SELECTED_TIME)); gc.drawLine(x, bounds.y, x, bounds.y + bounds.height); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java index 97168988bb..a72c3f47f6 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/TimeGraphTooltipHandler.java @@ -30,7 +30,6 @@ import org.eclipse.swt.events.MouseMoveListener; import org.eclipse.swt.events.MouseTrackAdapter; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -48,8 +47,8 @@ import org.eclipse.swt.widgets.TableItem; */ public class TimeGraphTooltipHandler { - private final Shell _tipShell; - private final Table _tipTable; + private Shell _tipShell; + private Table _tipTable; private Point _tipPosition; private final ITimeDataProvider _timeDataProvider; ITimeGraphPresentationProvider _utilImp = null; @@ -58,7 +57,7 @@ public class TimeGraphTooltipHandler { * Standard constructor * * @param parent - * The parent composite object + * The parent shell (unused, can be null) * @param rUtilImpl * The presentation provider * @param timeProv @@ -66,21 +65,23 @@ public class TimeGraphTooltipHandler { */ public TimeGraphTooltipHandler(Shell parent, ITimeGraphPresentationProvider rUtilImpl, ITimeDataProvider timeProv) { - final Display display = parent.getDisplay(); this._utilImp = rUtilImpl; this._timeDataProvider = timeProv; + } + + private void createTooltipShell(Shell parent) { + final Display display = parent.getDisplay(); + if (_tipShell != null && ! _tipShell.isDisposed()) { + _tipShell.dispose(); + } _tipShell = new Shell(parent, SWT.ON_TOP | SWT.TOOL); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; gridLayout.marginWidth = 2; gridLayout.marginHeight = 2; _tipShell.setLayout(gridLayout); - GridData data = new GridData(GridData.BEGINNING, GridData.BEGINNING, - true, true); - _tipShell.setLayoutData(data); - _tipShell.setBackground(display - .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + _tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); _tipTable = new Table(_tipShell, SWT.NONE); new TableColumn(_tipTable, SWT.NONE); @@ -92,8 +93,26 @@ public class TimeGraphTooltipHandler { _tipTable.setHeaderVisible(false); _tipTable.setLinesVisible(false); - // tipTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL - // | GridData.VERTICAL_ALIGN_CENTER)); + _tipTable.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + _tipShell.dispose(); + } + }); + + _tipTable.addMouseTrackListener(new MouseTrackAdapter() { + @Override + public void mouseExit(MouseEvent e) { + _tipShell.dispose(); + } + }); + + _tipTable.addMouseMoveListener(new MouseMoveListener() { + @Override + public void mouseMove(MouseEvent e) { + _tipShell.dispose(); + } + }); } /** @@ -103,12 +122,11 @@ public class TimeGraphTooltipHandler { * The control object to use */ public void activateHoverHelp(final Control control) { - //FIXME: remove old listeners control.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { - if (_tipShell.isVisible()) { - _tipShell.setVisible(false); + if (_tipShell != null && ! _tipShell.isDisposed()) { + _tipShell.dispose(); } } }); @@ -116,8 +134,8 @@ public class TimeGraphTooltipHandler { control.addMouseMoveListener(new MouseMoveListener() { @Override public void mouseMove(MouseEvent e) { - if (_tipShell.isVisible()) { - _tipShell.setVisible(false); + if (_tipShell != null && ! _tipShell.isDisposed()) { + _tipShell.dispose(); } } }); @@ -125,8 +143,11 @@ public class TimeGraphTooltipHandler { control.addMouseTrackListener(new MouseTrackAdapter() { @Override public void mouseExit(MouseEvent e) { - if (_tipShell.isVisible()) { - _tipShell.setVisible(false); + if (_tipShell != null && ! _tipShell.isDisposed()) { + Point pt = control.toDisplay(e.x, e.y); + if (! _tipShell.getBounds().contains(pt)) { + _tipShell.dispose(); + } } } @@ -136,28 +157,41 @@ public class TimeGraphTooltipHandler { line.setText(1, value); } - private void fillValues(Point pt, TimeGraphControl threadStates, ITimeGraphEntry entry) { + private void fillValues(Point pt, TimeGraphControl timeGraphControl, ITimeGraphEntry entry) { if (entry == null) { return; } if (entry.hasTimeEvents()) { - ITimeEvent threadEvent = Utils.findEvent(entry, threadStates.getTimeAtX(pt.x), 2); - ITimeEvent nextEvent = Utils.findEvent(entry, threadStates.getTimeAtX(pt.x), 1); + long currPixelTime = timeGraphControl.getTimeAtX(pt.x); + long nextPixelTime = timeGraphControl.getTimeAtX(pt.x + 1); + if (nextPixelTime == currPixelTime) { + nextPixelTime++; + } + ITimeEvent currEvent = Utils.findEvent(entry, currPixelTime, 0); + ITimeEvent nextEvent = Utils.findEvent(entry, currPixelTime, 1); + + // if there is no current event at the start of the current pixel range, + // or if the current event starts before the current pixel range, + // use the next event as long as it starts within the current pixel range + if (currEvent == null || currEvent.getTime() < currPixelTime) { + if (nextEvent != null && nextEvent.getTime() < nextPixelTime) { + currEvent = nextEvent; + } + } + // state name addItem(_utilImp.getStateTypeName(), entry.getName()); - if (threadEvent == null) { + if (currEvent == null) { return; } - // thread state - String state = _utilImp.getEventName(threadEvent); + // state + String state = _utilImp.getEventName(currEvent); if (state != null) { addItem(Messages.TmfTimeTipHandler_TRACE_STATE, state); } - // This block receives a - // list of values to be added to the tip - // table - Map eventAddOns = _utilImp.getEventHoverToolTipInfo(threadEvent); + // This block receives a list of values to be added to the tip table + Map eventAddOns = _utilImp.getEventHoverToolTipInfo(currEvent); if (eventAddOns != null) { for (Iterator iter = eventAddOns.keySet().iterator(); iter.hasNext();) { String message = iter.next(); @@ -169,8 +203,8 @@ public class TimeGraphTooltipHandler { long eventDuration = -1; long eventEndTime = -1; - eventStartTime = threadEvent.getTime(); - eventDuration = threadEvent.getDuration(); + eventStartTime = currEvent.getTime(); + eventDuration = currEvent.getDuration(); if (eventDuration < 0 && nextEvent != null) { eventEndTime = nextEvent.getTime(); eventDuration = eventEndTime - eventStartTime; @@ -178,13 +212,8 @@ public class TimeGraphTooltipHandler { eventEndTime = eventStartTime + eventDuration; } - // TODO: Check if we need "format" - // TimeFormat format = TimeFormat.RELATIVE; Resolution res = Resolution.NANOSEC; if (_timeDataProvider.isCalendarFormat()) { - // format = TimeFormat.ABSOLUTE; // Absolute format - // // (calendar) - // Add Date addItem(Messages.TmfTimeTipHandler_TRACE_DATE, eventStartTime > -1 ? Utils.formatDate(eventStartTime) : "?"); //$NON-NLS-1$ @@ -229,10 +258,11 @@ public class TimeGraphTooltipHandler { @Override public void mouseHover(MouseEvent event) { Point pt = new Point(event.x, event.y); - TimeGraphControl threadStates = (TimeGraphControl) event.widget; - ITimeGraphEntry entry = threadStates.getEntry(pt); + TimeGraphControl timeGraphControl = (TimeGraphControl) event.widget; + createTooltipShell(timeGraphControl.getShell()); + ITimeGraphEntry entry = timeGraphControl.getEntry(pt); _tipTable.remove(0, _tipTable.getItemCount() - 1); - fillValues(pt, threadStates, entry); + fillValues(pt, timeGraphControl, entry); if (_tipTable.getItemCount() == 0) { return; } @@ -250,10 +280,16 @@ public class TimeGraphTooltipHandler { private static void setHoverLocation(Shell shell, Point position) { Rectangle displayBounds = shell.getDisplay().getBounds(); Rectangle shellBounds = shell.getBounds(); - shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - - shellBounds.width), 0); - shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height - - shellBounds.height), 0); + if (position.x + shellBounds.width + 16 > displayBounds.width && position.x - shellBounds.width - 16 >= 0) { + shellBounds.x = position.x - shellBounds.width - 16; + } else { + shellBounds.x = Math.max(Math.min(position.x + 16, displayBounds.width - shellBounds.width), 0); + } + if (position.y + shellBounds.height + 16 > displayBounds.height && position.y - shellBounds.height - 16 >= 0) { + shellBounds.y = position.y - shellBounds.height - 16; + } else { + shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height - shellBounds.height), 0); + } shell.setBounds(shellBounds); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java index 7fb86d1a78..8d9e618660 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/widgets/Utils.java @@ -473,7 +473,10 @@ public class Utils { } return null; } else if (n == 1) { //next - return nextEvent; + if (nextEvent != null && nextEvent.getTime() > time) { + return nextEvent; + } + return null; } else if (n == 2) { //current or previous when in empty space return currEvent; } -- 2.34.1