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
CommitLineData
73005152 1/**********************************************************************
c8422608 2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
73005152
BH
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
abbdd66a
AM
7 *
8 * Contributors:
c8422608
AM
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
73005152 11 **********************************************************************/
c8422608 12
73005152
BH
13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
14
15import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor;
16import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
df0b8ff4 17import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
3145ec83 18import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
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
abbdd66a 23 *
73005152 24 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
abbdd66a 25 * @version 1.0
73005152 26 * @author sveyrier
abbdd66a 27 *
73005152
BH
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 /**
abbdd66a 44 * The corresponding lifeline.
df0b8ff4 45 */
eb63f5ff 46 protected Lifeline fLifeline = null;
df0b8ff4
BH
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51 /**
52 * Default constructore
53 */
73005152 54 public BasicExecutionOccurrence() {
eb63f5ff 55 fPrefId = ISDPreferences.PREF_EXEC;
73005152
BH
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() {
eb63f5ff 68 if (fLifeline == null) {
73005152 69 return 0;
df0b8ff4 70 }
eb63f5ff 71 return fLifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2;
73005152
BH
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() {
eb63f5ff 80 if (fLifeline == null) {
73005152 81 return 0;
df0b8ff4 82 }
eb63f5ff 83 return fLifeline.getY() + fLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fStartEventOccurrence;
73005152
BH
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() {
eb63f5ff 92 if (fLifeline == 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() {
eb63f5ff 104 if (fLifeline == null) {
73005152 105 return 0;
df0b8ff4 106 }
eb63f5ff 107 return ((Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing())) * (fEndEventOccurrence - fStartEventOccurrence);
73005152
BH
108 }
109
df0b8ff4
BH
110 /*
111 * (non-Javadoc)
112 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int)
113 */
73005152 114 @Override
eb63f5ff 115 public boolean contains(int xValue, int yValue) {
73005152
BH
116 int x = getX();
117 int y = getY();
118 int width = getWidth();
119 int height = getHeight();
120
abbdd66a 121 if (GraphNode.contains(x, y, width, height, xValue, yValue)) {
73005152
BH
122 return true;
123 }
124
eb63f5ff 125 if (getNodeAt(xValue, yValue) != 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$
eb63f5ff 138 return fLifeline.getToolTipText();
df0b8ff4 139 }
abbdd66a 140 return super.getName();
73005152
BH
141 }
142
143 /**
144 * Set the lifeline on which the execution occurrence appears.
abbdd66a 145 *
73005152
BH
146 * @param theLifeline - the parent lifeline
147 */
148 public void setLifeline(Lifeline theLifeline) {
eb63f5ff 149 fLifeline = theLifeline;
73005152
BH
150 }
151
152 /**
153 * Get the lifeline on which the execution occurrence appears.
abbdd66a 154 *
73005152
BH
155 * @return - the parent lifeline
156 */
157 public Lifeline getLifeline() {
eb63f5ff 158 return fLifeline;
73005152
BH
159 }
160
161 /**
162 * Get the execution start event occurrence
abbdd66a 163 *
73005152
BH
164 * @return the start event occurrence to set
165 */
166 @Override
167 public int getStartOccurrence() {
eb63f5ff 168 return fStartEventOccurrence;
73005152
BH
169 }
170
171 /**
172 * Set the execution end event occurrence
abbdd66a 173 *
73005152
BH
174 * @return the end event occurrence to set
175 */
176 @Override
177 public int getEndOccurrence() {
eb63f5ff 178 return fEndEventOccurrence;
73005152
BH
179 }
180
181 /**
182 * Set the execution start event occurrence
abbdd66a 183 *
73005152
BH
184 * @param occurrence the start event occurrence to set
185 */
186 public void setStartOccurrence(int occurrence) {
eb63f5ff 187 fStartEventOccurrence = occurrence;
73005152
BH
188 }
189
190 /**
191 * Set the execution end event occurrence
abbdd66a 192 *
73005152
BH
193 * @param occurrence the end event occurrence to set
194 */
195 public void setEndOccurrence(int occurrence) {
eb63f5ff 196 fEndEventOccurrence = occurrence;
73005152
BH
197 }
198
df0b8ff4
BH
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 */
73005152
BH
203 @Override
204 public void draw(IGC context) {
205 int x = getX();
206 int y = getY();
207 int width = getWidth();
208 int height = getHeight();
eb63f5ff
BH
209 IColor tempFillColor = null;
210 IColor tempStrokeColor = null;
73005152 211
3145ec83 212 ISDPreferences pref = SDViewPref.getInstance();
abbdd66a 213
73005152
BH
214 // The execution occurrence is selected
215 // if the owning lifeline is selected
eb63f5ff 216 if (fLifeline.isSelected() || isSelected()) {
3145ec83
BH
217 context.setBackground(pref.getBackGroundColorSelection());
218 context.setForeground(pref.getForeGroundColorSelection());
73005152
BH
219 } else {
220 tempFillColor = setUnselectedFillColor(context);
221 }
3145ec83 222 if (pref.useGradienColor()) {
73005152 223 context.fillGradientRectangle(x, y, width, height, false);
df0b8ff4 224 } else {
73005152 225 context.fillRectangle(x, y, width, height);
df0b8ff4 226 }
73005152
BH
227 tempStrokeColor = setUnselectedStrokeColor(context);
228 context.drawRectangle(x, y, width, height);
229 if (tempFillColor != null) {
230 tempFillColor.dispose();
73005152
BH
231 }
232 if (tempStrokeColor != null) {
233 tempStrokeColor.dispose();
73005152 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
abbdd66a 243 *
a0a88f65 244 * @param context Graphics context
73005152
BH
245 * @return IColor
246 */
247 protected IColor setUnselectedFillColor(IGC context) {
3145ec83
BH
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));
df0b8ff4 254 } else {
3145ec83 255 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
df0b8ff4 256 }
73005152
BH
257 return null;
258 }
259
260 /**
261 * Rewrite this method in your extension in order to support customized stroke colors
abbdd66a 262 *
a0a88f65 263 * @param context Graphics context
73005152
BH
264 * @return IColor
265 */
266 protected IColor setUnselectedStrokeColor(IGC context) {
3145ec83 267 context.setForeground(SDViewPref.getInstance().getForeGroundColor(ISDPreferences.PREF_EXEC));
73005152
BH
268 return null;
269 }
270
df0b8ff4
BH
271 /*
272 * (non-Javadoc)
273 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
274 */
73005152
BH
275 @Override
276 public String getArrayId() {
277 return EXEC_OCC_TAG;
278 }
279
df0b8ff4
BH
280 /*
281 * (non-Javadoc)
282 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
283 */
73005152
BH
284 @Override
285 public boolean positiveDistanceToPoint(int x, int y) {
df0b8ff4 286 if (getY() + getHeight() > y) {
73005152 287 return true;
df0b8ff4 288 }
73005152
BH
289 return false;
290 }
291
df0b8ff4
BH
292 /*
293 * (non-Javadoc)
294 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
295 */
73005152
BH
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();
df0b8ff4 301 if (ly >= y && ly < y + height) {
73005152 302 return true;
df0b8ff4
BH
303 }
304 if (ly + lh > y && ly + lh <= y + height) {
73005152 305 return true;
df0b8ff4
BH
306 }
307 if ((ly < y) && (ly + lh > y + height)) {
73005152 308 return true;
df0b8ff4 309 }
73005152
BH
310 }
311 return false;
312 }
313}
This page took 0.047811 seconds and 5 git commands to generate.