Commit | Line | Data |
---|---|---|
73005152 BH |
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: BasicExecutionOccurrence.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.ui.views.uml2sd.drawings.IColor; | |
16 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences; | |
18 | ||
19 | /** | |
20 | * BasicExecutionOccurrence is the UML2 execution occurrence graphical representation. It is attached to one Lifeline, | |
21 | * the event occurrence "duration" along the lifeline is defined by two event occurrences | |
22 | * | |
23 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details | |
24 | * @author sveyrier | |
25 | * | |
26 | */ | |
27 | public class BasicExecutionOccurrence extends GraphNode { | |
28 | ||
29 | protected Lifeline lifeline = null; | |
30 | ||
31 | public static final String EXEC_OCC_TAG = "Execution_Occ"; //$NON-NLS-1$ | |
32 | ||
33 | public BasicExecutionOccurrence() { | |
34 | prefId = ISDPreferences.PREF_EXEC; | |
35 | } | |
36 | ||
37 | @Override | |
38 | public int getX() { | |
39 | if (lifeline == null) | |
40 | return 0; | |
41 | return lifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2; | |
42 | } | |
43 | ||
44 | @Override | |
45 | public int getY() { | |
46 | if (lifeline == null) | |
47 | return 0; | |
48 | return lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * startEventOccurrence; | |
49 | } | |
50 | ||
51 | @Override | |
52 | public int getWidth() { | |
53 | if (lifeline == null) | |
54 | return 0; | |
55 | return Metrics.EXECUTION_OCCURRENCE_WIDTH; | |
56 | } | |
57 | ||
58 | @Override | |
59 | public int getHeight() { | |
60 | if (lifeline == null) | |
61 | return 0; | |
62 | return ((Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing())) * (endEventOccurrence - startEventOccurrence); | |
63 | } | |
64 | ||
65 | @Override | |
66 | public boolean contains(int _x, int _y) { | |
67 | int x = getX(); | |
68 | int y = getY(); | |
69 | int width = getWidth(); | |
70 | int height = getHeight(); | |
71 | ||
72 | if (Frame.contains(x, y, width, height, _x, _y)) { | |
73 | return true; | |
74 | } | |
75 | ||
76 | if (getNodeAt(_x, _y) != null) | |
77 | return true; | |
78 | return false; | |
79 | } | |
80 | ||
81 | @Override | |
82 | public String getName() { | |
83 | if (super.getName() == null || super.getName().equals("")) //$NON-NLS-1$ | |
84 | return lifeline.getToolTipText(); | |
85 | else | |
86 | return super.getName(); | |
87 | } | |
88 | ||
89 | /** | |
90 | * Set the lifeline on which the execution occurrence appears. | |
91 | * | |
92 | * @param theLifeline - the parent lifeline | |
93 | */ | |
94 | public void setLifeline(Lifeline theLifeline) { | |
95 | lifeline = theLifeline; | |
96 | } | |
97 | ||
98 | /** | |
99 | * Get the lifeline on which the execution occurrence appears. | |
100 | * | |
101 | * @return - the parent lifeline | |
102 | */ | |
103 | public Lifeline getLifeline() { | |
104 | return lifeline; | |
105 | } | |
106 | ||
107 | /** | |
108 | * Get the execution start event occurrence | |
109 | * | |
110 | * @return the start event occurrence to set | |
111 | */ | |
112 | @Override | |
113 | public int getStartOccurrence() { | |
114 | return startEventOccurrence; | |
115 | } | |
116 | ||
117 | /** | |
118 | * Set the execution end event occurrence | |
119 | * | |
120 | * @return the end event occurrence to set | |
121 | */ | |
122 | @Override | |
123 | public int getEndOccurrence() { | |
124 | return endEventOccurrence; | |
125 | } | |
126 | ||
127 | /** | |
128 | * Set the execution start event occurrence | |
129 | * | |
130 | * @param occurrence the start event occurrence to set | |
131 | */ | |
132 | public void setStartOccurrence(int occurrence) { | |
133 | startEventOccurrence = occurrence; | |
134 | } | |
135 | ||
136 | /** | |
137 | * Set the execution end event occurrence | |
138 | * | |
139 | * @param occurrence the end event occurrence to set | |
140 | */ | |
141 | public void setEndOccurrence(int occurrence) { | |
142 | endEventOccurrence = occurrence; | |
143 | } | |
144 | ||
145 | @Override | |
146 | public void draw(IGC context) { | |
147 | int x = getX(); | |
148 | int y = getY(); | |
149 | int width = getWidth(); | |
150 | int height = getHeight(); | |
151 | IColor tempFillColor = null, tempStrokeColor = null; | |
152 | ||
153 | // The execution occurrence is selected | |
154 | // if the owning lifeline is selected | |
155 | if (lifeline.isSelected() || isSelected()) { | |
156 | context.setBackground(Frame.getUserPref().getBackGroundColorSelection()); | |
157 | context.setForeground(Frame.getUserPref().getForeGroundColorSelection()); | |
158 | } else { | |
159 | tempFillColor = setUnselectedFillColor(context); | |
160 | } | |
161 | if (Frame.getUserPref().useGradienColor()) | |
162 | context.fillGradientRectangle(x, y, width, height, false); | |
163 | else | |
164 | context.fillRectangle(x, y, width, height); | |
165 | tempStrokeColor = setUnselectedStrokeColor(context); | |
166 | context.drawRectangle(x, y, width, height); | |
167 | if (tempFillColor != null) { | |
168 | tempFillColor.dispose(); | |
169 | tempFillColor = null; | |
170 | } | |
171 | if (tempStrokeColor != null) { | |
172 | tempStrokeColor.dispose(); | |
173 | tempStrokeColor = null; | |
174 | } | |
175 | if (hasFocus()) | |
176 | drawFocus(context); | |
177 | super.drawChildenNodes(context); | |
178 | } | |
179 | ||
180 | /** | |
181 | * Rewrite this method in your extension in order to support customized fill colors | |
182 | * | |
183 | * @param context | |
184 | * @return IColor | |
185 | */ | |
186 | protected IColor setUnselectedFillColor(IGC context) { | |
187 | if (Frame.getUserPref().useGradienColor()) { | |
188 | context.setGradientColor(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_EXEC)); | |
189 | context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_FRAME)); | |
190 | } else | |
191 | context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_EXEC)); | |
192 | return null; | |
193 | } | |
194 | ||
195 | /** | |
196 | * Rewrite this method in your extension in order to support customized stroke colors | |
197 | * | |
198 | * @param context | |
199 | * @return IColor | |
200 | */ | |
201 | protected IColor setUnselectedStrokeColor(IGC context) { | |
202 | context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_EXEC)); | |
203 | return null; | |
204 | } | |
205 | ||
206 | @Override | |
207 | public String getArrayId() { | |
208 | return EXEC_OCC_TAG; | |
209 | } | |
210 | ||
211 | @Override | |
212 | public boolean positiveDistanceToPoint(int x, int y) { | |
213 | if (getY() + getHeight() > y) | |
214 | return true; | |
215 | return false; | |
216 | } | |
217 | ||
218 | @Override | |
219 | public boolean isVisible(int x, int y, int width, int height) { | |
220 | if ((getLifeline() != null) && (getLifeline().isVisible(x, y, width, height))) { | |
221 | int ly = getY(); | |
222 | int lh = getHeight(); | |
223 | if (ly >= y && ly < y + height) | |
224 | return true; | |
225 | if (ly + lh > y && ly + lh <= y + height) | |
226 | return true; | |
227 | if ((ly < y) && (ly + lh > y + height)) | |
228 | return true; | |
229 | } | |
230 | return false; | |
231 | } | |
232 | } |