Java Doc and API clean up of TMF UML Sequence diagram framework
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / BasicExecutionOccurrence.java
CommitLineData
73005152 1/**********************************************************************
df0b8ff4
BH
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
73005152
BH
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
73005152
BH
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
15
16import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor;
17import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
df0b8ff4 18import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
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
23 *
24 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
df0b8ff4 25 * @version 1.0
73005152
BH
26 * @author sveyrier
27 *
28 */
29public 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 /**
44 * The corresponding lifeline.
45 */
46 protected Lifeline lifeline = null;
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51 /**
52 * Default constructore
53 */
73005152
BH
54 public BasicExecutionOccurrence() {
55 prefId = ISDPreferences.PREF_EXEC;
56 }
57
df0b8ff4
BH
58 // ------------------------------------------------------------------------
59 // Constants
60 // ------------------------------------------------------------------------
61
62 /*
63 * (non-Javadoc)
64 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX()
65 */
73005152
BH
66 @Override
67 public int getX() {
df0b8ff4 68 if (lifeline == null) {
73005152 69 return 0;
df0b8ff4 70 }
73005152
BH
71 return lifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2;
72 }
73
df0b8ff4
BH
74 /*
75 * (non-Javadoc)
76 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY()
77 */
73005152
BH
78 @Override
79 public int getY() {
df0b8ff4 80 if (lifeline == null) {
73005152 81 return 0;
df0b8ff4 82 }
73005152
BH
83 return lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * startEventOccurrence;
84 }
85
df0b8ff4
BH
86 /*
87 * (non-Javadoc)
88 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth()
89 */
73005152
BH
90 @Override
91 public int getWidth() {
df0b8ff4 92 if (lifeline == null) {
73005152 93 return 0;
df0b8ff4 94 }
73005152
BH
95 return Metrics.EXECUTION_OCCURRENCE_WIDTH;
96 }
97
df0b8ff4
BH
98 /*
99 * (non-Javadoc)
100 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight()
101 */
73005152
BH
102 @Override
103 public int getHeight() {
df0b8ff4 104 if (lifeline == null) {
73005152 105 return 0;
df0b8ff4 106 }
73005152
BH
107 return ((Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing())) * (endEventOccurrence - startEventOccurrence);
108 }
109
df0b8ff4
BH
110 /*
111 * (non-Javadoc)
112 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int)
113 */
73005152
BH
114 @Override
115 public boolean contains(int _x, int _y) {
116 int x = getX();
117 int y = getY();
118 int width = getWidth();
119 int height = getHeight();
120
121 if (Frame.contains(x, y, width, height, _x, _y)) {
122 return true;
123 }
124
df0b8ff4 125 if (getNodeAt(_x, _y) != null) {
73005152 126 return true;
df0b8ff4 127 }
73005152
BH
128 return false;
129 }
130
df0b8ff4
BH
131 /*
132 * (non-Javadoc)
133 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getName()
134 */
73005152
BH
135 @Override
136 public String getName() {
df0b8ff4 137 if (super.getName() == null || super.getName().equals("")) { //$NON-NLS-1$
73005152 138 return lifeline.getToolTipText();
df0b8ff4 139 } else {
73005152 140 return super.getName();
df0b8ff4 141 }
73005152
BH
142 }
143
144 /**
145 * Set the lifeline on which the execution occurrence appears.
146 *
147 * @param theLifeline - the parent lifeline
148 */
149 public void setLifeline(Lifeline theLifeline) {
150 lifeline = theLifeline;
151 }
152
153 /**
154 * Get the lifeline on which the execution occurrence appears.
155 *
156 * @return - the parent lifeline
157 */
158 public Lifeline getLifeline() {
159 return lifeline;
160 }
161
162 /**
163 * Get the execution start event occurrence
164 *
165 * @return the start event occurrence to set
166 */
167 @Override
168 public int getStartOccurrence() {
169 return startEventOccurrence;
170 }
171
172 /**
173 * Set the execution end event occurrence
174 *
175 * @return the end event occurrence to set
176 */
177 @Override
178 public int getEndOccurrence() {
179 return endEventOccurrence;
180 }
181
182 /**
183 * Set the execution start event occurrence
184 *
185 * @param occurrence the start event occurrence to set
186 */
187 public void setStartOccurrence(int occurrence) {
188 startEventOccurrence = occurrence;
189 }
190
191 /**
192 * Set the execution end event occurrence
193 *
194 * @param occurrence the end event occurrence to set
195 */
196 public void setEndOccurrence(int occurrence) {
197 endEventOccurrence = occurrence;
198 }
199
df0b8ff4
BH
200 /*
201 * (non-Javadoc)
202 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
203 */
73005152
BH
204 @Override
205 public void draw(IGC context) {
206 int x = getX();
207 int y = getY();
208 int width = getWidth();
209 int height = getHeight();
210 IColor tempFillColor = null, tempStrokeColor = null;
211
212 // The execution occurrence is selected
213 // if the owning lifeline is selected
214 if (lifeline.isSelected() || isSelected()) {
215 context.setBackground(Frame.getUserPref().getBackGroundColorSelection());
216 context.setForeground(Frame.getUserPref().getForeGroundColorSelection());
217 } else {
218 tempFillColor = setUnselectedFillColor(context);
219 }
df0b8ff4 220 if (Frame.getUserPref().useGradienColor()) {
73005152 221 context.fillGradientRectangle(x, y, width, height, false);
df0b8ff4 222 } else {
73005152 223 context.fillRectangle(x, y, width, height);
df0b8ff4 224 }
73005152
BH
225 tempStrokeColor = setUnselectedStrokeColor(context);
226 context.drawRectangle(x, y, width, height);
227 if (tempFillColor != null) {
228 tempFillColor.dispose();
229 tempFillColor = null;
230 }
231 if (tempStrokeColor != null) {
232 tempStrokeColor.dispose();
233 tempStrokeColor = null;
234 }
df0b8ff4 235 if (hasFocus()) {
73005152 236 drawFocus(context);
df0b8ff4 237 }
73005152
BH
238 super.drawChildenNodes(context);
239 }
240
241 /**
242 * Rewrite this method in your extension in order to support customized fill colors
243 *
244 * @param context
245 * @return IColor
246 */
247 protected IColor setUnselectedFillColor(IGC context) {
248 if (Frame.getUserPref().useGradienColor()) {
249 context.setGradientColor(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_EXEC));
250 context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_FRAME));
df0b8ff4 251 } else {
73005152 252 context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_EXEC));
df0b8ff4 253 }
73005152
BH
254 return null;
255 }
256
257 /**
258 * Rewrite this method in your extension in order to support customized stroke colors
259 *
260 * @param context
261 * @return IColor
262 */
263 protected IColor setUnselectedStrokeColor(IGC context) {
264 context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_EXEC));
265 return null;
266 }
267
df0b8ff4
BH
268 /*
269 * (non-Javadoc)
270 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
271 */
73005152
BH
272 @Override
273 public String getArrayId() {
274 return EXEC_OCC_TAG;
275 }
276
df0b8ff4
BH
277 /*
278 * (non-Javadoc)
279 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
280 */
73005152
BH
281 @Override
282 public boolean positiveDistanceToPoint(int x, int y) {
df0b8ff4 283 if (getY() + getHeight() > y) {
73005152 284 return true;
df0b8ff4 285 }
73005152
BH
286 return false;
287 }
288
df0b8ff4
BH
289 /*
290 * (non-Javadoc)
291 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
292 */
73005152
BH
293 @Override
294 public boolean isVisible(int x, int y, int width, int height) {
295 if ((getLifeline() != null) && (getLifeline().isVisible(x, y, width, height))) {
296 int ly = getY();
297 int lh = getHeight();
df0b8ff4 298 if (ly >= y && ly < y + height) {
73005152 299 return true;
df0b8ff4
BH
300 }
301 if (ly + lh > y && ly + lh <= y + height) {
73005152 302 return true;
df0b8ff4
BH
303 }
304 if ((ly < y) && (ly + lh > y + height)) {
73005152 305 return true;
df0b8ff4 306 }
73005152
BH
307 }
308 return false;
309 }
310}
This page took 0.042495 seconds and 5 git commands to generate.