Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
c8422608 | 2 | * Copyright (c) 2005, 2013 IBM Corporation, Ericsson |
73005152 BH |
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 | |
abbdd66a AM |
7 | * |
8 | * Contributors: | |
c8422608 AM |
9 | * IBM - Initial API and implementation |
10 | * Bernd Hufmann - Updated for TMF | |
73005152 | 11 | **********************************************************************/ |
c8422608 | 12 | |
73005152 BH |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core; |
14 | ||
cab6c8ff BH |
15 | import java.util.Arrays; |
16 | ||
3bd46eef | 17 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
73005152 BH |
18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; |
19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
20 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage; | |
df0b8ff4 | 21 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
3145ec83 | 22 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; |
73005152 BH |
23 | |
24 | /** | |
25 | * ExecutionOccurrence is the UML2 execution occurrence graphical representation. It is a BasicExecutionOccurrence on | |
df0b8ff4 | 26 | * which you can customize fill and/or. |
abbdd66a | 27 | * |
73005152 | 28 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details |
abbdd66a | 29 | * @version 1.0 |
73005152 | 30 | * @author sveyrier |
abbdd66a | 31 | * |
73005152 BH |
32 | */ |
33 | public class ExecutionOccurrence extends BasicExecutionOccurrence implements ITimeRange { | |
34 | ||
df0b8ff4 BH |
35 | // ------------------------------------------------------------------------ |
36 | // Attributes | |
37 | // ------------------------------------------------------------------------ | |
11252342 | 38 | |
df0b8ff4 | 39 | /** |
abbdd66a | 40 | * Set the red, green and blue value of the optional color to be used for filling the execution occurrence. |
df0b8ff4 | 41 | */ |
cab6c8ff | 42 | private int[] fFillRGB; |
df0b8ff4 BH |
43 | /** |
44 | * Set the red, green and blue value of the optional color to be used for drawing the execution occurrence | |
45 | */ | |
cab6c8ff | 46 | private int[] fStrokeRGB; |
df0b8ff4 BH |
47 | /** |
48 | * The occurrence image. | |
49 | */ | |
cab6c8ff | 50 | private IImage fImage; |
df0b8ff4 BH |
51 | /** |
52 | * The top ellipses image. | |
53 | */ | |
cab6c8ff | 54 | private IImage fEllipsesImage; |
df0b8ff4 | 55 | /** |
abbdd66a | 56 | * The start time stamp. |
df0b8ff4 | 57 | */ |
cab6c8ff | 58 | private ITmfTimestamp fStartTime; |
df0b8ff4 BH |
59 | /** |
60 | * The end time stamp; | |
61 | */ | |
cab6c8ff | 62 | private ITmfTimestamp fEndTime; |
df0b8ff4 | 63 | /** |
abbdd66a | 64 | * Flag to indicate whether time information is available or not. |
df0b8ff4 | 65 | */ |
cab6c8ff | 66 | private boolean fHasTimeInfo; |
73005152 | 67 | |
df0b8ff4 BH |
68 | // ------------------------------------------------------------------------ |
69 | // Methods | |
70 | // ------------------------------------------------------------------------ | |
11252342 | 71 | |
73005152 BH |
72 | @Override |
73 | public void setLifeline(Lifeline theLifeline) { | |
74 | super.setLifeline(theLifeline); | |
cab6c8ff BH |
75 | if (getLifeline() != null && fHasTimeInfo) { |
76 | getLifeline().setTimeInfo(true); | |
77 | if (getLifeline().getFrame() != null) { | |
78 | getLifeline().getFrame().setHasTimeInfo(true); | |
73005152 BH |
79 | } |
80 | } | |
81 | } | |
82 | ||
83 | /** | |
df0b8ff4 | 84 | * Set the red, green and blue value of the optional color to be used for filling the execution occurrence. |
abbdd66a | 85 | * |
eb63f5ff BH |
86 | * @param red A value for red. |
87 | * @param green A green value for green. | |
88 | * @param blue A value blue. | |
89 | */ | |
90 | public void setFillColor(int red, int green, int blue) { | |
91 | fFillRGB = new int[3]; | |
92 | fFillRGB[0] = red; | |
93 | fFillRGB[1] = green; | |
94 | fFillRGB[2] = blue; | |
73005152 BH |
95 | } |
96 | ||
97 | /** | |
98 | * Set the red, green and blue value of the optional color to be used for drawing the execution occurrence | |
abbdd66a | 99 | * |
eb63f5ff BH |
100 | * @param red A value for red. |
101 | * @param green A green value for green. | |
102 | * @param blue A value blue. | |
103 | */ | |
104 | public void setStrokeColor(int red, int green, int blue) { | |
105 | fStrokeRGB = new int[3]; | |
106 | fStrokeRGB[0] = red; | |
107 | fStrokeRGB[1] = green; | |
108 | fStrokeRGB[2] = blue; | |
73005152 BH |
109 | } |
110 | ||
df0b8ff4 BH |
111 | /** |
112 | * Set the corresponding image. | |
abbdd66a | 113 | * |
eb63f5ff | 114 | * @param image A image to set. |
df0b8ff4 | 115 | */ |
eb63f5ff BH |
116 | public void setImage(IImage image) { |
117 | fImage = image; | |
73005152 BH |
118 | } |
119 | ||
df0b8ff4 BH |
120 | /** |
121 | * Set the top ellipses image. | |
abbdd66a | 122 | * |
eb63f5ff | 123 | * @param image A image to set. |
df0b8ff4 | 124 | */ |
eb63f5ff BH |
125 | public void setTopEllipsesImage(IImage image) { |
126 | fEllipsesImage = image; | |
73005152 BH |
127 | } |
128 | ||
129 | /** | |
df0b8ff4 | 130 | * Set the time when the execution occurrence starts. |
abbdd66a | 131 | * |
73005152 | 132 | * @param time the time when the execution occurrence starts |
3bd46eef | 133 | * @since 2.0 |
73005152 | 134 | */ |
d7dbf09a | 135 | public void setStartTime(ITmfTimestamp time) { |
4593bd5b | 136 | fStartTime = time; |
eb63f5ff | 137 | fHasTimeInfo = true; |
cab6c8ff BH |
138 | if (getLifeline() != null) { |
139 | getLifeline().setTimeInfo(true); | |
73005152 BH |
140 | } |
141 | } | |
142 | ||
143 | /** | |
df0b8ff4 | 144 | * Set the time when the execution occurrence ends. |
abbdd66a | 145 | * |
73005152 | 146 | * @param time the time when the execution occurrence ends |
3bd46eef | 147 | * @since 2.0 |
73005152 | 148 | */ |
d7dbf09a | 149 | public void setEndTime(ITmfTimestamp time) { |
4593bd5b | 150 | fEndTime = time; |
eb63f5ff | 151 | fHasTimeInfo = true; |
cab6c8ff BH |
152 | if (getLifeline() != null) { |
153 | getLifeline().setTimeInfo(true); | |
73005152 BH |
154 | } |
155 | } | |
156 | ||
3bd46eef AM |
157 | /** |
158 | * @since 2.0 | |
73005152 BH |
159 | */ |
160 | @Override | |
4df4581d | 161 | public ITmfTimestamp getStartTime() { |
eb63f5ff | 162 | return fStartTime; |
73005152 BH |
163 | } |
164 | ||
3bd46eef AM |
165 | /** |
166 | * @since 2.0 | |
73005152 BH |
167 | */ |
168 | @Override | |
4df4581d | 169 | public ITmfTimestamp getEndTime() { |
eb63f5ff | 170 | return fEndTime; |
73005152 BH |
171 | } |
172 | ||
173 | @Override | |
174 | public boolean hasTimeInfo() { | |
eb63f5ff | 175 | return fHasTimeInfo; |
73005152 BH |
176 | } |
177 | ||
cab6c8ff BH |
178 | /** |
179 | * @return the RGB of the occurrence filler. | |
180 | * @since 2.0 | |
181 | */ | |
182 | public int[] getFillRGB() { | |
183 | if (fFillRGB == null) { | |
184 | return null; | |
185 | } | |
186 | return Arrays.copyOf(fFillRGB, fFillRGB.length); | |
187 | } | |
188 | ||
189 | /** | |
190 | * @return the RGB of the occurrence filler. | |
191 | * @since 2.0 | |
192 | */ | |
193 | public int[] getStrokeRGB() { | |
194 | if (fStrokeRGB == null) { | |
195 | return null; | |
196 | } | |
197 | return Arrays.copyOf(fStrokeRGB, fStrokeRGB.length); | |
198 | } | |
199 | ||
200 | /** | |
201 | * @return the image. | |
202 | * @since 2.0 | |
203 | */ | |
204 | protected IImage getImage() { | |
205 | return fImage; | |
206 | } | |
207 | ||
208 | /** | |
209 | * @return the image. | |
210 | * @since 2.0 | |
211 | */ | |
212 | protected IImage getEllipsesImage() { | |
213 | return fEllipsesImage; | |
214 | } | |
215 | ||
73005152 BH |
216 | @Override |
217 | public void draw(IGC context) { | |
218 | super.draw(context); | |
219 | int x = getX(); | |
220 | int y = getY(); | |
221 | int width = getWidth(); | |
222 | int height = getHeight(); | |
eb63f5ff BH |
223 | if (fImage != null) { |
224 | context.drawImage(fImage, x + width - 4, y + height - 11, 8, 11); | |
73005152 | 225 | } |
eb63f5ff BH |
226 | if (fEllipsesImage != null) { |
227 | context.drawImage(fEllipsesImage, x + width, y, 40, 10); | |
73005152 BH |
228 | } |
229 | } | |
230 | ||
73005152 BH |
231 | @Override |
232 | protected IColor setUnselectedFillColor(IGC context) { | |
3145ec83 | 233 | ISDPreferences pref = SDViewPref.getInstance(); |
eb63f5ff BH |
234 | if (fFillRGB != null) { |
235 | IColor tempFillColor = context.createColor(fFillRGB[0], fFillRGB[1], fFillRGB[2]); | |
3145ec83 | 236 | if (pref.useGradienColor()) { |
73005152 | 237 | context.setGradientColor(tempFillColor); |
3145ec83 BH |
238 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_EXEC)); |
239 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME)); | |
df0b8ff4 | 240 | } else { |
73005152 | 241 | context.setBackground(tempFillColor); |
df0b8ff4 | 242 | } |
73005152 | 243 | return tempFillColor; |
73005152 | 244 | } |
abbdd66a | 245 | return super.setUnselectedFillColor(context); |
73005152 BH |
246 | } |
247 | ||
73005152 BH |
248 | @Override |
249 | protected IColor setUnselectedStrokeColor(IGC context) { | |
eb63f5ff BH |
250 | if (fStrokeRGB != null) { |
251 | IColor tempStrokeColor = context.createColor(fStrokeRGB[0], fStrokeRGB[1], fStrokeRGB[2]); | |
73005152 BH |
252 | context.setForeground(tempStrokeColor); |
253 | return tempStrokeColor; | |
73005152 | 254 | } |
abbdd66a | 255 | return super.setUnselectedStrokeColor(context); |
73005152 | 256 | } |
cab6c8ff BH |
257 | |
258 | /** | |
259 | * Sets the flag whether the frame has time info or not | |
260 | * @since 2.0 | |
261 | * @param hasTimeInfo | |
262 | * true if frame has time info else false | |
263 | */ | |
264 | public void setHasTimeInfo(boolean hasTimeInfo) { | |
265 | fHasTimeInfo = hasTimeInfo; | |
266 | } | |
73005152 | 267 | } |