1 /**********************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
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
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
;
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
;
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
24 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
29 public class BasicExecutionOccurrence
extends GraphNode
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 * The grahNode ID constant
37 public static final String EXEC_OCC_TAG
= "Execution_Occ"; //$NON-NLS-1$
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 * The corresponding lifeline.
46 protected Lifeline fLifeline
= null;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 * Default constructore
54 public BasicExecutionOccurrence() {
55 fPrefId
= ISDPreferences
.PREF_EXEC
;
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
64 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX()
68 if (fLifeline
== null) {
71 return fLifeline
.getX() + Metrics
.getLifelineWidth() / 2 - Metrics
.EXECUTION_OCCURRENCE_WIDTH
/ 2;
76 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY()
80 if (fLifeline
== null) {
83 return fLifeline
.getY() + fLifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * fStartEventOccurrence
;
88 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth()
91 public int getWidth() {
92 if (fLifeline
== null) {
95 return Metrics
.EXECUTION_OCCURRENCE_WIDTH
;
100 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight()
103 public int getHeight() {
104 if (fLifeline
== null) {
107 return ((Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing())) * (fEndEventOccurrence
- fStartEventOccurrence
);
112 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int)
115 public boolean contains(int xValue
, int yValue
) {
118 int width
= getWidth();
119 int height
= getHeight();
121 if (Frame
.contains(x
, y
, width
, height
, xValue
, yValue
)) {
125 if (getNodeAt(xValue
, yValue
) != null) {
133 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getName()
136 public String
getName() {
137 if (super.getName() == null || super.getName().equals("")) { //$NON-NLS-1$
138 return fLifeline
.getToolTipText();
140 return super.getName();
145 * Set the lifeline on which the execution occurrence appears.
147 * @param theLifeline - the parent lifeline
149 public void setLifeline(Lifeline theLifeline
) {
150 fLifeline
= theLifeline
;
154 * Get the lifeline on which the execution occurrence appears.
156 * @return - the parent lifeline
158 public Lifeline
getLifeline() {
163 * Get the execution start event occurrence
165 * @return the start event occurrence to set
168 public int getStartOccurrence() {
169 return fStartEventOccurrence
;
173 * Set the execution end event occurrence
175 * @return the end event occurrence to set
178 public int getEndOccurrence() {
179 return fEndEventOccurrence
;
183 * Set the execution start event occurrence
185 * @param occurrence the start event occurrence to set
187 public void setStartOccurrence(int occurrence
) {
188 fStartEventOccurrence
= occurrence
;
192 * Set the execution end event occurrence
194 * @param occurrence the end event occurrence to set
196 public void setEndOccurrence(int occurrence
) {
197 fEndEventOccurrence
= occurrence
;
202 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
205 public void draw(IGC context
) {
208 int width
= getWidth();
209 int height
= getHeight();
210 IColor tempFillColor
= null;
211 IColor tempStrokeColor
= null;
213 // The execution occurrence is selected
214 // if the owning lifeline is selected
215 if (fLifeline
.isSelected() || isSelected()) {
216 context
.setBackground(Frame
.getUserPref().getBackGroundColorSelection());
217 context
.setForeground(Frame
.getUserPref().getForeGroundColorSelection());
219 tempFillColor
= setUnselectedFillColor(context
);
221 if (Frame
.getUserPref().useGradienColor()) {
222 context
.fillGradientRectangle(x
, y
, width
, height
, false);
224 context
.fillRectangle(x
, y
, width
, height
);
226 tempStrokeColor
= setUnselectedStrokeColor(context
);
227 context
.drawRectangle(x
, y
, width
, height
);
228 if (tempFillColor
!= null) {
229 tempFillColor
.dispose();
231 if (tempStrokeColor
!= null) {
232 tempStrokeColor
.dispose();
237 super.drawChildenNodes(context
);
241 * Rewrite this method in your extension in order to support customized fill colors
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
));
251 context
.setBackground(Frame
.getUserPref().getBackGroundColor(ISDPreferences
.PREF_EXEC
));
257 * Rewrite this method in your extension in order to support customized stroke colors
262 protected IColor
setUnselectedStrokeColor(IGC context
) {
263 context
.setForeground(Frame
.getUserPref().getForeGroundColor(ISDPreferences
.PREF_EXEC
));
269 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
272 public String
getArrayId() {
278 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
281 public boolean positiveDistanceToPoint(int x
, int y
) {
282 if (getY() + getHeight() > y
) {
290 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
293 public boolean isVisible(int x
, int y
, int width
, int height
) {
294 if ((getLifeline() != null) && (getLifeline().isVisible(x
, y
, width
, height
))) {
296 int lh
= getHeight();
297 if (ly
>= y
&& ly
< y
+ height
) {
300 if (ly
+ lh
> y
&& ly
+ lh
<= y
+ height
) {
303 if ((ly
< y
) && (ly
+ lh
> y
+ height
)) {