ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / HotSpot.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2013 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 private BasicExecutionOccurrence fExecOcc = null;
42 /**
43 * The occurrence number.
44 */
45 private int fOccurrence = 0;
46 /**
47 * The marker image to display.
48 */
49 private IImage fImage = null;
50
51 // ------------------------------------------------------------------------
52 // Constructors
53 // ------------------------------------------------------------------------
54
55 /**
56 * Default constructor
57 */
58 public HotSpot() {
59 setColorPrefId(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 * Returns the marker image.
77 *
78 * @return the image
79 * @since 2.0
80 */
81 protected IImage getImage() {
82 return fImage;
83 }
84
85 @Override
86 public int getX() {
87 if (fExecOcc != null) {
88 return fExecOcc.getX() - 3;
89 }
90 return 0;
91 }
92
93 @Override
94 public int getY() {
95 if (fExecOcc != null){
96 return fExecOcc.getY();
97 }
98 return 0;
99 }
100
101 @Override
102 public int getWidth() {
103 if (fExecOcc != null) {
104 return fExecOcc.getWidth() + 7;
105 }
106 return 0;
107 }
108
109 @Override
110 public int getHeight() {
111 if (fExecOcc != null) {
112 return fExecOcc.getWidth() + 10;
113 }
114 return 0;
115 }
116
117 /**
118 * Set the lifeline on which the execution occurrence appears.
119 *
120 * @param occ the parent lifeline
121 */
122 public void setExecution(BasicExecutionOccurrence occ) {
123 fExecOcc = occ;
124 fExecOcc.addNode(this);
125 }
126
127 /**
128 * Get the lifeline on which the execution occurrence appears.
129 *
130 * @return - the parent lifeline
131 */
132 public BasicExecutionOccurrence getExecOcc() {
133 return fExecOcc;
134 }
135
136 /**
137 * Returns the occurrence number.
138 *
139 * @return the occurrence number.
140 */
141 public int getOccurrence() {
142 return fOccurrence;
143 }
144
145 /**
146 * Set the occurrence number.
147 *
148 * @param occ A number to set.
149 */
150 public void setOccurrence(int occ) {
151 fOccurrence = occ;
152 }
153
154 @Override
155 public void draw(IGC context) {
156
157 ISDPreferences pref = SDViewPref.getInstance();
158
159 // The execution occurrence is selected
160 // if the owning lifeline is selected
161 if (isSelected() || (fExecOcc != null && fExecOcc.isSelected()) || (fExecOcc != null && fExecOcc.getLifeline() != null && fExecOcc.getLifeline().isSelected())) {
162 context.setBackground(pref.getBackGroundColorSelection());
163 context.setForeground(pref.getForeGroundColorSelection());
164 } else {
165 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
166 context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_EXEC));
167 }
168 context.drawImage(fImage, getX(), getY(), getWidth(), getHeight());
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
182 public boolean contains(int xValue, int yValue) {
183 int x = getX();
184 int y = getY();
185 int width = getWidth();
186 int height = getHeight();
187
188 if (GraphNode.contains(x, y, width, height, xValue, yValue)) {
189 return true;
190 }
191 return false;
192 }
193 }
This page took 0.036286 seconds and 5 git commands to generate.