Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
ed902a2b | 2 | * Copyright (c) 2005, 2014 IBM Corporation, Ericsson |
73005152 BH |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
a55887ca AM |
7 | * |
8 | * Contributors: | |
c8422608 AM |
9 | * IBM - Initial API and implementation |
10 | * Bernd Hufmann - Updated for TMF | |
73005152 | 11 | **********************************************************************/ |
c8422608 | 12 | |
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.ui.views.uml2sd.core; |
73005152 BH |
14 | |
15 | import java.util.ArrayList; | |
16 | import java.util.Iterator; | |
17 | import java.util.List; | |
18 | ||
2bdf0193 AM |
19 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
20 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; | |
21 | import org.eclipse.tracecompass.tmf.ui.views.uml2sd.drawings.IGC; | |
22 | import org.eclipse.tracecompass.tmf.ui.views.uml2sd.preferences.ISDPreferences; | |
23 | import org.eclipse.tracecompass.tmf.ui.views.uml2sd.preferences.SDViewPref; | |
73005152 BH |
24 | |
25 | /** | |
26 | * The Frame class is the base sequence diagram graph nodes container.<br> | |
27 | * For instance, only one frame can be drawn in the View.<br> | |
28 | * Lifelines, Messages and Stop which are supposed to represent a Sequence diagram are drawn in a Frame.<br> | |
29 | * Only the graph node added to their representing list will be drawn. | |
a55887ca | 30 | * |
73005152 BH |
31 | * The lifelines are appended along the X axsis when added in a frame.<br> |
32 | * The syncMessages are ordered along the Y axsis depending on the event occurrence they are attached to.<br> | |
a55887ca | 33 | * |
2bdf0193 | 34 | * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details |
73005152 BH |
35 | * @author sveyrier |
36 | * @version 1.0 | |
37 | */ | |
38 | public class BasicFrame extends GraphNode { | |
39 | ||
df0b8ff4 BH |
40 | // ------------------------------------------------------------------------ |
41 | // Attributes | |
42 | // ------------------------------------------------------------------------ | |
3145ec83 | 43 | |
73005152 BH |
44 | /** |
45 | * Contains the max elapsed time between two consecutive messages in the whole frame | |
46 | */ | |
cab6c8ff | 47 | private ITmfTimestamp fMaxTime = new TmfTimestamp(0); |
73005152 BH |
48 | /** |
49 | * Contains the min elapsed time between two consecutive messages in the whole frame | |
50 | */ | |
cab6c8ff | 51 | private ITmfTimestamp fMinTime = new TmfTimestamp(0); |
73005152 BH |
52 | /** |
53 | * Indicate if the min and max elapsed time between two consecutive messages in the whole frame need to be computed | |
54 | */ | |
cab6c8ff | 55 | private boolean fComputeMinMax = true; |
73005152 BH |
56 | /** |
57 | * Store the preference set by the user regarding the external time. This flag is used determine if the min and max | |
58 | * need to be recomputed in case this preference is changed. | |
59 | */ | |
cab6c8ff | 60 | private boolean fLastExternalTimePref = SDViewPref.getInstance().excludeExternalTime(); |
73005152 BH |
61 | /** |
62 | * The greater event occurrence created on graph nodes drawn in this Frame This directly impact the Frame height | |
63 | */ | |
cab6c8ff | 64 | private int fVerticalIndex = 0; |
73005152 BH |
65 | /** |
66 | * The index along the x axis where the next lifeline will is drawn This directly impact the Frame width | |
67 | */ | |
cab6c8ff | 68 | private int fHorizontalIndex = 0; |
df0b8ff4 | 69 | /** |
eb63f5ff | 70 | * The time information flag. |
df0b8ff4 | 71 | */ |
cab6c8ff | 72 | private boolean fHasTimeInfo = false; |
73005152 | 73 | /** |
df0b8ff4 | 74 | * The current Frame visible area - x coordinates |
73005152 | 75 | */ |
cab6c8ff | 76 | private int fVisibleAreaX; |
df0b8ff4 BH |
77 | /** |
78 | * The current Frame visible area - y coordinates | |
79 | */ | |
cab6c8ff | 80 | private int fVisibleAreaY; |
df0b8ff4 BH |
81 | /** |
82 | * The current Frame visible area - width | |
83 | */ | |
cab6c8ff | 84 | private int fVisibleAreaWidth; |
df0b8ff4 BH |
85 | /** |
86 | * The current Frame visible area - height | |
87 | */ | |
cab6c8ff | 88 | private int fVisibleAreaHeight; |
df0b8ff4 BH |
89 | /** |
90 | * The event occurrence spacing (-1 for none) | |
91 | */ | |
cab6c8ff | 92 | private int fForceEventOccurrenceSpacing = -1; |
df0b8ff4 BH |
93 | /** |
94 | * Flag to indicate customized minumum and maximum. | |
95 | */ | |
cab6c8ff | 96 | private boolean fCustomMinMax = false; |
df0b8ff4 BH |
97 | /** |
98 | * The minimum time between messages of the sequence diagram frame. | |
99 | */ | |
cab6c8ff | 100 | private ITmfTimestamp fMinSDTime = new TmfTimestamp(); |
df0b8ff4 BH |
101 | /** |
102 | * The maximum time between messages of the sequence diagram frame. | |
103 | */ | |
cab6c8ff | 104 | private ITmfTimestamp fMaxSDTime = new TmfTimestamp(); |
df0b8ff4 BH |
105 | /** |
106 | * Flag to indicate that initial minimum has to be computed. | |
107 | */ | |
cab6c8ff | 108 | private boolean fInitSDMin = true; |
73005152 | 109 | |
df0b8ff4 BH |
110 | // ------------------------------------------------------------------------ |
111 | // Constructors | |
112 | // ------------------------------------------------------------------------ | |
a55887ca | 113 | |
73005152 BH |
114 | /** |
115 | * Creates an empty frame. | |
116 | */ | |
117 | public BasicFrame() { | |
eb63f5ff | 118 | Metrics.setForcedEventSpacing(fForceEventOccurrenceSpacing); |
73005152 BH |
119 | } |
120 | ||
df0b8ff4 BH |
121 | // ------------------------------------------------------------------------ |
122 | // Methods | |
123 | // ------------------------------------------------------------------------ | |
124 | ||
73005152 | 125 | /** |
a55887ca | 126 | * |
73005152 | 127 | * Returns the greater event occurence known by the Frame |
a55887ca | 128 | * |
73005152 BH |
129 | * @return the greater event occurrence |
130 | */ | |
131 | protected int getMaxEventOccurrence() { | |
eb63f5ff | 132 | return fVerticalIndex; |
73005152 BH |
133 | } |
134 | ||
135 | /** | |
136 | * Set the greater event occurrence created in GraphNodes included in the frame | |
a55887ca | 137 | * |
73005152 BH |
138 | * @param eventOccurrence the new greater event occurrence |
139 | */ | |
140 | protected void setMaxEventOccurrence(int eventOccurrence) { | |
eb63f5ff | 141 | fVerticalIndex = eventOccurrence; |
73005152 BH |
142 | } |
143 | ||
144 | /** | |
145 | * This method increase the lifeline place holder The return value is usually assign to a lifeline. This can be used | |
146 | * to set the lifelines drawing order. Also, calling this method two times and assigning only the last given index | |
147 | * to a lifeline will increase this lifeline draw spacing (2 times the default spacing) from the last added | |
148 | * lifeline. | |
a55887ca | 149 | * |
73005152 BH |
150 | * @return a new lifeline index |
151 | */ | |
152 | protected int getNewHorizontalIndex() { | |
eb63f5ff | 153 | return ++fHorizontalIndex; |
73005152 BH |
154 | } |
155 | ||
156 | /** | |
157 | * Returns the current horizontal index | |
a55887ca | 158 | * |
73005152 BH |
159 | * @return the current horizontal index |
160 | * @see Frame#getNewHorizontalIndex() for horizontal index description | |
161 | */ | |
162 | protected int getHorizontalIndex() { | |
eb63f5ff | 163 | return fHorizontalIndex; |
73005152 BH |
164 | } |
165 | ||
73005152 BH |
166 | @Override |
167 | public void addNode(GraphNode nodeToAdd) { | |
cab6c8ff | 168 | setComputeMinMax(true); |
73005152 BH |
169 | super.addNode(nodeToAdd); |
170 | } | |
171 | ||
73005152 BH |
172 | @Override |
173 | public int getX() { | |
174 | return Metrics.FRAME_H_MARGIN; | |
175 | } | |
176 | ||
73005152 BH |
177 | @Override |
178 | public int getY() { | |
179 | return Metrics.FRAME_V_MARGIN; | |
180 | } | |
181 | ||
73005152 BH |
182 | @Override |
183 | public int getWidth() { | |
eb63f5ff | 184 | if (fHorizontalIndex == 0) { |
73005152 | 185 | return 3 * Metrics.swimmingLaneWidth() + Metrics.LIFELINE_H_MAGIN * 2 - Metrics.FRAME_H_MARGIN - Metrics.LIFELINE_SPACING / 2; |
df0b8ff4 | 186 | } |
abbdd66a | 187 | return fHorizontalIndex * Metrics.swimmingLaneWidth() + Metrics.LIFELINE_H_MAGIN * 2 + 1 - Metrics.LIFELINE_SPACING; |
73005152 BH |
188 | } |
189 | ||
73005152 BH |
190 | @Override |
191 | public int getHeight() { | |
df0b8ff4 | 192 | // The Frame height depends on the maximum number of messages added to a lifeline |
eb63f5ff | 193 | if (fVerticalIndex == 0) { |
73005152 BH |
194 | return 5 * (Metrics.getMessagesSpacing() + Metrics.getMessageFontHeigth()) + Metrics.LIFELINE_NAME_H_MARGIN + Metrics.FRAME_NAME_H_MARGIN + Metrics.getFrameFontHeigth() + Metrics.LIFELINE_VT_MAGIN + Metrics.LIFELINE_VB_MAGIN |
195 | + Metrics.LIFELINE_NAME_H_MARGIN + Metrics.FRAME_NAME_H_MARGIN + Metrics.getLifelineFontHeigth() * 2; | |
df0b8ff4 | 196 | } |
eb63f5ff BH |
197 | if (fForceEventOccurrenceSpacing >= 0) { |
198 | Metrics.setForcedEventSpacing(fForceEventOccurrenceSpacing); | |
df0b8ff4 | 199 | } |
eb63f5ff | 200 | return fVerticalIndex * (Metrics.getMessagesSpacing() + Metrics.getMessageFontHeigth()) + Metrics.LIFELINE_NAME_H_MARGIN + Metrics.FRAME_NAME_H_MARGIN + Metrics.getFrameFontHeigth() + Metrics.LIFELINE_VT_MAGIN + Metrics.LIFELINE_VB_MAGIN |
73005152 BH |
201 | + Metrics.LIFELINE_NAME_H_MARGIN + Metrics.FRAME_NAME_H_MARGIN + Metrics.getLifelineFontHeigth() * 2; |
202 | } | |
203 | ||
cab6c8ff BH |
204 | /** |
205 | * @return true if mininum and maximum time needs to be calculated else false | |
cab6c8ff BH |
206 | */ |
207 | protected boolean isComputeMinMax() { | |
208 | return fComputeMinMax; | |
209 | } | |
210 | ||
211 | /** | |
212 | * @return true if mininum and maximum time needs to be calculated else false | |
cab6c8ff BH |
213 | */ |
214 | protected boolean isCustomMinMax() { | |
215 | return fCustomMinMax; | |
216 | } | |
217 | ||
218 | /** | |
219 | * gets the initialization flag for SD minimum. | |
220 | * | |
221 | * @return the initialization flag for SD minimum | |
cab6c8ff BH |
222 | */ |
223 | protected boolean getInitSDMin() { | |
224 | return fInitSDMin; | |
225 | } | |
226 | ||
73005152 BH |
227 | /** |
228 | * Returns the graph node which contains the point given in parameter for the given graph node list and starting the | |
229 | * iteration at the given index<br> | |
230 | * WARNING: Only graph nodes with smaller coordinates than the current visible area can be returned.<br> | |
a55887ca | 231 | * |
73005152 BH |
232 | * @param x the x coordinate of the point to test |
233 | * @param y the y coordinate of the point to test | |
234 | * @param list the list to search in | |
235 | * @param fromIndex list browsing starting point | |
236 | * @return the graph node containing the point given in parameter, null otherwise | |
df0b8ff4 | 237 | * |
2bdf0193 | 238 | * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.GraphNode#getNodeFromListAt(int, int, java.util.List, int) |
73005152 BH |
239 | */ |
240 | @Override | |
241 | protected GraphNode getNodeFromListAt(int x, int y, List<GraphNode> list, int fromIndex) { | |
df0b8ff4 | 242 | if (list == null) { |
73005152 | 243 | return null; |
df0b8ff4 | 244 | } |
73005152 | 245 | for (int i = fromIndex; i < list.size(); i++) { |
abbdd66a | 246 | GraphNode node = list.get(i); |
73005152 BH |
247 | // only lifeline list is x ordered |
248 | // Stop browsing the list if the node is outside the visible area | |
249 | // all others nodes will be not visible | |
eb63f5ff | 250 | if ((node instanceof Lifeline) && (node.getX() > fVisibleAreaX + fVisibleAreaWidth)) { |
73005152 | 251 | break; |
df0b8ff4 | 252 | } |
73005152 | 253 | if (node.getHeight() < 0) { |
eb63f5ff | 254 | if (node.getY() + node.getHeight() > fVisibleAreaY + fVisibleAreaHeight) { |
73005152 | 255 | break; |
df0b8ff4 | 256 | } |
73005152 | 257 | } else { |
eb63f5ff | 258 | if (node.getY() > fVisibleAreaY + fVisibleAreaHeight) { |
73005152 | 259 | break; |
df0b8ff4 | 260 | } |
73005152 | 261 | } |
df0b8ff4 | 262 | if (node.contains(x, y)) { |
73005152 | 263 | return node; |
df0b8ff4 | 264 | } |
73005152 BH |
265 | } |
266 | return null; | |
267 | } | |
268 | ||
269 | /** | |
270 | * Draw the Frame rectangle | |
a55887ca | 271 | * |
73005152 BH |
272 | * @param context the context to draw to |
273 | */ | |
274 | protected void drawFrame(IGC context) { | |
a55887ca | 275 | |
3145ec83 | 276 | ISDPreferences pref = SDViewPref.getInstance(); |
a55887ca | 277 | |
3145ec83 BH |
278 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME)); |
279 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_FRAME)); | |
73005152 BH |
280 | |
281 | int x = getX(); | |
282 | int y = getY(); | |
283 | int w = getWidth(); | |
284 | int h = getHeight(); | |
285 | ||
286 | // Draw the frame main rectangle | |
287 | context.fillRectangle(x, y, w, h); | |
288 | context.drawRectangle(x, y, w, h); | |
289 | ||
3145ec83 BH |
290 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME_NAME)); |
291 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_FRAME_NAME)); | |
292 | context.setFont(pref.getFont(ISDPreferences.PREF_FRAME_NAME)); | |
73005152 BH |
293 | |
294 | int nameWidth = context.textExtent(getName()) + 2 * Metrics.FRAME_NAME_V_MARGIN; | |
295 | int nameHeight = Metrics.getFrameFontHeigth() + +Metrics.FRAME_NAME_H_MARGIN * 2; | |
296 | ||
297 | // Draw the frame name area | |
df0b8ff4 | 298 | if (nameWidth > w) { |
73005152 | 299 | nameWidth = w; |
df0b8ff4 | 300 | } |
73005152 BH |
301 | |
302 | int[] points = { x, y, x + nameWidth, y, x + nameWidth, y - 11 + nameHeight, x - 11 + nameWidth, y + nameHeight, x, y + nameHeight, x, y + nameHeight }; | |
303 | context.fillPolygon(points); | |
304 | context.drawPolygon(points); | |
305 | context.drawLine(x, y, x, y + nameHeight); | |
306 | ||
3145ec83 | 307 | context.setForeground(pref.getFontColor(ISDPreferences.PREF_FRAME_NAME)); |
73005152 BH |
308 | context.drawTextTruncatedCentred(getName(), x, y, nameWidth - 11, nameHeight, false); |
309 | ||
3145ec83 BH |
310 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME)); |
311 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_FRAME)); | |
73005152 BH |
312 | } |
313 | ||
73005152 BH |
314 | @Override |
315 | public void draw(IGC context) { | |
316 | draw(context, true); | |
317 | } | |
318 | ||
319 | /** | |
320 | * Draws the Frame on the given context.<br> | |
321 | * This method start width GraphNodes ordering if needed.<br> | |
322 | * After, depending on the visible area, only visible GraphNodes are drawn.<br> | |
a55887ca | 323 | * |
73005152 BH |
324 | * @param context the context to draw to |
325 | * @param drawFrame indicate if the frame rectangle need to be redrawn | |
2bdf0193 | 326 | * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.GraphNode#draw(IGC) |
73005152 BH |
327 | */ |
328 | protected void draw(IGC context, boolean drawFrame) { | |
eb63f5ff BH |
329 | fVisibleAreaHeight = context.getVisibleHeight(); |
330 | fVisibleAreaWidth = context.getVisibleWidth(); | |
331 | fVisibleAreaX = context.getContentsX(); | |
332 | fVisibleAreaY = context.getContentsY(); | |
73005152 | 333 | |
eb63f5ff BH |
334 | if (fForceEventOccurrenceSpacing >= 0) { |
335 | Metrics.setForcedEventSpacing(fForceEventOccurrenceSpacing); | |
df0b8ff4 | 336 | } else { |
73005152 | 337 | Metrics.setForcedEventSpacing(-1); |
df0b8ff4 | 338 | } |
73005152 | 339 | |
3145ec83 | 340 | super.drawChildenNodes(context); |
73005152 BH |
341 | } |
342 | ||
df0b8ff4 BH |
343 | /** |
344 | * Sets the event occurrence spacing (-1 for none) | |
a55887ca | 345 | * |
df0b8ff4 BH |
346 | * @param space A spacing to set. |
347 | */ | |
73005152 | 348 | public void forceEventOccurrenceSpacing(int space) { |
eb63f5ff | 349 | fForceEventOccurrenceSpacing = space; |
73005152 BH |
350 | } |
351 | ||
352 | /** | |
353 | * Return the X coordinates of the frame visible area | |
a55887ca | 354 | * |
73005152 BH |
355 | * @return the X coordinates of the frame visible area |
356 | */ | |
357 | public int getVisibleAreaX() { | |
eb63f5ff | 358 | return fVisibleAreaX; |
73005152 BH |
359 | } |
360 | ||
361 | /** | |
362 | * Return the frame visible area width | |
a55887ca | 363 | * |
73005152 BH |
364 | * @return the frame visible area width |
365 | */ | |
366 | public int getVisibleAreaWidth() { | |
eb63f5ff | 367 | return fVisibleAreaWidth; |
73005152 BH |
368 | } |
369 | ||
370 | /** | |
371 | * Return the frame visible area height | |
a55887ca | 372 | * |
73005152 BH |
373 | * @return the frame visible area height |
374 | */ | |
375 | public int getVisibleAreaHeight() { | |
eb63f5ff | 376 | return fVisibleAreaHeight; |
73005152 BH |
377 | } |
378 | ||
379 | /** | |
380 | * Return the X coordinates of the frame visible area | |
a55887ca | 381 | * |
73005152 BH |
382 | * @return the X coordinates of the frame visible area |
383 | */ | |
384 | public int getVisibleAreaY() { | |
eb63f5ff | 385 | return fVisibleAreaY; |
73005152 BH |
386 | } |
387 | ||
388 | /** | |
389 | * Return the minimum time stored in the frame taking all GraphNodes into account | |
a55887ca | 390 | * |
73005152 BH |
391 | * @return the minimum GraphNode time |
392 | */ | |
4df4581d | 393 | public ITmfTimestamp getMinTime() { |
eb63f5ff BH |
394 | if (fLastExternalTimePref != SDViewPref.getInstance().excludeExternalTime()) { |
395 | fLastExternalTimePref = SDViewPref.getInstance().excludeExternalTime(); | |
cab6c8ff | 396 | setComputeMinMax(true); |
73005152 | 397 | } |
eb63f5ff | 398 | if ((fComputeMinMax) && (!fCustomMinMax)) { |
73005152 | 399 | computeMinMax(); |
cab6c8ff | 400 | setComputeMinMax(false); |
73005152 | 401 | } |
eb63f5ff | 402 | return fMinTime; |
73005152 BH |
403 | } |
404 | ||
a55887ca AM |
405 | /** |
406 | * Set the minimum timestamp of the frame. | |
407 | * | |
408 | * @param min | |
409 | * The minimum timestamp | |
410 | */ | |
d7dbf09a | 411 | public void setMin(ITmfTimestamp min) { |
eb63f5ff BH |
412 | fMinTime = min; |
413 | fCustomMinMax = true; | |
73005152 BH |
414 | } |
415 | ||
a55887ca AM |
416 | /** |
417 | * Set the maximum timestamp of the frame. | |
418 | * | |
419 | * @param max | |
420 | * The maximum timestamp | |
421 | */ | |
d7dbf09a | 422 | public void setMax(ITmfTimestamp max) { |
eb63f5ff BH |
423 | fMaxTime = max; |
424 | fCustomMinMax = true; | |
73005152 BH |
425 | } |
426 | ||
a55887ca AM |
427 | /** |
428 | * Reset min/max timestamp values to the default ones. | |
429 | */ | |
73005152 | 430 | public void resetCustomMinMax() { |
eb63f5ff | 431 | fCustomMinMax = false; |
cab6c8ff | 432 | setComputeMinMax(true); |
73005152 BH |
433 | } |
434 | ||
435 | /** | |
436 | * Return the maximum time stored in the frame taking all GraphNodes into account | |
a55887ca | 437 | * |
73005152 BH |
438 | * @return the maximum GraphNode time |
439 | */ | |
4df4581d | 440 | public ITmfTimestamp getMaxTime() { |
eb63f5ff BH |
441 | if (fLastExternalTimePref != SDViewPref.getInstance().excludeExternalTime()) { |
442 | fLastExternalTimePref = SDViewPref.getInstance().excludeExternalTime(); | |
cab6c8ff | 443 | setComputeMinMax(true); |
73005152 | 444 | } |
eb63f5ff | 445 | if (fComputeMinMax) { |
73005152 | 446 | computeMinMax(); |
cab6c8ff | 447 | setComputeMinMax(false); |
73005152 | 448 | } |
eb63f5ff | 449 | return fMaxTime; |
73005152 BH |
450 | } |
451 | ||
df0b8ff4 | 452 | /** |
a55887ca | 453 | * Computes the minimum and maximum time between consecutive messages within the frame. |
df0b8ff4 | 454 | */ |
73005152 | 455 | protected void computeMaxMinTime() { |
eb63f5ff | 456 | if (!fInitSDMin) { |
73005152 | 457 | return; |
df0b8ff4 | 458 | } |
73005152 BH |
459 | |
460 | List<SDTimeEvent> timeArray = buildTimeArray(); | |
3145ec83 BH |
461 | |
462 | if ((timeArray == null) || timeArray.isEmpty()) { | |
73005152 | 463 | return; |
df0b8ff4 | 464 | } |
73005152 | 465 | for (int i = 0; i < timeArray.size(); i++) { |
abbdd66a | 466 | SDTimeEvent m = timeArray.get(i); |
73005152 | 467 | |
065cc19b | 468 | if (m.getTime().compareTo(fMaxSDTime) > 0) { |
eb63f5ff | 469 | fMaxSDTime = m.getTime(); |
73005152 BH |
470 | } |
471 | ||
065cc19b | 472 | if ((m.getTime().compareTo(fMinSDTime) < 0) || fInitSDMin) { |
eb63f5ff BH |
473 | fMinSDTime = m.getTime(); |
474 | fInitSDMin = false; | |
73005152 BH |
475 | } |
476 | } | |
477 | } | |
478 | ||
df0b8ff4 BH |
479 | /** |
480 | * Returns the minimum time between consecutive messages. | |
a55887ca | 481 | * |
df0b8ff4 BH |
482 | * @return the minimum time between consecutive messages |
483 | */ | |
4df4581d | 484 | public ITmfTimestamp getSDMinTime() { |
73005152 | 485 | computeMaxMinTime(); |
eb63f5ff | 486 | return fMinSDTime; |
73005152 BH |
487 | } |
488 | ||
df0b8ff4 BH |
489 | /** |
490 | * Returns the maximum time between consecutive messages. | |
a55887ca | 491 | * |
df0b8ff4 BH |
492 | * @return the maximum time between consecutive messages |
493 | */ | |
4df4581d | 494 | public ITmfTimestamp getSDMaxTime() { |
73005152 | 495 | computeMaxMinTime(); |
eb63f5ff | 496 | return fMaxSDTime; |
73005152 BH |
497 | } |
498 | ||
499 | /** | |
500 | * Browse all the GraphNode to compute the min and max times store in the Frame | |
501 | */ | |
502 | protected void computeMinMax() { | |
503 | List<SDTimeEvent> timeArray = buildTimeArray(); | |
3145ec83 BH |
504 | |
505 | if ((timeArray == null) || timeArray.isEmpty()) { | |
73005152 | 506 | return; |
df0b8ff4 | 507 | } |
73005152 | 508 | for (int i = 0; i < timeArray.size() - 1; i++) { |
abbdd66a AM |
509 | SDTimeEvent m1 = timeArray.get(i); |
510 | SDTimeEvent m2 = timeArray.get(i + 1); | |
a55887ca | 511 | |
73005152 | 512 | updateMinMax(m1, m2); |
73005152 BH |
513 | } |
514 | } | |
515 | ||
df0b8ff4 BH |
516 | /** |
517 | * Updates the minimum and maximum time between consecutive message within the frame based on the given values. | |
a55887ca | 518 | * |
df0b8ff4 BH |
519 | * @param m1 A first SD time event. |
520 | * @param m2 A second SD time event. | |
521 | */ | |
73005152 | 522 | protected void updateMinMax(SDTimeEvent m1, SDTimeEvent m2) { |
4df4581d | 523 | ITmfTimestamp delta = m2.getTime().getDelta(m1.getTime()); |
eb63f5ff | 524 | if (fComputeMinMax) { |
4593bd5b | 525 | fMinTime = delta; |
065cc19b AM |
526 | if (fMinTime.compareTo(TmfTimestamp.ZERO) < 0) { |
527 | fMinTime = new TmfTimestamp(0, m1.getTime().getScale()); | |
73005152 | 528 | } |
4593bd5b | 529 | fMaxTime = fMinTime; |
cab6c8ff | 530 | setComputeMinMax(false); |
73005152 BH |
531 | } |
532 | ||
065cc19b | 533 | if ((delta.compareTo(fMinTime) < 0) && (delta.compareTo(TmfTimestamp.ZERO) > 0)) { |
4593bd5b | 534 | fMinTime = delta; |
73005152 BH |
535 | } |
536 | ||
065cc19b | 537 | if ((delta.compareTo(fMaxTime) > 0) && (delta.compareTo(TmfTimestamp.ZERO) > 0)) { |
4593bd5b | 538 | fMaxTime = delta; |
73005152 BH |
539 | } |
540 | } | |
541 | ||
df0b8ff4 BH |
542 | /** |
543 | * Builds the time array based on the list of graph nodes. | |
a55887ca | 544 | * |
3145ec83 | 545 | * @return the time array else empty list. |
df0b8ff4 | 546 | */ |
73005152 | 547 | protected List<SDTimeEvent> buildTimeArray() { |
cab6c8ff | 548 | if (!hasChildren()) { |
507b1336 | 549 | return new ArrayList<>(); |
df0b8ff4 | 550 | } |
73005152 | 551 | |
cab6c8ff | 552 | Iterator<String> it = getForwardSortMap().keySet().iterator(); |
507b1336 | 553 | List<SDTimeEvent> timeArray = new ArrayList<>(); |
73005152 BH |
554 | while (it.hasNext()) { |
555 | String nodeType = it.next(); | |
cab6c8ff | 556 | List<GraphNode> list = getNodeMap().get(nodeType); |
73005152 BH |
557 | for (int i = 0; i < list.size(); i++) { |
558 | Object timedNode = list.get(i); | |
559 | if ((timedNode instanceof ITimeRange) && ((ITimeRange) timedNode).hasTimeInfo()) { | |
abbdd66a | 560 | int event = list.get(i).getStartOccurrence(); |
4df4581d | 561 | ITmfTimestamp time = ((ITimeRange) list.get(i)).getStartTime(); |
73005152 BH |
562 | SDTimeEvent f = new SDTimeEvent(time, event, (ITimeRange) list.get(i)); |
563 | timeArray.add(f); | |
abbdd66a | 564 | if (event != list.get(i).getEndOccurrence()) { |
cab6c8ff | 565 | event = (list.get(i)).getEndOccurrence(); |
73005152 BH |
566 | time = ((ITimeRange) list.get(i)).getEndTime(); |
567 | f = new SDTimeEvent(time, event, (ITimeRange) list.get(i)); | |
568 | timeArray.add(f); | |
569 | } | |
570 | } | |
571 | } | |
572 | } | |
573 | return timeArray; | |
574 | } | |
575 | ||
73005152 BH |
576 | @Override |
577 | public String getArrayId() { | |
578 | return null; | |
579 | } | |
580 | ||
73005152 BH |
581 | @Override |
582 | public boolean contains(int x, int y) { | |
583 | return false; | |
584 | } | |
cab6c8ff BH |
585 | |
586 | /** | |
587 | * @return true if frame has time info else false | |
cab6c8ff BH |
588 | */ |
589 | public boolean hasTimeInfo() { | |
590 | return fHasTimeInfo; | |
591 | } | |
592 | ||
593 | /** | |
594 | * Sets the flag whether the frame has time info or not | |
ae09c4ad | 595 | * |
cab6c8ff BH |
596 | * @param hasTimeInfo |
597 | * true if frame has time info else false | |
598 | */ | |
599 | public void setHasTimeInfo(boolean hasTimeInfo) { | |
600 | fHasTimeInfo = hasTimeInfo; | |
601 | } | |
602 | ||
603 | /** | |
604 | * Sets the flag for minimum and maximum computation. | |
ae09c4ad | 605 | * |
cab6c8ff BH |
606 | * @param computeMinMax |
607 | * true if mininum and maximum time needs to be calculated else false | |
cab6c8ff BH |
608 | */ |
609 | public void setComputeMinMax(boolean computeMinMax) { | |
610 | fComputeMinMax = computeMinMax; | |
611 | } | |
612 | ||
613 | /** | |
614 | * Sets the initialization flag for SD minimum. | |
615 | * | |
616 | * @param initSDMin | |
617 | * the flag to set | |
cab6c8ff BH |
618 | */ |
619 | public void setInitSDMin(boolean initSDMin) { | |
620 | fInitSDMin = initSDMin; | |
621 | } | |
73005152 | 622 | } |