Fix static analysis warnings for UML2SD
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / BasicExecutionOccurrence.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2006 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
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
25 * @version 1.0
26 * @author sveyrier
27 *
28 */
29 public class BasicExecutionOccurrence extends GraphNode {
30
31 // ------------------------------------------------------------------------
32 // Constants
33 // ------------------------------------------------------------------------
34 /**
35 * The grahNode ID constant
36 */
37 public static final String EXEC_OCC_TAG = "Execution_Occ"; //$NON-NLS-1$
38
39 // ------------------------------------------------------------------------
40 // Attributes
41 // ------------------------------------------------------------------------
42
43 /**
44 * The corresponding lifeline.
45 */
46 protected Lifeline fLifeline = null;
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51 /**
52 * Default constructore
53 */
54 public BasicExecutionOccurrence() {
55 fPrefId = ISDPreferences.PREF_EXEC;
56 }
57
58 // ------------------------------------------------------------------------
59 // Constants
60 // ------------------------------------------------------------------------
61
62 /*
63 * (non-Javadoc)
64 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX()
65 */
66 @Override
67 public int getX() {
68 if (fLifeline == null) {
69 return 0;
70 }
71 return fLifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2;
72 }
73
74 /*
75 * (non-Javadoc)
76 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY()
77 */
78 @Override
79 public int getY() {
80 if (fLifeline == null) {
81 return 0;
82 }
83 return fLifeline.getY() + fLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fStartEventOccurrence;
84 }
85
86 /*
87 * (non-Javadoc)
88 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth()
89 */
90 @Override
91 public int getWidth() {
92 if (fLifeline == null) {
93 return 0;
94 }
95 return Metrics.EXECUTION_OCCURRENCE_WIDTH;
96 }
97
98 /*
99 * (non-Javadoc)
100 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight()
101 */
102 @Override
103 public int getHeight() {
104 if (fLifeline == null) {
105 return 0;
106 }
107 return ((Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing())) * (fEndEventOccurrence - fStartEventOccurrence);
108 }
109
110 /*
111 * (non-Javadoc)
112 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int)
113 */
114 @Override
115 public boolean contains(int xValue, int yValue) {
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, xValue, yValue)) {
122 return true;
123 }
124
125 if (getNodeAt(xValue, yValue) != null) {
126 return true;
127 }
128 return false;
129 }
130
131 /*
132 * (non-Javadoc)
133 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getName()
134 */
135 @Override
136 public String getName() {
137 if (super.getName() == null || super.getName().equals("")) { //$NON-NLS-1$
138 return fLifeline.getToolTipText();
139 } else {
140 return super.getName();
141 }
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 fLifeline = 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 fLifeline;
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 fStartEventOccurrence;
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 fEndEventOccurrence;
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 fStartEventOccurrence = 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 fEndEventOccurrence = occurrence;
198 }
199
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 */
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;
211 IColor tempStrokeColor = null;
212
213 // The execution occurrence is selected
214 // if the owning lifeline is selected
215 if (fLifeline.isSelected() || isSelected()) {
216 context.setBackground(Frame.getUserPref().getBackGroundColorSelection());
217 context.setForeground(Frame.getUserPref().getForeGroundColorSelection());
218 } else {
219 tempFillColor = setUnselectedFillColor(context);
220 }
221 if (Frame.getUserPref().useGradienColor()) {
222 context.fillGradientRectangle(x, y, width, height, false);
223 } else {
224 context.fillRectangle(x, y, width, height);
225 }
226 tempStrokeColor = setUnselectedStrokeColor(context);
227 context.drawRectangle(x, y, width, height);
228 if (tempFillColor != null) {
229 tempFillColor.dispose();
230 }
231 if (tempStrokeColor != null) {
232 tempStrokeColor.dispose();
233 }
234 if (hasFocus()) {
235 drawFocus(context);
236 }
237 super.drawChildenNodes(context);
238 }
239
240 /**
241 * Rewrite this method in your extension in order to support customized fill colors
242 *
243 * @param context
244 * @return IColor
245 */
246 protected IColor setUnselectedFillColor(IGC context) {
247 if (Frame.getUserPref().useGradienColor()) {
248 context.setGradientColor(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_EXEC));
249 context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_FRAME));
250 } else {
251 context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_EXEC));
252 }
253 return null;
254 }
255
256 /**
257 * Rewrite this method in your extension in order to support customized stroke colors
258 *
259 * @param context
260 * @return IColor
261 */
262 protected IColor setUnselectedStrokeColor(IGC context) {
263 context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_EXEC));
264 return null;
265 }
266
267 /*
268 * (non-Javadoc)
269 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
270 */
271 @Override
272 public String getArrayId() {
273 return EXEC_OCC_TAG;
274 }
275
276 /*
277 * (non-Javadoc)
278 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
279 */
280 @Override
281 public boolean positiveDistanceToPoint(int x, int y) {
282 if (getY() + getHeight() > y) {
283 return true;
284 }
285 return false;
286 }
287
288 /*
289 * (non-Javadoc)
290 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
291 */
292 @Override
293 public boolean isVisible(int x, int y, int width, int height) {
294 if ((getLifeline() != null) && (getLifeline().isVisible(x, y, width, height))) {
295 int ly = getY();
296 int lh = getHeight();
297 if (ly >= y && ly < y + height) {
298 return true;
299 }
300 if (ly + lh > y && ly + lh <= y + height) {
301 return true;
302 }
303 if ((ly < y) && (ly + lh > y + height)) {
304 return true;
305 }
306 }
307 return false;
308 }
309 }
This page took 0.03766 seconds and 5 git commands to generate.