Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
11252342 | 2 | * Copyright (c) 2005, 2013 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 | */ | |
cab6c8ff | 41 | private BasicExecutionOccurrence fExecOcc = null; |
df0b8ff4 BH |
42 | /** |
43 | * The occurrence number. | |
44 | */ | |
cab6c8ff | 45 | private int fOccurrence = 0; |
df0b8ff4 BH |
46 | /** |
47 | * The marker image to display. | |
48 | */ | |
cab6c8ff | 49 | private 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() { |
cab6c8ff | 59 | setColorPrefId(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 | ||
cab6c8ff BH |
75 | /** |
76 | * Returns the marker image. | |
77 | * | |
78 | * @return the image | |
79 | * @since 2.0 | |
80 | */ | |
81 | protected IImage getImage() { | |
82 | return fImage; | |
83 | } | |
84 | ||
73005152 BH |
85 | @Override |
86 | public int getX() { | |
eb63f5ff BH |
87 | if (fExecOcc != null) { |
88 | return fExecOcc.getX() - 3; | |
df0b8ff4 BH |
89 | } |
90 | return 0; | |
73005152 BH |
91 | } |
92 | ||
93 | @Override | |
94 | public int getY() { | |
eb63f5ff BH |
95 | if (fExecOcc != null){ |
96 | return fExecOcc.getY(); | |
df0b8ff4 BH |
97 | } |
98 | return 0; | |
73005152 BH |
99 | } |
100 | ||
101 | @Override | |
102 | public int getWidth() { | |
eb63f5ff BH |
103 | if (fExecOcc != null) { |
104 | return fExecOcc.getWidth() + 7; | |
df0b8ff4 BH |
105 | } |
106 | return 0; | |
73005152 BH |
107 | } |
108 | ||
109 | @Override | |
110 | public int getHeight() { | |
eb63f5ff BH |
111 | if (fExecOcc != null) { |
112 | return fExecOcc.getWidth() + 10; | |
df0b8ff4 BH |
113 | } |
114 | return 0; | |
73005152 BH |
115 | } |
116 | ||
117 | /** | |
118 | * Set the lifeline on which the execution occurrence appears. | |
abbdd66a | 119 | * |
0d9a6d76 | 120 | * @param occ the parent lifeline |
73005152 BH |
121 | */ |
122 | public void setExecution(BasicExecutionOccurrence occ) { | |
eb63f5ff BH |
123 | fExecOcc = occ; |
124 | fExecOcc.addNode(this); | |
73005152 BH |
125 | } |
126 | ||
127 | /** | |
128 | * Get the lifeline on which the execution occurrence appears. | |
abbdd66a | 129 | * |
73005152 BH |
130 | * @return - the parent lifeline |
131 | */ | |
132 | public BasicExecutionOccurrence getExecOcc() { | |
eb63f5ff | 133 | return fExecOcc; |
73005152 BH |
134 | } |
135 | ||
df0b8ff4 | 136 | /** |
abbdd66a AM |
137 | * Returns the occurrence number. |
138 | * | |
df0b8ff4 BH |
139 | * @return the occurrence number. |
140 | */ | |
73005152 | 141 | public int getOccurrence() { |
eb63f5ff | 142 | return fOccurrence; |
73005152 BH |
143 | } |
144 | ||
df0b8ff4 BH |
145 | /** |
146 | * Set the occurrence number. | |
abbdd66a | 147 | * |
df0b8ff4 BH |
148 | * @param occ A number to set. |
149 | */ | |
73005152 | 150 | public void setOccurrence(int occ) { |
eb63f5ff | 151 | fOccurrence = occ; |
73005152 BH |
152 | } |
153 | ||
154 | @Override | |
155 | public void draw(IGC context) { | |
156 | ||
3145ec83 BH |
157 | ISDPreferences pref = SDViewPref.getInstance(); |
158 | ||
73005152 BH |
159 | // The execution occurrence is selected |
160 | // if the owning lifeline is selected | |
eb63f5ff | 161 | if (isSelected() || (fExecOcc != null && fExecOcc.isSelected()) || (fExecOcc != null && fExecOcc.getLifeline() != null && fExecOcc.getLifeline().isSelected())) { |
3145ec83 BH |
162 | context.setBackground(pref.getBackGroundColorSelection()); |
163 | context.setForeground(pref.getForeGroundColorSelection()); | |
73005152 | 164 | } else { |
3145ec83 BH |
165 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_EXEC)); |
166 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_EXEC)); | |
73005152 | 167 | } |
eb63f5ff | 168 | context.drawImage(fImage, getX(), getY(), getWidth(), getHeight()); |
73005152 BH |
169 | } |
170 | ||
171 | @Override | |
172 | public String getArrayId() { | |
173 | return GLYPH; | |
174 | } | |
175 | ||
176 | @Override | |
177 | public boolean isVisible(int x, int y, int width, int height) { | |
178 | return true; | |
179 | } | |
180 | ||
181 | @Override | |
eb63f5ff | 182 | public boolean contains(int xValue, int yValue) { |
73005152 BH |
183 | int x = getX(); |
184 | int y = getY(); | |
185 | int width = getWidth(); | |
186 | int height = getHeight(); | |
187 | ||
abbdd66a | 188 | if (GraphNode.contains(x, y, width, height, xValue, yValue)) { |
73005152 BH |
189 | return true; |
190 | } | |
191 | return false; | |
192 | } | |
193 | } |