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