f41b5e9d73f014fa82de1c6a2eab99fc209dc1f5
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / uml2sd / core / HotSpot.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2014 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.tracecompass.tmf.ui.views.uml2sd.core;
14
15 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.drawings.IGC;
16 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.drawings.IImage;
17 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.preferences.ISDPreferences;
18 import org.eclipse.tracecompass.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 */
80 protected IImage getImage() {
81 return fImage;
82 }
83
84 @Override
85 public int getX() {
86 if (fExecOcc != null) {
87 return fExecOcc.getX() - 3;
88 }
89 return 0;
90 }
91
92 @Override
93 public int getY() {
94 if (fExecOcc != null){
95 return fExecOcc.getY();
96 }
97 return 0;
98 }
99
100 @Override
101 public int getWidth() {
102 if (fExecOcc != null) {
103 return fExecOcc.getWidth() + 7;
104 }
105 return 0;
106 }
107
108 @Override
109 public int getHeight() {
110 if (fExecOcc != null) {
111 return fExecOcc.getWidth() + 10;
112 }
113 return 0;
114 }
115
116 /**
117 * Set the lifeline on which the execution occurrence appears.
118 *
119 * @param occ the parent lifeline
120 */
121 public void setExecution(BasicExecutionOccurrence occ) {
122 fExecOcc = occ;
123 fExecOcc.addNode(this);
124 }
125
126 /**
127 * Get the lifeline on which the execution occurrence appears.
128 *
129 * @return - the parent lifeline
130 */
131 public BasicExecutionOccurrence getExecOcc() {
132 return fExecOcc;
133 }
134
135 /**
136 * Returns the occurrence number.
137 *
138 * @return the occurrence number.
139 */
140 public int getOccurrence() {
141 return fOccurrence;
142 }
143
144 /**
145 * Set the occurrence number.
146 *
147 * @param occ A number to set.
148 */
149 public void setOccurrence(int occ) {
150 fOccurrence = occ;
151 }
152
153 @Override
154 public void draw(IGC context) {
155
156 ISDPreferences pref = SDViewPref.getInstance();
157
158 // The execution occurrence is selected
159 // if the owning lifeline is selected
160 if (isSelected() || (fExecOcc != null && fExecOcc.isSelected()) || (fExecOcc != null && fExecOcc.getLifeline() != null && fExecOcc.getLifeline().isSelected())) {
161 context.setBackground(pref.getBackGroundColorSelection());
162 context.setForeground(pref.getForeGroundColorSelection());
163 } else {
164 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
165 context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_EXEC));
166 }
167 context.drawImage(fImage, getX(), getY(), getWidth(), getHeight());
168 }
169
170 @Override
171 public String getArrayId() {
172 return GLYPH;
173 }
174
175 @Override
176 public boolean isVisible(int x, int y, int width, int height) {
177 return true;
178 }
179
180 @Override
181 public boolean contains(int xValue, int yValue) {
182 int x = getX();
183 int y = getY();
184 int width = getWidth();
185 int height = getHeight();
186
187 if (GraphNode.contains(x, y, width, height, xValue, yValue)) {
188 return true;
189 }
190 return false;
191 }
192 }
This page took 0.052028 seconds and 4 git commands to generate.