Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
c8422608 | 2 | * Copyright (c) 2005, 2013 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 | |
abbdd66a AM |
7 | * |
8 | * Contributors: | |
c8422608 AM |
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 BH |
19 | |
20 | /** | |
21 | * BasicExecutionOccurrence is the UML2 execution occurrence graphical representation. It is attached to one Lifeline, | |
22 | * the event occurrence "duration" along the lifeline is defined by two event occurrences | |
abbdd66a | 23 | * |
73005152 | 24 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details |
abbdd66a | 25 | * @version 1.0 |
73005152 | 26 | * @author sveyrier |
abbdd66a | 27 | * |
73005152 BH |
28 | */ |
29 | public class BasicExecutionOccurrence extends GraphNode { | |
30 | ||
df0b8ff4 BH |
31 | // ------------------------------------------------------------------------ |
32 | // Constants | |
33 | // ------------------------------------------------------------------------ | |
34 | /** | |
35 | * The grahNode ID constant | |
36 | */ | |
73005152 BH |
37 | public static final String EXEC_OCC_TAG = "Execution_Occ"; //$NON-NLS-1$ |
38 | ||
df0b8ff4 BH |
39 | // ------------------------------------------------------------------------ |
40 | // Attributes | |
41 | // ------------------------------------------------------------------------ | |
42 | ||
43 | /** | |
abbdd66a | 44 | * The corresponding lifeline. |
df0b8ff4 | 45 | */ |
cab6c8ff | 46 | private Lifeline fLifeline = null; |
df0b8ff4 BH |
47 | |
48 | // ------------------------------------------------------------------------ | |
49 | // Constructors | |
50 | // ------------------------------------------------------------------------ | |
51 | /** | |
52 | * Default constructore | |
53 | */ | |
73005152 | 54 | public BasicExecutionOccurrence() { |
cab6c8ff | 55 | setColorPrefId(ISDPreferences.PREF_EXEC); |
73005152 BH |
56 | } |
57 | ||
df0b8ff4 BH |
58 | // ------------------------------------------------------------------------ |
59 | // Constants | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
73005152 BH |
62 | @Override |
63 | public int getX() { | |
eb63f5ff | 64 | if (fLifeline == null) { |
73005152 | 65 | return 0; |
df0b8ff4 | 66 | } |
eb63f5ff | 67 | return fLifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2; |
73005152 BH |
68 | } |
69 | ||
70 | @Override | |
71 | public int getY() { | |
eb63f5ff | 72 | if (fLifeline == null) { |
73005152 | 73 | return 0; |
df0b8ff4 | 74 | } |
cab6c8ff | 75 | return fLifeline.getY() + fLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * getStartOccurrence(); |
73005152 BH |
76 | } |
77 | ||
78 | @Override | |
79 | public int getWidth() { | |
eb63f5ff | 80 | if (fLifeline == null) { |
73005152 | 81 | return 0; |
df0b8ff4 | 82 | } |
73005152 BH |
83 | return Metrics.EXECUTION_OCCURRENCE_WIDTH; |
84 | } | |
85 | ||
86 | @Override | |
87 | public int getHeight() { | |
eb63f5ff | 88 | if (fLifeline == null) { |
73005152 | 89 | return 0; |
df0b8ff4 | 90 | } |
cab6c8ff | 91 | return ((Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing())) * (getEndOccurrence() - getStartOccurrence()); |
73005152 BH |
92 | } |
93 | ||
94 | @Override | |
eb63f5ff | 95 | public boolean contains(int xValue, int yValue) { |
73005152 BH |
96 | int x = getX(); |
97 | int y = getY(); | |
98 | int width = getWidth(); | |
99 | int height = getHeight(); | |
100 | ||
abbdd66a | 101 | if (GraphNode.contains(x, y, width, height, xValue, yValue)) { |
73005152 BH |
102 | return true; |
103 | } | |
104 | ||
eb63f5ff | 105 | if (getNodeAt(xValue, yValue) != null) { |
73005152 | 106 | return true; |
df0b8ff4 | 107 | } |
73005152 BH |
108 | return false; |
109 | } | |
110 | ||
111 | @Override | |
112 | public String getName() { | |
df0b8ff4 | 113 | if (super.getName() == null || super.getName().equals("")) { //$NON-NLS-1$ |
eb63f5ff | 114 | return fLifeline.getToolTipText(); |
df0b8ff4 | 115 | } |
abbdd66a | 116 | return super.getName(); |
73005152 BH |
117 | } |
118 | ||
119 | /** | |
120 | * Set the lifeline on which the execution occurrence appears. | |
abbdd66a | 121 | * |
73005152 BH |
122 | * @param theLifeline - the parent lifeline |
123 | */ | |
124 | public void setLifeline(Lifeline theLifeline) { | |
eb63f5ff | 125 | fLifeline = theLifeline; |
73005152 BH |
126 | } |
127 | ||
128 | /** | |
129 | * Get the lifeline on which the execution occurrence appears. | |
abbdd66a | 130 | * |
73005152 BH |
131 | * @return - the parent lifeline |
132 | */ | |
133 | public Lifeline getLifeline() { | |
eb63f5ff | 134 | return fLifeline; |
73005152 BH |
135 | } |
136 | ||
137 | /** | |
138 | * Get the execution start event occurrence | |
abbdd66a | 139 | * |
73005152 BH |
140 | * @return the start event occurrence to set |
141 | */ | |
142 | @Override | |
143 | public int getStartOccurrence() { | |
cab6c8ff | 144 | return super.getStartOccurrence(); |
73005152 BH |
145 | } |
146 | ||
147 | /** | |
148 | * Set the execution end event occurrence | |
abbdd66a | 149 | * |
73005152 BH |
150 | * @return the end event occurrence to set |
151 | */ | |
152 | @Override | |
153 | public int getEndOccurrence() { | |
cab6c8ff | 154 | return super.getEndOccurrence(); |
73005152 BH |
155 | } |
156 | ||
157 | /** | |
158 | * Set the execution start event occurrence | |
abbdd66a | 159 | * |
73005152 BH |
160 | * @param occurrence the start event occurrence to set |
161 | */ | |
cab6c8ff | 162 | @Override |
73005152 | 163 | public void setStartOccurrence(int occurrence) { |
cab6c8ff | 164 | super.setStartOccurrence(occurrence); |
73005152 BH |
165 | } |
166 | ||
167 | /** | |
168 | * Set the execution end event occurrence | |
abbdd66a | 169 | * |
73005152 BH |
170 | * @param occurrence the end event occurrence to set |
171 | */ | |
cab6c8ff | 172 | @Override |
73005152 | 173 | public void setEndOccurrence(int occurrence) { |
cab6c8ff | 174 | super.setEndOccurrence(occurrence); |
73005152 BH |
175 | } |
176 | ||
177 | @Override | |
178 | public void draw(IGC context) { | |
179 | int x = getX(); | |
180 | int y = getY(); | |
181 | int width = getWidth(); | |
182 | int height = getHeight(); | |
eb63f5ff BH |
183 | IColor tempFillColor = null; |
184 | IColor tempStrokeColor = null; | |
73005152 | 185 | |
3145ec83 | 186 | ISDPreferences pref = SDViewPref.getInstance(); |
abbdd66a | 187 | |
73005152 BH |
188 | // The execution occurrence is selected |
189 | // if the owning lifeline is selected | |
eb63f5ff | 190 | if (fLifeline.isSelected() || isSelected()) { |
3145ec83 BH |
191 | context.setBackground(pref.getBackGroundColorSelection()); |
192 | context.setForeground(pref.getForeGroundColorSelection()); | |
73005152 BH |
193 | } else { |
194 | tempFillColor = setUnselectedFillColor(context); | |
195 | } | |
3145ec83 | 196 | if (pref.useGradienColor()) { |
73005152 | 197 | context.fillGradientRectangle(x, y, width, height, false); |
df0b8ff4 | 198 | } else { |
73005152 | 199 | context.fillRectangle(x, y, width, height); |
df0b8ff4 | 200 | } |
73005152 BH |
201 | tempStrokeColor = setUnselectedStrokeColor(context); |
202 | context.drawRectangle(x, y, width, height); | |
203 | if (tempFillColor != null) { | |
204 | tempFillColor.dispose(); | |
73005152 BH |
205 | } |
206 | if (tempStrokeColor != null) { | |
207 | tempStrokeColor.dispose(); | |
73005152 | 208 | } |
df0b8ff4 | 209 | if (hasFocus()) { |
73005152 | 210 | drawFocus(context); |
df0b8ff4 | 211 | } |
73005152 BH |
212 | super.drawChildenNodes(context); |
213 | } | |
214 | ||
215 | /** | |
216 | * Rewrite this method in your extension in order to support customized fill colors | |
abbdd66a | 217 | * |
a0a88f65 | 218 | * @param context Graphics context |
73005152 BH |
219 | * @return IColor |
220 | */ | |
221 | protected IColor setUnselectedFillColor(IGC context) { | |
3145ec83 BH |
222 | |
223 | ISDPreferences pref = SDViewPref.getInstance(); | |
224 | ||
225 | if (pref.useGradienColor()) { | |
226 | context.setGradientColor(pref.getBackGroundColor(ISDPreferences.PREF_EXEC)); | |
227 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME)); | |
df0b8ff4 | 228 | } else { |
3145ec83 | 229 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_EXEC)); |
df0b8ff4 | 230 | } |
73005152 BH |
231 | return null; |
232 | } | |
233 | ||
234 | /** | |
235 | * Rewrite this method in your extension in order to support customized stroke colors | |
abbdd66a | 236 | * |
a0a88f65 | 237 | * @param context Graphics context |
73005152 BH |
238 | * @return IColor |
239 | */ | |
240 | protected IColor setUnselectedStrokeColor(IGC context) { | |
3145ec83 | 241 | context.setForeground(SDViewPref.getInstance().getForeGroundColor(ISDPreferences.PREF_EXEC)); |
73005152 BH |
242 | return null; |
243 | } | |
244 | ||
245 | @Override | |
246 | public String getArrayId() { | |
247 | return EXEC_OCC_TAG; | |
248 | } | |
249 | ||
250 | @Override | |
251 | public boolean positiveDistanceToPoint(int x, int y) { | |
df0b8ff4 | 252 | if (getY() + getHeight() > y) { |
73005152 | 253 | return true; |
df0b8ff4 | 254 | } |
73005152 BH |
255 | return false; |
256 | } | |
257 | ||
258 | @Override | |
259 | public boolean isVisible(int x, int y, int width, int height) { | |
260 | if ((getLifeline() != null) && (getLifeline().isVisible(x, y, width, height))) { | |
261 | int ly = getY(); | |
262 | int lh = getHeight(); | |
df0b8ff4 | 263 | if (ly >= y && ly < y + height) { |
73005152 | 264 | return true; |
df0b8ff4 BH |
265 | } |
266 | if (ly + lh > y && ly + lh <= y + height) { | |
73005152 | 267 | return true; |
df0b8ff4 BH |
268 | } |
269 | if ((ly < y) && (ly + lh > y + height)) { | |
73005152 | 270 | return true; |
df0b8ff4 | 271 | } |
73005152 BH |
272 | } |
273 | return false; | |
274 | } | |
275 | } |