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