1 /**********************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.xycharts
;
14 import org
.eclipse
.swt
.events
.MouseEvent
;
15 import org
.eclipse
.swt
.events
.MouseTrackListener
;
16 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
17 import org
.swtchart
.IAxis
;
20 * Tool tip provider for TMF chart viewer. It displays the x and y
21 * value of the current mouse position.
23 * @author Bernd Hufmann
25 public class TmfSimpleTooltipProvider
extends TmfBaseProvider
implements MouseTrackListener
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
31 * Constructor for a tool tip provider.
33 * @param tmfChartViewer
34 * The parent chart viewer
36 public TmfSimpleTooltipProvider(ITmfChartTimeProvider tmfChartViewer
) {
37 super(tmfChartViewer
);
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 public void register() {
46 getChart().getPlotArea().addMouseTrackListener(this);
50 public void deregister() {
51 if ((getChartViewer().getControl() != null) && !getChartViewer().getControl().isDisposed()) {
52 getChart().getPlotArea().removeMouseTrackListener(this);
57 public void refresh() {
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 public void mouseEnter(MouseEvent e
) {
69 public void mouseExit(MouseEvent e
) {
73 public void mouseHover(MouseEvent e
) {
74 if (getChartViewer().getWindowDuration() == 0) {
78 IAxis xAxis
= getChart().getAxisSet().getXAxis(0);
79 IAxis yAxis
= getChart().getAxisSet().getYAxis(0);
81 double xCoordinate
= xAxis
.getDataCoordinate(e
.x
);
82 double yCoordinate
= yAxis
.getDataCoordinate(e
.y
);
84 ITmfChartTimeProvider viewer
= getChartViewer();
86 /* set tooltip of current data point */
87 StringBuffer buffer
= new StringBuffer();
88 buffer
.append("x="); //$NON-NLS-1$
89 buffer
.append(TmfTimestamp
.fromNanos((long) xCoordinate
+ viewer
.getTimeOffset()).toString());
90 buffer
.append("\n"); //$NON-NLS-1$
91 buffer
.append("y="); //$NON-NLS-1$
92 buffer
.append((long) yCoordinate
);
93 getChart().getPlotArea().setToolTipText(buffer
.toString());