Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
4 | * | |
73005152 BH |
5 | * All rights reserved. This program and the accompanying materials |
6 | * are made available under the terms of the Eclipse Public License v1.0 | |
7 | * which accompanies this distribution, and is available at | |
8 | * http://www.eclipse.org/legal/epl-v10.html | |
73005152 BH |
9 | * |
10 | * Contributors: | |
11 | * IBM - Initial API and implementation | |
12 | * Bernd Hufmann - Updated for TMF | |
13 | **********************************************************************/ | |
14 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core; | |
15 | ||
16 | import java.util.ArrayList; | |
17 | import java.util.List; | |
18 | ||
19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; | |
20 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
21 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage; | |
df0b8ff4 | 22 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
73005152 BH |
23 | |
24 | /** | |
25 | * Lifeline is the UML2 lifeline graphical representation.<br> | |
26 | * Each lifeline owns a set of event occurrences. An event occurrence is the base element in UML2 to set an event in a | |
27 | * sequence diagram.<br> | |
28 | * Event occurrence define the drawing order of graph node along a lifeline. In this lifeline implementation, event | |
29 | * occurrences are just integer index. The event occurrences with the same value on different lifelines will correspond | |
30 | * the same y coordinate value. | |
31 | * | |
df0b8ff4 | 32 | * @version 1.0 |
73005152 BH |
33 | * @author sveyrier |
34 | * | |
35 | */ | |
36 | public class Lifeline extends GraphNode { | |
df0b8ff4 BH |
37 | // ------------------------------------------------------------------------ |
38 | // Constants | |
39 | // ------------------------------------------------------------------------ | |
40 | /** | |
41 | * The life line tag. | |
42 | */ | |
43 | public static final String LIFELINE_TAG = "Lifeline"; //$NON-NLS-1$ | |
73005152 | 44 | |
df0b8ff4 BH |
45 | // ------------------------------------------------------------------------ |
46 | // Attribute | |
47 | // ------------------------------------------------------------------------ | |
73005152 BH |
48 | /** |
49 | * The lifeline position in the containing frame | |
50 | */ | |
51 | protected int indexInFrame = 0; | |
73005152 BH |
52 | /** |
53 | * The frame where the lifeline is drawn | |
54 | */ | |
55 | protected Frame frame = null; | |
73005152 BH |
56 | /** |
57 | * The current event occurrence created in the lifeline | |
58 | */ | |
59 | protected int eventOccurrence = 0; | |
df0b8ff4 BH |
60 | /** |
61 | * The lifeline category. | |
62 | */ | |
73005152 | 63 | protected int category = -1; |
df0b8ff4 BH |
64 | /** |
65 | * Flag whether lifeline has time information available or not | |
66 | */ | |
73005152 BH |
67 | protected boolean hasTime = false; |
68 | ||
df0b8ff4 BH |
69 | // ------------------------------------------------------------------------ |
70 | // Constructors | |
71 | // ------------------------------------------------------------------------ | |
72 | /** | |
73 | * Default constructor | |
74 | */ | |
75 | public Lifeline() { | |
76 | prefId = ISDPreferences.PREF_LIFELINE; | |
77 | } | |
78 | ||
79 | // ------------------------------------------------------------------------ | |
80 | // Methods | |
81 | // ------------------------------------------------------------------------ | |
82 | /* | |
83 | * (non-Javadoc) | |
84 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX() | |
85 | */ | |
73005152 BH |
86 | @Override |
87 | public int getX() { | |
88 | return Metrics.FRAME_H_MARGIN + Metrics.LIFELINE_H_MAGIN + (indexInFrame - 1) * Metrics.swimmingLaneWidth(); | |
89 | } | |
90 | ||
df0b8ff4 BH |
91 | /* |
92 | * (non-Javadoc) | |
93 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY() | |
94 | */ | |
73005152 BH |
95 | @Override |
96 | public int getY() { | |
97 | return 2 * Metrics.FRAME_NAME_H_MARGIN + Metrics.LIFELINE_VT_MAGIN / 2 + Metrics.getFrameFontHeigth() + Metrics.getLifelineHeaderFontHeigth() + Metrics.FRAME_V_MARGIN + 2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN; | |
98 | } | |
99 | ||
df0b8ff4 BH |
100 | /* |
101 | * (non-Javadoc) | |
102 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth() | |
103 | */ | |
73005152 BH |
104 | @Override |
105 | public int getWidth() { | |
106 | return Metrics.getLifelineWidth(); | |
107 | } | |
108 | ||
df0b8ff4 BH |
109 | /* |
110 | * (non-Javadoc) | |
111 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight() | |
112 | */ | |
73005152 BH |
113 | @Override |
114 | public int getHeight() { | |
115 | // Set room for two text lines | |
116 | return Metrics.getLifelineFontHeigth()/** 2 */ | |
117 | + 2 * Metrics.LIFELINE_NAME_H_MARGIN; | |
118 | } | |
119 | ||
73005152 BH |
120 | /** |
121 | * Set the lifeline category for this lifeline. | |
122 | * | |
123 | * @param arrayIndex the index of the category to use | |
124 | * @see Frame#setLifelineCategories(LifelineCategories[]) | |
125 | */ | |
126 | public void setCategory(int arrayIndex) { | |
127 | category = arrayIndex; | |
128 | } | |
129 | ||
130 | /** | |
131 | * Returns the tooltip text for the lifeline. It is the combination between the category name(if any) and the | |
132 | * lifeline name | |
133 | * | |
134 | * @return the tooltip text | |
135 | */ | |
136 | public String getToolTipText() { | |
137 | if (category >= 0) { | |
138 | LifelineCategories[] categories = frame.getLifelineCategories(); | |
139 | if (category < categories.length) { | |
140 | return categories[category].getName() + " " + getName(); //$NON-NLS-1$ | |
df0b8ff4 | 141 | } else { |
73005152 | 142 | return ""; //$NON-NLS-1$ |
df0b8ff4 BH |
143 | } |
144 | } else { | |
73005152 | 145 | return ""; //$NON-NLS-1$ |
df0b8ff4 | 146 | } |
73005152 BH |
147 | } |
148 | ||
149 | /** | |
150 | * Returns the index of the first visible Execution Occurrence in the execution occurrence array.<br> | |
151 | * Execution Occurrences are Y ordered in this array | |
152 | * | |
153 | * @return the first visible Execution Occurrence | |
154 | */ | |
155 | public int getExecOccurrenceDrawIndex() { | |
df0b8ff4 | 156 | if (!hasChilden) { |
73005152 | 157 | return 0; |
df0b8ff4 BH |
158 | } |
159 | if (indexes.get(BasicExecutionOccurrence.EXEC_OCC_TAG) != null) { | |
73005152 | 160 | return ((Integer) indexes.get(BasicExecutionOccurrence.EXEC_OCC_TAG)).intValue(); |
df0b8ff4 BH |
161 | } |
162 | return 0; | |
73005152 BH |
163 | } |
164 | ||
165 | /** | |
166 | * Set the frame on which this lifeline must be drawn | |
167 | * | |
168 | * @param parentFrame | |
169 | */ | |
170 | protected void setFrame(Frame parentFrame) { | |
171 | frame = parentFrame; | |
172 | if (hasTime) { | |
173 | frame.setHasTimeInfo(true); | |
174 | } | |
df0b8ff4 | 175 | if (frame.getMaxEventOccurrence() < getEventOccurrence() + 1) { |
73005152 | 176 | frame.setMaxEventOccurrence(getEventOccurrence() + 1); |
df0b8ff4 | 177 | } |
73005152 BH |
178 | } |
179 | ||
180 | /** | |
181 | * Returns the frame which this lifeline is drawn | |
182 | * | |
183 | * @return the Frame | |
184 | */ | |
185 | protected Frame getFrame() { | |
186 | return frame; | |
187 | } | |
188 | ||
189 | /** | |
190 | * Set the lifeline position index in the containing frame | |
191 | * | |
192 | * @param index the lifeline X position | |
193 | */ | |
73005152 BH |
194 | protected void setIndex(int index) { |
195 | indexInFrame = index; | |
196 | } | |
197 | ||
198 | /** | |
199 | * Returns the lifeline position in de the containing frame | |
200 | * | |
201 | * @return the X position | |
202 | */ | |
203 | public int getIndex() { | |
204 | return indexInFrame; | |
205 | } | |
206 | ||
207 | /** | |
208 | * Set the lifeline event occurrence to the value given in parameter This only change the current event occurrence, | |
209 | * greater event created on this lifeline are still valid and usable. This also need to inform the frame of the | |
210 | * operation mostly to store in the frame the greater event found in the diagram (used to determine the frame | |
211 | * height) | |
212 | * | |
0d9a6d76 | 213 | * @param eventOcc the new current event occurrence |
73005152 BH |
214 | */ |
215 | public void setCurrentEventOccurrence(int eventOcc) { | |
df0b8ff4 | 216 | if ((frame != null) && (frame.getMaxEventOccurrence() < eventOcc)) { |
73005152 | 217 | frame.setMaxEventOccurrence(eventOcc); |
df0b8ff4 | 218 | } |
73005152 BH |
219 | eventOccurrence = eventOcc; |
220 | } | |
221 | ||
222 | /** | |
223 | * Returns the last created event occurrence along the lifeline. | |
224 | * | |
225 | * @return the current event occurrence | |
226 | */ | |
227 | public int getEventOccurrence() { | |
228 | return eventOccurrence; | |
229 | } | |
230 | ||
231 | /** | |
232 | * Creates a new event occurrence along the lifeline. | |
233 | * | |
234 | * @return the new created event occurrence | |
235 | */ | |
236 | public int getNewEventOccurrence() { | |
237 | setCurrentEventOccurrence(eventOccurrence + 1); | |
238 | return eventOccurrence; | |
239 | } | |
240 | ||
241 | /** | |
242 | * Adds the execution occurrence given in parameter to the lifeline.<br> | |
243 | * A Execution occurrence is never drawn in the frame instead it is added to a lifeline | |
244 | * | |
245 | * @param exec the execution occurrence to add | |
246 | */ | |
247 | public void addExecution(BasicExecutionOccurrence exec) { | |
248 | exec.setLifeline(this); | |
249 | addNode(exec); | |
df0b8ff4 | 250 | if ((frame != null) && (frame.getMaxEventOccurrence() < exec.endEventOccurrence)) { |
73005152 | 251 | frame.setMaxEventOccurrence(exec.endEventOccurrence); |
df0b8ff4 | 252 | } |
73005152 BH |
253 | } |
254 | ||
df0b8ff4 BH |
255 | /** |
256 | * Set whether lifeline has time information available or not. | |
257 | * @param value The value to set | |
258 | */ | |
73005152 BH |
259 | protected void setTimeInfo(boolean value) { |
260 | hasTime = value; | |
df0b8ff4 | 261 | if ((frame != null) && (value == true)) { |
73005152 | 262 | frame.setHasTimeInfo(value); |
df0b8ff4 | 263 | } |
73005152 BH |
264 | } |
265 | ||
266 | /** | |
df0b8ff4 BH |
267 | * Returns true if at least one execution occurrence has time info. |
268 | * | |
73005152 BH |
269 | * @return true if at least one execution occurrence has time info |
270 | */ | |
271 | public boolean hasTimeInfo() { | |
272 | return hasTime; | |
273 | } | |
274 | ||
275 | /** | |
df0b8ff4 | 276 | * Returns the list of execution occurrence on this lifeline. |
73005152 BH |
277 | * |
278 | * @return the execution occurrence list | |
279 | */ | |
280 | public List<GraphNode> getExecutions() { | |
df0b8ff4 | 281 | if (hasChilden) { |
73005152 | 282 | return (List<GraphNode>) nodes.get(BasicExecutionOccurrence.EXEC_OCC_TAG); |
df0b8ff4 BH |
283 | } |
284 | return new ArrayList<GraphNode>(); | |
73005152 BH |
285 | } |
286 | ||
df0b8ff4 BH |
287 | /* |
288 | * (non-Javadoc) | |
289 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int) | |
290 | */ | |
73005152 BH |
291 | @Override |
292 | public boolean contains(int _x, int _y) { | |
293 | int x = getX(); | |
294 | int y = getY(); | |
295 | int width = getWidth(); | |
296 | int height = getHeight(); | |
297 | ||
df0b8ff4 | 298 | if (frame == null) { |
73005152 | 299 | return false; |
df0b8ff4 | 300 | } |
73005152 BH |
301 | if (Frame.contains(x, y, width, height, _x, _y)) { |
302 | return true; | |
303 | } | |
304 | if (Frame.contains(x + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2, y + height, Metrics.EXECUTION_OCCURRENCE_WIDTH, (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * frame.getMaxEventOccurrence() | |
305 | + Metrics.LIFELINE_VB_MAGIN - 4, _x, _y)) { | |
306 | return true; | |
307 | } | |
308 | ||
309 | height = Metrics.getLifelineFontHeigth() + 2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN; | |
310 | int hMargin = (Metrics.LIFELINE_VT_MAGIN - height) / 2; | |
311 | ||
312 | if (hMargin >= 2) { | |
313 | if (frame.getVisibleAreaY() < y - height - hMargin) { | |
df0b8ff4 | 314 | if (Frame.contains(x - Metrics.LIFELINE_SPACING / 2 + 1, y - height - hMargin, Metrics.swimmingLaneWidth() - 2, height + 1, _x, _y)) { |
73005152 | 315 | return true; |
df0b8ff4 | 316 | } |
73005152 | 317 | } else { |
df0b8ff4 | 318 | if (Frame.contains(x - Metrics.LIFELINE_SPACING / 2 + 1, frame.getVisibleAreaY(), Metrics.swimmingLaneWidth() - 2, height, _x, _y)) { |
73005152 | 319 | return true; |
df0b8ff4 | 320 | } |
73005152 BH |
321 | } |
322 | } | |
df0b8ff4 | 323 | if (getNodeAt(_x, _y) != null) { |
73005152 | 324 | return true; |
df0b8ff4 | 325 | } |
73005152 BH |
326 | return false; |
327 | } | |
328 | ||
329 | /** | |
330 | * Returns the lifeline visibility for the given visible area | |
331 | * | |
df0b8ff4 BH |
332 | * @param vx The x coordinate of the visible area |
333 | * @param vy The y coordinate of the visible area | |
334 | * @param vwidth The width of the visible area | |
335 | * @param vheight The height of the visible area | |
73005152 BH |
336 | * @return true if visible false otherwise |
337 | */ | |
338 | @Override | |
339 | public boolean isVisible(int vx, int vy, int vwidth, int vheight) { | |
340 | int x = getX(); | |
341 | int width = getWidth(); | |
df0b8ff4 | 342 | if (((x >= vx) && (x <= vx + vwidth)) || ((x + width >= vx) && (x <= vx))) { |
73005152 | 343 | return true; |
df0b8ff4 | 344 | } |
73005152 BH |
345 | return false; |
346 | } | |
347 | ||
df0b8ff4 BH |
348 | /** |
349 | * Draws the name within the graphical context. | |
350 | * | |
351 | * @param context The graphical context. | |
352 | */ | |
73005152 BH |
353 | protected void drawName(IGC context) { |
354 | int x = getX(); | |
355 | int y = getY(); | |
356 | int height = Metrics.getLifelineHeaderFontHeigth() + 2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN; | |
357 | int hMargin = Metrics.LIFELINE_VT_MAGIN / 4;// (Metrics.LIFELINE_NAME_H_MARGIN)/2; | |
358 | ||
359 | context.setLineStyle(context.getLineSolidStyle()); | |
360 | context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_LIFELINE_HEADER)); | |
361 | context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_LIFELINE_HEADER)); | |
362 | context.setFont(Frame.getUserPref().getFont(ISDPreferences.PREF_LIFELINE_HEADER)); | |
363 | if (hMargin >= 0) { | |
364 | if (frame.getVisibleAreaY() < y - height - hMargin) { | |
365 | context.fillRectangle(x - Metrics.LIFELINE_SPACING / 2 + 1, y - height - hMargin, Metrics.swimmingLaneWidth() - 2, height); | |
366 | context.drawRectangle(x - Metrics.LIFELINE_SPACING / 2 + 1, y - height - hMargin, Metrics.swimmingLaneWidth() - 2, height); | |
367 | context.setForeground(Frame.getUserPref().getFontColor(ISDPreferences.PREF_LIFELINE_HEADER)); | |
368 | context.drawTextTruncatedCentred(getName(), x + Metrics.LIFELINE_NAME_V_MARGIN - Metrics.LIFELINE_SPACING / 2 + 1, y - height - hMargin, Metrics.swimmingLaneWidth() - 2 * Metrics.LIFELINE_NAME_V_MARGIN - 2, height, true); | |
369 | } else { | |
370 | context.fillRectangle(x - Metrics.LIFELINE_SPACING / 2 + 1, frame.getVisibleAreaY(), Metrics.swimmingLaneWidth() - 2, height); | |
371 | context.drawRectangle(x - Metrics.LIFELINE_SPACING / 2 + 1, frame.getVisibleAreaY(), Metrics.swimmingLaneWidth() - 2, height); | |
372 | context.setForeground(Frame.getUserPref().getFontColor(ISDPreferences.PREF_LIFELINE_HEADER)); | |
373 | context.drawTextTruncatedCentred(getName(), x - Metrics.LIFELINE_SPACING / 2 + Metrics.LIFELINE_NAME_V_MARGIN + 1, frame.getVisibleAreaY(), Metrics.swimmingLaneWidth() - 2 * Metrics.LIFELINE_NAME_V_MARGIN - 2, height, true); | |
374 | } | |
375 | } | |
376 | } | |
377 | ||
378 | /** | |
379 | * Force the lifeline to be drawn at the given coordinate | |
380 | * | |
381 | * @param context - the context to draw into | |
0d9a6d76 FC |
382 | * @param x - the x coordinate |
383 | * @param y - the y coordinate | |
73005152 BH |
384 | */ |
385 | public void draw(IGC context, int x, int y) { | |
386 | // Set the draw color depending if the lifeline must be selected or not | |
387 | context.setLineWidth(Metrics.NORMAL_LINE_WIDTH); | |
388 | if (isSelected()) { | |
389 | if (Frame.getUserPref().useGradienColor()) { | |
390 | context.setGradientColor(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_LIFELINE)); | |
391 | } | |
392 | context.setBackground(Frame.getUserPref().getBackGroundColorSelection()); | |
393 | context.setForeground(Frame.getUserPref().getForeGroundColorSelection()); | |
394 | } else { | |
395 | if (Frame.getUserPref().useGradienColor()) { | |
396 | context.setGradientColor(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_LIFELINE)); | |
397 | context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_FRAME)); | |
df0b8ff4 | 398 | } else { |
73005152 | 399 | context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_LIFELINE)); |
df0b8ff4 | 400 | } |
73005152 BH |
401 | context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_LIFELINE)); |
402 | } | |
403 | // Store the lifeline coordinates to save some calls | |
404 | int width = getWidth(); | |
405 | int height = getHeight(); | |
406 | ||
407 | // Draw the rectangle which contain the lifeline name | |
408 | if (Frame.getUserPref().useGradienColor()) { | |
409 | context.fillGradientRectangle(x, y, width, height / 2 - 7, true); | |
410 | context.fillRectangle(x, y + height / 2 - 8, width, +height / 2 - 5); | |
411 | context.fillGradientRectangle(x, y + height, width, -height / 2 + 6, true); | |
df0b8ff4 | 412 | } else { |
73005152 | 413 | context.fillRectangle(x, y, width, height); |
df0b8ff4 | 414 | } |
73005152 BH |
415 | context.drawRectangle(x, y, width, height); |
416 | ||
417 | if (category >= 0) { | |
418 | LifelineCategories[] categories = frame.getLifelineCategories(); | |
419 | if (category < categories.length) { | |
420 | IImage image = categories[category].getImage(); | |
df0b8ff4 | 421 | if (image != null) { |
73005152 | 422 | context.drawImage(image, x, y, width, height); |
df0b8ff4 | 423 | } |
73005152 BH |
424 | } |
425 | } | |
426 | ||
427 | // Draw the lifeline label into the rectangle | |
428 | // The label is truncated if it cannot fit | |
429 | IColor temp = context.getForeground(); | |
430 | context.setFont(Frame.getUserPref().getFont(ISDPreferences.PREF_LIFELINE)); | |
431 | context.setForeground(Frame.getUserPref().getFontColor(ISDPreferences.PREF_LIFELINE)); | |
432 | context.drawTextTruncatedCentred(getName(), x + Metrics.LIFELINE_NAME_V_MARGIN, y, Metrics.getLifelineWidth() - 2 * Metrics.LIFELINE_NAME_V_MARGIN, height, true); | |
433 | ||
434 | context.setLineStyle(context.getLineDashStyle()); | |
435 | context.setForeground(temp); | |
436 | int oldStyle = context.getLineStyle(); | |
437 | ||
438 | // Now draw the lifeline vertical line | |
439 | // this line height depends on a stop assignment | |
440 | // if there is no stop the line is drawn to the bottom of the frame | |
441 | ||
442 | // by default set the height to reach the frame bottom | |
443 | int dashedLineEnd = y + height + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * frame.getMaxEventOccurrence() + Metrics.LIFELINE_VB_MAGIN; | |
444 | /* | |
445 | * if (stop != null) { dashedLineEnd = stop.getY(); } | |
446 | */ | |
447 | ||
448 | if (isSelected()) { | |
449 | context.setForeground(Frame.getUserPref().getBackGroundColorSelection()); | |
450 | context.setLineWidth(5); | |
451 | context.drawLine(x + Metrics.getLifelineWidth() / 2, y + height, x + Metrics.getLifelineWidth() / 2, dashedLineEnd - 4); | |
452 | context.setForeground(Frame.getUserPref().getForeGroundColorSelection()); | |
453 | } | |
454 | ||
455 | context.setLineWidth(Metrics.NORMAL_LINE_WIDTH); | |
456 | context.drawLine(x + Metrics.getLifelineWidth() / 2, y + height, x + Metrics.getLifelineWidth() / 2, dashedLineEnd - 4); | |
457 | context.drawLine(x + Metrics.getLifelineWidth() / 2, y + height, x + Metrics.getLifelineWidth() / 2, dashedLineEnd - 4); | |
458 | context.setLineStyle(oldStyle); | |
459 | ||
460 | context.setLineStyle(context.getLineSolidStyle()); | |
461 | ||
df0b8ff4 | 462 | if (hasFocus()) { |
73005152 | 463 | drawFocus(context); |
df0b8ff4 | 464 | } |
73005152 BH |
465 | |
466 | super.drawChildenNodes(context); | |
467 | } | |
468 | ||
469 | /** | |
470 | * Draws the select execution occurrence region using the given color | |
471 | * | |
472 | * @param context the graphical context | |
473 | * @param startEvent the region start | |
474 | * @param nbEvent the region height | |
475 | * @param color the color to use | |
476 | */ | |
477 | public void highlightExecOccurrenceRegion(IGC context, int startEvent, int nbEvent, IColor color) { | |
478 | IColor backupColor = context.getBackground(); | |
479 | context.setBackground(color); | |
480 | int x = getX() + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2; | |
481 | int y = getY() + getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * startEvent; | |
482 | int width = Metrics.EXECUTION_OCCURRENCE_WIDTH; | |
483 | int height = ((Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing())) * nbEvent; | |
484 | context.fillRectangle(x, y, width, height); | |
485 | context.setBackground(backupColor); | |
486 | } | |
487 | ||
df0b8ff4 BH |
488 | /* |
489 | * (non-Javadoc) | |
490 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) | |
491 | */ | |
73005152 BH |
492 | @Override |
493 | public void draw(IGC context) { | |
494 | draw(context, getX(), getY()); | |
495 | } | |
496 | ||
df0b8ff4 BH |
497 | /* |
498 | * (non-Javadoc) | |
499 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId() | |
500 | */ | |
73005152 BH |
501 | @Override |
502 | public String getArrayId() { | |
503 | return LIFELINE_TAG; | |
504 | } | |
505 | ||
df0b8ff4 BH |
506 | /* |
507 | * (non-Javadoc) | |
508 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int) | |
509 | */ | |
73005152 BH |
510 | @Override |
511 | public boolean positiveDistanceToPoint(int x, int y) { | |
512 | if (getX() > x - Metrics.swimmingLaneWidth()) | |
513 | return true; | |
514 | return false; | |
515 | } | |
516 | ||
df0b8ff4 BH |
517 | /* |
518 | * (non-Javadoc) | |
519 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getNodeAt(int, int) | |
520 | */ | |
73005152 BH |
521 | @Override |
522 | public GraphNode getNodeAt(int x, int y) { | |
523 | int vy = 0; | |
524 | int vh = 0; | |
525 | if (getFrame() != null) { | |
526 | vy = getFrame().getVisibleAreaY(); | |
527 | vh = getFrame().getVisibleAreaHeight(); | |
df0b8ff4 | 528 | } else { |
73005152 | 529 | return null; |
df0b8ff4 BH |
530 | } |
531 | if (getExecutions() == null) { | |
73005152 | 532 | return null; |
df0b8ff4 | 533 | } |
73005152 BH |
534 | for (int i = getExecOccurrenceDrawIndex(); i < getExecutions().size(); i++) { |
535 | GraphNode node = (GraphNode) getExecutions().get(i); | |
536 | if (node.getHeight() < 0) { | |
df0b8ff4 | 537 | if (node.getY() + node.getHeight() > vy + vh) { |
73005152 | 538 | break; |
df0b8ff4 | 539 | } |
73005152 | 540 | } else { |
df0b8ff4 | 541 | if (node.getY() > vy + vh) { |
73005152 | 542 | break; |
df0b8ff4 | 543 | } |
73005152 BH |
544 | } |
545 | if (node.contains(x, y)) { | |
546 | GraphNode internal = node.getNodeAt(x, y); | |
df0b8ff4 | 547 | if (internal != null) { |
73005152 | 548 | return internal; |
df0b8ff4 BH |
549 | } |
550 | return node; | |
73005152 BH |
551 | } |
552 | } | |
553 | return null; | |
554 | } | |
555 | } |