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