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