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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
;
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
;
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.tracecompass.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 private Lifeline fLifeline
= null;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 * Default constructore
54 public BasicExecutionOccurrence() {
55 setColorPrefId(ISDPreferences
.PREF_EXEC
);
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
64 if (fLifeline
== null) {
67 return fLifeline
.getX() + Metrics
.getLifelineWidth() / 2 - Metrics
.EXECUTION_OCCURRENCE_WIDTH
/ 2;
72 if (fLifeline
== null) {
75 return fLifeline
.getY() + fLifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * getStartOccurrence();
79 public int getWidth() {
80 if (fLifeline
== null) {
83 return Metrics
.EXECUTION_OCCURRENCE_WIDTH
;
87 public int getHeight() {
88 if (fLifeline
== null) {
91 return ((Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing())) * (getEndOccurrence() - getStartOccurrence());
95 public boolean contains(int xValue
, int yValue
) {
98 int width
= getWidth();
99 int height
= getHeight();
101 if (GraphNode
.contains(x
, y
, width
, height
, xValue
, yValue
)) {
105 if (getNodeAt(xValue
, yValue
) != null) {
112 public String
getName() {
113 if (super.getName() == null || super.getName().equals("")) { //$NON-NLS-1$
114 return fLifeline
.getToolTipText();
116 return super.getName();
120 * Set the lifeline on which the execution occurrence appears.
122 * @param theLifeline - the parent lifeline
124 public void setLifeline(Lifeline theLifeline
) {
125 fLifeline
= theLifeline
;
129 * Get the lifeline on which the execution occurrence appears.
131 * @return - the parent lifeline
133 public Lifeline
getLifeline() {
138 * Get the execution start event occurrence
140 * @return the start event occurrence to set
143 public int getStartOccurrence() {
144 return super.getStartOccurrence();
148 * Set the execution end event occurrence
150 * @return the end event occurrence to set
153 public int getEndOccurrence() {
154 return super.getEndOccurrence();
158 * Set the execution start event occurrence
160 * @param occurrence the start event occurrence to set
163 public void setStartOccurrence(int occurrence
) {
164 super.setStartOccurrence(occurrence
);
168 * Set the execution end event occurrence
170 * @param occurrence the end event occurrence to set
173 public void setEndOccurrence(int occurrence
) {
174 super.setEndOccurrence(occurrence
);
178 public void draw(IGC context
) {
181 int width
= getWidth();
182 int height
= getHeight();
183 IColor tempFillColor
= null;
184 IColor tempStrokeColor
= null;
186 ISDPreferences pref
= SDViewPref
.getInstance();
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());
194 tempFillColor
= setUnselectedFillColor(context
);
196 if (pref
.useGradienColor()) {
197 context
.fillGradientRectangle(x
, y
, width
, height
, false);
199 context
.fillRectangle(x
, y
, width
, height
);
201 tempStrokeColor
= setUnselectedStrokeColor(context
);
202 context
.drawRectangle(x
, y
, width
, height
);
203 if (tempFillColor
!= null) {
204 tempFillColor
.dispose();
206 if (tempStrokeColor
!= null) {
207 tempStrokeColor
.dispose();
212 super.drawChildenNodes(context
);
216 * Rewrite this method in your extension in order to support customized fill colors
218 * @param context Graphics context
221 protected IColor
setUnselectedFillColor(IGC context
) {
223 ISDPreferences pref
= SDViewPref
.getInstance();
225 if (pref
.useGradienColor()) {
226 context
.setGradientColor(pref
.getBackGroundColor(ISDPreferences
.PREF_EXEC
));
227 context
.setBackground(pref
.getBackGroundColor(ISDPreferences
.PREF_FRAME
));
229 context
.setBackground(pref
.getBackGroundColor(ISDPreferences
.PREF_EXEC
));
235 * Rewrite this method in your extension in order to support customized stroke colors
237 * @param context Graphics context
240 protected IColor
setUnselectedStrokeColor(IGC context
) {
241 context
.setForeground(SDViewPref
.getInstance().getForeGroundColor(ISDPreferences
.PREF_EXEC
));
246 public String
getArrayId() {
251 public boolean positiveDistanceToPoint(int x
, int y
) {
252 if (getY() + getHeight() > y
) {
259 public boolean isVisible(int x
, int y
, int width
, int height
) {
260 if ((getLifeline() != null) && (getLifeline().isVisible(x
, y
, width
, height
))) {
262 int lh
= getHeight();
263 if (ly
>= y
&& ly
< y
+ height
) {
266 if (ly
+ lh
> y
&& ly
+ lh
<= y
+ height
) {
269 if ((ly
< y
) && (ly
+ lh
> y
+ height
)) {