81a79eb0c7b9623daeed22c2c087eebfc04a0d83
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / uml2sd / core / BasicExecutionOccurrence.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2014 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.tracecompass.tmf.ui.views.uml2sd.core;
14
15 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.drawings.IColor;
16 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.drawings.IGC;
17 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.preferences.ISDPreferences;
18 import org.eclipse.tracecompass.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.tracecompass.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 private Lifeline fLifeline = null;
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51 /**
52 * Default constructore
53 */
54 public BasicExecutionOccurrence() {
55 setColorPrefId(ISDPreferences.PREF_EXEC);
56 }
57
58 // ------------------------------------------------------------------------
59 // Constants
60 // ------------------------------------------------------------------------
61
62 @Override
63 public int getX() {
64 if (fLifeline == null) {
65 return 0;
66 }
67 return fLifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2;
68 }
69
70 @Override
71 public int getY() {
72 if (fLifeline == null) {
73 return 0;
74 }
75 return fLifeline.getY() + fLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * getStartOccurrence();
76 }
77
78 @Override
79 public int getWidth() {
80 if (fLifeline == null) {
81 return 0;
82 }
83 return Metrics.EXECUTION_OCCURRENCE_WIDTH;
84 }
85
86 @Override
87 public int getHeight() {
88 if (fLifeline == null) {
89 return 0;
90 }
91 return ((Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing())) * (getEndOccurrence() - getStartOccurrence());
92 }
93
94 @Override
95 public boolean contains(int xValue, int yValue) {
96 int x = getX();
97 int y = getY();
98 int width = getWidth();
99 int height = getHeight();
100
101 if (GraphNode.contains(x, y, width, height, xValue, yValue)) {
102 return true;
103 }
104
105 if (getNodeAt(xValue, yValue) != null) {
106 return true;
107 }
108 return false;
109 }
110
111 @Override
112 public String getName() {
113 if (super.getName() == null || super.getName().equals("")) { //$NON-NLS-1$
114 return fLifeline.getToolTipText();
115 }
116 return super.getName();
117 }
118
119 /**
120 * Set the lifeline on which the execution occurrence appears.
121 *
122 * @param theLifeline - the parent lifeline
123 */
124 public void setLifeline(Lifeline theLifeline) {
125 fLifeline = theLifeline;
126 }
127
128 /**
129 * Get the lifeline on which the execution occurrence appears.
130 *
131 * @return - the parent lifeline
132 */
133 public Lifeline getLifeline() {
134 return fLifeline;
135 }
136
137 /**
138 * Get the execution start event occurrence
139 *
140 * @return the start event occurrence to set
141 */
142 @Override
143 public int getStartOccurrence() {
144 return super.getStartOccurrence();
145 }
146
147 /**
148 * Set the execution end event occurrence
149 *
150 * @return the end event occurrence to set
151 */
152 @Override
153 public int getEndOccurrence() {
154 return super.getEndOccurrence();
155 }
156
157 /**
158 * Set the execution start event occurrence
159 *
160 * @param occurrence the start event occurrence to set
161 */
162 @Override
163 public void setStartOccurrence(int occurrence) {
164 super.setStartOccurrence(occurrence);
165 }
166
167 /**
168 * Set the execution end event occurrence
169 *
170 * @param occurrence the end event occurrence to set
171 */
172 @Override
173 public void setEndOccurrence(int occurrence) {
174 super.setEndOccurrence(occurrence);
175 }
176
177 @Override
178 public void draw(IGC context) {
179 int x = getX();
180 int y = getY();
181 int width = getWidth();
182 int height = getHeight();
183 IColor tempFillColor = null;
184 IColor tempStrokeColor = null;
185
186 ISDPreferences pref = SDViewPref.getInstance();
187
188 // The execution occurrence is selected
189 // if the owning lifeline is selected
190 if (fLifeline.isSelected() || isSelected()) {
191 context.setBackground(pref.getBackGroundColorSelection());
192 context.setForeground(pref.getForeGroundColorSelection());
193 } else {
194 tempFillColor = setUnselectedFillColor(context);
195 }
196 if (pref.useGradienColor()) {
197 context.fillGradientRectangle(x, y, width, height, false);
198 } else {
199 context.fillRectangle(x, y, width, height);
200 }
201 tempStrokeColor = setUnselectedStrokeColor(context);
202 context.drawRectangle(x, y, width, height);
203 if (tempFillColor != null) {
204 tempFillColor.dispose();
205 }
206 if (tempStrokeColor != null) {
207 tempStrokeColor.dispose();
208 }
209 if (hasFocus()) {
210 drawFocus(context);
211 }
212 super.drawChildenNodes(context);
213 }
214
215 /**
216 * Rewrite this method in your extension in order to support customized fill colors
217 *
218 * @param context Graphics context
219 * @return IColor
220 */
221 protected IColor setUnselectedFillColor(IGC context) {
222
223 ISDPreferences pref = SDViewPref.getInstance();
224
225 if (pref.useGradienColor()) {
226 context.setGradientColor(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
227 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME));
228 } else {
229 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
230 }
231 return null;
232 }
233
234 /**
235 * Rewrite this method in your extension in order to support customized stroke colors
236 *
237 * @param context Graphics context
238 * @return IColor
239 */
240 protected IColor setUnselectedStrokeColor(IGC context) {
241 context.setForeground(SDViewPref.getInstance().getForeGroundColor(ISDPreferences.PREF_EXEC));
242 return null;
243 }
244
245 @Override
246 public String getArrayId() {
247 return EXEC_OCC_TAG;
248 }
249
250 @Override
251 public boolean positiveDistanceToPoint(int x, int y) {
252 if (getY() + getHeight() > y) {
253 return true;
254 }
255 return false;
256 }
257
258 @Override
259 public boolean isVisible(int x, int y, int width, int height) {
260 if ((getLifeline() != null) && (getLifeline().isVisible(x, y, width, height))) {
261 int ly = getY();
262 int lh = getHeight();
263 if (ly >= y && ly < y + height) {
264 return true;
265 }
266 if (ly + lh > y && ly + lh <= y + height) {
267 return true;
268 }
269 if ((ly < y) && (ly + lh > y + height)) {
270 return true;
271 }
272 }
273 return false;
274 }
275 }
This page took 0.037278 seconds and 4 git commands to generate.