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