21990c88d1359fb82ad304ccf98cde5378ce8e76
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / EllipsisMessage.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2013 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
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
14
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;
19
20 /**
21 * Class to draw Ellipsis Message.
22 *
23 * @version 1.0
24 * @author sveyrier
25 *
26 */
27 public class EllipsisMessage extends AsyncMessage {
28
29 @Override
30 public int getX() {
31 if (getStartLifeline() == null) {
32 return super.getX() + super.getWidth() - 16;
33 }
34 return super.getX();
35 }
36
37 @Override
38 public int getY() {
39 return super.getY() + 3;
40 }
41
42 @Override
43 public int getWidth() {
44 return 16;
45 }
46
47 @Override
48 protected void drawMessage(IGC context) {
49 // temporary store the coordinates to avoid more methods calls
50 int x = super.getX();
51 int y = getY();
52 int width = super.getWidth();
53 int height = getHeight();
54
55 // UML2 found message (always drawn from left to right)
56 if (getStartLifeline() == null && getEndLifeline() != null) {
57 // Draw the message label above the message and centered
58 // The label is truncated if it cannot fit between the two message end
59 // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label
60 context.drawTextTruncatedCentred(getName(), x, y - Metrics.getMessageFontHeigth() - 2 * Metrics.MESSAGES_NAME_SPACING, width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected());
61
62 int currentStyle = context.getLineStyle();
63 context.setLineStyle(context.getLineSolidStyle());
64 // Draw the message main line
65 context.drawRectangle(x + width - 5, y, x + width - 6, y + height);
66 context.drawRectangle(x + width - 10, y, x + width - 11, y + height);
67 context.drawRectangle(x + width - 15, y, x + width - 16, y + height);
68 context.setLineStyle(currentStyle);
69
70 IColor storedColor = context.getBackground();
71 context.setBackground(context.getForeground());
72 context.fillRectangle(x + width - 5, y, x + width - 6, y + height);
73 context.fillRectangle(x + width - 10, y, x + width - 11, y + height);
74 context.fillRectangle(x + width - 15, y, x + width - 16, y + height);
75 context.setBackground(storedColor);
76 }
77 // UML2 lost message (always drawn from left to right)
78 else if (getEndLifeline() == null && getStartLifeline() != null) {
79 // Draw the message label above the message and centered
80 // The label is truncated if it cannot fit between the two message end
81 // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label
82 context.drawTextTruncatedCentred(getName(), x, y - Metrics.getMessageFontHeigth() - 2 * Metrics.MESSAGES_NAME_SPACING, width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected());
83
84 int currentStyle = context.getLineStyle();
85 context.setLineStyle(context.getLineSolidStyle());
86 // Draw the message main line
87 context.drawRectangle(x + 5, y, 1, 1);
88 context.drawRectangle(x + 10, y, 1, 1);
89 context.drawRectangle(x + 15, y, 1, 1);
90
91 context.setLineStyle(currentStyle);
92
93 IColor storedColor = context.getBackground();
94 context.setBackground(context.getForeground());
95 context.fillRectangle(x + 5, y, 1, 1);
96 context.fillRectangle(x + 10, y, 1, 1);
97 context.fillRectangle(x + 15, y, 1, 1);
98
99 context.setBackground(storedColor);
100
101 } else {
102 super.draw(context);
103 }
104 }
105
106 @Override
107 public void draw(IGC context) {
108 if (!isVisible()) {
109 return;
110 }
111
112 ISDPreferences pref = SDViewPref.getInstance();
113
114 // Draw it selected?*/
115 if (isSelected()) {
116
117 /*
118 * Draw it twice First time, bigger inverting selection colors Second time, regular drawing using selection
119 * colors This create the highlight effect
120 */
121 context.setForeground(pref.getBackGroundColorSelection());
122 context.setLineWidth(Metrics.SELECTION_LINE_WIDTH);
123 drawMessage(context);
124 context.setBackground(pref.getBackGroundColorSelection());
125 context.setForeground(pref.getForeGroundColorSelection());
126 // Second drawing is done after the else
127 } else {
128 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_ASYNC_MESS));
129 context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_ASYNC_MESS));
130 }
131 if (hasFocus()) {
132 context.setDrawTextWithFocusStyle(true);
133 }
134 context.setLineWidth(Metrics.NORMAL_LINE_WIDTH);
135 drawMessage(context);
136 context.setLineWidth(Metrics.NORMAL_LINE_WIDTH);
137 if (hasFocus()) {
138 context.setDrawTextWithFocusStyle(false);
139 }
140 }
141 }
This page took 0.056572 seconds and 4 git commands to generate.