1 /*******************************************************************************
2 * Copyright (c) 2010 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.timechart
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Iterator
;
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
;
24 * Event in the time chart view
27 * @author Patrick Tasse
29 public class TimeChartEvent
implements ITimeEvent
{
31 private static final byte TIMESTAMP_SCALE
= -9;
33 private final TimeChartAnalysisEntry fParentEntry
;
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
;
47 public TimeChartEvent(TimeChartAnalysisEntry parentEntry
, ITmfEvent event
, long rank
, TimeChartDecorationProvider decorationProvider
) {
48 fParentEntry
= parentEntry
;
49 fTime
= event
.getTimestamp().normalize(0, TIMESTAMP_SCALE
).getValue();
51 fFirstRank
= fLastRank
= rank
;
52 fRankRangeList
= new RankRangeList(rank
);
54 fColorSettingPriority
= ColorSettingsManager
.getColorSettingPriority(event
);
55 fIsBookmark
= decorationProvider
.isBookmark(rank
);
56 fIsVisible
= decorationProvider
.isVisible(event
);
57 fIsSearchMatch
= decorationProvider
.isSearchMatch(event
);
61 public ITimeGraphEntry
getEntry() {
66 public long getTime() {
71 public long getDuration() {
75 public long getFirstRank() {
79 public long getLastRank() {
83 public RankRangeList
getRankRangeList() {
84 return fRankRangeList
;
87 public void merge(TimeChartEvent event
) {
88 mergeDecorations(event
);
89 if (fTime
== event
.getTime() && fDuration
== event
.getDuration()) {
92 long endTime
= Math
.max(fTime
+ fDuration
, event
.getTime() + event
.getDuration());
93 fTime
= Math
.min(fTime
, event
.getTime());
94 fDuration
= endTime
- fTime
;
95 fFirstRank
= Math
.min(fFirstRank
, event
.fFirstRank
);
96 fLastRank
= Math
.max(fLastRank
, event
.fLastRank
);
97 fNbEvents
+= event
.fNbEvents
;
98 fItemizedEntry
= null;
99 synchronized (fRankRangeList
) {
100 fRankRangeList
.merge(event
.getRankRangeList());
104 public void mergeDecorations(TimeChartEvent event
) {
105 fColorSettingPriority
= Math
.min(fColorSettingPriority
, event
.getColorSettingPriority());
106 fIsBookmark
|= event
.fIsBookmark
;
107 fIsVisible
|= event
.fIsVisible
;
108 fIsSearchMatch
|= event
.fIsSearchMatch
;
111 public long getNbEvents() {
115 public int getColorSettingPriority() {
116 return fColorSettingPriority
;
119 public void setColorSettingPriority(int priority
) {
120 fColorSettingPriority
= priority
;
123 public boolean isBookmarked() {
127 public void setIsBookmarked(boolean isBookmarked
) {
128 fIsBookmark
= isBookmarked
;
131 public boolean isVisible() {
135 public void setIsVisible(boolean isVisible
) {
136 fIsVisible
= isVisible
;
139 public boolean isSearchMatch() {
140 return fIsSearchMatch
;
143 public void setIsSearchMatch(boolean isSearchMatch
) {
144 fIsSearchMatch
= isSearchMatch
;
147 public void setItemizedEntry(TimeChartAnalysisEntry timeAnalysisEntry
) {
148 fItemizedEntry
= timeAnalysisEntry
;
151 public TimeChartAnalysisEntry
getItemizedEntry() {
152 return fItemizedEntry
;
155 public boolean isItemizing() {
159 public void setItemizing(boolean itemizing
) {
160 fItemizing
= itemizing
;
163 public class RankRange
{
164 private long firstRank
;
165 private long lastRank
;
167 public RankRange(long firstRank
, long lastRank
) {
168 this.firstRank
= firstRank
;
169 this.lastRank
= lastRank
;
172 public long getFirstRank() {
176 public long getLastRank() {
180 public long distanceFrom(RankRange range
) {
181 if (range
.lastRank
< fFirstRank
) {
182 return fFirstRank
- range
.lastRank
;
183 } else if (range
.firstRank
> fLastRank
) {
184 return range
.firstRank
- fLastRank
;
191 public String
toString() {
192 return "["+firstRank
+","+lastRank
+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
196 private class RankRangeList
extends ArrayList
<RankRange
> {
198 private static final long serialVersionUID
= 6060485531208535986L;
200 public RankRangeList(long rank
) {
202 add(new RankRange(rank
, rank
));
205 public void merge(RankRangeList rankRangeList
) {
206 long threshold
= fParentEntry
.getTrace().getCacheSize();
207 for (RankRange newRange
: rankRangeList
) {
208 boolean merged
= false;
209 for (RankRange oldRange
: fRankRangeList
) {
210 if (newRange
.distanceFrom(oldRange
) <= threshold
) {
211 oldRange
.firstRank
= Math
.min(oldRange
.firstRank
, newRange
.firstRank
);
212 oldRange
.lastRank
= Math
.max(oldRange
.lastRank
, newRange
.lastRank
);
221 Iterator
<RankRange
> iterator
= fRankRangeList
.iterator();
222 RankRange previous
= null;
223 while (iterator
.hasNext()) {
224 RankRange range
= iterator
.next();
225 if (previous
!= null && range
.distanceFrom(previous
) <= threshold
) {
226 previous
.firstRank
= Math
.min(previous
.firstRank
, range
.firstRank
);
227 previous
.lastRank
= Math
.max(previous
.lastRank
, range
.lastRank
);