Internalize lttng.ui APIs
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / views / latency / HistogramViewer.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 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 * Contributors:
10 * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11 * Mathieu Denis (mathieu.denis55@gmail.com) - Refactored code
12 * Bernd Hufmann - Adapted to new model-view-controller design
13 *******************************************************************************/
14 package org.eclipse.linuxtools.internal.lttng.ui.views.latency;
15
16 import org.eclipse.linuxtools.internal.lttng.ui.views.latency.listeners.HistogramPaintListener;
17 import org.eclipse.linuxtools.internal.lttng.ui.views.latency.listeners.TooltipListener;
18 import org.eclipse.linuxtools.internal.lttng.ui.views.latency.listeners.ZoomListener;
19 import org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramDataModel;
20 import org.eclipse.linuxtools.tmf.ui.views.histogram.IHistogramDataModel;
21 import org.eclipse.linuxtools.tmf.ui.views.histogram.IHistogramModelListener;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.widgets.Composite;
24
25 /**
26 * <b><u>HistogramViewer</u></b>
27 * <p>
28 *
29 * Histogram viewer.
30 *
31 * @author Philippe Sawicki
32 */
33 public class HistogramViewer extends AbstractViewer implements IHistogramModelListener {
34
35 // ------------------------------------------------------------------------
36 // Attributes
37 // ------------------------------------------------------------------------
38
39 /**
40 * Usable width for data plotting.
41 */
42 protected int fUsableWidth;
43
44 /**
45 * Latency histogram model.
46 */
47 private HistogramDataModel fModel;
48
49 // ------------------------------------------------------------------------
50 // Constructors
51 // ------------------------------------------------------------------------
52
53 /**
54 * Constructor.
55 * @param parent The parent composite node.
56 * @param style The SWT style to use to render the view.
57 */
58 public HistogramViewer(Composite parent, int style) {
59 super(parent, style);
60
61 // Register the paint listener
62 fPaintListener = new HistogramPaintListener(this);
63 addPaintListener(fPaintListener);
64
65 // Register the zoom listener
66 fZoomListener = new ZoomListener(this);
67 addListener(SWT.MouseWheel, fZoomListener);
68
69 // Register the mouse click listener
70 fMouseTraceListener = new TooltipListener(this, (HistogramPaintListener)fPaintListener);
71 addMouseTrackListener(fMouseTraceListener);
72
73 fModel = new HistogramDataModel();
74 fModel.addHistogramListener(this);
75 }
76
77 // ------------------------------------------------------------------------
78 // Operations
79 // ------------------------------------------------------------------------
80
81 /*
82 * (non-Javadoc)
83 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#dispose()
84 */
85 @Override
86 public void dispose() {
87 fModel.removeHistogramListener(this);
88 fPaintListener.dispose();
89 super.dispose();
90 }
91
92 /*
93 * (non-Javadoc)
94 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#clear()
95 */
96 @Override
97 public void clear() {
98 fPaintListener.clear();
99 }
100
101 /*
102 * (non-Javadoc)
103 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#clearBackground()
104 */
105 @Override
106 public void clearBackground() {
107 fPaintListener.clear();
108 }
109
110 /*
111 * (non-Javadoc)
112 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#increaseBarWidth()
113 */
114 @Override
115 public void increaseBarWidth() {
116 fPaintListener.increaseBarWitdh();
117 modelUpdated();
118 }
119
120 /*
121 * (non-Javadoc)
122 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#decreaseBarWidth()
123 */
124 @Override
125 public void decreaseBarWidth() {
126 fPaintListener.decreaseBarWitdh();
127 modelUpdated();
128 }
129
130 /*
131 * (non-Javadoc)
132 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#getModel()
133 */
134 @Override
135 public IHistogramDataModel getModel() {
136 return fModel;
137 }
138
139 /*
140 * (non-Javadoc)
141 * @see org.eclipse.linuxtools.lttng.ui.views.histogram.IHistogramModelListener#modelUpdated()
142 */
143 @Override
144 public void modelUpdated() {
145
146 if (!isDisposed() && getDisplay() != null) {
147 getDisplay().asyncExec(new Runnable() {
148 @Override
149 public void run() {
150 if (!isDisposed()) {
151 redraw();
152 }
153 }
154 });
155 }
156 }
157 }
This page took 0.033114 seconds and 5 git commands to generate.