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