1 /**********************************************************************
2 * Copyright (c) 2005, 2012 IBM Corporation, Ericsson
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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
;
15 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
16 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IGC
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.ISDPreferences
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
21 * The base UML2 syncMessages implementation.<br>
22 * This abstract class only define one event occurrence to attach to the message.<br>
23 * Usually a message has two event occurrences attached, one for both ends. But some syncMessages(like synchronous
24 * syncMessages) only need one event occurrence to represent the time when they appear. Others kind of message
25 * representations (like asynchronous syncMessages) will be responsible to define the missing second eventOccurrence
29 * @see Lifeline Lifeline for more event occurence details
33 public abstract class BaseMessage
extends GraphNode
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 * The lifeline which send the message
41 protected Lifeline fStartLifeline
= null;
43 * The lifeline which receive the message
45 protected Lifeline fEndLifeline
= null;
47 * The visiblitiy flag.
49 protected boolean fVisible
= true;
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
56 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX()
60 // returns the exact x coordinate
66 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY()
71 * Note: lifeline.getY() return the y coordinate of the top left corner of the rectangle which contain the
72 * lifeline name getHeight return the height of this rectangle The message y coordinate is then relative to this
73 * position depending of its eventOccurrence Space between syncMessages is constant
75 if ((fStartLifeline
!= null) && (fEndLifeline
!= null)) {
77 * Regular message, both ends are attached to a lifeline
79 return fEndLifeline
.getY() + fEndLifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * fEndEventOccurrence
;
83 * UML2 lost message kind
85 if (fStartLifeline
!= null) {
86 return fStartLifeline
.getY() + fStartLifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * fEndEventOccurrence
;
90 * UML2 found message kind
92 if (fEndLifeline
!= null) {
93 return fEndLifeline
.getY() + fEndLifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * fEndEventOccurrence
;
95 // return 0 by default
101 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth()
104 public int getWidth() {
105 // Returns the exact width
106 return getWidth(false);
111 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight()
114 public int getHeight() {
119 * Returns the graph node x coordinate.<br>
120 * Depending on the quick parameter a approximative or exact value is return.<br>
121 * The approximative value does not take into account if both message ends are connected to a Lifeline Execution
123 * Execution occurrence on a lifeline increase the vertical line width which represent the lifeline, this directly
124 * affect the message x coordinate and width.<br>
126 * This method is typically used to faster execute none graphical operation like tooltip lookup.<br>
129 * @param quick true to get an approximative value<br>
130 * false to get the exact x value<br>
131 * @return the graph node x coordinate
133 protected int getX(boolean quick
) {
135 int activationWidth
= Metrics
.EXECUTION_OCCURRENCE_WIDTH
/ 2;
136 if ((fStartLifeline
!= null) && (fEndLifeline
!= null)) {
137 x
= fStartLifeline
.getX() + Metrics
.getLifelineWidth() / 2;
139 if (fStartLifeline
!= null) {
140 x
= fStartLifeline
.getX() + Metrics
.getLifelineWidth() / 2;
143 if (fEndLifeline
!= null) {
144 x
= fEndLifeline
.getX() - Metrics
.LIFELINE_SPACING
/ 2;
152 if ((fStartLifeline
!= null) && (fEndLifeline
!= null) && (fStartLifeline
.getX() > fEndLifeline
.getX())) {
153 activationWidth
= -activationWidth
;
156 if (isMessageStartInActivation(fEndEventOccurrence
)) {
157 x
= x
+ activationWidth
;
164 * Returns the graph node width.<br>
165 * Depending on the quick parameter a approximative or exact value is returned.<br>
166 * The approximative value does not take into account if both message ends are connected to a Lifeline Execution
168 * Execution occurrence on a lifeline increase the vertical line width which represent the lifeline, this directly
169 * affect the message x coordinate and width.<br>
171 * This method is typically used to faster execute none graphical operation like tooltip lookup.<br>
174 * @param quick true to get an approximative value<br>
175 * false to get the exact x value
176 * @return the graph node width
178 protected int getWidth(boolean quick
) {
180 int activationWidth
= Metrics
.EXECUTION_OCCURRENCE_WIDTH
/ 2;
181 if ((fStartLifeline
!= null) && (fEndLifeline
!= null)) {
182 if (fStartLifeline
== fEndLifeline
) {
183 width
= Metrics
.INTERNAL_MESSAGE_WIDTH
+ Metrics
.EXECUTION_OCCURRENCE_WIDTH
;
185 width
= fEndLifeline
.getX() + Metrics
.getLifelineWidth() / 2 - getX(true);
188 if (fStartLifeline
!= null) {
189 width
= Metrics
.swimmingLaneWidth() / 2;
191 if (fEndLifeline
!= null) {
192 width
= Metrics
.swimmingLaneWidth() / 2;
200 if ((fStartLifeline
!= null) && (fEndLifeline
!= null) && (fStartLifeline
.getX() > fEndLifeline
.getX())) {
201 activationWidth
= -activationWidth
;
204 if (isMessageStartInActivation(fEndEventOccurrence
)) {
205 width
= width
- activationWidth
;
208 if (isMessageEndInActivation(fEndEventOccurrence
)) {
209 width
= width
- activationWidth
;
217 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
220 public boolean isVisible(int x
, int y
, int width
, int height
) {
221 // ***Common*** syncMessages visibility
222 // draw the message only if at least one end is visible
223 if (fEndLifeline
!= null && (fEndLifeline
.isVisible(x
, y
, width
, height
)) || (fStartLifeline
!= null && fStartLifeline
.isVisible(x
, y
, width
, height
))) {
226 // In this case it can be a message which cross the whole visible area
227 else if (fEndLifeline
!= null && (!fEndLifeline
.isVisible(x
, y
, width
, height
)) && (fStartLifeline
!= null && !fStartLifeline
.isVisible(x
, y
, width
, height
))) {
228 if (fEndLifeline
.getX() > x
+ width
&& fStartLifeline
.getX() < x
) {
230 } else if (fStartLifeline
.getX() > x
+ width
&& fEndLifeline
.getX() < x
) {
238 * Sets the visibility value.
240 * @param value The visibility to set.
242 public void setVisible(boolean value
) {
247 * @return the visibility value.
249 public boolean isVisible() {
254 * Set the lifeline from which this message has been sent.
256 * @param lifeline - the message sender
258 public void setStartLifeline(Lifeline lifeline
) {
259 fStartLifeline
= lifeline
;
263 * Returns the lifeline from which this message has been sent.
265 * @return the message sender
267 public Lifeline
getStartLifeline() {
268 return fStartLifeline
;
272 * Returns the lifeline which has received this message.
274 * @return the message receiver
276 public Lifeline
getEndLifeline() {
281 * Set the lifeline which has receive this message.
283 * @param lifeline the message receiver
285 public void setEndLifeline(Lifeline lifeline
) {
286 fEndLifeline
= lifeline
;
290 * Set the event occurrence when this message occurs.<br>
292 * @param occurrence the event occurrence to assign to this message.<br>
293 * @see Lifeline Lifeline for more event occurence details
295 protected void setEventOccurrence(int occurrence
) {
296 fEndEventOccurrence
= occurrence
;
300 * Returns the event occurence when is message occurs.<br>
302 * @return the event occurrence assigned to this message.<br>
303 * @see Lifeline Lifeline for more event occurence details
305 public int getEventOccurrence() {
306 return fEndEventOccurrence
;
310 * Determines if the given eventOccurence occurs on a executionOccurence owned by the sending lifeline.<br>
311 * WARNING: this method will return a valid result only for execution occurrences which are visible in the View.<br>
312 * As consequence this method is only used for drawing purpose, especially to determine the exact message x
313 * coordinate and width.<br>
315 * @see BaseMessage#getX(boolean)
316 * @param event the event occurrence to test
317 * @return true if occurs on a execution occurrence owned by the sending lifeine, false otherwise
319 protected boolean isMessageStartInActivation(int event
) {
320 boolean inActivation
= false;
321 if ((fStartLifeline
!= null) && (fStartLifeline
.getExecutions() != null)) {
322 // int acIndex=startLifeline.getExecOccurrenceDrawIndex();
323 // acIndex = first visible execution occurrence
324 // for drawing speed reason with only search on the visivle subset
326 for (int i
= 0; i
< fStartLifeline
.getExecutions().size(); i
++) {
327 BasicExecutionOccurrence toDraw
= (BasicExecutionOccurrence
) fStartLifeline
.getExecutions().get(i
);
328 if ((event
>= toDraw
.fStartEventOccurrence
) && (event
<= toDraw
.fEndEventOccurrence
)) {
331 // if we are outside the visible area we stop right now
332 // This works because execution occurrences are ordered along the Y axis
333 if (toDraw
.getY() > thisY
) {
342 * Determines if the given event occurrence occurs on a execution occurrence owned by the receiving lifeline.<br>
343 * WARNING: this method will return a valid result only for execution occurrences which are visible in the View.<br>
344 * As consequence this method is only used for drawing purpose, especially to determine the exact message x
345 * coordinate and width.<br>
347 * @see BaseMessage#getX(boolean)
348 * @param event the event occurrence to test
349 * @return true if occurs on a execution occurrence owned by the receiving lifeline, false otherwise
351 protected boolean isMessageEndInActivation(int event
) {
352 boolean inActivation
= false;
353 if ((fEndLifeline
!= null) && (fEndLifeline
.getExecutions() != null)) {
354 // acIndex = first visible execution occurrence
355 // for drawing speed reason with only search on the visivle subset
356 for (int i
= 0; i
< fEndLifeline
.getExecutions().size(); i
++) {
357 BasicExecutionOccurrence toDraw
= (BasicExecutionOccurrence
) fEndLifeline
.getExecutions().get(i
);
358 if ((event
>= toDraw
.fStartEventOccurrence
) && (event
<= toDraw
.fEndEventOccurrence
)) {
361 // if we are outside the visible area we stop right now
362 // This works because execution occurrences are ordered along the Y axis
363 if (toDraw
.getY() > getY()) {
373 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int)
376 public boolean contains(int xValue
, int yValue
) {
379 int width
= getWidth();
380 int height
= getHeight();
382 // Used to create a rectangle which contains the message label to allow selection when clicking the label
383 int tempHeight
= Metrics
.MESSAGES_NAME_SPACING
+ Metrics
.getMessageFontHeigth();
385 // Is it a self message?
386 if (fStartLifeline
== fEndLifeline
) {
388 * Rectangle.contains(x,y, width, height) does not works with negative height or width We check here if the
389 * rectangle width is negative.
391 if (getName().length() * Metrics
.getAverageCharWidth() > Metrics
.swimmingLaneWidth() - Metrics
.EXECUTION_OCCURRENCE_WIDTH
/ 2 + -Metrics
.INTERNAL_MESSAGE_WIDTH
) {
392 if (GraphNode
.contains(x
+ Metrics
.INTERNAL_MESSAGE_WIDTH
+ 10, y
, Metrics
.swimmingLaneWidth() - Metrics
.EXECUTION_OCCURRENCE_WIDTH
/ 2 + -Metrics
.INTERNAL_MESSAGE_WIDTH
, Metrics
.getMessageFontHeigth(), xValue
, yValue
)) {
396 if (GraphNode
.contains(x
+ Metrics
.INTERNAL_MESSAGE_WIDTH
+ 10, y
, getName().length() * Metrics
.getAverageCharWidth(), Metrics
.getMessageFontHeigth(), xValue
, yValue
)) {
401 // Test if the point is in part 1 of the self message
402 // see: "private void drawMessage (NGC context)" method for self message drawing schema
403 if (GraphNode
.contains(x
, y
- Metrics
.MESSAGE_SELECTION_TOLERANCE
/ 2, Metrics
.INTERNAL_MESSAGE_WIDTH
/ 2, Metrics
.MESSAGE_SELECTION_TOLERANCE
, xValue
, yValue
)) {
407 // Test if the point is in part 3 of the self message
408 if (GraphNode
.contains(x
+ Metrics
.INTERNAL_MESSAGE_WIDTH
- Metrics
.MESSAGE_SELECTION_TOLERANCE
/ 2, y
, Metrics
.MESSAGE_SELECTION_TOLERANCE
, height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
, xValue
, yValue
)) {
412 // Test if the point is in part 5 of the self message
413 if (GraphNode
.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
)) {
420 if (GraphNode
.contains(x
, y
- tempHeight
, width
, tempHeight
, xValue
, yValue
)) {
428 * Method to draw the message using the graphical context.
430 * @param context A graphical context to draw in.
432 protected void drawMessage(IGC context
) {
434 fX
= fY
= fW
= fH
= 0;
436 // temporary store the coordinates to avoid more methods calls
439 int width
= getWidth();
440 int height
= getHeight();
442 ISDPreferences pref
= SDViewPref
.getInstance();
444 // UML2 found message (always drawn from left to right)
445 // or UML2 lost message (always drawn from left to right)
446 if ((fStartLifeline
== null || fEndLifeline
== null) && fStartLifeline
!= fEndLifeline
) {
447 // Draw the message label above the message and centered
448 // The label is truncated if it cannot fit between the two message end
449 // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label
450 IColor temp
= context
.getForeground();
451 context
.setForeground(pref
.getFontColor(fPrefId
));
452 context
.drawTextTruncatedCentred(getName(), x
, y
- Metrics
.getMessageFontHeigth() - 2 * Metrics
.MESSAGES_NAME_SPACING
, width
, 2 * Metrics
.MESSAGES_NAME_SPACING
+ Metrics
.getMessageFontHeigth(), !isSelected());
453 context
.setForeground(temp
);
455 if (fEndLifeline
== null) {
456 margin
= Metrics
.MESSAGE_CIRCLE_RAY
;
459 // Draw the message main line
460 context
.drawLine(x
, y
, x
+ width
, y
+ height
);
461 // Draw the two little lines which make a arrow part of the message
462 Double xt
= Double
.valueOf(Math
.cos(0.75) * 7);
463 Double yt
= Double
.valueOf(Math
.sin(0.75) * 7);
464 if (context
.getLineStyle() == context
.getLineSolidStyle()) {
465 IColor backcolor
= context
.getBackground();
466 context
.setBackground(context
.getForeground());
467 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
};
468 context
.fillPolygon(points
);
469 context
.drawPolygon(points
);
470 context
.setBackground(backcolor
);
472 int currentStyle
= context
.getLineStyle();
473 int currentWidth
= context
.getLineWidth();
474 context
.setLineWidth(currentWidth
+ 2);
475 context
.setLineStyle(context
.getLineSolidStyle());
476 context
.drawLine(x
+ width
- xt
.intValue() - margin
, y
+ height
- yt
.intValue(), x
+ width
- margin
, y
+ height
);
477 context
.drawLine(x
+ width
- xt
.intValue() - margin
, y
+ height
+ yt
.intValue(), x
+ width
- margin
, y
+ height
);
478 context
.setLineStyle(currentStyle
);
479 context
.setLineWidth(currentWidth
);
481 IColor storedColor
= context
.getBackground();
482 context
.setBackground(context
.getForeground());
484 // Draw a circle at the message end (endLifeline side)
485 int ray
= Metrics
.MESSAGE_CIRCLE_RAY
;
486 if (context
.getLineWidth() != Metrics
.NORMAL_LINE_WIDTH
) {
487 ray
= ray
+ Metrics
.SELECTION_LINE_WIDTH
- Metrics
.NORMAL_LINE_WIDTH
;
489 if (fStartLifeline
== null) {
490 context
.fillOval(x
- ray
, y
- ray
, ray
* 2, ray
* 2);
492 context
.fillOval(x
+ width
- ray
, y
+ height
- ray
, ray
* 2, ray
* 2);
494 context
.setBackground(storedColor
);
495 context
.setForeground(pref
.getFontColor(fPrefId
));
497 fY
= y
- yt
.intValue();
499 fH
= height
+ 2 * yt
.intValue();
501 // it is self message (always drawn at the left side of the owning lifeLifeline)
502 else if (fStartLifeline
!= null && fEndLifeline
!= null && fStartLifeline
== fEndLifeline
) {
504 * Self syncMessages are drawn in 5 parts 1 -----------+ + 2 + | | | 3 | + 5 + 4 -----------+
506 int tempy
= Metrics
.INTERNAL_MESSAGE_WIDTH
/ 2;
507 if (Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
<= Metrics
.INTERNAL_MESSAGE_WIDTH
) {
508 tempy
= Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
/ 2;
512 context
.drawLine(x
, y
, x
+ Metrics
.INTERNAL_MESSAGE_WIDTH
/ 2, y
);
514 context
.drawLine(x
+ Metrics
.INTERNAL_MESSAGE_WIDTH
, y
+ tempy
, x
+ Metrics
.INTERNAL_MESSAGE_WIDTH
, y
+ height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
- tempy
);
516 context
.drawLine(x
, y
+ height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
, x
+ Metrics
.INTERNAL_MESSAGE_WIDTH
/ 2, y
+ height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
);
518 Double xt
= Double
.valueOf(Math
.cos(0.75) * 7);
519 Double yt
= Double
.valueOf(Math
.sin(0.75) * 7);
523 fW
= Metrics
.INTERNAL_MESSAGE_WIDTH
;
524 fH
= height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
;
526 // Draw the two little lines which make a arrow part of the message
527 if (context
.getLineStyle() == context
.getLineSolidStyle()) {
528 IColor backcolor
= context
.getBackground();
529 context
.setBackground(context
.getForeground());
530 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(),
531 y
+ height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
- yt
.intValue(), x
, y
+ height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
};
532 context
.fillPolygon(points
);
533 context
.drawPolygon(points
);
534 context
.setBackground(backcolor
);
536 int currentStyle
= context
.getLineStyle();
537 int currentWidth
= context
.getLineWidth();
538 context
.setLineWidth(currentWidth
+ 2);
539 context
.setLineStyle(context
.getLineSolidStyle());
540 context
.drawLine(x
+ xt
.intValue(), y
+ height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
+ yt
.intValue(), x
, y
+ height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
);
541 context
.drawLine(x
+ xt
.intValue(), y
+ height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
- yt
.intValue(), x
, y
+ height
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
);
542 context
.setLineStyle(currentStyle
);
543 context
.setLineWidth(currentWidth
);
547 context
.drawArc(x
, y
, Metrics
.INTERNAL_MESSAGE_WIDTH
, 2 * tempy
, 0, 90);
549 context
.drawArc(x
, y
+ Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
, Metrics
.INTERNAL_MESSAGE_WIDTH
, -2 * tempy
, 0, -90);
551 // Draw the message label above the message and centered
552 // The label is truncated if it cannot fit between the two message end
553 // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label
555 // the space available for the text is sorter if are drawing internal message on the last lifeline
556 context
.setForeground(pref
.getFontColor(fPrefId
));
557 if (fStartLifeline
.getIndex() == fStartLifeline
.getFrame().getHorizontalIndex()) {
558 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
559 - Metrics
.getMessageFontHeigth(), !isSelected());
561 context
.drawTextTruncated(getName(), x
+ width
+ Metrics
.INTERNAL_MESSAGE_V_MARGIN
/ 2, y
, Metrics
.swimmingLaneWidth() - Metrics
.EXECUTION_OCCURRENCE_WIDTH
+ -Metrics
.INTERNAL_MESSAGE_WIDTH
,
562 +Metrics
.MESSAGES_NAME_SPACING
- Metrics
.getMessageFontHeigth(), !isSelected());
565 // it is regular message
566 else if (fStartLifeline
!= null && fEndLifeline
!= null) {
567 // Draw the message main line
568 context
.drawLine(x
, y
, x
+ width
, y
+ height
);
570 int spaceBTWStartEnd
= fEndLifeline
.getX() - fStartLifeline
.getX();
574 double angle
= Math
.atan(a
/ b
);
575 // Compute the coordinates of the two little lines which make the arrow part of the message
577 if (spaceBTWStartEnd
< 0) {
580 Double x1
= Double
.valueOf(sign
* Math
.cos(angle
- 0.75) * 7);
581 Double y1
= Double
.valueOf(sign
* Math
.sin(angle
- 0.75) * 7);
582 Double x2
= Double
.valueOf(sign
* Math
.cos(angle
+ 0.75) * 7);
583 Double y2
= Double
.valueOf(sign
* Math
.sin(angle
+ 0.75) * 7);
586 fY
= y
+ height
- y2
.intValue();
588 fH
= y2
.intValue() - y1
.intValue() + 1;
599 // Draw the two little lines which make a arrow part of the message
600 if (context
.getLineStyle() == context
.getLineSolidStyle()) {
601 IColor backcolor
= context
.getBackground();
602 context
.setBackground(context
.getForeground());
603 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() };
604 context
.fillPolygon(points
);
605 context
.drawPolygon(points
);
606 context
.setBackground(backcolor
);
608 int currentStyle
= context
.getLineStyle();
609 int currentWidth
= context
.getLineWidth();
610 context
.setLineWidth(currentWidth
+ 2);
611 context
.setLineStyle(context
.getLineSolidStyle());
612 context
.drawLine(x
+ width
- x1
.intValue(), y
+ height
- y1
.intValue(), x
+ width
, y
+ height
);
613 context
.drawLine(x
+ width
- x2
.intValue(), y
+ height
- y2
.intValue(), x
+ width
, y
+ height
);
614 context
.setLineStyle(currentStyle
);
615 context
.setLineWidth(currentWidth
);
618 // Draw the message label above the message and centered
619 // The label is truncated if it cannot fit between the two message end
620 // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label
621 context
.setForeground(pref
.getFontColor(fPrefId
));
622 if (spaceBTWStartEnd
> 0) {
623 context
.drawTextTruncatedCentred(getName(), x
, y
+ height
/ 2 - (2 * Metrics
.MESSAGES_NAME_SPACING
+ Metrics
.getMessageFontHeigth()), width
, 2 * Metrics
.MESSAGES_NAME_SPACING
+ Metrics
.getMessageFontHeigth(), !isSelected());
625 context
.drawTextTruncatedCentred(getName(), x
+ width
, y
+ height
/ 2 - (2 * Metrics
.MESSAGES_NAME_SPACING
+ Metrics
.getMessageFontHeigth()), -width
, 2 * Metrics
.MESSAGES_NAME_SPACING
+ +Metrics
.getMessageFontHeigth(), !isSelected());
632 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNodee#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
635 public void draw(IGC context
) {
640 // Draw it selected?*/
642 ISDPreferences pref
= SDViewPref
.getInstance();
644 * Draw it twice First time, bigger inverting selection colors Second time, regular drawing using selection
645 * colors This create the highlight effect
647 context
.setForeground(pref
.getBackGroundColorSelection());
648 context
.setLineWidth(Metrics
.SELECTION_LINE_WIDTH
);
649 drawMessage(context
);
650 context
.setBackground(pref
.getBackGroundColorSelection());
651 context
.setForeground(pref
.getForeGroundColorSelection());
652 // Second drawing is done after
654 context
.setLineWidth(Metrics
.NORMAL_LINE_WIDTH
);
656 context
.setDrawTextWithFocusStyle(true);
658 drawMessage(context
);
659 int oldStyle
= context
.getLineStyle();
661 context
.setDrawTextWithFocusStyle(false);
664 // restore the context
665 context
.setLineStyle(oldStyle
);
669 * Determine if two messages are identical. This default implementation considers that overlapping messages with
670 * same coordinates are identical.
672 * @param message - the message to compare with
673 * @return true if identical false otherwise
675 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isSameAs(org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode)
678 public boolean isSameAs(GraphNode message
) {
679 if (message
== null) {
682 if (!(message
instanceof BaseMessage
)) {
683 return super.isSameAs(message
);
685 return ((getX() == message
.getX()) && (getY() == message
.getY()) && (getWidth() == message
.getWidth()) && (getHeight() == message
.getHeight()));
691 * @param x A x coordinate
692 * @param y A y coordinate
695 * @param context A graphical context
697 public void drawRot(int x
, int y
, int w
, int h
, IGC context
) {
698 double angleA
= Math
.atan2(getHeight(), getWidth());
699 double cosA
= Math
.cos(angleA
);
700 double sinA
= Math
.sin(angleA
);
706 localHeight
= localHeight
/ 2;
708 double cw
= Math
.sqrt(w
* w
+ getHeight() * getHeight());
710 int x1
= Math
.round((float) ((x
- gx
) * cosA
- (y
- gy
) * sinA
));
711 int y1
= Math
.round((float) ((x
- gx
) * sinA
+ (y
- gy
) * cosA
));
713 int x2
= Math
.round((float) (cw
* cosA
- (y
- gy
) * sinA
));
714 int y2
= Math
.round((float) (cw
* sinA
+ (y
- gy
) * cosA
));
716 int x3
= Math
.round((float) (cw
* cosA
- (localHeight
) * sinA
));
717 int y3
= Math
.round((float) (cw
* sinA
+ (localHeight
) * cosA
));
719 int x4
= Math
.round((float) ((x
- gx
) * cosA
- (localHeight
) * sinA
));
720 int y4
= Math
.round((float) ((x
- gx
) * sinA
+ (localHeight
) * cosA
));
722 int[] points
= { x1
+ getX(), y1
+ getY(), x2
+ getX(), y2
+ getY(), x3
+ getX(), y3
+ getY(), x4
+ getX(), y4
+ getY() };
723 context
.drawPolygon(points
);
728 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#drawFocus(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
731 public void drawFocus(IGC context
) {
733 ISDPreferences pref
= SDViewPref
.getInstance();
735 if ((fStartLifeline
!= fEndLifeline
) && (fStartEventOccurrence
== fEndEventOccurrence
)) {
736 context
.setLineStyle(context
.getLineDotStyle());
737 context
.setLineWidth(Metrics
.NORMAL_LINE_WIDTH
);
738 context
.setBackground(pref
.getBackGroundColorSelection());
739 context
.setForeground(pref
.getForeGroundColorSelection());
740 context
.drawFocus(getX(), getY() - 3, getWidth(), getHeight() + 6);
741 } else if ((fStartLifeline
== fEndLifeline
) && (fStartEventOccurrence
== fEndEventOccurrence
)) {
742 context
.drawFocus(getX(), getY() - 3, getWidth(), Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
+ 6);
743 } else if ((fStartLifeline
!= fEndLifeline
) && (fStartEventOccurrence
!= fEndEventOccurrence
)) {
744 context
.setLineStyle(context
.getLineDotStyle());
745 context
.setLineWidth(Metrics
.NORMAL_LINE_WIDTH
);
746 context
.setBackground(pref
.getBackGroundColor(ISDPreferences
.PREF_LIFELINE_HEADER
));
747 context
.setForeground(pref
.getForeGroundColor(ISDPreferences
.PREF_LIFELINE_HEADER
));
748 drawRot(getX(), getY() - 5, getWidth(), 10, context
);
750 super.drawFocus(context
);