tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / BasicExecutionOccurrence.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
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
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
12
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;
17 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
18 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
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 (GraphNode.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 }
140 return super.getName();
141 }
142
143 /**
144 * Set the lifeline on which the execution occurrence appears.
145 *
146 * @param theLifeline - the parent lifeline
147 */
148 public void setLifeline(Lifeline theLifeline) {
149 fLifeline = theLifeline;
150 }
151
152 /**
153 * Get the lifeline on which the execution occurrence appears.
154 *
155 * @return - the parent lifeline
156 */
157 public Lifeline getLifeline() {
158 return fLifeline;
159 }
160
161 /**
162 * Get the execution start event occurrence
163 *
164 * @return the start event occurrence to set
165 */
166 @Override
167 public int getStartOccurrence() {
168 return fStartEventOccurrence;
169 }
170
171 /**
172 * Set the execution end event occurrence
173 *
174 * @return the end event occurrence to set
175 */
176 @Override
177 public int getEndOccurrence() {
178 return fEndEventOccurrence;
179 }
180
181 /**
182 * Set the execution start event occurrence
183 *
184 * @param occurrence the start event occurrence to set
185 */
186 public void setStartOccurrence(int occurrence) {
187 fStartEventOccurrence = occurrence;
188 }
189
190 /**
191 * Set the execution end event occurrence
192 *
193 * @param occurrence the end event occurrence to set
194 */
195 public void setEndOccurrence(int occurrence) {
196 fEndEventOccurrence = occurrence;
197 }
198
199 /*
200 * (non-Javadoc)
201 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
202 */
203 @Override
204 public void draw(IGC context) {
205 int x = getX();
206 int y = getY();
207 int width = getWidth();
208 int height = getHeight();
209 IColor tempFillColor = null;
210 IColor tempStrokeColor = null;
211
212 ISDPreferences pref = SDViewPref.getInstance();
213
214 // The execution occurrence is selected
215 // if the owning lifeline is selected
216 if (fLifeline.isSelected() || isSelected()) {
217 context.setBackground(pref.getBackGroundColorSelection());
218 context.setForeground(pref.getForeGroundColorSelection());
219 } else {
220 tempFillColor = setUnselectedFillColor(context);
221 }
222 if (pref.useGradienColor()) {
223 context.fillGradientRectangle(x, y, width, height, false);
224 } else {
225 context.fillRectangle(x, y, width, height);
226 }
227 tempStrokeColor = setUnselectedStrokeColor(context);
228 context.drawRectangle(x, y, width, height);
229 if (tempFillColor != null) {
230 tempFillColor.dispose();
231 }
232 if (tempStrokeColor != null) {
233 tempStrokeColor.dispose();
234 }
235 if (hasFocus()) {
236 drawFocus(context);
237 }
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 Graphics context
245 * @return IColor
246 */
247 protected IColor setUnselectedFillColor(IGC context) {
248
249 ISDPreferences pref = SDViewPref.getInstance();
250
251 if (pref.useGradienColor()) {
252 context.setGradientColor(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
253 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME));
254 } else {
255 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
256 }
257 return null;
258 }
259
260 /**
261 * Rewrite this method in your extension in order to support customized stroke colors
262 *
263 * @param context Graphics context
264 * @return IColor
265 */
266 protected IColor setUnselectedStrokeColor(IGC context) {
267 context.setForeground(SDViewPref.getInstance().getForeGroundColor(ISDPreferences.PREF_EXEC));
268 return null;
269 }
270
271 /*
272 * (non-Javadoc)
273 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
274 */
275 @Override
276 public String getArrayId() {
277 return EXEC_OCC_TAG;
278 }
279
280 /*
281 * (non-Javadoc)
282 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
283 */
284 @Override
285 public boolean positiveDistanceToPoint(int x, int y) {
286 if (getY() + getHeight() > y) {
287 return true;
288 }
289 return false;
290 }
291
292 /*
293 * (non-Javadoc)
294 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
295 */
296 @Override
297 public boolean isVisible(int x, int y, int width, int height) {
298 if ((getLifeline() != null) && (getLifeline().isVisible(x, y, width, height))) {
299 int ly = getY();
300 int lh = getHeight();
301 if (ly >= y && ly < y + height) {
302 return true;
303 }
304 if (ly + lh > y && ly + lh <= y + height) {
305 return true;
306 }
307 if ((ly < y) && (ly + lh > y + height)) {
308 return true;
309 }
310 }
311 return false;
312 }
313 }
This page took 0.038672 seconds and 5 git commands to generate.