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 | ||
16 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage; | |
df0b8ff4 | 18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
73005152 BH |
19 | |
20 | /** | |
df0b8ff4 BH |
21 | * Class to add a hot spot marker. |
22 | * | |
23 | * @version 1.0 | |
73005152 BH |
24 | * @author sveyrier |
25 | */ | |
26 | public class HotSpot extends GraphNode { | |
df0b8ff4 BH |
27 | // ------------------------------------------------------------------------ |
28 | // Constants | |
29 | // ------------------------------------------------------------------------ | |
30 | /** | |
31 | * The grahNode ID constant | |
32 | */ | |
33 | public static final String GLYPH = "Glyph"; //$NON-NLS-1$ | |
73005152 | 34 | |
df0b8ff4 BH |
35 | // ------------------------------------------------------------------------ |
36 | // Attributes | |
37 | // ------------------------------------------------------------------------ | |
38 | /** | |
39 | * The execution occurrence the hot spot marker is for. | |
40 | */ | |
73005152 | 41 | protected BasicExecutionOccurrence execOcc = null; |
df0b8ff4 BH |
42 | /** |
43 | * The occurrence number. | |
44 | */ | |
73005152 | 45 | protected int occurrence = 0; |
df0b8ff4 BH |
46 | /** |
47 | * The marker image to display. | |
48 | */ | |
73005152 BH |
49 | protected IImage image = null; |
50 | ||
df0b8ff4 BH |
51 | // ------------------------------------------------------------------------ |
52 | // Constructors | |
53 | // ------------------------------------------------------------------------ | |
54 | ||
73005152 | 55 | /** |
df0b8ff4 | 56 | * Default constructor |
73005152 | 57 | */ |
73005152 BH |
58 | public HotSpot() { |
59 | prefId = ISDPreferences.PREF_EXEC; | |
60 | } | |
61 | ||
df0b8ff4 BH |
62 | // ------------------------------------------------------------------------ |
63 | // Methods | |
64 | // ------------------------------------------------------------------------ | |
65 | ||
66 | /** | |
67 | * Set the marker image. | |
68 | * | |
69 | * @param img A image to set | |
70 | */ | |
73005152 BH |
71 | public void setImage(IImage img) { |
72 | image = img; | |
73 | } | |
74 | ||
df0b8ff4 BH |
75 | /* |
76 | * (non-Javadoc) | |
77 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX() | |
78 | */ | |
73005152 BH |
79 | @Override |
80 | public int getX() { | |
df0b8ff4 | 81 | if (execOcc != null) { |
73005152 | 82 | return execOcc.getX() - 3; |
df0b8ff4 BH |
83 | } |
84 | return 0; | |
73005152 BH |
85 | } |
86 | ||
df0b8ff4 BH |
87 | /* |
88 | * (non-Javadoc) | |
89 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY() | |
90 | */ | |
73005152 BH |
91 | @Override |
92 | public int getY() { | |
df0b8ff4 | 93 | if (execOcc != null){ |
73005152 | 94 | return execOcc.getY(); |
df0b8ff4 BH |
95 | } |
96 | return 0; | |
73005152 BH |
97 | } |
98 | ||
df0b8ff4 BH |
99 | /* |
100 | * (non-Javadoc) | |
101 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth() | |
102 | */ | |
73005152 BH |
103 | @Override |
104 | public int getWidth() { | |
df0b8ff4 | 105 | if (execOcc != null) { |
73005152 | 106 | return execOcc.getWidth() + 7; |
df0b8ff4 BH |
107 | } |
108 | return 0; | |
73005152 BH |
109 | } |
110 | ||
df0b8ff4 BH |
111 | /* |
112 | * (non-Javadoc) | |
113 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight() | |
114 | */ | |
73005152 BH |
115 | @Override |
116 | public int getHeight() { | |
df0b8ff4 | 117 | if (execOcc != null) { |
73005152 | 118 | return execOcc.getWidth() + 10; |
df0b8ff4 BH |
119 | } |
120 | return 0; | |
73005152 BH |
121 | } |
122 | ||
123 | /** | |
124 | * Set the lifeline on which the execution occurrence appears. | |
125 | * | |
0d9a6d76 | 126 | * @param occ the parent lifeline |
73005152 BH |
127 | */ |
128 | public void setExecution(BasicExecutionOccurrence occ) { | |
129 | execOcc = occ; | |
130 | execOcc.addNode(this); | |
131 | } | |
132 | ||
133 | /** | |
134 | * Get the lifeline on which the execution occurrence appears. | |
135 | * | |
136 | * @return - the parent lifeline | |
137 | */ | |
138 | public BasicExecutionOccurrence getExecOcc() { | |
139 | return execOcc; | |
140 | } | |
141 | ||
df0b8ff4 BH |
142 | /** |
143 | * Returns the occurrence number. | |
144 | * | |
145 | * @return the occurrence number. | |
146 | */ | |
73005152 BH |
147 | public int getOccurrence() { |
148 | return occurrence; | |
149 | } | |
150 | ||
df0b8ff4 BH |
151 | /** |
152 | * Set the occurrence number. | |
153 | * | |
154 | * @param occ A number to set. | |
155 | */ | |
73005152 BH |
156 | public void setOccurrence(int occ) { |
157 | occurrence = occ; | |
158 | } | |
159 | ||
df0b8ff4 BH |
160 | /* |
161 | * (non-Javadoc) | |
162 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) | |
163 | */ | |
73005152 BH |
164 | @Override |
165 | public void draw(IGC context) { | |
166 | ||
167 | // The execution occurrence is selected | |
168 | // if the owning lifeline is selected | |
169 | if (isSelected() || (execOcc != null && execOcc.isSelected()) || (execOcc != null && execOcc.getLifeline() != null && execOcc.getLifeline().isSelected())) { | |
170 | context.setBackground(Frame.getUserPref().getBackGroundColorSelection()); | |
171 | context.setForeground(Frame.getUserPref().getForeGroundColorSelection()); | |
172 | } else { | |
173 | context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_EXEC)); | |
174 | context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_EXEC)); | |
175 | } | |
176 | context.drawImage(image, getX(), getY(), getWidth(), getHeight()); | |
177 | } | |
178 | ||
df0b8ff4 BH |
179 | /* |
180 | * (non-Javadoc) | |
181 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId() | |
182 | */ | |
73005152 BH |
183 | @Override |
184 | public String getArrayId() { | |
185 | return GLYPH; | |
186 | } | |
187 | ||
df0b8ff4 BH |
188 | /* |
189 | * (non-Javadoc) | |
190 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int) | |
191 | */ | |
73005152 BH |
192 | @Override |
193 | public boolean isVisible(int x, int y, int width, int height) { | |
194 | return true; | |
195 | } | |
196 | ||
df0b8ff4 BH |
197 | /* |
198 | * (non-Javadoc) | |
199 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int) | |
200 | */ | |
73005152 BH |
201 | @Override |
202 | public boolean contains(int _x, int _y) { | |
203 | int x = getX(); | |
204 | int y = getY(); | |
205 | int width = getWidth(); | |
206 | int height = getHeight(); | |
207 | ||
208 | if (Frame.contains(x, y, width, height, _x, _y)) { | |
209 | return true; | |
210 | } | |
211 | return false; | |
212 | } | |
213 | } |