ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / xycharts / TmfSimpleTooltipProvider.java
CommitLineData
5791dcef 1/**********************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 Ericsson
5791dcef
BH
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12package org.eclipse.linuxtools.tmf.ui.viewers.xycharts;
13
14import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
15import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
16import org.eclipse.swt.events.MouseEvent;
17import org.eclipse.swt.events.MouseTrackListener;
18import org.swtchart.IAxis;
19
20/**
21 * Tool tip provider for TMF chart viewer. It displays the x and y
22 * value of the current mouse position.
23 *
24 * @author Bernd Hufmann
25 * @since 3.0
26 */
27public class TmfSimpleTooltipProvider extends TmfBaseProvider implements MouseTrackListener {
28
29 // ------------------------------------------------------------------------
30 // Constructors
31 // ------------------------------------------------------------------------
32 /**
33 * Constructor for a tool tip provider.
34 *
35 * @param tmfChartViewer
36 * The parent chart viewer
37 */
38 public TmfSimpleTooltipProvider(ITmfChartTimeProvider tmfChartViewer) {
39 super(tmfChartViewer);
40 register();
41 }
42
43 // ------------------------------------------------------------------------
44 // TmfBaseProvider
45 // ------------------------------------------------------------------------
46 @Override
47 public void register() {
48 getChart().getPlotArea().addMouseTrackListener(this);
49 }
50
51 @Override
52 public void deregister() {
53 if ((getChartViewer().getControl() != null) && !getChartViewer().getControl().isDisposed()) {
54 getChart().getPlotArea().removeMouseTrackListener(this);
55 }
56 }
57
58 @Override
59 public void refresh() {
60 // nothing to do
61 }
62
63 // ------------------------------------------------------------------------
64 // MouseTrackListener
65 // ------------------------------------------------------------------------
66 @Override
67 public void mouseEnter(MouseEvent e) {
68 }
69
70 @Override
71 public void mouseExit(MouseEvent e) {
72 }
73
74 @Override
75 public void mouseHover(MouseEvent e) {
76 if (getChartViewer().getWindowDuration() == 0) {
77 return;
78 }
79
80 IAxis xAxis = getChart().getAxisSet().getXAxis(0);
81 IAxis yAxis = getChart().getAxisSet().getYAxis(0);
82
83 double xCoordinate = xAxis.getDataCoordinate(e.x);
84 double yCoordinate = yAxis.getDataCoordinate(e.y);
85
86 ITmfChartTimeProvider viewer = getChartViewer();
87
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());
96 }
97}
This page took 0.046078 seconds and 5 git commands to generate.