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
.linuxtools
.tmf
.ui
.viewers
.xycharts
;
14 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
16 import org
.eclipse
.swt
.events
.MouseEvent
;
17 import org
.eclipse
.swt
.events
.MouseTrackListener
;
18 import org
.swtchart
.IAxis
;
21 * Tool tip provider for TMF chart viewer. It displays the x and y
22 * value of the current mouse position.
24 * @author Bernd Hufmann
27 public class TmfSimpleTooltipProvider
extends TmfBaseProvider
implements MouseTrackListener
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 * Constructor for a tool tip provider.
35 * @param tmfChartViewer
36 * The parent chart viewer
38 public TmfSimpleTooltipProvider(ITmfChartTimeProvider tmfChartViewer
) {
39 super(tmfChartViewer
);
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 public void register() {
48 getChart().getPlotArea().addMouseTrackListener(this);
52 public void deregister() {
53 if ((getChartViewer().getControl() != null) && !getChartViewer().getControl().isDisposed()) {
54 getChart().getPlotArea().removeMouseTrackListener(this);
59 public void refresh() {
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
67 public void mouseEnter(MouseEvent e
) {
71 public void mouseExit(MouseEvent e
) {
75 public void mouseHover(MouseEvent e
) {
76 if (getChartViewer().getWindowDuration() == 0) {
80 IAxis xAxis
= getChart().getAxisSet().getXAxis(0);
81 IAxis yAxis
= getChart().getAxisSet().getYAxis(0);
83 double xCoordinate
= xAxis
.getDataCoordinate(e
.x
);
84 double yCoordinate
= yAxis
.getDataCoordinate(e
.y
);
86 ITmfChartTimeProvider viewer
= getChartViewer();
88 /* set tooltip of current data point */
89 StringBuffer buffer
= new StringBuffer();
90 buffer
.append("x="); //$NON-NLS-1$
91 buffer
.append(new TmfTimestamp((long) xCoordinate
+ viewer
.getTimeOffset(), ITmfTimestamp
.NANOSECOND_SCALE
).toString());
92 buffer
.append("\n"); //$NON-NLS-1$
93 buffer
.append("y="); //$NON-NLS-1$
94 buffer
.append((long) yCoordinate
);
95 getChart().getPlotArea().setToolTipText(buffer
.toString());