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