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