Contribution for Bug352466: [TMF] Implement UML2 Sequence Diagram
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / ExecutionOccurrence.java
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: ExecutionOccurrence.java,v 1.2 2006/09/20 20:56:25 ewchan Exp $
8 *
9 * Contributors:
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
14
15 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
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.drawings.IImage;
19 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences;
20
21 /**
22 * ExecutionOccurrence is the UML2 execution occurrence graphical representation. It is a BasicExecutionOccurrence on
23 * which you can customize fill and/or
24 *
25 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
26 * @author sveyrier
27 *
28 */
29 public class ExecutionOccurrence extends BasicExecutionOccurrence implements ITimeRange {
30
31 protected int[] fillRGB;
32 protected int[] strokeRGB;
33 protected IImage image, ellipsesImage;
34
35 protected TmfTimestamp startTime, endTime;
36 protected boolean hasTime;
37
38 /**
39 * Set the lifeline on which the execution occurrence appears.
40 *
41 * @param theLifeline - the parent lifeline
42 */
43 @Override
44 public void setLifeline(Lifeline theLifeline) {
45 super.setLifeline(theLifeline);
46 if (lifeline != null && hasTime) {
47 lifeline.hasTime = true;
48 if (lifeline.getFrame() != null) {
49 lifeline.getFrame().setHasTimeInfo(true);
50 }
51 }
52 }
53
54 /**
55 * Set the red, green and blue value of the optional color to be used for filling the execution occurrence
56 *
57 * @param _r
58 * @param _g
59 * @param _b
60 */
61 public void setFillColor(int _r, int _g, int _b) {
62 fillRGB = new int[3];
63 fillRGB[0] = _r;
64 fillRGB[1] = _g;
65 fillRGB[2] = _b;
66 }
67
68 /**
69 * Set the red, green and blue value of the optional color to be used for drawing the execution occurrence
70 *
71 * @param _r
72 * @param _g
73 * @param _b
74 */
75 public void setStrokeColor(int _r, int _g, int _b) {
76 strokeRGB = new int[3];
77 strokeRGB[0] = _r;
78 strokeRGB[1] = _g;
79 strokeRGB[2] = _b;
80 }
81
82 public void setImage(IImage image_) {
83 image = image_;
84 }
85
86 public void setTopEllipsesImage(IImage image_) {
87 ellipsesImage = image_;
88 }
89
90 /**
91 * Set the time when the execution occurrence starts.<br>
92 *
93 * @param time the time when the execution occurrence starts
94 */
95 public void setStartTime(TmfTimestamp time) {
96 startTime = time.clone();
97 hasTime = true;
98 if (lifeline != null) {
99 lifeline.setTimeInfo(true);
100 }
101 }
102
103 /**
104 * Set the time when the execution occurrence ends.<br>
105 *
106 * @param time the time when the execution occurrence ends
107 */
108 public void setEndTime(TmfTimestamp time) {
109 endTime = time.clone();
110 hasTime = true;
111 if (lifeline != null) {
112 lifeline.setTimeInfo(true);
113 }
114 }
115
116 /**
117 * Returns the time when the execution occurrence starts
118 *
119 * @return the time
120 */
121 @Override
122 public TmfTimestamp getStartTime() {
123 return startTime;
124 }
125
126 /**
127 * Returns the time when the execution occurrence ends
128 *
129 * @return the time
130 */
131 @Override
132 public TmfTimestamp getEndTime() {
133 return endTime;
134 }
135
136 @Override
137 public boolean hasTimeInfo() {
138 return hasTime;
139 }
140
141 @Override
142 public void draw(IGC context) {
143 super.draw(context);
144 int x = getX();
145 int y = getY();
146 int width = getWidth();
147 int height = getHeight();
148 if (image != null) {
149 context.drawImage(image, x + width - 4, y + height - 11, 8, 11);
150 }
151 if (ellipsesImage != null) {
152 context.drawImage(ellipsesImage, x + width, y, 40, 10);
153 }
154 }
155
156 /**
157 * Extension in order to support customized fill colors
158 *
159 * @param context
160 * @return IColor
161 */
162 @Override
163 protected IColor setUnselectedFillColor(IGC context) {
164 if (fillRGB != null) {
165 IColor tempFillColor = context.createColor(fillRGB[0], fillRGB[1], fillRGB[2]);
166 if (Frame.getUserPref().useGradienColor()) {
167 context.setGradientColor(tempFillColor);
168 context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_EXEC));
169 context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_FRAME));
170 } else
171 context.setBackground(tempFillColor);
172 return tempFillColor;
173 } else {
174 return super.setUnselectedFillColor(context);
175 }
176 }
177
178 /**
179 * Extension in order to support customized stroke colors
180 *
181 * @param context
182 * @return IColor
183 */
184 @Override
185 protected IColor setUnselectedStrokeColor(IGC context) {
186 if (strokeRGB != null) {
187 IColor tempStrokeColor = context.createColor(strokeRGB[0], strokeRGB[1], strokeRGB[2]);
188 context.setForeground(tempStrokeColor);
189 return tempStrokeColor;
190 } else {
191 return super.setUnselectedStrokeColor(context);
192 }
193 }
194 }
This page took 0.053016 seconds and 5 git commands to generate.