1 /**********************************************************************
2 * Copyright (c) 2005, 2013 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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
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
.preferences
.ISDPreferences
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
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 (GraphNode
.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();
144 * Set the lifeline on which the execution occurrence appears.
146 * @param theLifeline - the parent lifeline
148 public void setLifeline(Lifeline theLifeline
) {
149 fLifeline
= theLifeline
;
153 * Get the lifeline on which the execution occurrence appears.
155 * @return - the parent lifeline
157 public Lifeline
getLifeline() {
162 * Get the execution start event occurrence
164 * @return the start event occurrence to set
167 public int getStartOccurrence() {
168 return fStartEventOccurrence
;
172 * Set the execution end event occurrence
174 * @return the end event occurrence to set
177 public int getEndOccurrence() {
178 return fEndEventOccurrence
;
182 * Set the execution start event occurrence
184 * @param occurrence the start event occurrence to set
186 public void setStartOccurrence(int occurrence
) {
187 fStartEventOccurrence
= occurrence
;
191 * Set the execution end event occurrence
193 * @param occurrence the end event occurrence to set
195 public void setEndOccurrence(int occurrence
) {
196 fEndEventOccurrence
= occurrence
;
201 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
204 public void draw(IGC context
) {
207 int width
= getWidth();
208 int height
= getHeight();
209 IColor tempFillColor
= null;
210 IColor tempStrokeColor
= null;
212 ISDPreferences pref
= SDViewPref
.getInstance();
214 // The execution occurrence is selected
215 // if the owning lifeline is selected
216 if (fLifeline
.isSelected() || isSelected()) {
217 context
.setBackground(pref
.getBackGroundColorSelection());
218 context
.setForeground(pref
.getForeGroundColorSelection());
220 tempFillColor
= setUnselectedFillColor(context
);
222 if (pref
.useGradienColor()) {
223 context
.fillGradientRectangle(x
, y
, width
, height
, false);
225 context
.fillRectangle(x
, y
, width
, height
);
227 tempStrokeColor
= setUnselectedStrokeColor(context
);
228 context
.drawRectangle(x
, y
, width
, height
);
229 if (tempFillColor
!= null) {
230 tempFillColor
.dispose();
232 if (tempStrokeColor
!= null) {
233 tempStrokeColor
.dispose();
238 super.drawChildenNodes(context
);
242 * Rewrite this method in your extension in order to support customized fill colors
244 * @param context Graphics context
247 protected IColor
setUnselectedFillColor(IGC context
) {
249 ISDPreferences pref
= SDViewPref
.getInstance();
251 if (pref
.useGradienColor()) {
252 context
.setGradientColor(pref
.getBackGroundColor(ISDPreferences
.PREF_EXEC
));
253 context
.setBackground(pref
.getBackGroundColor(ISDPreferences
.PREF_FRAME
));
255 context
.setBackground(pref
.getBackGroundColor(ISDPreferences
.PREF_EXEC
));
261 * Rewrite this method in your extension in order to support customized stroke colors
263 * @param context Graphics context
266 protected IColor
setUnselectedStrokeColor(IGC context
) {
267 context
.setForeground(SDViewPref
.getInstance().getForeGroundColor(ISDPreferences
.PREF_EXEC
));
273 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
276 public String
getArrayId() {
282 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
285 public boolean positiveDistanceToPoint(int x
, int y
) {
286 if (getY() + getHeight() > y
) {
294 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
297 public boolean isVisible(int x
, int y
, int width
, int height
) {
298 if ((getLifeline() != null) && (getLifeline().isVisible(x
, y
, width
, height
))) {
300 int lh
= getHeight();
301 if (ly
>= y
&& ly
< y
+ height
) {
304 if (ly
+ lh
> y
&& ly
+ lh
<= y
+ height
) {
307 if ((ly
< y
) && (ly
+ lh
> y
+ height
)) {