Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2006 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
4 | * | |
73005152 BH |
5 | * All rights reserved. This program and the accompanying materials |
6 | * are made available under the terms of the Eclipse Public License v1.0 | |
7 | * which accompanies this distribution, and is available at | |
8 | * http://www.eclipse.org/legal/epl-v10.html | |
73005152 BH |
9 | * |
10 | * Contributors: | |
11 | * IBM - Initial API and implementation | |
12 | * Bernd Hufmann - Updated for TMF | |
13 | **********************************************************************/ | |
14 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core; | |
15 | ||
4df4581d | 16 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
73005152 BH |
17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; |
18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage; | |
df0b8ff4 | 20 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
73005152 BH |
21 | |
22 | /** | |
23 | * ExecutionOccurrence is the UML2 execution occurrence graphical representation. It is a BasicExecutionOccurrence on | |
df0b8ff4 | 24 | * which you can customize fill and/or. |
73005152 BH |
25 | * |
26 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details | |
df0b8ff4 | 27 | * @version 1.0 |
73005152 BH |
28 | * @author sveyrier |
29 | * | |
30 | */ | |
31 | public class ExecutionOccurrence extends BasicExecutionOccurrence implements ITimeRange { | |
32 | ||
df0b8ff4 BH |
33 | // ------------------------------------------------------------------------ |
34 | // Attributes | |
35 | // ------------------------------------------------------------------------ | |
36 | /** | |
37 | * Set the red, green and blue value of the optional color to be used for filling the execution occurrence. | |
38 | */ | |
eb63f5ff | 39 | protected int[] fFillRGB; |
df0b8ff4 BH |
40 | /** |
41 | * Set the red, green and blue value of the optional color to be used for drawing the execution occurrence | |
42 | */ | |
eb63f5ff | 43 | protected int[] fStrokeRGB; |
df0b8ff4 BH |
44 | /** |
45 | * The occurrence image. | |
46 | */ | |
eb63f5ff | 47 | protected IImage fImage; |
df0b8ff4 BH |
48 | /** |
49 | * The top ellipses image. | |
50 | */ | |
eb63f5ff | 51 | protected IImage fEllipsesImage; |
df0b8ff4 BH |
52 | /** |
53 | * The start time stamp. | |
54 | */ | |
eb63f5ff | 55 | protected ITmfTimestamp fStartTime; |
df0b8ff4 BH |
56 | /** |
57 | * The end time stamp; | |
58 | */ | |
eb63f5ff | 59 | protected ITmfTimestamp fEndTime; |
df0b8ff4 BH |
60 | /** |
61 | * Flag to indicate whether time information is available or not. | |
62 | */ | |
eb63f5ff | 63 | protected boolean fHasTimeInfo; |
73005152 | 64 | |
df0b8ff4 BH |
65 | // ------------------------------------------------------------------------ |
66 | // Methods | |
67 | // ------------------------------------------------------------------------ | |
68 | /* | |
69 | * (non-Javadoc) | |
70 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#setLifeline(org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline) | |
73005152 BH |
71 | */ |
72 | @Override | |
73 | public void setLifeline(Lifeline theLifeline) { | |
74 | super.setLifeline(theLifeline); | |
eb63f5ff BH |
75 | if (fLifeline != null && fHasTimeInfo) { |
76 | fLifeline.fHasTimeInfo = true; | |
77 | if (fLifeline.getFrame() != null) { | |
78 | fLifeline.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. |
73005152 | 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 | |
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. | |
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. | |
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. |
73005152 BH |
131 | * |
132 | * @param time the time when the execution occurrence starts | |
133 | */ | |
d7dbf09a | 134 | public void setStartTime(ITmfTimestamp time) { |
eb63f5ff BH |
135 | fStartTime = time.clone(); |
136 | fHasTimeInfo = true; | |
137 | if (fLifeline != null) { | |
138 | fLifeline.setTimeInfo(true); | |
73005152 BH |
139 | } |
140 | } | |
141 | ||
142 | /** | |
df0b8ff4 | 143 | * Set the time when the execution occurrence ends. |
73005152 BH |
144 | * |
145 | * @param time the time when the execution occurrence ends | |
146 | */ | |
d7dbf09a | 147 | public void setEndTime(ITmfTimestamp time) { |
eb63f5ff BH |
148 | fEndTime = time.clone(); |
149 | fHasTimeInfo = true; | |
150 | if (fLifeline != null) { | |
151 | fLifeline.setTimeInfo(true); | |
73005152 BH |
152 | } |
153 | } | |
154 | ||
df0b8ff4 BH |
155 | /* |
156 | * (non-Javadoc) | |
157 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#getStartTime() | |
73005152 BH |
158 | */ |
159 | @Override | |
4df4581d | 160 | public ITmfTimestamp getStartTime() { |
eb63f5ff | 161 | return fStartTime; |
73005152 BH |
162 | } |
163 | ||
df0b8ff4 BH |
164 | /* |
165 | * (non-Javadoc) | |
166 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#getEndTime() | |
73005152 BH |
167 | */ |
168 | @Override | |
4df4581d | 169 | public ITmfTimestamp getEndTime() { |
eb63f5ff | 170 | return fEndTime; |
73005152 BH |
171 | } |
172 | ||
df0b8ff4 BH |
173 | /* |
174 | * (non-Javadoc) | |
175 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#hasTimeInfo() | |
176 | */ | |
73005152 BH |
177 | @Override |
178 | public boolean hasTimeInfo() { | |
eb63f5ff | 179 | return fHasTimeInfo; |
73005152 BH |
180 | } |
181 | ||
df0b8ff4 BH |
182 | /* |
183 | * (non-Javadoc) | |
184 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) | |
185 | */ | |
73005152 BH |
186 | @Override |
187 | public void draw(IGC context) { | |
188 | super.draw(context); | |
189 | int x = getX(); | |
190 | int y = getY(); | |
191 | int width = getWidth(); | |
192 | int height = getHeight(); | |
eb63f5ff BH |
193 | if (fImage != null) { |
194 | context.drawImage(fImage, x + width - 4, y + height - 11, 8, 11); | |
73005152 | 195 | } |
eb63f5ff BH |
196 | if (fEllipsesImage != null) { |
197 | context.drawImage(fEllipsesImage, x + width, y, 40, 10); | |
73005152 BH |
198 | } |
199 | } | |
200 | ||
df0b8ff4 BH |
201 | /* |
202 | * (non-Javadoc) | |
203 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#setUnselectedFillColor(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) | |
73005152 BH |
204 | */ |
205 | @Override | |
206 | protected IColor setUnselectedFillColor(IGC context) { | |
eb63f5ff BH |
207 | if (fFillRGB != null) { |
208 | IColor tempFillColor = context.createColor(fFillRGB[0], fFillRGB[1], fFillRGB[2]); | |
73005152 BH |
209 | if (Frame.getUserPref().useGradienColor()) { |
210 | context.setGradientColor(tempFillColor); | |
211 | context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_EXEC)); | |
212 | context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_FRAME)); | |
df0b8ff4 | 213 | } else { |
73005152 | 214 | context.setBackground(tempFillColor); |
df0b8ff4 | 215 | } |
73005152 BH |
216 | return tempFillColor; |
217 | } else { | |
218 | return super.setUnselectedFillColor(context); | |
219 | } | |
220 | } | |
221 | ||
df0b8ff4 BH |
222 | /* |
223 | * (non-Javadoc) | |
224 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#setUnselectedStrokeColor(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) | |
73005152 BH |
225 | */ |
226 | @Override | |
227 | protected IColor setUnselectedStrokeColor(IGC context) { | |
eb63f5ff BH |
228 | if (fStrokeRGB != null) { |
229 | IColor tempStrokeColor = context.createColor(fStrokeRGB[0], fStrokeRGB[1], fStrokeRGB[2]); | |
73005152 BH |
230 | context.setForeground(tempStrokeColor); |
231 | return tempStrokeColor; | |
232 | } else { | |
233 | return super.setUnselectedStrokeColor(context); | |
234 | } | |
235 | } | |
236 | } |