From 3431355338300c3770bf7b65cd74b1165c5911a3 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Wed, 12 Sep 2012 10:11:50 -0400 Subject: [PATCH] Fix for bug 389328: Provide hover time for time graph tool tip info. Change-Id: I2eaf701ff090fbac1a48f5bc159d27e64dd3938d Reviewed-on: https://git.eclipse.org/r/7713 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann --- .../ITimeGraphPresentationProvider.java | 292 +++++---- .../TimeGraphPresentationProvider.java | 291 +++++---- .../widgets/TimeGraphTooltipHandler.java | 618 +++++++++--------- 3 files changed, 616 insertions(+), 585 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphPresentationProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphPresentationProvider.java index f5f51cad73..799fc6b74a 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphPresentationProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/ITimeGraphPresentationProvider.java @@ -1,141 +1,153 @@ -/******************************************************************************* - * Copyright (c) 2012 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Patrick Tasse - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import java.util.Map; - -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Rectangle; - -/** - * Interface for the time graph widget provider - * - * @version 1.0 - * @author Patrick Tasse - */ -public interface ITimeGraphPresentationProvider { - - /** - * Returns the name of state types. - * - * @return the name of state types - */ - public String getStateTypeName(); - - /** - * Returns the name of state type depending on the given entry. - * Note that this overwrites the name which is return by getStateTypeName(). - * - * @param entry - * the entry - * @return the name of state type depending on the given entry or null. - * @since 2.0 - */ - public String getStateTypeName(ITimeGraphEntry entry); - - /** - * Returns table of states with state name to state color relationship. - * - * @return table of states with color and name - * - * @see #getStateTableIndex - */ - public StateItem[] getStateTable(); - - /** - * Returns the index in the state table corresponding to this time event. - * The index should correspond to a state in the state table, - * otherwise the color SWT.COLOR_BLACK will be used. - * If the index returned is negative, the event will not be drawn. - * - * @param event the time event - * @return the corresponding state table index - * - * @see #getStateTable - */ - public int getStateTableIndex(ITimeEvent event); - - /** - * Called after drawing the control - * - * @param bounds - * The drawing rectangle - * @param gc - * The graphics context - */ - public void postDrawControl(Rectangle bounds, GC gc); - - /** - * Called after drawing an entry - * - * @param entry - * the entry that was drawn - * @param bounds - * the drawing rectangle - * @param gc - * the graphics context - */ - public void postDrawEntry(ITimeGraphEntry entry, Rectangle bounds, GC gc); - - /** - * Called after drawing an event - * - * @param event - * the event that was drawn - * @param bounds - * the drawing rectangle - * @param gc - * the graphics context - */ - public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc); - - /** - * Returns the height of this item. This value is ignored if the time graph has a fixed item height. - * - * @param entry the entry - * @return the item height - * - * @see TimeGraphViewer#setItemHeight - */ - public int getItemHeight(ITimeGraphEntry entry); - - /** - * Provides the image icon for a given entry. - * - * @param entry the entry - * @return the image icon - */ - public Image getItemImage(ITimeGraphEntry entry); - - /** - * Returns the name of this event. - * - * @param event - * The event - * @return The event name - */ - public String getEventName(ITimeEvent event); - - /** - * Returns a map of name and value providing additional information - * to display in the tool tip for this event. - * - * @param event the time event - * @return a map of tool tip information - */ - public Map getEventHoverToolTipInfo(ITimeEvent event); - +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.Map; + +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; + +/** + * Interface for the time graph widget provider + * + * @version 1.0 + * @author Patrick Tasse + */ +public interface ITimeGraphPresentationProvider { + + /** + * Returns the name of state types. + * + * @return the name of state types + */ + public String getStateTypeName(); + + /** + * Returns the name of state type depending on the given entry. + * Note that this overwrites the name which is return by getStateTypeName(). + * + * @param entry + * the entry + * @return the name of state type depending on the given entry or null. + * @since 2.0 + */ + public String getStateTypeName(ITimeGraphEntry entry); + + /** + * Returns table of states with state name to state color relationship. + * + * @return table of states with color and name + * + * @see #getStateTableIndex + */ + public StateItem[] getStateTable(); + + /** + * Returns the index in the state table corresponding to this time event. + * The index should correspond to a state in the state table, + * otherwise the color SWT.COLOR_BLACK will be used. + * If the index returned is negative, the event will not be drawn. + * + * @param event the time event + * @return the corresponding state table index + * + * @see #getStateTable + */ + public int getStateTableIndex(ITimeEvent event); + + /** + * Called after drawing the control + * + * @param bounds + * The drawing rectangle + * @param gc + * The graphics context + */ + public void postDrawControl(Rectangle bounds, GC gc); + + /** + * Called after drawing an entry + * + * @param entry + * the entry that was drawn + * @param bounds + * the drawing rectangle + * @param gc + * the graphics context + */ + public void postDrawEntry(ITimeGraphEntry entry, Rectangle bounds, GC gc); + + /** + * Called after drawing an event + * + * @param event + * the event that was drawn + * @param bounds + * the drawing rectangle + * @param gc + * the graphics context + */ + public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc); + + /** + * Returns the height of this item. This value is ignored if the time graph has a fixed item height. + * + * @param entry the entry + * @return the item height + * + * @see TimeGraphViewer#setItemHeight + */ + public int getItemHeight(ITimeGraphEntry entry); + + /** + * Provides the image icon for a given entry. + * + * @param entry the entry + * @return the image icon + */ + public Image getItemImage(ITimeGraphEntry entry); + + /** + * Returns the name of this event. + * + * @param event + * The event + * @return The event name + */ + public String getEventName(ITimeEvent event); + + /** + * Returns a map of name and value providing additional information + * to display in the tool tip for this event. + * + * @param event the time event + * @return a map of tool tip information + */ + public Map getEventHoverToolTipInfo(ITimeEvent event); + + /** + * Returns a map of name and value providing additional information + * to display in the tool tip for this event. + * + * @param event the time event + * @param hoverTime the time corresponding to the mouse hover position + * @return a map of tool tip information + * + * @since 2.0 + */ + public Map getEventHoverToolTipInfo(ITimeEvent event, long hoverTime); + } \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphPresentationProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphPresentationProvider.java index 53b50fc499..19b4cf383c 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphPresentationProvider.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/timegraph/TimeGraphPresentationProvider.java @@ -1,141 +1,152 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010, 2012 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alvaro Sanchez-Leon - Initial API and implementation - * Patrick Tasse - Refactoring - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; - -import java.util.Map; - -import org.eclipse.linuxtools.internal.tmf.ui.Messages; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Rectangle; - -/** - * Provider class for the time graph provider - * - * @version 1.0 - * @author Patrick Tasse - * - */ -public class TimeGraphPresentationProvider implements ITimeGraphPresentationProvider { - - // ------------------------------------------------------------------------ - // Constants - // ------------------------------------------------------------------------ - private static final int DEFAULT_ITEM_HEIGHT = 19; - - // ------------------------------------------------------------------------ - // Operations - // ------------------------------------------------------------------------ - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getStateTypeName() - */ - @Override - public String getStateTypeName() { - return Messages.TmfTimeLegend_TRACE_STATES; - } - - /** - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getStateTypeName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) - * @since 2.0 - */ - @Override - public String getStateTypeName(ITimeGraphEntry entry) { - return null; - } - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getStateTable() - */ - @Override - public StateItem[] getStateTable() { - return null; - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getEventTableIndex(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) - */ - @Override - public int getStateTableIndex(ITimeEvent event) { - return 0; - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#postDrawControl(org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC) - */ - @Override - public void postDrawControl(Rectangle bounds, GC gc) { - // Override to add own drawing code - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#postDrawEntry(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC) - */ - @Override - public void postDrawEntry(ITimeGraphEntry entry, Rectangle bounds, GC gc) { - // Override to add own drawing code - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#postDrawEvent(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC) - */ - @Override - public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) { - // Override to add own drawing code - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getItemHeight(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) - */ - @Override - public int getItemHeight(ITimeGraphEntry entry) { - return DEFAULT_ITEM_HEIGHT; - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getItemImage(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) - */ - @Override - public Image getItemImage(ITimeGraphEntry entry) { - return null; - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getEventName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) - */ - @Override - public String getEventName(ITimeEvent event) { - return null; - } - - /* - * (non-Javadoc) - * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getEventHoverToolTipInfo(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) - */ - @Override - public Map getEventHoverToolTipInfo(ITimeEvent event) { - return null; - } - +/******************************************************************************* + * Copyright (c) 2009, 2010, 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alvaro Sanchez-Leon - Initial API and implementation + * Patrick Tasse - Refactoring + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph; + +import java.util.Map; + +import org.eclipse.linuxtools.internal.tmf.ui.Messages; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; + +/** + * Provider class for the time graph provider + * + * @version 1.0 + * @author Patrick Tasse + * + */ +public class TimeGraphPresentationProvider implements ITimeGraphPresentationProvider { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + private static final int DEFAULT_ITEM_HEIGHT = 19; + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getStateTypeName() + */ + @Override + public String getStateTypeName() { + return Messages.TmfTimeLegend_TRACE_STATES; + } + + /** + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getStateTypeName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) + * @since 2.0 + */ + @Override + public String getStateTypeName(ITimeGraphEntry entry) { + return null; + } + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getStateTable() + */ + @Override + public StateItem[] getStateTable() { + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getEventTableIndex(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public int getStateTableIndex(ITimeEvent event) { + return 0; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#postDrawControl(org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC) + */ + @Override + public void postDrawControl(Rectangle bounds, GC gc) { + // Override to add own drawing code + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#postDrawEntry(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC) + */ + @Override + public void postDrawEntry(ITimeGraphEntry entry, Rectangle bounds, GC gc) { + // Override to add own drawing code + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#postDrawEvent(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent, org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.GC) + */ + @Override + public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) { + // Override to add own drawing code + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getItemHeight(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) + */ + @Override + public int getItemHeight(ITimeGraphEntry entry) { + return DEFAULT_ITEM_HEIGHT; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getItemImage(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) + */ + @Override + public Image getItemImage(ITimeGraphEntry entry) { + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getEventName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public String getEventName(ITimeEvent event) { + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getEventHoverToolTipInfo(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent) + */ + @Override + public Map getEventHoverToolTipInfo(ITimeEvent event) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getEventHoverToolTipInfo(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent, long) + */ + /** + * @since 2.0 + */ + @Override + public Map getEventHoverToolTipInfo(ITimeEvent event, long hoverTime) { + return getEventHoverToolTipInfo(event); + } + } \ No newline at end of file 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 f2b8040d8d..11c65a8a94 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 @@ -1,306 +1,314 @@ -/***************************************************************************** - * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Intel Corporation - Initial API and implementation - * Vitaly A. Provodin, Intel - Initial API and implementation - * Alvaro Sanchez-Leon - Updated for TMF - * Patrick Tasse - Refactoring - * - *****************************************************************************/ -package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; - -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.linuxtools.internal.tmf.ui.Messages; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution; -import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -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.GridLayout; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; - -/** - * Handler for the tool tips in the generic time graph view. - * - * @version 1.0 - * @author Alvaro Sanchez-Leon - * @author Patrick Tasse - */ -public class TimeGraphTooltipHandler { - - private Shell _tipShell; - private Table _tipTable; - private Point _tipPosition; - private final ITimeDataProvider _timeDataProvider; - ITimeGraphPresentationProvider _utilImp = null; - - /** - * Standard constructor - * - * @param parent - * The parent shell (unused, can be null) - * @param rUtilImpl - * The presentation provider - * @param timeProv - * The time provider - */ - public TimeGraphTooltipHandler(Shell parent, ITimeGraphPresentationProvider rUtilImpl, - ITimeDataProvider timeProv) { - - 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); - _tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - - _tipTable = new Table(_tipShell, SWT.NONE); - new TableColumn(_tipTable, SWT.NONE); - new TableColumn(_tipTable, SWT.NONE); - _tipTable.setForeground(display - .getSystemColor(SWT.COLOR_INFO_FOREGROUND)); - _tipTable.setBackground(display - .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - _tipTable.setHeaderVisible(false); - _tipTable.setLinesVisible(false); - - _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(); - } - }); - } - - /** - * Callback for the mouse-over tooltip - * - * @param control - * The control object to use - */ - public void activateHoverHelp(final Control control) { - control.addMouseListener(new MouseAdapter() { - @Override - public void mouseDown(MouseEvent e) { - if (_tipShell != null && ! _tipShell.isDisposed()) { - _tipShell.dispose(); - } - } - }); - - control.addMouseMoveListener(new MouseMoveListener() { - @Override - public void mouseMove(MouseEvent e) { - if (_tipShell != null && ! _tipShell.isDisposed()) { - _tipShell.dispose(); - } - } - }); - - control.addMouseTrackListener(new MouseTrackAdapter() { - @Override - public void mouseExit(MouseEvent e) { - if (_tipShell != null && ! _tipShell.isDisposed()) { - Point pt = control.toDisplay(e.x, e.y); - if (! _tipShell.getBounds().contains(pt)) { - _tipShell.dispose(); - } - } - } - - private void addItem(String name, String value) { - TableItem line = new TableItem(_tipTable, SWT.NONE); - line.setText(0, name); - line.setText(1, value); - } - - private void fillValues(Point pt, TimeGraphControl timeGraphControl, ITimeGraphEntry entry) { - if (entry == null) { - return; - } - if (entry.hasTimeEvents()) { - 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 - String stateTypeName = _utilImp.getStateTypeName(entry); - String entryName = entry.getName(); - if (stateTypeName == null) { - stateTypeName = _utilImp.getStateTypeName(); - } - - if (!entryName.isEmpty()) { - addItem(stateTypeName, entry.getName()); - } - - if (currEvent == null) { - return; - } - - // 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(currEvent); - if (eventAddOns != null) { - for (Iterator iter = eventAddOns.keySet().iterator(); iter.hasNext();) { - String message = iter.next(); - addItem(message, eventAddOns.get(message)); - } - } - - long eventStartTime = -1; - long eventDuration = -1; - long eventEndTime = -1; - - eventStartTime = currEvent.getTime(); - eventDuration = currEvent.getDuration(); - if (eventDuration < 0 && nextEvent != null) { - eventEndTime = nextEvent.getTime(); - eventDuration = eventEndTime - eventStartTime; - } else { - eventEndTime = eventStartTime + eventDuration; - } - - Resolution res = Resolution.NANOSEC; - if (_timeDataProvider.isCalendarFormat()) { - addItem(Messages.TmfTimeTipHandler_TRACE_DATE, eventStartTime > -1 ? - Utils.formatDate(eventStartTime) - : "?"); //$NON-NLS-1$ - if (eventDuration > 0) { - addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ? - Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res) - : "?"); //$NON-NLS-1$ - - addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ? - Utils.formatTime(eventEndTime, TimeFormat.ABSOLUTE, res) - : "?"); //$NON-NLS-1$ - } else { - addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ? - Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res) - : "?"); //$NON-NLS-1$ - } - } else { - if (eventDuration > 0) { - addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ? - Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res) - : "?"); //$NON-NLS-1$ - - addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ? - Utils.formatTime(eventEndTime, TimeFormat.RELATIVE, res) - : "?"); //$NON-NLS-1$ - } else { - addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ? - Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res) - : "?"); //$NON-NLS-1$ - } - } - - if (eventDuration > 0) { - // Duration in relative format in any case - addItem(Messages.TmfTimeTipHandler_DURATION, eventDuration > -1 ? - Utils.formatTime(eventDuration, TimeFormat.RELATIVE, res) - : "?"); //$NON-NLS-1$ - } - } - } - - @Override - public void mouseHover(MouseEvent event) { - Point pt = new Point(event.x, event.y); - TimeGraphControl timeGraphControl = (TimeGraphControl) event.widget; - createTooltipShell(timeGraphControl.getShell()); - ITimeGraphEntry entry = timeGraphControl.getEntry(pt); - _tipTable.remove(0, _tipTable.getItemCount() - 1); - fillValues(pt, timeGraphControl, entry); - if (_tipTable.getItemCount() == 0) { - return; - } - _tipTable.getColumn(0).pack(); - _tipTable.getColumn(1).pack(); - _tipShell.pack(); - _tipPosition = control.toDisplay(pt); - _tipShell.pack(); - setHoverLocation(_tipShell, _tipPosition); - _tipShell.setVisible(true); - } - }); - } - - private static void setHoverLocation(Shell shell, Point position) { - Rectangle displayBounds = shell.getDisplay().getBounds(); - Rectangle shellBounds = shell.getBounds(); - 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); - } - +/***************************************************************************** + * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - Initial API and implementation + * Vitaly A. Provodin, Intel - Initial API and implementation + * Alvaro Sanchez-Leon - Updated for TMF + * Patrick Tasse - Refactoring + * + *****************************************************************************/ +package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets; + +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.linuxtools.internal.tmf.ui.Messages; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution; +import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +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.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +/** + * Handler for the tool tips in the generic time graph view. + * + * @version 1.0 + * @author Alvaro Sanchez-Leon + * @author Patrick Tasse + */ +public class TimeGraphTooltipHandler { + + private Shell _tipShell; + private Composite _tipComposite; + private Point _tipPosition; + private final ITimeDataProvider _timeDataProvider; + ITimeGraphPresentationProvider _utilImp = null; + + /** + * Standard constructor + * + * @param parent + * The parent shell (unused, can be null) + * @param rUtilImpl + * The presentation provider + * @param timeProv + * The time provider + */ + public TimeGraphTooltipHandler(Shell parent, ITimeGraphPresentationProvider rUtilImpl, + ITimeDataProvider timeProv) { + + 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); + _tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + + _tipComposite = new Composite(_tipShell, SWT.NONE); + _tipComposite.setLayout(new GridLayout(3, false)); + setupControl(_tipComposite); + + } + + /** + * Callback for the mouse-over tooltip + * + * @param control + * The control object to use + */ + public void activateHoverHelp(final Control control) { + control.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + if (_tipShell != null && ! _tipShell.isDisposed()) { + _tipShell.dispose(); + } + } + }); + + control.addMouseMoveListener(new MouseMoveListener() { + @Override + public void mouseMove(MouseEvent e) { + if (_tipShell != null && ! _tipShell.isDisposed()) { + _tipShell.dispose(); + } + } + }); + + control.addMouseTrackListener(new MouseTrackAdapter() { + @Override + public void mouseExit(MouseEvent e) { + if (_tipShell != null && ! _tipShell.isDisposed()) { + Point pt = control.toDisplay(e.x, e.y); + if (! _tipShell.getBounds().contains(pt)) { + _tipShell.dispose(); + } + } + } + + private void addItem(String name, String value) { + Label nameLabel = new Label(_tipComposite, SWT.NO_FOCUS); + nameLabel.setText(name); + setupControl(nameLabel); + Label separator = new Label(_tipComposite, SWT.NO_FOCUS | SWT.SEPARATOR | SWT.VERTICAL); + GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false); + gd.heightHint = nameLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; + separator.setLayoutData(gd); + setupControl(separator); + Label valueLabel = new Label(_tipComposite, SWT.NO_FOCUS); + valueLabel.setText(value); + setupControl(valueLabel); + } + + private void fillValues(Point pt, TimeGraphControl timeGraphControl, ITimeGraphEntry entry) { + if (entry == null) { + return; + } + if (entry.hasTimeEvents()) { + 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; + currPixelTime = nextEvent.getTime(); + } + } + + // state name + String stateTypeName = _utilImp.getStateTypeName(entry); + String entryName = entry.getName(); + if (stateTypeName == null) { + stateTypeName = _utilImp.getStateTypeName(); + } + + if (!entryName.isEmpty()) { + addItem(stateTypeName, entry.getName()); + } + + if (currEvent == null) { + return; + } + + // 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(currEvent, currPixelTime); + if (eventAddOns != null) { + for (Iterator iter = eventAddOns.keySet().iterator(); iter.hasNext();) { + String message = iter.next(); + addItem(message, eventAddOns.get(message)); + } + } + + long eventStartTime = -1; + long eventDuration = -1; + long eventEndTime = -1; + + eventStartTime = currEvent.getTime(); + eventDuration = currEvent.getDuration(); + if (eventDuration < 0 && nextEvent != null) { + eventEndTime = nextEvent.getTime(); + eventDuration = eventEndTime - eventStartTime; + } else { + eventEndTime = eventStartTime + eventDuration; + } + + Resolution res = Resolution.NANOSEC; + if (_timeDataProvider.isCalendarFormat()) { + addItem(Messages.TmfTimeTipHandler_TRACE_DATE, eventStartTime > -1 ? + Utils.formatDate(eventStartTime) + : "?"); //$NON-NLS-1$ + if (eventDuration > 0) { + addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ? + Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res) + : "?"); //$NON-NLS-1$ + + addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ? + Utils.formatTime(eventEndTime, TimeFormat.ABSOLUTE, res) + : "?"); //$NON-NLS-1$ + } else { + addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ? + Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res) + : "?"); //$NON-NLS-1$ + } + } else { + if (eventDuration > 0) { + addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ? + Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res) + : "?"); //$NON-NLS-1$ + + addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ? + Utils.formatTime(eventEndTime, TimeFormat.RELATIVE, res) + : "?"); //$NON-NLS-1$ + } else { + addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ? + Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res) + : "?"); //$NON-NLS-1$ + } + } + + if (eventDuration > 0) { + // Duration in relative format in any case + addItem(Messages.TmfTimeTipHandler_DURATION, eventDuration > -1 ? + Utils.formatTime(eventDuration, TimeFormat.RELATIVE, res) + : "?"); //$NON-NLS-1$ + } + } + } + + @Override + public void mouseHover(MouseEvent event) { + Point pt = new Point(event.x, event.y); + TimeGraphControl timeGraphControl = (TimeGraphControl) event.widget; + createTooltipShell(timeGraphControl.getShell()); + ITimeGraphEntry entry = timeGraphControl.getEntry(pt); + for (Control child : _tipComposite.getChildren()) { + child.dispose(); + } + fillValues(pt, timeGraphControl, entry); + if (_tipComposite.getChildren().length == 0) { + return; + } + _tipShell.pack(); + _tipPosition = control.toDisplay(pt); + _tipShell.pack(); + setHoverLocation(_tipShell, _tipPosition); + _tipShell.setVisible(true); + } + }); + } + + private static void setHoverLocation(Shell shell, Point position) { + Rectangle displayBounds = shell.getDisplay().getBounds(); + Rectangle shellBounds = shell.getBounds(); + 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); + } + + private void setupControl(Control control) { + control.setForeground(_tipShell.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); + control.setBackground(_tipShell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + + control.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + _tipShell.dispose(); + } + }); + + control.addMouseTrackListener(new MouseTrackAdapter() { + @Override + public void mouseExit(MouseEvent e) { + _tipShell.dispose(); + } + }); + + control.addMouseMoveListener(new MouseMoveListener() { + @Override + public void mouseMove(MouseEvent e) { + _tipShell.dispose(); + } + }); + } } -- 2.34.1