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
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
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
25 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
30 public class BasicExecutionOccurrence
extends GraphNode
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 * The grahNode ID constant
38 public static final String EXEC_OCC_TAG
= "Execution_Occ"; //$NON-NLS-1$
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
45 * The corresponding lifeline.
47 protected Lifeline fLifeline
= null;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 * Default constructore
55 public BasicExecutionOccurrence() {
56 fPrefId
= ISDPreferences
.PREF_EXEC
;
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
65 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX()
69 if (fLifeline
== null) {
72 return fLifeline
.getX() + Metrics
.getLifelineWidth() / 2 - Metrics
.EXECUTION_OCCURRENCE_WIDTH
/ 2;
77 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY()
81 if (fLifeline
== null) {
84 return fLifeline
.getY() + fLifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * fStartEventOccurrence
;
89 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth()
92 public int getWidth() {
93 if (fLifeline
== null) {
96 return Metrics
.EXECUTION_OCCURRENCE_WIDTH
;
101 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight()
104 public int getHeight() {
105 if (fLifeline
== null) {
108 return ((Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing())) * (fEndEventOccurrence
- fStartEventOccurrence
);
113 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int)
116 public boolean contains(int xValue
, int yValue
) {
119 int width
= getWidth();
120 int height
= getHeight();
122 if (GraphNode
.contains(x
, y
, width
, height
, xValue
, yValue
)) {
126 if (getNodeAt(xValue
, yValue
) != null) {
134 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getName()
137 public String
getName() {
138 if (super.getName() == null || super.getName().equals("")) { //$NON-NLS-1$
139 return fLifeline
.getToolTipText();
141 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 ISDPreferences pref
= SDViewPref
.getInstance();
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());
221 tempFillColor
= setUnselectedFillColor(context
);
223 if (pref
.useGradienColor()) {
224 context
.fillGradientRectangle(x
, y
, width
, height
, false);
226 context
.fillRectangle(x
, y
, width
, height
);
228 tempStrokeColor
= setUnselectedStrokeColor(context
);
229 context
.drawRectangle(x
, y
, width
, height
);
230 if (tempFillColor
!= null) {
231 tempFillColor
.dispose();
233 if (tempStrokeColor
!= null) {
234 tempStrokeColor
.dispose();
239 super.drawChildenNodes(context
);
243 * Rewrite this method in your extension in order to support customized fill colors
245 * @param context Graphics context
248 protected IColor
setUnselectedFillColor(IGC context
) {
250 ISDPreferences pref
= SDViewPref
.getInstance();
252 if (pref
.useGradienColor()) {
253 context
.setGradientColor(pref
.getBackGroundColor(ISDPreferences
.PREF_EXEC
));
254 context
.setBackground(pref
.getBackGroundColor(ISDPreferences
.PREF_FRAME
));
256 context
.setBackground(pref
.getBackGroundColor(ISDPreferences
.PREF_EXEC
));
262 * Rewrite this method in your extension in order to support customized stroke colors
264 * @param context Graphics context
267 protected IColor
setUnselectedStrokeColor(IGC context
) {
268 context
.setForeground(SDViewPref
.getInstance().getForeGroundColor(ISDPreferences
.PREF_EXEC
));
274 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
277 public String
getArrayId() {
283 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
286 public boolean positiveDistanceToPoint(int x
, int y
) {
287 if (getY() + getHeight() > y
) {
295 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
298 public boolean isVisible(int x
, int y
, int width
, int height
) {
299 if ((getLifeline() != null) && (getLifeline().isVisible(x
, y
, width
, height
))) {
301 int lh
= getHeight();
302 if (ly
>= y
&& ly
< y
+ height
) {
305 if (ly
+ lh
> y
&& ly
+ lh
<= y
+ height
) {
308 if ((ly
< y
) && (ly
+ lh
> y
+ height
)) {