tmf/lttng: Remove unneeded (non-Javadoc) comments
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / FullTraceHistogram.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 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.ui.views.histogram;
15
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.MouseEvent;
18 import org.eclipse.swt.events.MouseMoveListener;
19 import org.eclipse.swt.events.PaintEvent;
20 import org.eclipse.swt.graphics.Color;
21 import org.eclipse.swt.graphics.GC;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Display;
25
26 /**
27 * A histogram widget that displays the event distribution of a whole trace.
28 * <p>
29 * It also features a selected range window that can be dragged and zoomed.
30 *
31 * @version 1.1
32 * @author Francois Chouinard
33 */
34 public class FullTraceHistogram extends Histogram implements MouseMoveListener {
35
36 // ------------------------------------------------------------------------
37 // Constants
38 // ------------------------------------------------------------------------
39
40 // Histogram colors
41 private final Color fTimeRangeColor = new Color(Display.getCurrent(), 255, 128, 0);
42
43 // ------------------------------------------------------------------------
44 // Attributes
45 // ------------------------------------------------------------------------
46
47 private final HistogramZoom fZoom;
48
49 private long fRangeStartTime = 0L;
50 private long fRangeDuration;
51
52 // ------------------------------------------------------------------------
53 // Construction
54 // ------------------------------------------------------------------------
55
56 /**
57 * Full Constructor
58 *
59 * @param view A reference to the parent histogram view
60 * @param parent A reference to the parent composite
61 */
62 public FullTraceHistogram(HistogramView view, Composite parent) {
63 super(view, parent);
64 fZoom = new HistogramZoom(this, fCanvas, getStartTime(), getTimeLimit());
65 fCanvas.addMouseMoveListener(this);
66 }
67
68 @Override
69 public void dispose() {
70 fTimeRangeColor.dispose();
71 super.dispose();
72 }
73
74 // ------------------------------------------------------------------------
75 // Operations
76 // ------------------------------------------------------------------------
77
78 @Override
79 public void clear() {
80 fRangeStartTime = 0L;
81 fRangeDuration = 0L;
82 if (fZoom != null) {
83 fZoom.setFullRange(0L, 0L);
84 fZoom.setNewRange(0L, 0L);
85 }
86 super.clear();
87 }
88
89 /**
90 * Sets the time range of the full histogram.
91 *
92 * @param startTime A start time
93 * @param endTime A end time
94 */
95 public void setFullRange(long startTime, long endTime) {
96 fZoom.setFullRange(startTime, endTime);
97 }
98
99 /**
100 * Sets the selected time range.
101 *
102 * @param startTime The histogram start time
103 * @param duration The histogram duration
104 */
105 public void setTimeRange(long startTime, long duration) {
106 fRangeStartTime = startTime;
107 fRangeDuration = duration;
108 fZoom.setNewRange(fRangeStartTime, fRangeDuration);
109 fDataModel.complete();
110 }
111
112 @Override
113 public void updateTimeRange(long startTime, long endTime) {
114 ((HistogramView) fParentView).updateTimeRange(startTime, endTime);
115 }
116
117 // ------------------------------------------------------------------------
118 // MouseListener
119 // ------------------------------------------------------------------------
120
121 private boolean fMouseDown;
122 private int fStartPosition;
123
124 @Override
125 public void mouseDown(MouseEvent event) {
126 fMouseDown = true;
127 fStartPosition = event.x;
128 }
129
130 @Override
131 public void mouseUp(MouseEvent event) {
132 if (fMouseDown) {
133 fMouseDown = false;
134 // Check if mouse click without move; if so, just set the current event time
135 if (event.x == fStartPosition) {
136 super.mouseDown(event);
137 return;
138 }
139
140 ((HistogramView) fParentView).updateTimeRange(fRangeStartTime, fRangeStartTime + fRangeDuration);
141
142 }
143 }
144
145
146 // ------------------------------------------------------------------------
147 // MouseMoveListener
148 // ------------------------------------------------------------------------
149
150 @Override
151 public void mouseMove(MouseEvent event) {
152
153 if (fMouseDown) {
154 int nbBuckets = event.x - fStartPosition;
155 long delta = nbBuckets * fScaledData.fBucketDuration;
156 long newStart = fZoom.getStartTime() + delta;
157 if (newStart < getStartTime()) {
158 newStart = getStartTime();
159 }
160 long newEnd = newStart + fZoom.getDuration();
161 if (newEnd > getEndTime()) {
162 newEnd = getEndTime();
163 newStart = newEnd - fZoom.getDuration();
164 }
165 fRangeStartTime = newStart;
166 fDataModel.complete();
167 }
168 }
169
170 // ------------------------------------------------------------------------
171 // PaintListener
172 // ------------------------------------------------------------------------
173
174 @Override
175 public void paintControl(PaintEvent event) {
176 super.paintControl(event);
177
178 Image image = (Image) fCanvas.getData(IMAGE_KEY);
179 assert image != null;
180
181 Image rangeRectangleImage = new Image(image.getDevice(), image, SWT.IMAGE_COPY);
182 GC rangeWindowGC = new GC(rangeRectangleImage);
183
184 if ((fScaledData != null) && (fRangeStartTime != 0)) {
185 drawTimeRangeWindow(rangeWindowGC);
186 }
187
188 // Draws the buffer image onto the canvas.
189 event.gc.drawImage(rangeRectangleImage, 0, 0);
190
191 rangeWindowGC.dispose();
192 rangeRectangleImage.dispose();
193 }
194
195 private void drawTimeRangeWindow(GC imageGC) {
196
197 // Map times to histogram coordinates
198 long bucketSpan = Math.max(fScaledData.fBucketDuration, 1);
199 int rangeWidth = (int) (fRangeDuration / bucketSpan);
200
201 int left = (int) ((fRangeStartTime - fDataModel.getFirstBucketTime()) / bucketSpan);
202 int right = left + rangeWidth;
203 int center = (left + right) / 2;
204 int height = fCanvas.getSize().y;
205
206 // Draw the selection window
207 imageGC.setForeground(fTimeRangeColor);
208 imageGC.setLineWidth(1);
209 imageGC.setLineStyle(SWT.LINE_SOLID);
210 imageGC.drawRoundRectangle(left, 0, rangeWidth, height - 1, 15, 15);
211
212 // Fill the selection window
213 imageGC.setBackground(fTimeRangeColor);
214 imageGC.setAlpha(35);
215 imageGC.fillRoundRectangle(left + 1, 1, rangeWidth - 1, height - 2, 15, 15);
216 imageGC.setAlpha(255);
217
218 // Draw the cross hair
219 imageGC.setForeground(fTimeRangeColor);
220 imageGC.setLineWidth(1);
221 imageGC.setLineStyle(SWT.LINE_SOLID);
222
223 int chHalfWidth = ((rangeWidth < 60) ? (rangeWidth * 2) / 3 : 40) / 2;
224 imageGC.drawLine(center - chHalfWidth, height / 2, center + chHalfWidth, height / 2);
225 imageGC.drawLine(center, (height / 2) - chHalfWidth, center, (height / 2) + chHalfWidth);
226 }
227
228 }
This page took 0.037747 seconds and 6 git commands to generate.