tmf: Move timestamps to their own package
[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 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
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
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
16 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
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;
20 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
21 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
22
23 /**
24 * ExecutionOccurrence is the UML2 execution occurrence graphical representation. It is a BasicExecutionOccurrence on
25 * which you can customize fill and/or.
26 *
27 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
28 * @version 1.0
29 * @author sveyrier
30 *
31 */
32 public class ExecutionOccurrence extends BasicExecutionOccurrence implements ITimeRange {
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37 /**
38 * Set the red, green and blue value of the optional color to be used for filling the execution occurrence.
39 */
40 protected int[] fFillRGB;
41 /**
42 * Set the red, green and blue value of the optional color to be used for drawing the execution occurrence
43 */
44 protected int[] fStrokeRGB;
45 /**
46 * The occurrence image.
47 */
48 protected IImage fImage;
49 /**
50 * The top ellipses image.
51 */
52 protected IImage fEllipsesImage;
53 /**
54 * The start time stamp.
55 */
56 protected ITmfTimestamp fStartTime;
57 /**
58 * The end time stamp;
59 */
60 protected ITmfTimestamp fEndTime;
61 /**
62 * Flag to indicate whether time information is available or not.
63 */
64 protected boolean fHasTimeInfo;
65
66 // ------------------------------------------------------------------------
67 // Methods
68 // ------------------------------------------------------------------------
69 /*
70 * (non-Javadoc)
71 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#setLifeline(org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline)
72 */
73 @Override
74 public void setLifeline(Lifeline theLifeline) {
75 super.setLifeline(theLifeline);
76 if (fLifeline != null && fHasTimeInfo) {
77 fLifeline.fHasTimeInfo = true;
78 if (fLifeline.getFrame() != null) {
79 fLifeline.getFrame().setHasTimeInfo(true);
80 }
81 }
82 }
83
84 /**
85 * Set the red, green and blue value of the optional color to be used for filling the execution occurrence.
86 *
87 * @param red A value for red.
88 * @param green A green value for green.
89 * @param blue A value blue.
90 */
91 public void setFillColor(int red, int green, int blue) {
92 fFillRGB = new int[3];
93 fFillRGB[0] = red;
94 fFillRGB[1] = green;
95 fFillRGB[2] = blue;
96 }
97
98 /**
99 * Set the red, green and blue value of the optional color to be used for drawing the execution occurrence
100 *
101 * @param red A value for red.
102 * @param green A green value for green.
103 * @param blue A value blue.
104 */
105 public void setStrokeColor(int red, int green, int blue) {
106 fStrokeRGB = new int[3];
107 fStrokeRGB[0] = red;
108 fStrokeRGB[1] = green;
109 fStrokeRGB[2] = blue;
110 }
111
112 /**
113 * Set the corresponding image.
114 *
115 * @param image A image to set.
116 */
117 public void setImage(IImage image) {
118 fImage = image;
119 }
120
121 /**
122 * Set the top ellipses image.
123 *
124 * @param image A image to set.
125 */
126 public void setTopEllipsesImage(IImage image) {
127 fEllipsesImage = image;
128 }
129
130 /**
131 * Set the time when the execution occurrence starts.
132 *
133 * @param time the time when the execution occurrence starts
134 * @since 2.0
135 */
136 public void setStartTime(ITmfTimestamp time) {
137 fStartTime = time;
138 fHasTimeInfo = true;
139 if (fLifeline != null) {
140 fLifeline.setTimeInfo(true);
141 }
142 }
143
144 /**
145 * Set the time when the execution occurrence ends.
146 *
147 * @param time the time when the execution occurrence ends
148 * @since 2.0
149 */
150 public void setEndTime(ITmfTimestamp time) {
151 fEndTime = time;
152 fHasTimeInfo = true;
153 if (fLifeline != null) {
154 fLifeline.setTimeInfo(true);
155 }
156 }
157
158 /**
159 * @since 2.0
160 */
161 @Override
162 public ITmfTimestamp getStartTime() {
163 return fStartTime;
164 }
165
166 /**
167 * @since 2.0
168 */
169 @Override
170 public ITmfTimestamp getEndTime() {
171 return fEndTime;
172 }
173
174 /*
175 * (non-Javadoc)
176 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#hasTimeInfo()
177 */
178 @Override
179 public boolean hasTimeInfo() {
180 return fHasTimeInfo;
181 }
182
183 /*
184 * (non-Javadoc)
185 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
186 */
187 @Override
188 public void draw(IGC context) {
189 super.draw(context);
190 int x = getX();
191 int y = getY();
192 int width = getWidth();
193 int height = getHeight();
194 if (fImage != null) {
195 context.drawImage(fImage, x + width - 4, y + height - 11, 8, 11);
196 }
197 if (fEllipsesImage != null) {
198 context.drawImage(fEllipsesImage, x + width, y, 40, 10);
199 }
200 }
201
202 /*
203 * (non-Javadoc)
204 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#setUnselectedFillColor(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
205 */
206 @Override
207 protected IColor setUnselectedFillColor(IGC context) {
208 ISDPreferences pref = SDViewPref.getInstance();
209 if (fFillRGB != null) {
210 IColor tempFillColor = context.createColor(fFillRGB[0], fFillRGB[1], fFillRGB[2]);
211 if (pref.useGradienColor()) {
212 context.setGradientColor(tempFillColor);
213 context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_EXEC));
214 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME));
215 } else {
216 context.setBackground(tempFillColor);
217 }
218 return tempFillColor;
219 }
220 return super.setUnselectedFillColor(context);
221 }
222
223 /*
224 * (non-Javadoc)
225 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#setUnselectedStrokeColor(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
226 */
227 @Override
228 protected IColor setUnselectedStrokeColor(IGC context) {
229 if (fStrokeRGB != null) {
230 IColor tempStrokeColor = context.createColor(fStrokeRGB[0], fStrokeRGB[1], fStrokeRGB[2]);
231 context.setForeground(tempStrokeColor);
232 return tempStrokeColor;
233 }
234 return super.setUnselectedStrokeColor(context);
235 }
236 }
This page took 0.050926 seconds and 5 git commands to generate.