Fix for Linux display bugs in TimeGraphCombo.
[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;
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
23 *
24 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
df0b8ff4 25 * @version 1.0
73005152
BH
26 * @author sveyrier
27 *
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 /**
44 * The corresponding lifeline.
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
eb63f5ff 121 if (Frame.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 } else {
73005152 140 return super.getName();
df0b8ff4 141 }
73005152
BH
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) {
eb63f5ff 150 fLifeline = theLifeline;
73005152
BH
151 }
152
153 /**
154 * Get the lifeline on which the execution occurrence appears.
155 *
156 * @return - the parent lifeline
157 */
158 public Lifeline getLifeline() {
eb63f5ff 159 return fLifeline;
73005152
BH
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() {
eb63f5ff 169 return fStartEventOccurrence;
73005152
BH
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() {
eb63f5ff 179 return fEndEventOccurrence;
73005152
BH
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) {
eb63f5ff 188 fStartEventOccurrence = occurrence;
73005152
BH
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) {
eb63f5ff 197 fEndEventOccurrence = occurrence;
73005152
BH
198 }
199
df0b8ff4
BH
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 */
73005152
BH
204 @Override
205 public void draw(IGC context) {
206 int x = getX();
207 int y = getY();
208 int width = getWidth();
209 int height = getHeight();
eb63f5ff
BH
210 IColor tempFillColor = null;
211 IColor tempStrokeColor = null;
73005152
BH
212
213 // The execution occurrence is selected
214 // if the owning lifeline is selected
eb63f5ff 215 if (fLifeline.isSelected() || isSelected()) {
73005152
BH
216 context.setBackground(Frame.getUserPref().getBackGroundColorSelection());
217 context.setForeground(Frame.getUserPref().getForeGroundColorSelection());
218 } else {
219 tempFillColor = setUnselectedFillColor(context);
220 }
df0b8ff4 221 if (Frame.getUserPref().useGradienColor()) {
73005152 222 context.fillGradientRectangle(x, y, width, height, false);
df0b8ff4 223 } else {
73005152 224 context.fillRectangle(x, y, width, height);
df0b8ff4 225 }
73005152
BH
226 tempStrokeColor = setUnselectedStrokeColor(context);
227 context.drawRectangle(x, y, width, height);
228 if (tempFillColor != null) {
229 tempFillColor.dispose();
73005152
BH
230 }
231 if (tempStrokeColor != null) {
232 tempStrokeColor.dispose();
73005152 233 }
df0b8ff4 234 if (hasFocus()) {
73005152 235 drawFocus(context);
df0b8ff4 236 }
73005152
BH
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));
df0b8ff4 250 } else {
73005152 251 context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_EXEC));
df0b8ff4 252 }
73005152
BH
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
df0b8ff4
BH
267 /*
268 * (non-Javadoc)
269 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
270 */
73005152
BH
271 @Override
272 public String getArrayId() {
273 return EXEC_OCC_TAG;
274 }
275
df0b8ff4
BH
276 /*
277 * (non-Javadoc)
278 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
279 */
73005152
BH
280 @Override
281 public boolean positiveDistanceToPoint(int x, int y) {
df0b8ff4 282 if (getY() + getHeight() > y) {
73005152 283 return true;
df0b8ff4 284 }
73005152
BH
285 return false;
286 }
287
df0b8ff4
BH
288 /*
289 * (non-Javadoc)
290 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
291 */
73005152
BH
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();
df0b8ff4 297 if (ly >= y && ly < y + height) {
73005152 298 return true;
df0b8ff4
BH
299 }
300 if (ly + lh > y && ly + lh <= y + height) {
73005152 301 return true;
df0b8ff4
BH
302 }
303 if ((ly < y) && (ly + lh > y + height)) {
73005152 304 return true;
df0b8ff4 305 }
73005152
BH
306 }
307 return false;
308 }
309}
This page took 0.060109 seconds and 5 git commands to generate.