1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 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 * 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
.lttng
.ui
.views
.latency
;
16 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.latency
.listeners
.HistogramPaintListener
;
17 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.latency
.listeners
.TooltipListener
;
18 import org
.eclipse
.linuxtools
.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
;
26 * <b><u>HistogramViewer</u></b>
31 * @author Philippe Sawicki
33 public class HistogramViewer
extends AbstractViewer
implements IHistogramModelListener
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
40 * Usable width for data plotting.
42 protected int fUsableWidth
;
45 * Latency histogram model.
47 private HistogramDataModel fModel
;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
55 * @param parent The parent composite node.
56 * @param style The SWT style to use to render the view.
58 public HistogramViewer(Composite parent
, int style
) {
61 // Register the paint listener
62 fPaintListener
= new HistogramPaintListener(this);
63 addPaintListener(fPaintListener
);
65 // Register the zoom listener
66 fZoomListener
= new ZoomListener(this);
67 addListener(SWT
.MouseWheel
, fZoomListener
);
69 // Register the mouse click listener
70 fMouseTraceListener
= new TooltipListener(this, (HistogramPaintListener
)fPaintListener
);
71 addMouseTrackListener(fMouseTraceListener
);
73 fModel
= new HistogramDataModel();
74 fModel
.addHistogramListener(this);
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
83 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#dispose()
86 public void dispose() {
87 fModel
.removeHistogramListener(this);
88 fPaintListener
.dispose();
94 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#clear()
98 fPaintListener
.clear();
103 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#clearBackground()
106 public void clearBackground() {
107 fPaintListener
.clear();
112 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#increaseBarWidth()
115 public void increaseBarWidth() {
116 fPaintListener
.increaseBarWitdh();
122 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#decreaseBarWidth()
125 public void decreaseBarWidth() {
126 fPaintListener
.decreaseBarWitdh();
132 * @see org.eclipse.linuxtools.lttng.ui.views.latency.AbstractViewer#getModel()
135 public IHistogramDataModel
getModel() {
141 * @see org.eclipse.linuxtools.lttng.ui.views.histogram.IHistogramModelListener#modelUpdated()
144 public void modelUpdated() {
146 if (!isDisposed() && getDisplay() != null) {
147 getDisplay().asyncExec(new Runnable() {