Merge remote-tracking branch 'eclipse/master' into luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / TimeRangeHistogram.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Changed to updated histogram data model
12 * Francois Chouinard - Moved from LTTng to TMF
13 * Patrick Tasse - Update for mouse wheel zoom
14 *******************************************************************************/
15
16 package org.eclipse.linuxtools.tmf.ui.views.histogram;
17
18 import org.eclipse.swt.widgets.Composite;
19
20 /**
21 * A basic histogram widget that displays the event distribution of a specific time range of a trace.
22 * It has the following additional features:
23 * <ul>
24 * <li>zoom in: mouse wheel up (or forward)
25 * <li>zoom out: mouse wheel down (or backward)
26 * </ul>
27 *
28 * @version 1.1
29 * @author Francois Chouinard
30 */
31 public class TimeRangeHistogram extends Histogram {
32
33 // ------------------------------------------------------------------------
34 // Attributes
35 // ------------------------------------------------------------------------
36
37 private HistogramZoom fZoom = null;
38
39 // ------------------------------------------------------------------------
40 // Constructor
41 // ------------------------------------------------------------------------
42 /**
43 * Constructor
44 * @param view The parent histogram view
45 * @param parent The parent composite
46 */
47 public TimeRangeHistogram(HistogramView view, Composite parent) {
48 super(view, parent);
49 fZoom = new HistogramZoom(this, getStartTime(), getTimeLimit());
50 addMouseWheelListener(fZoom);
51 }
52
53 // ------------------------------------------------------------------------
54 // Operations
55 // ------------------------------------------------------------------------
56
57 @Override
58 public void updateTimeRange(long startTime, long endTime) {
59 ((HistogramView) fParentView).updateTimeRange(startTime, endTime);
60 }
61
62 @Override
63 public synchronized void clear() {
64 if (fZoom != null) {
65 fZoom.setFullRange(0L, 0L);
66 fZoom.setNewRange(0L, 0L);
67 }
68 super.clear();
69 }
70
71 /**
72 * Sets the time range of the histogram
73 * @param startTime The start time
74 * @param duration The duration of the time range
75 */
76 public synchronized void setTimeRange(long startTime, long duration) {
77 fZoom.setNewRange(startTime, duration);
78 if (getDataModel().getNbEvents() == 0) {
79 getDataModel().setTimeRange(startTime, startTime + duration);
80 }
81 }
82
83 /**
84 * Sets the full time range of the whole trace.
85 * @param startTime The start time
86 * @param endTime The end time
87 */
88 public void setFullRange(long startTime, long endTime) {
89 long currentFirstEvent = getStartTime();
90 fZoom.setFullRange((currentFirstEvent == 0) ? startTime : currentFirstEvent, endTime);
91 }
92
93 }
This page took 0.033718 seconds and 5 git commands to generate.