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
.ITmfTimestamp
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
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
26 public class TmfSimpleTooltipProvider
extends TmfBaseProvider
implements MouseTrackListener
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 * Constructor for a tool tip provider.
34 * @param tmfChartViewer
35 * The parent chart viewer
37 public TmfSimpleTooltipProvider(ITmfChartTimeProvider tmfChartViewer
) {
38 super(tmfChartViewer
);
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 public void register() {
47 getChart().getPlotArea().addMouseTrackListener(this);
51 public void deregister() {
52 if ((getChartViewer().getControl() != null) && !getChartViewer().getControl().isDisposed()) {
53 getChart().getPlotArea().removeMouseTrackListener(this);
58 public void refresh() {
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 public void mouseEnter(MouseEvent e
) {
70 public void mouseExit(MouseEvent e
) {
74 public void mouseHover(MouseEvent e
) {
75 if (getChartViewer().getWindowDuration() == 0) {
79 IAxis xAxis
= getChart().getAxisSet().getXAxis(0);
80 IAxis yAxis
= getChart().getAxisSet().getYAxis(0);
82 double xCoordinate
= xAxis
.getDataCoordinate(e
.x
);
83 double yCoordinate
= yAxis
.getDataCoordinate(e
.y
);
85 ITmfChartTimeProvider viewer
= getChartViewer();
87 /* set tooltip of current data point */
88 StringBuffer buffer
= new StringBuffer();
89 buffer
.append("x="); //$NON-NLS-1$
90 buffer
.append(new TmfTimestamp((long) xCoordinate
+ viewer
.getTimeOffset(), ITmfTimestamp
.NANOSECOND_SCALE
).toString());
91 buffer
.append("\n"); //$NON-NLS-1$
92 buffer
.append("y="); //$NON-NLS-1$
93 buffer
.append((long) yCoordinate
);
94 getChart().getPlotArea().setToolTipText(buffer
.toString());