Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
c8422608 | 2 | * Copyright (c) 2005, 2013 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 | |
73005152 BH |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core; |
14 | ||
15 | import java.util.ArrayList; | |
16 | import java.util.Iterator; | |
17 | import java.util.List; | |
18 | ||
3bd46eef AM |
19 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
20 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
73005152 | 21 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; |
df0b8ff4 | 22 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
73005152 BH |
23 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; |
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 | * |
73005152 BH |
34 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details |
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 | */ | |
eb63f5ff | 47 | protected ITmfTimestamp fMaxTime = new TmfTimestamp(0); |
73005152 BH |
48 | /** |
49 | * Contains the min elapsed time between two consecutive messages in the whole frame | |
50 | */ | |
eb63f5ff | 51 | protected 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 | */ | |
eb63f5ff | 55 | protected 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 | */ | |
eb63f5ff | 60 | protected 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 | */ | |
eb63f5ff | 64 | protected 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 | */ | |
eb63f5ff | 68 | protected int fHorizontalIndex = 0; |
df0b8ff4 | 69 | /** |
eb63f5ff | 70 | * The time information flag. |
df0b8ff4 | 71 | */ |
eb63f5ff | 72 | protected boolean fHasTimeInfo = false; |
73005152 | 73 | /** |
df0b8ff4 | 74 | * The current Frame visible area - x coordinates |
73005152 | 75 | */ |
eb63f5ff | 76 | protected int fVisibleAreaX; |
df0b8ff4 BH |
77 | /** |
78 | * The current Frame visible area - y coordinates | |
79 | */ | |
eb63f5ff | 80 | protected int fVisibleAreaY; |
df0b8ff4 BH |
81 | /** |
82 | * The current Frame visible area - width | |
83 | */ | |
eb63f5ff | 84 | protected int fVisibleAreaWidth; |
df0b8ff4 BH |
85 | /** |
86 | * The current Frame visible area - height | |
87 | */ | |
eb63f5ff | 88 | protected int fVisibleAreaHeight; |
df0b8ff4 BH |
89 | /** |
90 | * The event occurrence spacing (-1 for none) | |
91 | */ | |
eb63f5ff | 92 | protected int fForceEventOccurrenceSpacing = -1; |
df0b8ff4 BH |
93 | /** |
94 | * Flag to indicate customized minumum and maximum. | |
95 | */ | |
eb63f5ff | 96 | protected boolean fCustomMinMax = false; |
df0b8ff4 BH |
97 | /** |
98 | * The minimum time between messages of the sequence diagram frame. | |
99 | */ | |
eb63f5ff | 100 | protected ITmfTimestamp fMinSDTime = new TmfTimestamp(); |
df0b8ff4 BH |
101 | /** |
102 | * The maximum time between messages of the sequence diagram frame. | |
103 | */ | |
eb63f5ff | 104 | protected ITmfTimestamp fMaxSDTime = new TmfTimestamp(); |
df0b8ff4 BH |
105 | /** |
106 | * Flag to indicate that initial minimum has to be computed. | |
107 | */ | |
eb63f5ff | 108 | protected 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) { | |
eb63f5ff | 168 | fComputeMinMax = 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 | ||
204 | /** | |
205 | * Returns the graph node which contains the point given in parameter for the given graph node list and starting the | |
206 | * iteration at the given index<br> | |
207 | * WARNING: Only graph nodes with smaller coordinates than the current visible area can be returned.<br> | |
a55887ca | 208 | * |
73005152 BH |
209 | * @param x the x coordinate of the point to test |
210 | * @param y the y coordinate of the point to test | |
211 | * @param list the list to search in | |
212 | * @param fromIndex list browsing starting point | |
213 | * @return the graph node containing the point given in parameter, null otherwise | |
df0b8ff4 BH |
214 | * |
215 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getNodeFromListAt(int, int, java.util.List, int) | |
73005152 BH |
216 | */ |
217 | @Override | |
218 | protected GraphNode getNodeFromListAt(int x, int y, List<GraphNode> list, int fromIndex) { | |
df0b8ff4 | 219 | if (list == null) { |
73005152 | 220 | return null; |
df0b8ff4 | 221 | } |
73005152 | 222 | for (int i = fromIndex; i < list.size(); i++) { |
abbdd66a | 223 | GraphNode node = list.get(i); |
73005152 BH |
224 | // only lifeline list is x ordered |
225 | // Stop browsing the list if the node is outside the visible area | |
226 | // all others nodes will be not visible | |
eb63f5ff | 227 | if ((node instanceof Lifeline) && (node.getX() > fVisibleAreaX + fVisibleAreaWidth)) { |
73005152 | 228 | break; |
df0b8ff4 | 229 | } |
73005152 | 230 | if (node.getHeight() < 0) { |
eb63f5ff | 231 | if (node.getY() + node.getHeight() > fVisibleAreaY + fVisibleAreaHeight) { |
73005152 | 232 | break; |
df0b8ff4 | 233 | } |
73005152 | 234 | } else { |
eb63f5ff | 235 | if (node.getY() > fVisibleAreaY + fVisibleAreaHeight) { |
73005152 | 236 | break; |
df0b8ff4 | 237 | } |
73005152 | 238 | } |
df0b8ff4 | 239 | if (node.contains(x, y)) { |
73005152 | 240 | return node; |
df0b8ff4 | 241 | } |
73005152 BH |
242 | } |
243 | return null; | |
244 | } | |
245 | ||
246 | /** | |
247 | * Draw the Frame rectangle | |
a55887ca | 248 | * |
73005152 BH |
249 | * @param context the context to draw to |
250 | */ | |
251 | protected void drawFrame(IGC context) { | |
a55887ca | 252 | |
3145ec83 | 253 | ISDPreferences pref = SDViewPref.getInstance(); |
a55887ca | 254 | |
3145ec83 BH |
255 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME)); |
256 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_FRAME)); | |
73005152 BH |
257 | |
258 | int x = getX(); | |
259 | int y = getY(); | |
260 | int w = getWidth(); | |
261 | int h = getHeight(); | |
262 | ||
263 | // Draw the frame main rectangle | |
264 | context.fillRectangle(x, y, w, h); | |
265 | context.drawRectangle(x, y, w, h); | |
266 | ||
3145ec83 BH |
267 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME_NAME)); |
268 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_FRAME_NAME)); | |
269 | context.setFont(pref.getFont(ISDPreferences.PREF_FRAME_NAME)); | |
73005152 BH |
270 | |
271 | int nameWidth = context.textExtent(getName()) + 2 * Metrics.FRAME_NAME_V_MARGIN; | |
272 | int nameHeight = Metrics.getFrameFontHeigth() + +Metrics.FRAME_NAME_H_MARGIN * 2; | |
273 | ||
274 | // Draw the frame name area | |
df0b8ff4 | 275 | if (nameWidth > w) { |
73005152 | 276 | nameWidth = w; |
df0b8ff4 | 277 | } |
73005152 BH |
278 | |
279 | int[] points = { x, y, x + nameWidth, y, x + nameWidth, y - 11 + nameHeight, x - 11 + nameWidth, y + nameHeight, x, y + nameHeight, x, y + nameHeight }; | |
280 | context.fillPolygon(points); | |
281 | context.drawPolygon(points); | |
282 | context.drawLine(x, y, x, y + nameHeight); | |
283 | ||
3145ec83 | 284 | context.setForeground(pref.getFontColor(ISDPreferences.PREF_FRAME_NAME)); |
73005152 BH |
285 | context.drawTextTruncatedCentred(getName(), x, y, nameWidth - 11, nameHeight, false); |
286 | ||
3145ec83 BH |
287 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME)); |
288 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_FRAME)); | |
73005152 BH |
289 | } |
290 | ||
73005152 BH |
291 | @Override |
292 | public void draw(IGC context) { | |
293 | draw(context, true); | |
294 | } | |
295 | ||
296 | /** | |
297 | * Draws the Frame on the given context.<br> | |
298 | * This method start width GraphNodes ordering if needed.<br> | |
299 | * After, depending on the visible area, only visible GraphNodes are drawn.<br> | |
a55887ca | 300 | * |
73005152 BH |
301 | * @param context the context to draw to |
302 | * @param drawFrame indicate if the frame rectangle need to be redrawn | |
303 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(IGC) | |
304 | */ | |
305 | protected void draw(IGC context, boolean drawFrame) { | |
eb63f5ff BH |
306 | fVisibleAreaHeight = context.getVisibleHeight(); |
307 | fVisibleAreaWidth = context.getVisibleWidth(); | |
308 | fVisibleAreaX = context.getContentsX(); | |
309 | fVisibleAreaY = context.getContentsY(); | |
73005152 | 310 | |
eb63f5ff BH |
311 | if (fForceEventOccurrenceSpacing >= 0) { |
312 | Metrics.setForcedEventSpacing(fForceEventOccurrenceSpacing); | |
df0b8ff4 | 313 | } else { |
73005152 | 314 | Metrics.setForcedEventSpacing(-1); |
df0b8ff4 | 315 | } |
73005152 | 316 | |
3145ec83 | 317 | super.drawChildenNodes(context); |
73005152 BH |
318 | } |
319 | ||
df0b8ff4 BH |
320 | /** |
321 | * Sets the event occurrence spacing (-1 for none) | |
a55887ca | 322 | * |
df0b8ff4 BH |
323 | * @param space A spacing to set. |
324 | */ | |
73005152 | 325 | public void forceEventOccurrenceSpacing(int space) { |
eb63f5ff | 326 | fForceEventOccurrenceSpacing = space; |
73005152 BH |
327 | } |
328 | ||
329 | /** | |
330 | * Return the X coordinates of the frame visible area | |
a55887ca | 331 | * |
73005152 BH |
332 | * @return the X coordinates of the frame visible area |
333 | */ | |
334 | public int getVisibleAreaX() { | |
eb63f5ff | 335 | return fVisibleAreaX; |
73005152 BH |
336 | } |
337 | ||
338 | /** | |
339 | * Return the frame visible area width | |
a55887ca | 340 | * |
73005152 BH |
341 | * @return the frame visible area width |
342 | */ | |
343 | public int getVisibleAreaWidth() { | |
eb63f5ff | 344 | return fVisibleAreaWidth; |
73005152 BH |
345 | } |
346 | ||
347 | /** | |
348 | * Return the frame visible area height | |
a55887ca | 349 | * |
73005152 BH |
350 | * @return the frame visible area height |
351 | */ | |
352 | public int getVisibleAreaHeight() { | |
eb63f5ff | 353 | return fVisibleAreaHeight; |
73005152 BH |
354 | } |
355 | ||
356 | /** | |
357 | * Return the X coordinates of the frame visible area | |
a55887ca | 358 | * |
73005152 BH |
359 | * @return the X coordinates of the frame visible area |
360 | */ | |
361 | public int getVisibleAreaY() { | |
eb63f5ff | 362 | return fVisibleAreaY; |
73005152 BH |
363 | } |
364 | ||
365 | /** | |
366 | * Return the minimum time stored in the frame taking all GraphNodes into account | |
a55887ca | 367 | * |
73005152 | 368 | * @return the minimum GraphNode time |
3bd46eef | 369 | * @since 2.0 |
73005152 | 370 | */ |
4df4581d | 371 | public ITmfTimestamp getMinTime() { |
eb63f5ff BH |
372 | if (fLastExternalTimePref != SDViewPref.getInstance().excludeExternalTime()) { |
373 | fLastExternalTimePref = SDViewPref.getInstance().excludeExternalTime(); | |
374 | fComputeMinMax = true; | |
73005152 | 375 | } |
eb63f5ff | 376 | if ((fComputeMinMax) && (!fCustomMinMax)) { |
73005152 | 377 | computeMinMax(); |
eb63f5ff | 378 | fComputeMinMax = false; |
73005152 | 379 | } |
eb63f5ff | 380 | return fMinTime; |
73005152 BH |
381 | } |
382 | ||
a55887ca AM |
383 | /** |
384 | * Set the minimum timestamp of the frame. | |
385 | * | |
386 | * @param min | |
387 | * The minimum timestamp | |
3bd46eef | 388 | * @since 2.0 |
a55887ca | 389 | */ |
d7dbf09a | 390 | public void setMin(ITmfTimestamp min) { |
eb63f5ff BH |
391 | fMinTime = min; |
392 | fCustomMinMax = true; | |
73005152 BH |
393 | } |
394 | ||
a55887ca AM |
395 | /** |
396 | * Set the maximum timestamp of the frame. | |
397 | * | |
398 | * @param max | |
399 | * The maximum timestamp | |
3bd46eef | 400 | * @since 2.0 |
a55887ca | 401 | */ |
d7dbf09a | 402 | public void setMax(ITmfTimestamp max) { |
eb63f5ff BH |
403 | fMaxTime = max; |
404 | fCustomMinMax = true; | |
73005152 BH |
405 | } |
406 | ||
a55887ca AM |
407 | /** |
408 | * Reset min/max timestamp values to the default ones. | |
409 | */ | |
73005152 | 410 | public void resetCustomMinMax() { |
eb63f5ff BH |
411 | fCustomMinMax = false; |
412 | fComputeMinMax = true; | |
73005152 BH |
413 | } |
414 | ||
415 | /** | |
416 | * Return the maximum time stored in the frame taking all GraphNodes into account | |
a55887ca | 417 | * |
73005152 | 418 | * @return the maximum GraphNode time |
3bd46eef | 419 | * @since 2.0 |
73005152 | 420 | */ |
4df4581d | 421 | public ITmfTimestamp getMaxTime() { |
eb63f5ff BH |
422 | if (fLastExternalTimePref != SDViewPref.getInstance().excludeExternalTime()) { |
423 | fLastExternalTimePref = SDViewPref.getInstance().excludeExternalTime(); | |
424 | fComputeMinMax = true; | |
73005152 | 425 | } |
eb63f5ff | 426 | if (fComputeMinMax) { |
73005152 | 427 | computeMinMax(); |
eb63f5ff | 428 | fComputeMinMax = false; |
73005152 | 429 | } |
eb63f5ff | 430 | return fMaxTime; |
73005152 BH |
431 | } |
432 | ||
df0b8ff4 | 433 | /** |
a55887ca | 434 | * Computes the minimum and maximum time between consecutive messages within the frame. |
df0b8ff4 | 435 | */ |
73005152 | 436 | protected void computeMaxMinTime() { |
eb63f5ff | 437 | if (!fInitSDMin) { |
73005152 | 438 | return; |
df0b8ff4 | 439 | } |
73005152 BH |
440 | |
441 | List<SDTimeEvent> timeArray = buildTimeArray(); | |
3145ec83 BH |
442 | |
443 | if ((timeArray == null) || timeArray.isEmpty()) { | |
73005152 | 444 | return; |
df0b8ff4 | 445 | } |
73005152 | 446 | for (int i = 0; i < timeArray.size(); i++) { |
abbdd66a | 447 | SDTimeEvent m = timeArray.get(i); |
73005152 | 448 | |
eb63f5ff BH |
449 | if (m.getTime().compareTo(fMaxSDTime, true) > 0) { |
450 | fMaxSDTime = m.getTime(); | |
73005152 BH |
451 | } |
452 | ||
eb63f5ff BH |
453 | if ((m.getTime().compareTo(fMinSDTime, true) < 0) || fInitSDMin) { |
454 | fMinSDTime = m.getTime(); | |
455 | fInitSDMin = false; | |
73005152 BH |
456 | } |
457 | } | |
458 | } | |
459 | ||
df0b8ff4 BH |
460 | /** |
461 | * Returns the minimum time between consecutive messages. | |
a55887ca | 462 | * |
df0b8ff4 | 463 | * @return the minimum time between consecutive messages |
3bd46eef | 464 | * @since 2.0 |
df0b8ff4 | 465 | */ |
4df4581d | 466 | public ITmfTimestamp getSDMinTime() { |
73005152 | 467 | computeMaxMinTime(); |
eb63f5ff | 468 | return fMinSDTime; |
73005152 BH |
469 | } |
470 | ||
df0b8ff4 BH |
471 | /** |
472 | * Returns the maximum time between consecutive messages. | |
a55887ca | 473 | * |
df0b8ff4 | 474 | * @return the maximum time between consecutive messages |
3bd46eef | 475 | * @since 2.0 |
df0b8ff4 | 476 | */ |
4df4581d | 477 | public ITmfTimestamp getSDMaxTime() { |
73005152 | 478 | computeMaxMinTime(); |
eb63f5ff | 479 | return fMaxSDTime; |
73005152 BH |
480 | } |
481 | ||
482 | /** | |
483 | * Browse all the GraphNode to compute the min and max times store in the Frame | |
484 | */ | |
485 | protected void computeMinMax() { | |
486 | List<SDTimeEvent> timeArray = buildTimeArray(); | |
3145ec83 BH |
487 | |
488 | if ((timeArray == null) || timeArray.isEmpty()) { | |
73005152 | 489 | return; |
df0b8ff4 | 490 | } |
73005152 | 491 | for (int i = 0; i < timeArray.size() - 1; i++) { |
abbdd66a AM |
492 | SDTimeEvent m1 = timeArray.get(i); |
493 | SDTimeEvent m2 = timeArray.get(i + 1); | |
a55887ca | 494 | |
73005152 | 495 | updateMinMax(m1, m2); |
73005152 BH |
496 | } |
497 | } | |
498 | ||
df0b8ff4 BH |
499 | /** |
500 | * Updates the minimum and maximum time between consecutive message within the frame based on the given values. | |
a55887ca | 501 | * |
df0b8ff4 BH |
502 | * @param m1 A first SD time event. |
503 | * @param m2 A second SD time event. | |
504 | */ | |
73005152 | 505 | protected void updateMinMax(SDTimeEvent m1, SDTimeEvent m2) { |
4df4581d | 506 | ITmfTimestamp delta = m2.getTime().getDelta(m1.getTime()); |
eb63f5ff | 507 | if (fComputeMinMax) { |
4593bd5b | 508 | fMinTime = delta; |
eb63f5ff BH |
509 | if (fMinTime.compareTo(TmfTimestamp.ZERO, false) < 0) { |
510 | fMinTime = new TmfTimestamp(0, m1.getTime().getScale(), m1.getTime().getPrecision()); | |
73005152 | 511 | } |
4593bd5b | 512 | fMaxTime = fMinTime; |
eb63f5ff | 513 | fComputeMinMax = false; |
73005152 BH |
514 | } |
515 | ||
eb63f5ff | 516 | if ((delta.compareTo(fMinTime, true) < 0) && (delta.compareTo(TmfTimestamp.ZERO, false) > 0)) { |
4593bd5b | 517 | fMinTime = delta; |
73005152 BH |
518 | } |
519 | ||
eb63f5ff | 520 | if ((delta.compareTo(fMaxTime, true) > 0) && (delta.compareTo(TmfTimestamp.ZERO, false) > 0)) { |
4593bd5b | 521 | fMaxTime = delta; |
73005152 BH |
522 | } |
523 | } | |
524 | ||
df0b8ff4 BH |
525 | /** |
526 | * Builds the time array based on the list of graph nodes. | |
a55887ca | 527 | * |
3145ec83 | 528 | * @return the time array else empty list. |
df0b8ff4 | 529 | */ |
73005152 | 530 | protected List<SDTimeEvent> buildTimeArray() { |
eb63f5ff | 531 | if (!fHasChilden) { |
3145ec83 | 532 | return new ArrayList<SDTimeEvent>(); |
df0b8ff4 | 533 | } |
73005152 | 534 | |
eb63f5ff | 535 | Iterator<String> it = fForwardSort.keySet().iterator(); |
73005152 BH |
536 | List<SDTimeEvent> timeArray = new ArrayList<SDTimeEvent>(); |
537 | while (it.hasNext()) { | |
538 | String nodeType = it.next(); | |
abbdd66a | 539 | List<GraphNode> list = fNodes.get(nodeType); |
73005152 BH |
540 | for (int i = 0; i < list.size(); i++) { |
541 | Object timedNode = list.get(i); | |
542 | if ((timedNode instanceof ITimeRange) && ((ITimeRange) timedNode).hasTimeInfo()) { | |
abbdd66a | 543 | int event = list.get(i).getStartOccurrence(); |
4df4581d | 544 | ITmfTimestamp time = ((ITimeRange) list.get(i)).getStartTime(); |
73005152 BH |
545 | SDTimeEvent f = new SDTimeEvent(time, event, (ITimeRange) list.get(i)); |
546 | timeArray.add(f); | |
abbdd66a | 547 | if (event != list.get(i).getEndOccurrence()) { |
73005152 BH |
548 | event = ((AsyncMessage) list.get(i)).getEndOccurrence(); |
549 | time = ((ITimeRange) list.get(i)).getEndTime(); | |
550 | f = new SDTimeEvent(time, event, (ITimeRange) list.get(i)); | |
551 | timeArray.add(f); | |
552 | } | |
553 | } | |
554 | } | |
555 | } | |
556 | return timeArray; | |
557 | } | |
558 | ||
73005152 BH |
559 | @Override |
560 | public String getArrayId() { | |
561 | return null; | |
562 | } | |
563 | ||
73005152 BH |
564 | @Override |
565 | public boolean contains(int x, int y) { | |
566 | return false; | |
567 | } | |
568 | } |