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