tmf: Update some Javadoc in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / timechart / TimeChartEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2010 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.timechart;
14
15 import java.util.ArrayList;
16 import java.util.Iterator;
17
18 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
19 import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;
20 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
21 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
22
23 /**
24 * Event in the time chart view
25 *
26 * @version 1.0
27 * @author Patrick Tasse
28 */
29 public class TimeChartEvent implements ITimeEvent {
30
31 private static final byte TIMESTAMP_SCALE = -9;
32
33 private final TimeChartAnalysisEntry fParentEntry;
34 private long fTime;
35 private long fDuration;
36 private long fFirstRank;
37 private long fLastRank;
38 private final RankRangeList fRankRangeList;
39 private long fNbEvents;
40 private int fColorSettingPriority;
41 private boolean fIsBookmark;
42 private boolean fIsVisible;
43 private boolean fIsSearchMatch;
44 private TimeChartAnalysisEntry fItemizedEntry;
45 private boolean fItemizing;
46
47 /**
48 * Standard constructor
49 *
50 * @param parentEntry
51 * The parent entry
52 * @param event
53 * The event from which this time chart event originates
54 * @param rank
55 * The rank of the event in the trace
56 * @param decorationProvider
57 * The decoration provider to use
58 */
59 public TimeChartEvent(TimeChartAnalysisEntry parentEntry, ITmfEvent event,
60 long rank, TimeChartDecorationProvider decorationProvider) {
61 fParentEntry = parentEntry;
62 fTime = event.getTimestamp().normalize(0, TIMESTAMP_SCALE).getValue();
63 fDuration = 0;
64 fFirstRank = fLastRank = rank;
65 fRankRangeList = new RankRangeList(rank);
66 fNbEvents = 1;
67 fColorSettingPriority = ColorSettingsManager.getColorSettingPriority(event);
68 fIsBookmark = decorationProvider.isBookmark(rank);
69 fIsVisible = decorationProvider.isVisible(event);
70 fIsSearchMatch = decorationProvider.isSearchMatch(event);
71 }
72
73 @Override
74 public ITimeGraphEntry getEntry() {
75 return fParentEntry;
76 }
77
78 @Override
79 public long getTime() {
80 return fTime;
81 }
82
83 @Override
84 public long getDuration() {
85 return fDuration;
86 }
87
88 /**
89 * Retrieve the rank of the trace event which started this time event.
90 *
91 * @return The rank of the beginning
92 */
93 public long getFirstRank() {
94 return fFirstRank;
95 }
96
97 /**
98 * Retrieve the rank of the trace event which *finished* this time event.
99 *
100 * @return The rank of the end
101 */
102 public long getLastRank() {
103 return fLastRank;
104 }
105
106 /**
107 * Get the list of rank ranges corresponding to this time event.
108 *
109 * @return The rank range list
110 */
111 public RankRangeList getRankRangeList() {
112 return fRankRangeList;
113 }
114
115 /**
116 * Merge another time event with this one.
117 *
118 * @param event
119 * The other event
120 */
121 public void merge(TimeChartEvent event) {
122 mergeDecorations(event);
123 if (fTime == event.getTime() && fDuration == event.getDuration()) {
124 return;
125 }
126 long endTime = Math.max(fTime + fDuration, event.getTime() + event.getDuration());
127 fTime = Math.min(fTime, event.getTime());
128 fDuration = endTime - fTime;
129 fFirstRank = Math.min(fFirstRank, event.fFirstRank);
130 fLastRank = Math.max(fLastRank, event.fLastRank);
131 fNbEvents += event.fNbEvents;
132 fItemizedEntry = null;
133 synchronized (fRankRangeList) {
134 fRankRangeList.merge(event.getRankRangeList());
135 }
136 }
137
138 /**
139 * Merge the decorations of another time event with the decorations of this
140 * one.
141 *
142 * @param event
143 * The other event
144 */
145 public void mergeDecorations(TimeChartEvent event) {
146 fColorSettingPriority = Math.min(fColorSettingPriority, event.getColorSettingPriority());
147 fIsBookmark |= event.fIsBookmark;
148 fIsVisible |= event.fIsVisible;
149 fIsSearchMatch |= event.fIsSearchMatch;
150 }
151
152 /**
153 * Get the number of time events that have been merged with this one (starts
154 * counting at 1 if no merge happened).
155 *
156 * @return The current number of events in the bath
157 */
158 public long getNbEvents() {
159 return fNbEvents;
160 }
161
162 /**
163 * Retrieve the color setting priority.
164 *
165 * @return The priority
166 */
167 public int getColorSettingPriority() {
168 return fColorSettingPriority;
169 }
170
171 /**
172 * Set the color setting priority.
173 *
174 * @param priority
175 * The priority to set
176 */
177 public void setColorSettingPriority(int priority) {
178 fColorSettingPriority = priority;
179 }
180
181 /**
182 * Check if this time event is bookmarked
183 *
184 * @return Y/N
185 */
186 public boolean isBookmarked() {
187 return fIsBookmark;
188 }
189
190 /**
191 * Set this time event to be bookmarked or not.
192 *
193 * @param isBookmarked
194 * Should time time event become a bookmark, or not
195 */
196 public void setIsBookmarked(boolean isBookmarked) {
197 fIsBookmark = isBookmarked;
198 }
199
200 /**
201 * Check if this time is currently visible or not.
202 *
203 * @return If the event is visible
204 */
205 public boolean isVisible() {
206 return fIsVisible;
207 }
208
209 /**
210 * Set this time event to visible (or to non-visible).
211 *
212 * @param isVisible The new status
213 */
214 public void setIsVisible(boolean isVisible) {
215 fIsVisible = isVisible;
216 }
217
218 /**
219 * Check if the time event matches the current search.
220 *
221 * @return If it matches, Y/N
222 */
223 public boolean isSearchMatch() {
224 return fIsSearchMatch;
225 }
226
227 /**
228 * Mark this event as matching (or non-matching) the current search.
229 *
230 * @param isSearchMatch
231 * The new matching status
232 */
233 public void setIsSearchMatch(boolean isSearchMatch) {
234 fIsSearchMatch = isSearchMatch;
235 }
236
237 public void setItemizedEntry(TimeChartAnalysisEntry timeAnalysisEntry) {
238 fItemizedEntry = timeAnalysisEntry;
239 }
240
241 public TimeChartAnalysisEntry getItemizedEntry() {
242 return fItemizedEntry;
243 }
244
245 public boolean isItemizing() {
246 return fItemizing;
247 }
248
249 public void setItemizing(boolean itemizing) {
250 fItemizing = itemizing;
251 }
252
253 public class RankRange {
254 private long firstRank;
255 private long lastRank;
256
257 public RankRange(long firstRank, long lastRank) {
258 this.firstRank = firstRank;
259 this.lastRank = lastRank;
260 }
261
262 public long getFirstRank() {
263 return firstRank;
264 }
265
266 public long getLastRank() {
267 return lastRank;
268 }
269
270 public long distanceFrom(RankRange range) {
271 if (range.lastRank < fFirstRank) {
272 return fFirstRank - range.lastRank;
273 } else if (range.firstRank > fLastRank) {
274 return range.firstRank - fLastRank;
275 } else {
276 return 0;
277 }
278 }
279
280 @Override
281 public String toString() {
282 return "["+firstRank+","+lastRank+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
283 }
284 }
285
286 private class RankRangeList extends ArrayList<RankRange> {
287
288 private static final long serialVersionUID = 6060485531208535986L;
289
290 public RankRangeList(long rank) {
291 super(1);
292 add(new RankRange(rank, rank));
293 }
294
295 public void merge(RankRangeList rankRangeList) {
296 long threshold = fParentEntry.getTrace().getCacheSize();
297 for (RankRange newRange : rankRangeList) {
298 boolean merged = false;
299 for (RankRange oldRange : fRankRangeList) {
300 if (newRange.distanceFrom(oldRange) <= threshold) {
301 oldRange.firstRank = Math.min(oldRange.firstRank, newRange.firstRank);
302 oldRange.lastRank = Math.max(oldRange.lastRank, newRange.lastRank);
303 merged = true;
304 break;
305 }
306 }
307 if (!merged) {
308 add(newRange);
309 }
310 }
311 Iterator<RankRange> iterator = fRankRangeList.iterator();
312 RankRange previous = null;
313 while (iterator.hasNext()) {
314 RankRange range = iterator.next();
315 if (previous != null && range.distanceFrom(previous) <= threshold) {
316 previous.firstRank = Math.min(previous.firstRank, range.firstRank);
317 previous.lastRank = Math.max(previous.lastRank, range.lastRank);
318 iterator.remove();
319 }
320 previous = range;
321 }
322 }
323 }
324 }
This page took 0.038755 seconds and 6 git commands to generate.