Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
c8422608 | 2 | * Copyright (c) 2005, 2012 IBM Corporation, Ericsson |
73005152 BH |
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 | |
abbdd66a AM |
7 | * |
8 | * Contributors: | |
c8422608 AM |
9 | * IBM - Initial API and implementation |
10 | * Bernd Hufmann - Updated for TMF | |
73005152 | 11 | **********************************************************************/ |
c8422608 | 12 | |
73005152 BH |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core; |
14 | ||
15 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
16 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage; | |
df0b8ff4 | 17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
3145ec83 | 18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; |
73005152 BH |
19 | |
20 | /** | |
df0b8ff4 | 21 | * Class to add a hot spot marker. |
abbdd66a | 22 | * |
df0b8ff4 | 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 | */ | |
eb63f5ff | 41 | protected BasicExecutionOccurrence fExecOcc = null; |
df0b8ff4 BH |
42 | /** |
43 | * The occurrence number. | |
44 | */ | |
eb63f5ff | 45 | protected int fOccurrence = 0; |
df0b8ff4 BH |
46 | /** |
47 | * The marker image to display. | |
48 | */ | |
eb63f5ff | 49 | protected IImage fImage = null; |
73005152 | 50 | |
df0b8ff4 BH |
51 | // ------------------------------------------------------------------------ |
52 | // Constructors | |
53 | // ------------------------------------------------------------------------ | |
abbdd66a | 54 | |
73005152 | 55 | /** |
df0b8ff4 | 56 | * Default constructor |
73005152 | 57 | */ |
73005152 | 58 | public HotSpot() { |
eb63f5ff | 59 | fPrefId = ISDPreferences.PREF_EXEC; |
73005152 BH |
60 | } |
61 | ||
df0b8ff4 BH |
62 | // ------------------------------------------------------------------------ |
63 | // Methods | |
64 | // ------------------------------------------------------------------------ | |
65 | ||
66 | /** | |
67 | * Set the marker image. | |
abbdd66a | 68 | * |
df0b8ff4 BH |
69 | * @param img A image to set |
70 | */ | |
73005152 | 71 | public void setImage(IImage img) { |
eb63f5ff | 72 | fImage = img; |
73005152 BH |
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() { | |
eb63f5ff BH |
81 | if (fExecOcc != null) { |
82 | return fExecOcc.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() { | |
eb63f5ff BH |
93 | if (fExecOcc != null){ |
94 | return fExecOcc.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() { | |
eb63f5ff BH |
105 | if (fExecOcc != null) { |
106 | return fExecOcc.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() { | |
eb63f5ff BH |
117 | if (fExecOcc != null) { |
118 | return fExecOcc.getWidth() + 10; | |
df0b8ff4 BH |
119 | } |
120 | return 0; | |
73005152 BH |
121 | } |
122 | ||
123 | /** | |
124 | * Set the lifeline on which the execution occurrence appears. | |
abbdd66a | 125 | * |
0d9a6d76 | 126 | * @param occ the parent lifeline |
73005152 BH |
127 | */ |
128 | public void setExecution(BasicExecutionOccurrence occ) { | |
eb63f5ff BH |
129 | fExecOcc = occ; |
130 | fExecOcc.addNode(this); | |
73005152 BH |
131 | } |
132 | ||
133 | /** | |
134 | * Get the lifeline on which the execution occurrence appears. | |
abbdd66a | 135 | * |
73005152 BH |
136 | * @return - the parent lifeline |
137 | */ | |
138 | public BasicExecutionOccurrence getExecOcc() { | |
eb63f5ff | 139 | return fExecOcc; |
73005152 BH |
140 | } |
141 | ||
df0b8ff4 | 142 | /** |
abbdd66a AM |
143 | * Returns the occurrence number. |
144 | * | |
df0b8ff4 BH |
145 | * @return the occurrence number. |
146 | */ | |
73005152 | 147 | public int getOccurrence() { |
eb63f5ff | 148 | return fOccurrence; |
73005152 BH |
149 | } |
150 | ||
df0b8ff4 BH |
151 | /** |
152 | * Set the occurrence number. | |
abbdd66a | 153 | * |
df0b8ff4 BH |
154 | * @param occ A number to set. |
155 | */ | |
73005152 | 156 | public void setOccurrence(int occ) { |
eb63f5ff | 157 | fOccurrence = occ; |
73005152 BH |
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 | ||
3145ec83 BH |
167 | ISDPreferences pref = SDViewPref.getInstance(); |
168 | ||
73005152 BH |
169 | // The execution occurrence is selected |
170 | // if the owning lifeline is selected | |
eb63f5ff | 171 | if (isSelected() || (fExecOcc != null && fExecOcc.isSelected()) || (fExecOcc != null && fExecOcc.getLifeline() != null && fExecOcc.getLifeline().isSelected())) { |
3145ec83 BH |
172 | context.setBackground(pref.getBackGroundColorSelection()); |
173 | context.setForeground(pref.getForeGroundColorSelection()); | |
73005152 | 174 | } else { |
3145ec83 BH |
175 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_EXEC)); |
176 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_EXEC)); | |
73005152 | 177 | } |
eb63f5ff | 178 | context.drawImage(fImage, getX(), getY(), getWidth(), getHeight()); |
73005152 BH |
179 | } |
180 | ||
df0b8ff4 BH |
181 | /* |
182 | * (non-Javadoc) | |
183 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId() | |
184 | */ | |
73005152 BH |
185 | @Override |
186 | public String getArrayId() { | |
187 | return GLYPH; | |
188 | } | |
189 | ||
df0b8ff4 BH |
190 | /* |
191 | * (non-Javadoc) | |
192 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int) | |
193 | */ | |
73005152 BH |
194 | @Override |
195 | public boolean isVisible(int x, int y, int width, int height) { | |
196 | return true; | |
197 | } | |
198 | ||
df0b8ff4 BH |
199 | /* |
200 | * (non-Javadoc) | |
201 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int) | |
202 | */ | |
73005152 | 203 | @Override |
eb63f5ff | 204 | public boolean contains(int xValue, int yValue) { |
73005152 BH |
205 | int x = getX(); |
206 | int y = getY(); | |
207 | int width = getWidth(); | |
208 | int height = getHeight(); | |
209 | ||
abbdd66a | 210 | if (GraphNode.contains(x, y, width, height, xValue, yValue)) { |
73005152 BH |
211 | return true; |
212 | } | |
213 | return false; | |
214 | } | |
215 | } |