-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.views.timechart;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-\r
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
-import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-\r
-/**\r
- * Event in the time chart view\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeChartEvent implements ITimeEvent {\r
-\r
- private static final byte TIMESTAMP_SCALE = -9;\r
-\r
- private final TimeChartAnalysisEntry fParentEntry;\r
- private long fTime;\r
- private long fDuration;\r
- private long fFirstRank;\r
- private long fLastRank;\r
- private final RankRangeList fRankRangeList;\r
- private long fNbEvents;\r
- private int fColorSettingPriority;\r
- private boolean fIsBookmark;\r
- private boolean fIsVisible;\r
- private boolean fIsSearchMatch;\r
- private TimeChartAnalysisEntry fItemizedEntry;\r
- private boolean fItemizing;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param parentEntry\r
- * The parent entry\r
- * @param event\r
- * The event from which this time chart event originates\r
- * @param rank\r
- * The rank of the event in the trace\r
- * @param decorationProvider\r
- * The decoration provider to use\r
- */\r
- public TimeChartEvent(TimeChartAnalysisEntry parentEntry, ITmfEvent event,\r
- long rank, TimeChartDecorationProvider decorationProvider) {\r
- fParentEntry = parentEntry;\r
- fTime = event.getTimestamp().normalize(0, TIMESTAMP_SCALE).getValue();\r
- fDuration = 0;\r
- fFirstRank = fLastRank = rank;\r
- fRankRangeList = new RankRangeList(rank);\r
- fNbEvents = 1;\r
- fColorSettingPriority = ColorSettingsManager.getColorSettingPriority(event);\r
- fIsBookmark = decorationProvider.isBookmark(rank);\r
- fIsVisible = decorationProvider.isVisible(event);\r
- fIsSearchMatch = decorationProvider.isSearchMatch(event);\r
- }\r
-\r
- @Override\r
- public ITimeGraphEntry getEntry() {\r
- return fParentEntry;\r
- }\r
-\r
- @Override\r
- public long getTime() {\r
- return fTime;\r
- }\r
-\r
- @Override\r
- public long getDuration() {\r
- return fDuration;\r
- }\r
-\r
- /**\r
- * Retrieve the rank of the trace event which started this time event.\r
- *\r
- * @return The rank of the beginning\r
- */\r
- public long getFirstRank() {\r
- return fFirstRank;\r
- }\r
-\r
- /**\r
- * Retrieve the rank of the trace event which *finished* this time event.\r
- *\r
- * @return The rank of the end\r
- */\r
- public long getLastRank() {\r
- return fLastRank;\r
- }\r
-\r
- /**\r
- * Get the list of rank ranges corresponding to this time event.\r
- *\r
- * @return The rank range list\r
- */\r
- public RankRangeList getRankRangeList() {\r
- return fRankRangeList;\r
- }\r
-\r
- /**\r
- * Merge another time event with this one.\r
- *\r
- * @param event\r
- * The other event\r
- */\r
- public void merge(TimeChartEvent event) {\r
- mergeDecorations(event);\r
- if (fTime == event.getTime() && fDuration == event.getDuration()) {\r
- return;\r
- }\r
- long endTime = Math.max(fTime + fDuration, event.getTime() + event.getDuration());\r
- fTime = Math.min(fTime, event.getTime());\r
- fDuration = endTime - fTime;\r
- fFirstRank = Math.min(fFirstRank, event.fFirstRank);\r
- fLastRank = Math.max(fLastRank, event.fLastRank);\r
- fNbEvents += event.fNbEvents;\r
- fItemizedEntry = null;\r
- synchronized (fRankRangeList) {\r
- fRankRangeList.merge(event.getRankRangeList());\r
- }\r
- }\r
-\r
- /**\r
- * Merge the decorations of another time event with the decorations of this\r
- * one.\r
- *\r
- * @param event\r
- * The other event\r
- */\r
- public void mergeDecorations(TimeChartEvent event) {\r
- fColorSettingPriority = Math.min(fColorSettingPriority, event.getColorSettingPriority());\r
- fIsBookmark |= event.fIsBookmark;\r
- fIsVisible |= event.fIsVisible;\r
- fIsSearchMatch |= event.fIsSearchMatch;\r
- }\r
-\r
- /**\r
- * Get the number of time events that have been merged with this one (starts\r
- * counting at 1 if no merge happened).\r
- *\r
- * @return The current number of events in the bath\r
- */\r
- public long getNbEvents() {\r
- return fNbEvents;\r
- }\r
-\r
- /**\r
- * Retrieve the color setting priority.\r
- *\r
- * @return The priority\r
- */\r
- public int getColorSettingPriority() {\r
- return fColorSettingPriority;\r
- }\r
-\r
- /**\r
- * Set the color setting priority.\r
- *\r
- * @param priority\r
- * The priority to set\r
- */\r
- public void setColorSettingPriority(int priority) {\r
- fColorSettingPriority = priority;\r
- }\r
-\r
- /**\r
- * Check if this time event is bookmarked\r
- *\r
- * @return Y/N\r
- */\r
- public boolean isBookmarked() {\r
- return fIsBookmark;\r
- }\r
-\r
- /**\r
- * Set this time event to be bookmarked or not.\r
- *\r
- * @param isBookmarked\r
- * Should time time event become a bookmark, or not\r
- */\r
- public void setIsBookmarked(boolean isBookmarked) {\r
- fIsBookmark = isBookmarked;\r
- }\r
-\r
- /**\r
- * Check if this time is currently visible or not.\r
- *\r
- * @return If the event is visible\r
- */\r
- public boolean isVisible() {\r
- return fIsVisible;\r
- }\r
-\r
- /**\r
- * Set this time event to visible (or to non-visible).\r
- *\r
- * @param isVisible The new status\r
- */\r
- public void setIsVisible(boolean isVisible) {\r
- fIsVisible = isVisible;\r
- }\r
-\r
- /**\r
- * Check if the time event matches the current search.\r
- *\r
- * @return If it matches, Y/N\r
- */\r
- public boolean isSearchMatch() {\r
- return fIsSearchMatch;\r
- }\r
-\r
- /**\r
- * Mark this event as matching (or non-matching) the current search.\r
- *\r
- * @param isSearchMatch\r
- * The new matching status\r
- */\r
- public void setIsSearchMatch(boolean isSearchMatch) {\r
- fIsSearchMatch = isSearchMatch;\r
- }\r
-\r
- /**\r
- * Set this event's itemized entry.\r
- *\r
- * @param timeAnalysisEntry\r
- * The entry to set\r
- */\r
- public void setItemizedEntry(TimeChartAnalysisEntry timeAnalysisEntry) {\r
- fItemizedEntry = timeAnalysisEntry;\r
- }\r
-\r
- /**\r
- * Retrieve this event's itemized entry.\r
- *\r
- * @return The itemized entry that was previously set\r
- */\r
- public TimeChartAnalysisEntry getItemizedEntry() {\r
- return fItemizedEntry;\r
- }\r
-\r
- /**\r
- * @return Has this time event been set to itemizing?\r
- */\r
- public boolean isItemizing() {\r
- return fItemizing;\r
- }\r
-\r
- /**\r
- * Set this event's itemizing flag to true or false.\r
- *\r
- * @param itemizing\r
- * The new value\r
- */\r
- public void setItemizing(boolean itemizing) {\r
- fItemizing = itemizing;\r
- }\r
-\r
- /**\r
- * Inner class to define a range in terms of ranks in the trace.\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
- public class RankRange {\r
- private long firstRank;\r
- private long lastRank;\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param firstRank\r
- * The first (earliest) rank of the range\r
- * @param lastRank\r
- * The last (latest) rank of the range\r
- */\r
- public RankRange(long firstRank, long lastRank) {\r
- this.firstRank = firstRank;\r
- this.lastRank = lastRank;\r
- }\r
-\r
- /**\r
- * Retrieve the start rank of this range.\r
- *\r
- * @return The first rank\r
- */\r
- public long getFirstRank() {\r
- return firstRank;\r
- }\r
-\r
- /**\r
- * Retrieve the end rank of this range\r
- *\r
- * @return The end rank\r
- */\r
- public long getLastRank() {\r
- return lastRank;\r
- }\r
-\r
- /**\r
- * Calculate the minimal distance between two RankRange's\r
- *\r
- * @param range\r
- * The other range\r
- * @return The distance, in "number of events" between the two ranges\r
- */\r
- public long distanceFrom(RankRange range) {\r
- if (range.lastRank < fFirstRank) {\r
- return fFirstRank - range.lastRank;\r
- } else if (range.firstRank > fLastRank) {\r
- return range.firstRank - fLastRank;\r
- } else {\r
- return 0;\r
- }\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "["+firstRank+","+lastRank+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
- }\r
- }\r
-\r
- private class RankRangeList extends ArrayList<RankRange> {\r
-\r
- private static final long serialVersionUID = 6060485531208535986L;\r
-\r
- public RankRangeList(long rank) {\r
- super(1);\r
- add(new RankRange(rank, rank));\r
- }\r
-\r
- public void merge(RankRangeList rankRangeList) {\r
- long threshold = fParentEntry.getTrace().getCacheSize();\r
- for (RankRange newRange : rankRangeList) {\r
- boolean merged = false;\r
- for (RankRange oldRange : fRankRangeList) {\r
- if (newRange.distanceFrom(oldRange) <= threshold) {\r
- oldRange.firstRank = Math.min(oldRange.firstRank, newRange.firstRank);\r
- oldRange.lastRank = Math.max(oldRange.lastRank, newRange.lastRank);\r
- merged = true;\r
- break;\r
- }\r
- }\r
- if (!merged) {\r
- add(newRange);\r
- }\r
- }\r
- Iterator<RankRange> iterator = fRankRangeList.iterator();\r
- RankRange previous = null;\r
- while (iterator.hasNext()) {\r
- RankRange range = iterator.next();\r
- if (previous != null && range.distanceFrom(previous) <= threshold) {\r
- previous.firstRank = Math.min(previous.firstRank, range.firstRank);\r
- previous.lastRank = Math.max(previous.lastRank, range.lastRank);\r
- iterator.remove();\r
- }\r
- previous = range;\r
- }\r
- }\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.views.timechart;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+
+/**
+ * Event in the time chart view
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeChartEvent implements ITimeEvent {
+
+ private static final byte TIMESTAMP_SCALE = -9;
+
+ private final TimeChartAnalysisEntry fParentEntry;
+ private long fTime;
+ private long fDuration;
+ private long fFirstRank;
+ private long fLastRank;
+ private final RankRangeList fRankRangeList;
+ private long fNbEvents;
+ private int fColorSettingPriority;
+ private boolean fIsBookmark;
+ private boolean fIsVisible;
+ private boolean fIsSearchMatch;
+ private TimeChartAnalysisEntry fItemizedEntry;
+ private boolean fItemizing;
+
+ /**
+ * Standard constructor
+ *
+ * @param parentEntry
+ * The parent entry
+ * @param event
+ * The event from which this time chart event originates
+ * @param rank
+ * The rank of the event in the trace
+ * @param decorationProvider
+ * The decoration provider to use
+ */
+ public TimeChartEvent(TimeChartAnalysisEntry parentEntry, ITmfEvent event,
+ long rank, TimeChartDecorationProvider decorationProvider) {
+ fParentEntry = parentEntry;
+ fTime = event.getTimestamp().normalize(0, TIMESTAMP_SCALE).getValue();
+ fDuration = 0;
+ fFirstRank = fLastRank = rank;
+ fRankRangeList = new RankRangeList(rank);
+ fNbEvents = 1;
+ fColorSettingPriority = ColorSettingsManager.getColorSettingPriority(event);
+ fIsBookmark = decorationProvider.isBookmark(rank);
+ fIsVisible = decorationProvider.isVisible(event);
+ fIsSearchMatch = decorationProvider.isSearchMatch(event);
+ }
+
+ @Override
+ public ITimeGraphEntry getEntry() {
+ return fParentEntry;
+ }
+
+ @Override
+ public long getTime() {
+ return fTime;
+ }
+
+ @Override
+ public long getDuration() {
+ return fDuration;
+ }
+
+ /**
+ * Retrieve the rank of the trace event which started this time event.
+ *
+ * @return The rank of the beginning
+ */
+ public long getFirstRank() {
+ return fFirstRank;
+ }
+
+ /**
+ * Retrieve the rank of the trace event which *finished* this time event.
+ *
+ * @return The rank of the end
+ */
+ public long getLastRank() {
+ return fLastRank;
+ }
+
+ /**
+ * Get the list of rank ranges corresponding to this time event.
+ *
+ * @return The rank range list
+ */
+ public RankRangeList getRankRangeList() {
+ return fRankRangeList;
+ }
+
+ /**
+ * Merge another time event with this one.
+ *
+ * @param event
+ * The other event
+ */
+ public void merge(TimeChartEvent event) {
+ mergeDecorations(event);
+ if (fTime == event.getTime() && fDuration == event.getDuration()) {
+ return;
+ }
+ long endTime = Math.max(fTime + fDuration, event.getTime() + event.getDuration());
+ fTime = Math.min(fTime, event.getTime());
+ fDuration = endTime - fTime;
+ fFirstRank = Math.min(fFirstRank, event.fFirstRank);
+ fLastRank = Math.max(fLastRank, event.fLastRank);
+ fNbEvents += event.fNbEvents;
+ fItemizedEntry = null;
+ synchronized (fRankRangeList) {
+ fRankRangeList.merge(event.getRankRangeList());
+ }
+ }
+
+ /**
+ * Merge the decorations of another time event with the decorations of this
+ * one.
+ *
+ * @param event
+ * The other event
+ */
+ public void mergeDecorations(TimeChartEvent event) {
+ fColorSettingPriority = Math.min(fColorSettingPriority, event.getColorSettingPriority());
+ fIsBookmark |= event.fIsBookmark;
+ fIsVisible |= event.fIsVisible;
+ fIsSearchMatch |= event.fIsSearchMatch;
+ }
+
+ /**
+ * Get the number of time events that have been merged with this one (starts
+ * counting at 1 if no merge happened).
+ *
+ * @return The current number of events in the bath
+ */
+ public long getNbEvents() {
+ return fNbEvents;
+ }
+
+ /**
+ * Retrieve the color setting priority.
+ *
+ * @return The priority
+ */
+ public int getColorSettingPriority() {
+ return fColorSettingPriority;
+ }
+
+ /**
+ * Set the color setting priority.
+ *
+ * @param priority
+ * The priority to set
+ */
+ public void setColorSettingPriority(int priority) {
+ fColorSettingPriority = priority;
+ }
+
+ /**
+ * Check if this time event is bookmarked
+ *
+ * @return Y/N
+ */
+ public boolean isBookmarked() {
+ return fIsBookmark;
+ }
+
+ /**
+ * Set this time event to be bookmarked or not.
+ *
+ * @param isBookmarked
+ * Should time time event become a bookmark, or not
+ */
+ public void setIsBookmarked(boolean isBookmarked) {
+ fIsBookmark = isBookmarked;
+ }
+
+ /**
+ * Check if this time is currently visible or not.
+ *
+ * @return If the event is visible
+ */
+ public boolean isVisible() {
+ return fIsVisible;
+ }
+
+ /**
+ * Set this time event to visible (or to non-visible).
+ *
+ * @param isVisible The new status
+ */
+ public void setIsVisible(boolean isVisible) {
+ fIsVisible = isVisible;
+ }
+
+ /**
+ * Check if the time event matches the current search.
+ *
+ * @return If it matches, Y/N
+ */
+ public boolean isSearchMatch() {
+ return fIsSearchMatch;
+ }
+
+ /**
+ * Mark this event as matching (or non-matching) the current search.
+ *
+ * @param isSearchMatch
+ * The new matching status
+ */
+ public void setIsSearchMatch(boolean isSearchMatch) {
+ fIsSearchMatch = isSearchMatch;
+ }
+
+ /**
+ * Set this event's itemized entry.
+ *
+ * @param timeAnalysisEntry
+ * The entry to set
+ */
+ public void setItemizedEntry(TimeChartAnalysisEntry timeAnalysisEntry) {
+ fItemizedEntry = timeAnalysisEntry;
+ }
+
+ /**
+ * Retrieve this event's itemized entry.
+ *
+ * @return The itemized entry that was previously set
+ */
+ public TimeChartAnalysisEntry getItemizedEntry() {
+ return fItemizedEntry;
+ }
+
+ /**
+ * @return Has this time event been set to itemizing?
+ */
+ public boolean isItemizing() {
+ return fItemizing;
+ }
+
+ /**
+ * Set this event's itemizing flag to true or false.
+ *
+ * @param itemizing
+ * The new value
+ */
+ public void setItemizing(boolean itemizing) {
+ fItemizing = itemizing;
+ }
+
+ /**
+ * Inner class to define a range in terms of ranks in the trace.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+ public class RankRange {
+ private long firstRank;
+ private long lastRank;
+
+ /**
+ * Standard constructor
+ *
+ * @param firstRank
+ * The first (earliest) rank of the range
+ * @param lastRank
+ * The last (latest) rank of the range
+ */
+ public RankRange(long firstRank, long lastRank) {
+ this.firstRank = firstRank;
+ this.lastRank = lastRank;
+ }
+
+ /**
+ * Retrieve the start rank of this range.
+ *
+ * @return The first rank
+ */
+ public long getFirstRank() {
+ return firstRank;
+ }
+
+ /**
+ * Retrieve the end rank of this range
+ *
+ * @return The end rank
+ */
+ public long getLastRank() {
+ return lastRank;
+ }
+
+ /**
+ * Calculate the minimal distance between two RankRange's
+ *
+ * @param range
+ * The other range
+ * @return The distance, in "number of events" between the two ranges
+ */
+ public long distanceFrom(RankRange range) {
+ if (range.lastRank < fFirstRank) {
+ return fFirstRank - range.lastRank;
+ } else if (range.firstRank > fLastRank) {
+ return range.firstRank - fLastRank;
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "["+firstRank+","+lastRank+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+
+ private class RankRangeList extends ArrayList<RankRange> {
+
+ private static final long serialVersionUID = 6060485531208535986L;
+
+ public RankRangeList(long rank) {
+ super(1);
+ add(new RankRange(rank, rank));
+ }
+
+ public void merge(RankRangeList rankRangeList) {
+ long threshold = fParentEntry.getTrace().getCacheSize();
+ for (RankRange newRange : rankRangeList) {
+ boolean merged = false;
+ for (RankRange oldRange : fRankRangeList) {
+ if (newRange.distanceFrom(oldRange) <= threshold) {
+ oldRange.firstRank = Math.min(oldRange.firstRank, newRange.firstRank);
+ oldRange.lastRank = Math.max(oldRange.lastRank, newRange.lastRank);
+ merged = true;
+ break;
+ }
+ }
+ if (!merged) {
+ add(newRange);
+ }
+ }
+ Iterator<RankRange> iterator = fRankRangeList.iterator();
+ RankRange previous = null;
+ while (iterator.hasNext()) {
+ RankRange range = iterator.next();
+ if (previous != null && range.distanceFrom(previous) <= threshold) {
+ previous.firstRank = Math.min(previous.firstRank, range.firstRank);
+ previous.lastRank = Math.max(previous.lastRank, range.lastRank);
+ iterator.remove();
+ }
+ previous = range;
+ }
+ }
+ }
+}