1 /**********************************************************************
2 * Copyright (c) 2005, 2006, 2011 IBM Corporation and others.
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 * $Id: BasicExecutionOccurrence.java,v 1.2 2006/09/20 20:56:25 ewchan Exp $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
;
15 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
16 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IGC
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.ISDPreferences
;
20 * BasicExecutionOccurrence is the UML2 execution occurrence graphical representation. It is attached to one Lifeline,
21 * the event occurrence "duration" along the lifeline is defined by two event occurrences
23 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
27 public class BasicExecutionOccurrence
extends GraphNode
{
29 protected Lifeline lifeline
= null;
31 public static final String EXEC_OCC_TAG
= "Execution_Occ"; //$NON-NLS-1$
33 public BasicExecutionOccurrence() {
34 prefId
= ISDPreferences
.PREF_EXEC
;
41 return lifeline
.getX() + Metrics
.getLifelineWidth() / 2 - Metrics
.EXECUTION_OCCURRENCE_WIDTH
/ 2;
48 return lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * startEventOccurrence
;
52 public int getWidth() {
55 return Metrics
.EXECUTION_OCCURRENCE_WIDTH
;
59 public int getHeight() {
62 return ((Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing())) * (endEventOccurrence
- startEventOccurrence
);
66 public boolean contains(int _x
, int _y
) {
69 int width
= getWidth();
70 int height
= getHeight();
72 if (Frame
.contains(x
, y
, width
, height
, _x
, _y
)) {
76 if (getNodeAt(_x
, _y
) != null)
82 public String
getName() {
83 if (super.getName() == null || super.getName().equals("")) //$NON-NLS-1$
84 return lifeline
.getToolTipText();
86 return super.getName();
90 * Set the lifeline on which the execution occurrence appears.
92 * @param theLifeline - the parent lifeline
94 public void setLifeline(Lifeline theLifeline
) {
95 lifeline
= theLifeline
;
99 * Get the lifeline on which the execution occurrence appears.
101 * @return - the parent lifeline
103 public Lifeline
getLifeline() {
108 * Get the execution start event occurrence
110 * @return the start event occurrence to set
113 public int getStartOccurrence() {
114 return startEventOccurrence
;
118 * Set the execution end event occurrence
120 * @return the end event occurrence to set
123 public int getEndOccurrence() {
124 return endEventOccurrence
;
128 * Set the execution start event occurrence
130 * @param occurrence the start event occurrence to set
132 public void setStartOccurrence(int occurrence
) {
133 startEventOccurrence
= occurrence
;
137 * Set the execution end event occurrence
139 * @param occurrence the end event occurrence to set
141 public void setEndOccurrence(int occurrence
) {
142 endEventOccurrence
= occurrence
;
146 public void draw(IGC context
) {
149 int width
= getWidth();
150 int height
= getHeight();
151 IColor tempFillColor
= null, tempStrokeColor
= null;
153 // The execution occurrence is selected
154 // if the owning lifeline is selected
155 if (lifeline
.isSelected() || isSelected()) {
156 context
.setBackground(Frame
.getUserPref().getBackGroundColorSelection());
157 context
.setForeground(Frame
.getUserPref().getForeGroundColorSelection());
159 tempFillColor
= setUnselectedFillColor(context
);
161 if (Frame
.getUserPref().useGradienColor())
162 context
.fillGradientRectangle(x
, y
, width
, height
, false);
164 context
.fillRectangle(x
, y
, width
, height
);
165 tempStrokeColor
= setUnselectedStrokeColor(context
);
166 context
.drawRectangle(x
, y
, width
, height
);
167 if (tempFillColor
!= null) {
168 tempFillColor
.dispose();
169 tempFillColor
= null;
171 if (tempStrokeColor
!= null) {
172 tempStrokeColor
.dispose();
173 tempStrokeColor
= null;
177 super.drawChildenNodes(context
);
181 * Rewrite this method in your extension in order to support customized fill colors
186 protected IColor
setUnselectedFillColor(IGC context
) {
187 if (Frame
.getUserPref().useGradienColor()) {
188 context
.setGradientColor(Frame
.getUserPref().getBackGroundColor(ISDPreferences
.PREF_EXEC
));
189 context
.setBackground(Frame
.getUserPref().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
191 context
.setBackground(Frame
.getUserPref().getBackGroundColor(ISDPreferences
.PREF_EXEC
));
196 * Rewrite this method in your extension in order to support customized stroke colors
201 protected IColor
setUnselectedStrokeColor(IGC context
) {
202 context
.setForeground(Frame
.getUserPref().getForeGroundColor(ISDPreferences
.PREF_EXEC
));
207 public String
getArrayId() {
212 public boolean positiveDistanceToPoint(int x
, int y
) {
213 if (getY() + getHeight() > y
)
219 public boolean isVisible(int x
, int y
, int width
, int height
) {
220 if ((getLifeline() != null) && (getLifeline().isVisible(x
, y
, width
, height
))) {
222 int lh
= getHeight();
223 if (ly
>= y
&& ly
< y
+ height
)
225 if (ly
+ lh
> y
&& ly
+ lh
<= y
+ height
)
227 if ((ly
< y
) && (ly
+ lh
> y
+ height
))