Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
c8422608 | 2 | * Copyright (c) 2005, 2012 IBM Corporation, Ericsson |
73005152 BH |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
c8422608 AM |
7 | * |
8 | * Contributors: | |
9 | * IBM - Initial API and implementation | |
10 | * Bernd Hufmann - Updated for TMF | |
73005152 | 11 | **********************************************************************/ |
c8422608 | 12 | |
73005152 BH |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core; |
14 | ||
15 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; | |
16 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
df0b8ff4 | 17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
3145ec83 | 18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; |
73005152 | 19 | |
df0b8ff4 BH |
20 | /** |
21 | * Class to draw Ellipsis Message. | |
c8422608 | 22 | * |
df0b8ff4 BH |
23 | * @version 1.0 |
24 | * @author sveyrier | |
c8422608 | 25 | * |
df0b8ff4 | 26 | */ |
eb63f5ff | 27 | public class EllipsisMessage extends AsyncMessage { |
73005152 | 28 | |
df0b8ff4 BH |
29 | /* |
30 | * (non-Javadoc) | |
31 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage#getX() | |
32 | */ | |
73005152 BH |
33 | @Override |
34 | public int getX() { | |
eb63f5ff | 35 | if (fStartLifeline == null) { |
73005152 | 36 | return super.getX() + super.getWidth() - 16; |
c8422608 | 37 | } |
df0b8ff4 | 38 | return super.getX(); |
73005152 BH |
39 | } |
40 | ||
df0b8ff4 BH |
41 | /* |
42 | * (non-Javadoc) | |
43 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage#getY() | |
44 | */ | |
73005152 BH |
45 | @Override |
46 | public int getY() { | |
47 | return super.getY() + 3; | |
48 | } | |
49 | ||
df0b8ff4 BH |
50 | /* |
51 | * (non-Javadoc) | |
52 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage#getWidth() | |
53 | */ | |
73005152 BH |
54 | @Override |
55 | public int getWidth() { | |
56 | return 16; | |
57 | } | |
58 | ||
df0b8ff4 BH |
59 | /* |
60 | * (non-Javadoc) | |
61 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage#drawMessage(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) | |
c8422608 | 62 | */ |
73005152 BH |
63 | @Override |
64 | protected void drawMessage(IGC context) { | |
df0b8ff4 | 65 | // temporary store the coordinates to avoid more methods calls |
73005152 BH |
66 | int x = super.getX(); |
67 | int y = getY(); | |
68 | int width = super.getWidth(); | |
69 | int height = getHeight(); | |
70 | ||
71 | // UML2 found message (always drawn from left to right) | |
eb63f5ff | 72 | if (fStartLifeline == null && fEndLifeline != null) { |
73005152 BH |
73 | // Draw the message label above the message and centered |
74 | // The label is truncated if it cannot fit between the two message end | |
75 | // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label | |
76 | context.drawTextTruncatedCentred(getName(), x, y - Metrics.getMessageFontHeigth() - 2 * Metrics.MESSAGES_NAME_SPACING, width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected()); | |
77 | ||
78 | int currentStyle = context.getLineStyle(); | |
79 | context.setLineStyle(context.getLineSolidStyle()); | |
80 | // Draw the message main line | |
81 | context.drawRectangle(x + width - 5, y, x + width - 6, y + height); | |
82 | context.drawRectangle(x + width - 10, y, x + width - 11, y + height); | |
83 | context.drawRectangle(x + width - 15, y, x + width - 16, y + height); | |
84 | context.setLineStyle(currentStyle); | |
85 | ||
86 | IColor storedColor = context.getBackground(); | |
87 | context.setBackground(context.getForeground()); | |
88 | context.fillRectangle(x + width - 5, y, x + width - 6, y + height); | |
89 | context.fillRectangle(x + width - 10, y, x + width - 11, y + height); | |
90 | context.fillRectangle(x + width - 15, y, x + width - 16, y + height); | |
91 | context.setBackground(storedColor); | |
92 | } | |
93 | // UML2 lost message (always drawn from left to right) | |
eb63f5ff | 94 | else if (fEndLifeline == null && fStartLifeline != null) { |
73005152 BH |
95 | // Draw the message label above the message and centered |
96 | // The label is truncated if it cannot fit between the two message end | |
97 | // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label | |
98 | context.drawTextTruncatedCentred(getName(), x, y - Metrics.getMessageFontHeigth() - 2 * Metrics.MESSAGES_NAME_SPACING, width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected()); | |
99 | ||
100 | int currentStyle = context.getLineStyle(); | |
101 | context.setLineStyle(context.getLineSolidStyle()); | |
102 | // Draw the message main line | |
103 | context.drawRectangle(x + 5, y, 1, 1); | |
104 | context.drawRectangle(x + 10, y, 1, 1); | |
105 | context.drawRectangle(x + 15, y, 1, 1); | |
106 | ||
107 | context.setLineStyle(currentStyle); | |
108 | ||
109 | IColor storedColor = context.getBackground(); | |
110 | context.setBackground(context.getForeground()); | |
111 | context.fillRectangle(x + 5, y, 1, 1); | |
112 | context.fillRectangle(x + 10, y, 1, 1); | |
113 | context.fillRectangle(x + 15, y, 1, 1); | |
114 | ||
115 | context.setBackground(storedColor); | |
116 | ||
df0b8ff4 | 117 | } else { |
73005152 | 118 | super.draw(context); |
df0b8ff4 | 119 | } |
73005152 BH |
120 | } |
121 | ||
df0b8ff4 BH |
122 | /* |
123 | * (non-Javadoc) | |
124 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) | |
c8422608 | 125 | */ |
73005152 BH |
126 | @Override |
127 | public void draw(IGC context) { | |
df0b8ff4 | 128 | if (!isVisible()) { |
73005152 | 129 | return; |
df0b8ff4 | 130 | } |
3145ec83 BH |
131 | |
132 | ISDPreferences pref = SDViewPref.getInstance(); | |
133 | ||
73005152 BH |
134 | // Draw it selected?*/ |
135 | if (isSelected()) { | |
3145ec83 | 136 | |
73005152 BH |
137 | /* |
138 | * Draw it twice First time, bigger inverting selection colors Second time, regular drawing using selection | |
139 | * colors This create the highlight effect | |
140 | */ | |
3145ec83 | 141 | context.setForeground(pref.getBackGroundColorSelection()); |
73005152 BH |
142 | context.setLineWidth(Metrics.SELECTION_LINE_WIDTH); |
143 | drawMessage(context); | |
3145ec83 BH |
144 | context.setBackground(pref.getBackGroundColorSelection()); |
145 | context.setForeground(pref.getForeGroundColorSelection()); | |
73005152 BH |
146 | // Second drawing is done after the else |
147 | } else { | |
3145ec83 BH |
148 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_ASYNC_MESS)); |
149 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_ASYNC_MESS)); | |
73005152 BH |
150 | } |
151 | if (hasFocus()) { | |
152 | context.setDrawTextWithFocusStyle(true); | |
153 | } | |
154 | context.setLineWidth(Metrics.NORMAL_LINE_WIDTH); | |
155 | drawMessage(context); | |
156 | context.setLineWidth(Metrics.NORMAL_LINE_WIDTH); | |
157 | if (hasFocus()) { | |
158 | context.setDrawTextWithFocusStyle(false); | |
159 | } | |
160 | } | |
161 | } |