analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / 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 **********************************************************************/
2bdf0193 12package org.eclipse.tracecompass.tmf.ui.viewers.xycharts;
5791dcef 13
5791dcef
BH
14import org.eclipse.swt.events.MouseEvent;
15import org.eclipse.swt.events.MouseTrackListener;
2bdf0193
AM
16import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
17import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
5791dcef
BH
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
5791dcef
BH
25 */
26public class TmfSimpleTooltipProvider extends TmfBaseProvider implements MouseTrackListener {
27
28 // ------------------------------------------------------------------------
29 // Constructors
30 // ------------------------------------------------------------------------
31 /**
32 * Constructor for a tool tip provider.
33 *
34 * @param tmfChartViewer
35 * The parent chart viewer
36 */
37 public TmfSimpleTooltipProvider(ITmfChartTimeProvider tmfChartViewer) {
38 super(tmfChartViewer);
39 register();
40 }
41
42 // ------------------------------------------------------------------------
43 // TmfBaseProvider
44 // ------------------------------------------------------------------------
45 @Override
46 public void register() {
47 getChart().getPlotArea().addMouseTrackListener(this);
48 }
49
50 @Override
51 public void deregister() {
52 if ((getChartViewer().getControl() != null) && !getChartViewer().getControl().isDisposed()) {
53 getChart().getPlotArea().removeMouseTrackListener(this);
54 }
55 }
56
57 @Override
58 public void refresh() {
59 // nothing to do
60 }
61
62 // ------------------------------------------------------------------------
63 // MouseTrackListener
64 // ------------------------------------------------------------------------
65 @Override
66 public void mouseEnter(MouseEvent e) {
67 }
68
69 @Override
70 public void mouseExit(MouseEvent e) {
71 }
72
73 @Override
74 public void mouseHover(MouseEvent e) {
75 if (getChartViewer().getWindowDuration() == 0) {
76 return;
77 }
78
79 IAxis xAxis = getChart().getAxisSet().getXAxis(0);
80 IAxis yAxis = getChart().getAxisSet().getYAxis(0);
81
82 double xCoordinate = xAxis.getDataCoordinate(e.x);
83 double yCoordinate = yAxis.getDataCoordinate(e.y);
84
85 ITmfChartTimeProvider viewer = getChartViewer();
86
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());
95 }
96}
This page took 0.080994 seconds and 5 git commands to generate.