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 org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; | |
17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
df0b8ff4 | 18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
3145ec83 | 19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; |
73005152 BH |
20 | |
21 | /** | |
22 | * The base UML2 syncMessages implementation.<br> | |
23 | * This abstract class only define one event occurrence to attach to the message.<br> | |
24 | * Usually a message has two event occurrences attached, one for both ends. But some syncMessages(like synchronous | |
25 | * syncMessages) only need one event occurrence to represent the time when they appear. Others kind of message | |
26 | * representations (like asynchronous syncMessages) will be responsible to define the missing second eventOccurrence | |
27 | * property.<br> | |
28 | * <br> | |
29 | * | |
30 | * @see Lifeline Lifeline for more event occurence details | |
df0b8ff4 | 31 | * @version 1.0 |
73005152 BH |
32 | * @author sveyrier |
33 | */ | |
34 | public abstract class BaseMessage extends GraphNode { | |
df0b8ff4 BH |
35 | |
36 | // ------------------------------------------------------------------------ | |
37 | // Attributes | |
38 | // ------------------------------------------------------------------------ | |
73005152 BH |
39 | /** |
40 | * The lifeline which send the message | |
41 | */ | |
eb63f5ff | 42 | protected Lifeline fStartLifeline = null; |
73005152 BH |
43 | /** |
44 | * The lifeline which receive the message | |
45 | */ | |
eb63f5ff | 46 | protected Lifeline fEndLifeline = null; |
df0b8ff4 BH |
47 | /** |
48 | * The visiblitiy flag. | |
49 | */ | |
eb63f5ff | 50 | protected boolean fVisible = true; |
73005152 | 51 | |
df0b8ff4 BH |
52 | // ------------------------------------------------------------------------ |
53 | // Methods | |
54 | // ------------------------------------------------------------------------ | |
55 | /* | |
56 | * (non-Javadoc) | |
57 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX() | |
58 | */ | |
73005152 BH |
59 | @Override |
60 | public int getX() { | |
61 | // returns the exact x coordinate | |
62 | return getX(false); | |
63 | } | |
64 | ||
df0b8ff4 BH |
65 | /* |
66 | * (non-Javadoc) | |
67 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY() | |
68 | */ | |
73005152 BH |
69 | @Override |
70 | public int getY() { | |
71 | /* | |
72 | * Note: lifeline.getY() return the y coordinate of the top left corner of the rectangle which contain the | |
73 | * lifeline name getHeight return the height of this rectangle The message y coordinate is then relative to this | |
74 | * position depending of its eventOccurrence Space between syncMessages is constant | |
75 | */ | |
eb63f5ff | 76 | if ((fStartLifeline != null) && (fEndLifeline != null)) { |
73005152 BH |
77 | /* |
78 | * Regular message, both ends are attached to a lifeline | |
79 | */ | |
eb63f5ff | 80 | return fEndLifeline.getY() + fEndLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fEndEventOccurrence; |
73005152 BH |
81 | |
82 | } else { | |
83 | /* | |
84 | * UML2 lost message kind | |
85 | */ | |
eb63f5ff BH |
86 | if (fStartLifeline != null) { |
87 | return fStartLifeline.getY() + fStartLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fEndEventOccurrence; | |
73005152 BH |
88 | } |
89 | ||
90 | /* | |
91 | * UML2 found message kind | |
92 | */ | |
eb63f5ff BH |
93 | if (fEndLifeline != null) { |
94 | return fEndLifeline.getY() + fEndLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fEndEventOccurrence; | |
73005152 BH |
95 | } |
96 | } | |
97 | // return 0 by default | |
98 | return 0; | |
99 | } | |
100 | ||
df0b8ff4 BH |
101 | /* |
102 | * (non-Javadoc) | |
103 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth() | |
104 | */ | |
73005152 BH |
105 | @Override |
106 | public int getWidth() { | |
107 | // Returns the exact width | |
108 | return getWidth(false); | |
109 | } | |
110 | ||
df0b8ff4 BH |
111 | /* |
112 | * (non-Javadoc) | |
113 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight() | |
114 | */ | |
73005152 BH |
115 | @Override |
116 | public int getHeight() { | |
117 | return 0; | |
118 | } | |
119 | ||
120 | /** | |
121 | * Returns the graph node x coordinate.<br> | |
122 | * Depending on the quick parameter a approximative or exact value is return.<br> | |
123 | * The approximative value does not take into account if both message ends are connected to a Lifeline Execution | |
124 | * Occurrence.<br> | |
125 | * Execution occurrence on a lifeline increase the vertical line width which represent the lifeline, this directly | |
126 | * affect the message x coordinate and width.<br> | |
127 | * <br> | |
128 | * This method is typically used to faster execute none graphical operation like tooltip lookup.<br> | |
129 | * <br> | |
130 | * | |
131 | * @param quick true to get an approximative value<br> | |
132 | * false to get the exact x value<br> | |
133 | * @return the graph node x coordinate | |
134 | */ | |
135 | protected int getX(boolean quick) { | |
136 | int x = 0; | |
137 | int activationWidth = Metrics.EXECUTION_OCCURRENCE_WIDTH / 2; | |
eb63f5ff BH |
138 | if ((fStartLifeline != null) && (fEndLifeline != null)) { |
139 | x = fStartLifeline.getX() + Metrics.getLifelineWidth() / 2; | |
73005152 | 140 | } else { |
eb63f5ff BH |
141 | if (fStartLifeline != null) { |
142 | x = fStartLifeline.getX() + Metrics.getLifelineWidth() / 2; | |
73005152 BH |
143 | } |
144 | ||
eb63f5ff BH |
145 | if (fEndLifeline != null) { |
146 | x = fEndLifeline.getX() - Metrics.LIFELINE_SPACING / 2; | |
73005152 BH |
147 | } |
148 | } | |
149 | ||
df0b8ff4 | 150 | if (quick) { |
73005152 | 151 | return x; |
df0b8ff4 | 152 | } |
73005152 | 153 | |
eb63f5ff | 154 | if ((fStartLifeline != null) && (fEndLifeline != null) && (fStartLifeline.getX() > fEndLifeline.getX())) { |
73005152 BH |
155 | activationWidth = -activationWidth; |
156 | } | |
157 | ||
eb63f5ff | 158 | if (isMessageStartInActivation(fEndEventOccurrence)) { |
73005152 BH |
159 | x = x + activationWidth; |
160 | } | |
161 | ||
162 | return x; | |
163 | } | |
164 | ||
165 | /** | |
166 | * Returns the graph node width.<br> | |
167 | * Depending on the quick parameter a approximative or exact value is returned.<br> | |
168 | * The approximative value does not take into account if both message ends are connected to a Lifeline Execution | |
169 | * Occurrence.<br> | |
170 | * Execution occurrence on a lifeline increase the vertical line width which represent the lifeline, this directly | |
171 | * affect the message x coordinate and width.<br> | |
172 | * <br> | |
173 | * This method is typically used to faster execute none graphical operation like tooltip lookup.<br> | |
174 | * <br> | |
175 | * | |
176 | * @param quick true to get an approximative value<br> | |
177 | * false to get the exact x value | |
178 | * @return the graph node width | |
179 | */ | |
180 | protected int getWidth(boolean quick) { | |
181 | int width = 0; | |
182 | int activationWidth = Metrics.EXECUTION_OCCURRENCE_WIDTH / 2; | |
eb63f5ff BH |
183 | if ((fStartLifeline != null) && (fEndLifeline != null)) { |
184 | if (fStartLifeline == fEndLifeline) { | |
73005152 | 185 | width = Metrics.INTERNAL_MESSAGE_WIDTH + Metrics.EXECUTION_OCCURRENCE_WIDTH; |
df0b8ff4 | 186 | } else { |
eb63f5ff | 187 | width = fEndLifeline.getX() + Metrics.getLifelineWidth() / 2 - getX(true); |
df0b8ff4 | 188 | } |
73005152 | 189 | } else { |
eb63f5ff | 190 | if (fStartLifeline != null) { |
73005152 BH |
191 | width = Metrics.swimmingLaneWidth() / 2; |
192 | } | |
eb63f5ff | 193 | if (fEndLifeline != null) { |
73005152 BH |
194 | width = Metrics.swimmingLaneWidth() / 2; |
195 | } | |
196 | } | |
197 | ||
df0b8ff4 | 198 | if (quick) { |
73005152 | 199 | return width; |
df0b8ff4 | 200 | } |
73005152 | 201 | |
eb63f5ff | 202 | if ((fStartLifeline != null) && (fEndLifeline != null) && (fStartLifeline.getX() > fEndLifeline.getX())) { |
73005152 BH |
203 | activationWidth = -activationWidth; |
204 | } | |
205 | ||
eb63f5ff | 206 | if (isMessageStartInActivation(fEndEventOccurrence)) { |
73005152 | 207 | width = width - activationWidth; |
df0b8ff4 | 208 | } |
73005152 | 209 | |
eb63f5ff | 210 | if (isMessageEndInActivation(fEndEventOccurrence)) { |
73005152 | 211 | width = width - activationWidth; |
df0b8ff4 | 212 | } |
73005152 BH |
213 | |
214 | return width; | |
215 | } | |
216 | ||
df0b8ff4 BH |
217 | /* |
218 | * (non-Javadoc) | |
219 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int) | |
220 | */ | |
73005152 BH |
221 | @Override |
222 | public boolean isVisible(int x, int y, int width, int height) { | |
223 | // ***Common*** syncMessages visibility | |
224 | // draw the message only if at least one end is visible | |
eb63f5ff | 225 | if (fEndLifeline != null && (fEndLifeline.isVisible(x, y, width, height)) || (fStartLifeline != null && fStartLifeline.isVisible(x, y, width, height))) { |
73005152 | 226 | return true; |
df0b8ff4 | 227 | } |
73005152 | 228 | // In this case it can be a message which cross the whole visible area |
eb63f5ff BH |
229 | else if (fEndLifeline != null && (!fEndLifeline.isVisible(x, y, width, height)) && (fStartLifeline != null && !fStartLifeline.isVisible(x, y, width, height))) { |
230 | if (fEndLifeline.getX() > x + width && fStartLifeline.getX() < x) { | |
73005152 | 231 | return true; |
eb63f5ff | 232 | } else if (fStartLifeline.getX() > x + width && fEndLifeline.getX() < x) { |
73005152 | 233 | return true; |
df0b8ff4 | 234 | } |
73005152 BH |
235 | } |
236 | return false; | |
237 | } | |
238 | ||
df0b8ff4 BH |
239 | /** |
240 | * Sets the visibility value. | |
241 | * | |
242 | * @param value The visibility to set. | |
243 | */ | |
73005152 | 244 | public void setVisible(boolean value) { |
eb63f5ff | 245 | fVisible = value; |
73005152 BH |
246 | } |
247 | ||
df0b8ff4 BH |
248 | /** |
249 | * @return the visibility value. | |
250 | */ | |
73005152 | 251 | public boolean isVisible() { |
eb63f5ff | 252 | return fVisible; |
73005152 BH |
253 | } |
254 | ||
255 | /** | |
256 | * Set the lifeline from which this message has been sent. | |
257 | * | |
258 | * @param lifeline - the message sender | |
259 | */ | |
260 | public void setStartLifeline(Lifeline lifeline) { | |
eb63f5ff | 261 | fStartLifeline = lifeline; |
73005152 BH |
262 | } |
263 | ||
264 | /** | |
265 | * Returns the lifeline from which this message has been sent. | |
266 | * | |
267 | * @return the message sender | |
268 | */ | |
269 | public Lifeline getStartLifeline() { | |
eb63f5ff | 270 | return fStartLifeline; |
73005152 BH |
271 | } |
272 | ||
273 | /** | |
274 | * Returns the lifeline which has received this message. | |
275 | * | |
276 | * @return the message receiver | |
277 | */ | |
278 | public Lifeline getEndLifeline() { | |
eb63f5ff | 279 | return fEndLifeline; |
73005152 BH |
280 | } |
281 | ||
282 | /** | |
283 | * Set the lifeline which has receive this message. | |
284 | * | |
285 | * @param lifeline the message receiver | |
286 | */ | |
287 | public void setEndLifeline(Lifeline lifeline) { | |
eb63f5ff | 288 | fEndLifeline = lifeline; |
73005152 BH |
289 | } |
290 | ||
291 | /** | |
292 | * Set the event occurrence when this message occurs.<br> | |
293 | * | |
294 | * @param occurrence the event occurrence to assign to this message.<br> | |
295 | * @see Lifeline Lifeline for more event occurence details | |
296 | */ | |
297 | protected void setEventOccurrence(int occurrence) { | |
eb63f5ff | 298 | fEndEventOccurrence = occurrence; |
73005152 BH |
299 | } |
300 | ||
301 | /** | |
302 | * Returns the event occurence when is message occurs.<br> | |
303 | * | |
304 | * @return the event occurrence assigned to this message.<br> | |
305 | * @see Lifeline Lifeline for more event occurence details | |
306 | */ | |
307 | public int getEventOccurrence() { | |
eb63f5ff | 308 | return fEndEventOccurrence; |
73005152 BH |
309 | } |
310 | ||
311 | /** | |
312 | * Determines if the given eventOccurence occurs on a executionOccurence owned by the sending lifeline.<br> | |
313 | * WARNING: this method will return a valid result only for execution occurrences which are visible in the View.<br> | |
314 | * As consequence this method is only used for drawing purpose, especially to determine the exact message x | |
315 | * coordinate and width.<br> | |
316 | * | |
317 | * @see BaseMessage#getX(boolean) | |
318 | * @param event the event occurrence to test | |
319 | * @return true if occurs on a execution occurrence owned by the sending lifeine, false otherwise | |
320 | */ | |
321 | protected boolean isMessageStartInActivation(int event) { | |
322 | boolean inActivation = false; | |
eb63f5ff | 323 | if ((fStartLifeline != null) && (fStartLifeline.getExecutions() != null)) { |
73005152 BH |
324 | // int acIndex=startLifeline.getExecOccurrenceDrawIndex(); |
325 | // acIndex = first visible execution occurrence | |
326 | // for drawing speed reason with only search on the visivle subset | |
327 | int thisY = getY(); | |
eb63f5ff BH |
328 | for (int i = 0; i < fStartLifeline.getExecutions().size(); i++) { |
329 | BasicExecutionOccurrence toDraw = (BasicExecutionOccurrence) fStartLifeline.getExecutions().get(i); | |
330 | if ((event >= toDraw.fStartEventOccurrence) && (event <= toDraw.fEndEventOccurrence)) { | |
73005152 | 331 | inActivation = true; |
df0b8ff4 | 332 | } |
73005152 BH |
333 | // if we are outside the visible area we stop right now |
334 | // This works because execution occurrences are ordered along the Y axis | |
df0b8ff4 | 335 | if (toDraw.getY() > thisY) { |
73005152 | 336 | break; |
df0b8ff4 | 337 | } |
73005152 BH |
338 | } |
339 | } | |
340 | return inActivation; | |
341 | } | |
342 | ||
343 | /** | |
344 | * Determines if the given event occurrence occurs on a execution occurrence owned by the receiving lifeline.<br> | |
345 | * WARNING: this method will return a valid result only for execution occurrences which are visible in the View.<br> | |
346 | * As consequence this method is only used for drawing purpose, especially to determine the exact message x | |
347 | * coordinate and width.<br> | |
348 | * | |
349 | * @see BaseMessage#getX(boolean) | |
350 | * @param event the event occurrence to test | |
351 | * @return true if occurs on a execution occurrence owned by the receiving lifeline, false otherwise | |
352 | */ | |
353 | protected boolean isMessageEndInActivation(int event) { | |
354 | boolean inActivation = false; | |
eb63f5ff | 355 | if ((fEndLifeline != null) && (fEndLifeline.getExecutions() != null)) { |
73005152 BH |
356 | // acIndex = first visible execution occurrence |
357 | // for drawing speed reason with only search on the visivle subset | |
eb63f5ff BH |
358 | for (int i = 0; i < fEndLifeline.getExecutions().size(); i++) { |
359 | BasicExecutionOccurrence toDraw = (BasicExecutionOccurrence) fEndLifeline.getExecutions().get(i); | |
360 | if ((event >= toDraw.fStartEventOccurrence) && (event <= toDraw.fEndEventOccurrence)) { | |
73005152 | 361 | inActivation = true; |
df0b8ff4 | 362 | } |
73005152 BH |
363 | // if we are outside the visible area we stop right now |
364 | // This works because execution occurrences are ordered along the Y axis | |
df0b8ff4 | 365 | if (toDraw.getY() > getY()) { |
73005152 | 366 | break; |
df0b8ff4 | 367 | } |
73005152 BH |
368 | } |
369 | } | |
370 | return inActivation; | |
371 | } | |
372 | ||
df0b8ff4 BH |
373 | /* |
374 | * (non-Javadoc) | |
375 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int) | |
73005152 BH |
376 | */ |
377 | @Override | |
eb63f5ff | 378 | public boolean contains(int xValue, int yValue) { |
73005152 BH |
379 | int x = getX(); |
380 | int y = getY(); | |
381 | int width = getWidth(); | |
382 | int height = getHeight(); | |
383 | ||
384 | // Used to create a rectangle which contains the message label to allow selection when clicking the label | |
385 | int tempHeight = Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(); | |
386 | ||
387 | // Is it a self message? | |
eb63f5ff | 388 | if (fStartLifeline == fEndLifeline) { |
73005152 BH |
389 | /* |
390 | * Rectangle.contains(x,y, width, height) does not works with negative height or width We check here if the | |
391 | * rectangle width is negative. | |
392 | */ | |
393 | if (getName().length() * Metrics.getAverageCharWidth() > Metrics.swimmingLaneWidth() - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2 + -Metrics.INTERNAL_MESSAGE_WIDTH) { | |
eb63f5ff | 394 | if (Frame.contains(x + Metrics.INTERNAL_MESSAGE_WIDTH + 10, y, Metrics.swimmingLaneWidth() - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2 + -Metrics.INTERNAL_MESSAGE_WIDTH, Metrics.getMessageFontHeigth(), xValue, yValue)) { |
73005152 | 395 | return true; |
df0b8ff4 | 396 | } |
73005152 | 397 | } else { |
eb63f5ff | 398 | if (Frame.contains(x + Metrics.INTERNAL_MESSAGE_WIDTH + 10, y, getName().length() * Metrics.getAverageCharWidth(), Metrics.getMessageFontHeigth(), xValue, yValue)) { |
73005152 | 399 | return true; |
df0b8ff4 | 400 | } |
73005152 BH |
401 | } |
402 | ||
403 | // Test if the point is in part 1 of the self message | |
404 | // see: "private void drawMessage (NGC context)" method for self message drawing schema | |
eb63f5ff | 405 | if (Frame.contains(x, y - Metrics.MESSAGE_SELECTION_TOLERANCE / 2, Metrics.INTERNAL_MESSAGE_WIDTH / 2, Metrics.MESSAGE_SELECTION_TOLERANCE, xValue, yValue)) { |
73005152 | 406 | return true; |
df0b8ff4 | 407 | } |
73005152 BH |
408 | |
409 | // Test if the point is in part 3 of the self message | |
eb63f5ff | 410 | if (Frame.contains(x + Metrics.INTERNAL_MESSAGE_WIDTH - Metrics.MESSAGE_SELECTION_TOLERANCE / 2, y, Metrics.MESSAGE_SELECTION_TOLERANCE, height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT, xValue, yValue)) { |
73005152 | 411 | return true; |
df0b8ff4 | 412 | } |
73005152 BH |
413 | |
414 | // Test if the point is in part 5 of the self message | |
eb63f5ff | 415 | if (Frame.contains(x, y + height - Metrics.MESSAGE_SELECTION_TOLERANCE / 2 + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT, Metrics.INTERNAL_MESSAGE_WIDTH / 2, Metrics.MESSAGE_SELECTION_TOLERANCE, xValue, yValue)) { |
73005152 | 416 | return true; |
df0b8ff4 | 417 | } |
73005152 BH |
418 | |
419 | // false otherwise | |
420 | return false; | |
421 | } | |
eb63f5ff | 422 | if (Frame.contains(x, y - tempHeight, width, tempHeight, xValue, yValue)) { |
73005152 | 423 | return true; |
df0b8ff4 | 424 | } |
73005152 BH |
425 | // false otherwise |
426 | return false; | |
427 | } | |
428 | ||
df0b8ff4 BH |
429 | /** |
430 | * Method to draw the message using the graphical context. | |
431 | * | |
432 | * @param context A graphical context to draw in. | |
433 | */ | |
73005152 BH |
434 | protected void drawMessage(IGC context) { |
435 | int fX, fY, fW, fH; | |
436 | fX = fY = fW = fH = 0; | |
437 | ||
3145ec83 | 438 | // temporary store the coordinates to avoid more methods calls |
73005152 BH |
439 | int x = getX(); |
440 | int y = getY(); | |
441 | int width = getWidth(); | |
442 | int height = getHeight(); | |
443 | ||
3145ec83 BH |
444 | ISDPreferences pref = SDViewPref.getInstance(); |
445 | ||
73005152 BH |
446 | // UML2 found message (always drawn from left to right) |
447 | // or UML2 lost message (always drawn from left to right) | |
eb63f5ff | 448 | if ((fStartLifeline == null || fEndLifeline == null) && fStartLifeline != fEndLifeline) { |
73005152 BH |
449 | // Draw the message label above the message and centered |
450 | // The label is truncated if it cannot fit between the two message end | |
451 | // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label | |
452 | IColor temp = context.getForeground(); | |
3145ec83 | 453 | context.setForeground(pref.getFontColor(fPrefId)); |
73005152 BH |
454 | context.drawTextTruncatedCentred(getName(), x, y - Metrics.getMessageFontHeigth() - 2 * Metrics.MESSAGES_NAME_SPACING, width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected()); |
455 | context.setForeground(temp); | |
456 | int margin = 0; | |
eb63f5ff | 457 | if (fEndLifeline == null) { |
73005152 | 458 | margin = Metrics.MESSAGE_CIRCLE_RAY; |
df0b8ff4 | 459 | } |
73005152 BH |
460 | |
461 | // Draw the message main line | |
462 | context.drawLine(x, y, x + width, y + height); | |
463 | // Draw the two little lines which make a arrow part of the message | |
eb63f5ff BH |
464 | Double xt = Double.valueOf(Math.cos(0.75) * 7); |
465 | Double yt = Double.valueOf(Math.sin(0.75) * 7); | |
73005152 BH |
466 | if (context.getLineStyle() == context.getLineSolidStyle()) { |
467 | IColor backcolor = context.getBackground(); | |
468 | context.setBackground(context.getForeground()); | |
469 | int[] points = { x + width - margin, y + height, x + width - xt.intValue() - margin, y + height - yt.intValue(), x + width - xt.intValue() - margin, y + height + yt.intValue(), x + width - margin, y + height }; | |
470 | context.fillPolygon(points); | |
471 | context.drawPolygon(points); | |
472 | context.setBackground(backcolor); | |
473 | } else { | |
474 | int currentStyle = context.getLineStyle(); | |
475 | int currentWidth = context.getLineWidth(); | |
476 | context.setLineWidth(currentWidth + 2); | |
477 | context.setLineStyle(context.getLineSolidStyle()); | |
478 | context.drawLine(x + width - xt.intValue() - margin, y + height - yt.intValue(), x + width - margin, y + height); | |
479 | context.drawLine(x + width - xt.intValue() - margin, y + height + yt.intValue(), x + width - margin, y + height); | |
480 | context.setLineStyle(currentStyle); | |
481 | context.setLineWidth(currentWidth); | |
482 | } | |
483 | IColor storedColor = context.getBackground(); | |
484 | context.setBackground(context.getForeground()); | |
485 | ||
486 | // Draw a circle at the message end (endLifeline side) | |
487 | int ray = Metrics.MESSAGE_CIRCLE_RAY; | |
df0b8ff4 | 488 | if (context.getLineWidth() != Metrics.NORMAL_LINE_WIDTH) { |
73005152 | 489 | ray = ray + Metrics.SELECTION_LINE_WIDTH - Metrics.NORMAL_LINE_WIDTH; |
df0b8ff4 | 490 | } |
eb63f5ff | 491 | if (fStartLifeline == null) { |
73005152 | 492 | context.fillOval(x - ray, y - ray, ray * 2, ray * 2); |
df0b8ff4 | 493 | } else { |
73005152 | 494 | context.fillOval(x + width - ray, y + height - ray, ray * 2, ray * 2); |
df0b8ff4 | 495 | } |
73005152 | 496 | context.setBackground(storedColor); |
3145ec83 | 497 | context.setForeground(pref.getFontColor(fPrefId)); |
73005152 BH |
498 | fX = x; |
499 | fY = y - yt.intValue(); | |
500 | fW = width; | |
501 | fH = height + 2 * yt.intValue(); | |
502 | } | |
503 | // it is self message (always drawn at the left side of the owning lifeLifeline) | |
eb63f5ff | 504 | else if (fStartLifeline != null && fEndLifeline != null && fStartLifeline == fEndLifeline) { |
73005152 BH |
505 | /* |
506 | * Self syncMessages are drawn in 5 parts 1 -----------+ + 2 + | | | 3 | + 5 + 4 -----------+ | |
507 | */ | |
508 | int tempy = Metrics.INTERNAL_MESSAGE_WIDTH / 2; | |
df0b8ff4 | 509 | if (Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT <= Metrics.INTERNAL_MESSAGE_WIDTH) { |
73005152 | 510 | tempy = Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT / 2; |
df0b8ff4 | 511 | } |
73005152 BH |
512 | |
513 | // Part 1 | |
514 | context.drawLine(x, y, x + Metrics.INTERNAL_MESSAGE_WIDTH / 2, y); | |
515 | // Part 3 | |
516 | context.drawLine(x + Metrics.INTERNAL_MESSAGE_WIDTH, y + tempy, x + Metrics.INTERNAL_MESSAGE_WIDTH, y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT - tempy); | |
517 | // Part 5 | |
518 | context.drawLine(x, y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT, x + Metrics.INTERNAL_MESSAGE_WIDTH / 2, y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT); | |
519 | ||
eb63f5ff BH |
520 | Double xt = Double.valueOf(Math.cos(0.75) * 7); |
521 | Double yt = Double.valueOf(Math.sin(0.75) * 7); | |
73005152 BH |
522 | |
523 | fX = x; | |
524 | fY = y; | |
525 | fW = Metrics.INTERNAL_MESSAGE_WIDTH; | |
526 | fH = height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT; | |
527 | ||
528 | // Draw the two little lines which make a arrow part of the message | |
529 | if (context.getLineStyle() == context.getLineSolidStyle()) { | |
530 | IColor backcolor = context.getBackground(); | |
531 | context.setBackground(context.getForeground()); | |
532 | int[] points = { x, y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT, x + xt.intValue(), y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT + yt.intValue(), x + xt.intValue(), | |
533 | y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT - yt.intValue(), x, y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT }; | |
534 | context.fillPolygon(points); | |
535 | context.drawPolygon(points); | |
536 | context.setBackground(backcolor); | |
537 | } else { | |
538 | int currentStyle = context.getLineStyle(); | |
539 | int currentWidth = context.getLineWidth(); | |
540 | context.setLineWidth(currentWidth + 2); | |
541 | context.setLineStyle(context.getLineSolidStyle()); | |
542 | context.drawLine(x + xt.intValue(), y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT + yt.intValue(), x, y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT); | |
543 | context.drawLine(x + xt.intValue(), y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT - yt.intValue(), x, y + height + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT); | |
544 | context.setLineStyle(currentStyle); | |
545 | context.setLineWidth(currentWidth); | |
546 | } | |
547 | ||
548 | // Part 2 | |
549 | context.drawArc(x, y, Metrics.INTERNAL_MESSAGE_WIDTH, 2 * tempy, 0, 90); | |
550 | // Part 4 | |
551 | context.drawArc(x, y + Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT, Metrics.INTERNAL_MESSAGE_WIDTH, -2 * tempy, 0, -90); | |
552 | ||
553 | // Draw the message label above the message and centered | |
554 | // The label is truncated if it cannot fit between the two message end | |
555 | // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label | |
556 | ||
557 | // the space available for the text is sorter if are drawing internal message on the last lifeline | |
3145ec83 | 558 | context.setForeground(pref.getFontColor(fPrefId)); |
eb63f5ff | 559 | if (fStartLifeline.getIndex() == fStartLifeline.getFrame().getHorizontalIndex()) { |
73005152 BH |
560 | context.drawTextTruncated(getName(), x + width + Metrics.INTERNAL_MESSAGE_V_MARGIN / 2, y, Metrics.swimmingLaneWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH + -Metrics.INTERNAL_MESSAGE_WIDTH, +Metrics.MESSAGES_NAME_SPACING |
561 | - Metrics.getMessageFontHeigth(), !isSelected()); | |
df0b8ff4 | 562 | } else { |
73005152 BH |
563 | context.drawTextTruncated(getName(), x + width + Metrics.INTERNAL_MESSAGE_V_MARGIN / 2, y, Metrics.swimmingLaneWidth() - Metrics.EXECUTION_OCCURRENCE_WIDTH + -Metrics.INTERNAL_MESSAGE_WIDTH, |
564 | +Metrics.MESSAGES_NAME_SPACING - Metrics.getMessageFontHeigth(), !isSelected()); | |
df0b8ff4 | 565 | } |
73005152 BH |
566 | } |
567 | // it is regular message | |
eb63f5ff | 568 | else if (fStartLifeline != null && fEndLifeline != null) { |
73005152 BH |
569 | // Draw the message main line |
570 | context.drawLine(x, y, x + width, y + height); | |
571 | ||
eb63f5ff | 572 | int spaceBTWStartEnd = fEndLifeline.getX() - fStartLifeline.getX(); |
73005152 BH |
573 | |
574 | double a = height; | |
575 | double b = width; | |
576 | double angle = Math.atan(a / b); | |
577 | // Compute the coordinates of the two little lines which make the arrow part of the message | |
578 | int sign = 1; | |
df0b8ff4 | 579 | if (spaceBTWStartEnd < 0) { |
73005152 | 580 | sign = -1; |
df0b8ff4 | 581 | } |
eb63f5ff BH |
582 | Double x1 = Double.valueOf(sign * Math.cos(angle - 0.75) * 7); |
583 | Double y1 = Double.valueOf(sign * Math.sin(angle - 0.75) * 7); | |
584 | Double x2 = Double.valueOf(sign * Math.cos(angle + 0.75) * 7); | |
585 | Double y2 = Double.valueOf(sign * Math.sin(angle + 0.75) * 7); | |
73005152 BH |
586 | |
587 | fX = getX(); | |
588 | fY = y + height - y2.intValue(); | |
589 | fW = getWidth(); | |
590 | fH = y2.intValue() - y1.intValue() + 1; | |
591 | if (fW < 0) { | |
592 | fW = -fW; | |
593 | fX = fX - fW; | |
594 | } | |
595 | ||
596 | if (fH < 0) { | |
597 | fH = -fH; | |
598 | fY = fY - fH; | |
599 | } | |
600 | ||
601 | // Draw the two little lines which make a arrow part of the message | |
602 | if (context.getLineStyle() == context.getLineSolidStyle()) { | |
603 | IColor backcolor = context.getBackground(); | |
604 | context.setBackground(context.getForeground()); | |
605 | int[] points = { x + width - x1.intValue(), y + height - y1.intValue(), x + width, y + height, x + width - x2.intValue(), y + height - y2.intValue(), x + width - x1.intValue(), y + height - y1.intValue() }; | |
606 | context.fillPolygon(points); | |
607 | context.drawPolygon(points); | |
608 | context.setBackground(backcolor); | |
609 | } else { | |
610 | int currentStyle = context.getLineStyle(); | |
611 | int currentWidth = context.getLineWidth(); | |
612 | context.setLineWidth(currentWidth + 2); | |
613 | context.setLineStyle(context.getLineSolidStyle()); | |
614 | context.drawLine(x + width - x1.intValue(), y + height - y1.intValue(), x + width, y + height); | |
615 | context.drawLine(x + width - x2.intValue(), y + height - y2.intValue(), x + width, y + height); | |
616 | context.setLineStyle(currentStyle); | |
617 | context.setLineWidth(currentWidth); | |
618 | } | |
619 | ||
620 | // Draw the message label above the message and centered | |
621 | // The label is truncated if it cannot fit between the two message end | |
622 | // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label | |
3145ec83 | 623 | context.setForeground(pref.getFontColor(fPrefId)); |
df0b8ff4 | 624 | if (spaceBTWStartEnd > 0) { |
73005152 | 625 | context.drawTextTruncatedCentred(getName(), x, y + height / 2 - (2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth()), width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected()); |
df0b8ff4 | 626 | } else { |
73005152 | 627 | context.drawTextTruncatedCentred(getName(), x + width, y + height / 2 - (2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth()), -width, 2 * Metrics.MESSAGES_NAME_SPACING + +Metrics.getMessageFontHeigth(), !isSelected()); |
df0b8ff4 | 628 | } |
73005152 BH |
629 | } |
630 | } | |
df0b8ff4 BH |
631 | |
632 | /* | |
633 | * (non-Javadoc) | |
634 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNodee#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) | |
635 | */ | |
73005152 BH |
636 | @Override |
637 | public void draw(IGC context) { | |
df0b8ff4 | 638 | if (!isVisible()) { |
73005152 | 639 | return; |
df0b8ff4 | 640 | } |
3145ec83 | 641 | |
73005152 BH |
642 | // Draw it selected?*/ |
643 | if (isSelected()) { | |
3145ec83 | 644 | ISDPreferences pref = SDViewPref.getInstance(); |
73005152 BH |
645 | /* |
646 | * Draw it twice First time, bigger inverting selection colors Second time, regular drawing using selection | |
647 | * colors This create the highlight effect | |
648 | */ | |
3145ec83 | 649 | context.setForeground(pref.getBackGroundColorSelection()); |
73005152 BH |
650 | context.setLineWidth(Metrics.SELECTION_LINE_WIDTH); |
651 | drawMessage(context); | |
3145ec83 BH |
652 | context.setBackground(pref.getBackGroundColorSelection()); |
653 | context.setForeground(pref.getForeGroundColorSelection()); | |
73005152 BH |
654 | // Second drawing is done after |
655 | } | |
656 | context.setLineWidth(Metrics.NORMAL_LINE_WIDTH); | |
657 | if (hasFocus()) { | |
658 | context.setDrawTextWithFocusStyle(true); | |
659 | } | |
660 | drawMessage(context); | |
661 | int oldStyle = context.getLineStyle(); | |
662 | if (hasFocus()) { | |
663 | context.setDrawTextWithFocusStyle(false); | |
664 | drawFocus(context); | |
665 | } | |
666 | // restore the context | |
667 | context.setLineStyle(oldStyle); | |
668 | } | |
669 | ||
670 | /** | |
671 | * Determine if two messages are identical. This default implementation considers that overlapping messages with | |
672 | * same coordinates are identical. | |
673 | * | |
674 | * @param message - the message to compare with | |
675 | * @return true if identical false otherwise | |
df0b8ff4 BH |
676 | * |
677 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isSameAs(org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode) | |
73005152 BH |
678 | */ |
679 | @Override | |
680 | public boolean isSameAs(GraphNode message) { | |
df0b8ff4 | 681 | if (message == null) { |
73005152 | 682 | return false; |
df0b8ff4 BH |
683 | } |
684 | if (!(message instanceof BaseMessage)) { | |
73005152 | 685 | return super.isSameAs(message); |
df0b8ff4 | 686 | } |
eb63f5ff | 687 | return ((getX() == message.getX()) && (getY() == message.getY()) && (getWidth() == message.getWidth()) && (getHeight() == message.getHeight())); |
73005152 BH |
688 | } |
689 | ||
df0b8ff4 BH |
690 | /** |
691 | * Method drawRot. | |
692 | * | |
693 | * @param x A x coordinate | |
694 | * @param y A y coordinate | |
695 | * @param w A width | |
696 | * @param h A height | |
697 | * @param context A graphical context | |
698 | */ | |
73005152 BH |
699 | public void drawRot(int x, int y, int w, int h, IGC context) { |
700 | double angleA = Math.atan2(getHeight(), getWidth()); | |
701 | double cosA = Math.cos(angleA); | |
702 | double sinA = Math.sin(angleA); | |
703 | ||
704 | int gx = getX(); | |
705 | int gy = getY(); | |
706 | ||
eb63f5ff BH |
707 | int localHeight = h; |
708 | localHeight = localHeight / 2; | |
73005152 BH |
709 | |
710 | double cw = Math.sqrt(w * w + getHeight() * getHeight()); | |
711 | ||
712 | int x1 = Math.round((float) ((x - gx) * cosA - (y - gy) * sinA)); | |
713 | int y1 = Math.round((float) ((x - gx) * sinA + (y - gy) * cosA)); | |
714 | ||
715 | int x2 = Math.round((float) (cw * cosA - (y - gy) * sinA)); | |
716 | int y2 = Math.round((float) (cw * sinA + (y - gy) * cosA)); | |
717 | ||
eb63f5ff BH |
718 | int x3 = Math.round((float) (cw * cosA - (localHeight) * sinA)); |
719 | int y3 = Math.round((float) (cw * sinA + (localHeight) * cosA)); | |
73005152 | 720 | |
eb63f5ff BH |
721 | int x4 = Math.round((float) ((x - gx) * cosA - (localHeight) * sinA)); |
722 | int y4 = Math.round((float) ((x - gx) * sinA + (localHeight) * cosA)); | |
73005152 BH |
723 | |
724 | int[] points = { x1 + getX(), y1 + getY(), x2 + getX(), y2 + getY(), x3 + getX(), y3 + getY(), x4 + getX(), y4 + getY() }; | |
725 | context.drawPolygon(points); | |
726 | } | |
727 | ||
df0b8ff4 BH |
728 | /* |
729 | * (non-Javadoc) | |
730 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#drawFocus(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) | |
731 | */ | |
73005152 BH |
732 | @Override |
733 | public void drawFocus(IGC context) { | |
3145ec83 BH |
734 | |
735 | ISDPreferences pref = SDViewPref.getInstance(); | |
736 | ||
eb63f5ff | 737 | if ((fStartLifeline != fEndLifeline) && (fStartEventOccurrence == fEndEventOccurrence)) { |
73005152 BH |
738 | context.setLineStyle(context.getLineDotStyle()); |
739 | context.setLineWidth(Metrics.NORMAL_LINE_WIDTH); | |
3145ec83 BH |
740 | context.setBackground(pref.getBackGroundColorSelection()); |
741 | context.setForeground(pref.getForeGroundColorSelection()); | |
73005152 | 742 | context.drawFocus(getX(), getY() - 3, getWidth(), getHeight() + 6); |
eb63f5ff | 743 | } else if ((fStartLifeline == fEndLifeline) && (fStartEventOccurrence == fEndEventOccurrence)) { |
73005152 | 744 | context.drawFocus(getX(), getY() - 3, getWidth(), Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT + 6); |
eb63f5ff | 745 | } else if ((fStartLifeline != fEndLifeline) && (fStartEventOccurrence != fEndEventOccurrence)) { |
73005152 BH |
746 | context.setLineStyle(context.getLineDotStyle()); |
747 | context.setLineWidth(Metrics.NORMAL_LINE_WIDTH); | |
3145ec83 BH |
748 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_LIFELINE_HEADER)); |
749 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_LIFELINE_HEADER)); | |
73005152 | 750 | drawRot(getX(), getY() - 5, getWidth(), 10, context); |
df0b8ff4 | 751 | } else { |
73005152 | 752 | super.drawFocus(context); |
df0b8ff4 | 753 | } |
73005152 BH |
754 | } |
755 | } |