analysis: no longer call overridable methods from constructors
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.ui / src / org / eclipse / tracecompass / internal / analysis / timing / ui / views / segmentstore / density / SimpleTooltipProvider.java
1 /**********************************************************************
2 * Copyright (c) 2015, 2016 Ericsson
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 package org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.density;
10
11 import java.text.Format;
12 import java.text.MessageFormat;
13
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.eclipse.swt.events.MouseEvent;
16 import org.eclipse.swt.events.MouseTrackListener;
17 import org.eclipse.swt.graphics.Rectangle;
18 import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.SubSecondTimeWithUnitFormat;
19 import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.density.AbstractSegmentStoreDensityViewer;
20 import org.swtchart.IAxis;
21 import org.swtchart.IBarSeries;
22 import org.swtchart.ISeries;
23
24 /**
25 * Tool tip provider for density viewer. It displays the x and y value of the
26 * current mouse position.
27 *
28 * @author Bernd Hufmann
29 * @author Marc-Andre Laperle
30 */
31 public class SimpleTooltipProvider extends BaseMouseProvider implements MouseTrackListener {
32
33 private static final Format FORMAT = new SubSecondTimeWithUnitFormat();
34
35 /**
36 * Constructor for a tool tip provider.
37 *
38 * @param densityViewer
39 * The parent density viewer
40 */
41 public SimpleTooltipProvider(AbstractSegmentStoreDensityViewer densityViewer) {
42 super(densityViewer);
43 register();
44 }
45
46 @Override
47 public final void register() {
48 getChart().getPlotArea().addMouseTrackListener(this);
49 }
50
51 @Override
52 public final void deregister() {
53 if (!getChart().isDisposed()) {
54 getChart().getPlotArea().removeMouseTrackListener(this);
55 }
56 }
57
58 @Override
59 public void mouseEnter(@Nullable MouseEvent e) {
60 }
61
62 @Override
63 public void mouseExit(@Nullable MouseEvent e) {
64 }
65
66 @Override
67 public void mouseHover(@Nullable MouseEvent e) {
68 if (e == null || getChart().getAxisSet().getXAxes().length == 0 || getChart().getAxisSet().getYAxes().length == 0 || getDensityViewer().getControl().getSeriesSet().getSeries().length == 0) {
69 return;
70 }
71 ISeries series = getDensityViewer().getControl().getSeriesSet().getSeries()[0];
72 getChart().getPlotArea().setToolTipText(null);
73 if (series instanceof IBarSeries) {
74 IBarSeries barSeries = (IBarSeries) series;
75 // Note: getBounds is broken in SWTChart 0.9.0
76 Rectangle[] bounds = barSeries.getBounds();
77
78 if (barSeries.getXSeries().length < 2) {
79 return;
80 }
81 double delta = barSeries.getXSeries()[1] - barSeries.getXSeries()[0];
82 for (int i = 0; i < bounds.length; i++) {
83 Rectangle rec = bounds[i];
84 if (rec == null) {
85 continue;
86 }
87 int start = rec.x;
88 int end = start + rec.width;
89 if (e.x >= start && e.x <= end) {
90 long x1 = (long) barSeries.getXSeries()[i];
91 long x2 = (long) (x1 + delta);
92 IAxis yAxis = getChart().getAxisSet().getYAxes()[0];
93 long y = Math.round(yAxis.getDataCoordinate(rec.y)) - 1;
94 if (y > 0) {
95 String toolTipText = MessageFormat.format(Messages.SimpleTooltipProvider_toolTipText, FORMAT.format(x1), FORMAT.format(x2), y);
96 getChart().getPlotArea().setToolTipText(toolTipText);
97 }
98 break;
99 }
100 }
101 }
102 }
103 }
This page took 0.035791 seconds and 5 git commands to generate.