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