lttng ui: Fix minor sonar warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / BasicExecutionOccurrence.java
CommitLineData
73005152 1/**********************************************************************
c8422608 2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
73005152
BH
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
abbdd66a
AM
7 *
8 * Contributors:
c8422608
AM
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
73005152 11 **********************************************************************/
c8422608 12
73005152
BH
13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
14
15import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor;
16import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
df0b8ff4 17import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
3145ec83 18import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
73005152
BH
19
20/**
21 * BasicExecutionOccurrence is the UML2 execution occurrence graphical representation. It is attached to one Lifeline,
22 * the event occurrence "duration" along the lifeline is defined by two event occurrences
abbdd66a 23 *
73005152 24 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
abbdd66a 25 * @version 1.0
73005152 26 * @author sveyrier
abbdd66a 27 *
73005152
BH
28 */
29public class BasicExecutionOccurrence extends GraphNode {
30
df0b8ff4
BH
31 // ------------------------------------------------------------------------
32 // Constants
33 // ------------------------------------------------------------------------
34 /**
35 * The grahNode ID constant
36 */
73005152
BH
37 public static final String EXEC_OCC_TAG = "Execution_Occ"; //$NON-NLS-1$
38
df0b8ff4
BH
39 // ------------------------------------------------------------------------
40 // Attributes
41 // ------------------------------------------------------------------------
42
43 /**
abbdd66a 44 * The corresponding lifeline.
df0b8ff4 45 */
eb63f5ff 46 protected Lifeline fLifeline = null;
df0b8ff4
BH
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51 /**
52 * Default constructore
53 */
73005152 54 public BasicExecutionOccurrence() {
eb63f5ff 55 fPrefId = ISDPreferences.PREF_EXEC;
73005152
BH
56 }
57
df0b8ff4
BH
58 // ------------------------------------------------------------------------
59 // Constants
60 // ------------------------------------------------------------------------
61
73005152
BH
62 @Override
63 public int getX() {
eb63f5ff 64 if (fLifeline == null) {
73005152 65 return 0;
df0b8ff4 66 }
eb63f5ff 67 return fLifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2;
73005152
BH
68 }
69
70 @Override
71 public int getY() {
eb63f5ff 72 if (fLifeline == null) {
73005152 73 return 0;
df0b8ff4 74 }
eb63f5ff 75 return fLifeline.getY() + fLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fStartEventOccurrence;
73005152
BH
76 }
77
78 @Override
79 public int getWidth() {
eb63f5ff 80 if (fLifeline == null) {
73005152 81 return 0;
df0b8ff4 82 }
73005152
BH
83 return Metrics.EXECUTION_OCCURRENCE_WIDTH;
84 }
85
86 @Override
87 public int getHeight() {
eb63f5ff 88 if (fLifeline == null) {
73005152 89 return 0;
df0b8ff4 90 }
eb63f5ff 91 return ((Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing())) * (fEndEventOccurrence - fStartEventOccurrence);
73005152
BH
92 }
93
94 @Override
eb63f5ff 95 public boolean contains(int xValue, int yValue) {
73005152
BH
96 int x = getX();
97 int y = getY();
98 int width = getWidth();
99 int height = getHeight();
100
abbdd66a 101 if (GraphNode.contains(x, y, width, height, xValue, yValue)) {
73005152
BH
102 return true;
103 }
104
eb63f5ff 105 if (getNodeAt(xValue, yValue) != null) {
73005152 106 return true;
df0b8ff4 107 }
73005152
BH
108 return false;
109 }
110
111 @Override
112 public String getName() {
df0b8ff4 113 if (super.getName() == null || super.getName().equals("")) { //$NON-NLS-1$
eb63f5ff 114 return fLifeline.getToolTipText();
df0b8ff4 115 }
abbdd66a 116 return super.getName();
73005152
BH
117 }
118
119 /**
120 * Set the lifeline on which the execution occurrence appears.
abbdd66a 121 *
73005152
BH
122 * @param theLifeline - the parent lifeline
123 */
124 public void setLifeline(Lifeline theLifeline) {
eb63f5ff 125 fLifeline = theLifeline;
73005152
BH
126 }
127
128 /**
129 * Get the lifeline on which the execution occurrence appears.
abbdd66a 130 *
73005152
BH
131 * @return - the parent lifeline
132 */
133 public Lifeline getLifeline() {
eb63f5ff 134 return fLifeline;
73005152
BH
135 }
136
137 /**
138 * Get the execution start event occurrence
abbdd66a 139 *
73005152
BH
140 * @return the start event occurrence to set
141 */
142 @Override
143 public int getStartOccurrence() {
eb63f5ff 144 return fStartEventOccurrence;
73005152
BH
145 }
146
147 /**
148 * Set the execution end event occurrence
abbdd66a 149 *
73005152
BH
150 * @return the end event occurrence to set
151 */
152 @Override
153 public int getEndOccurrence() {
eb63f5ff 154 return fEndEventOccurrence;
73005152
BH
155 }
156
157 /**
158 * Set the execution start event occurrence
abbdd66a 159 *
73005152
BH
160 * @param occurrence the start event occurrence to set
161 */
162 public void setStartOccurrence(int occurrence) {
eb63f5ff 163 fStartEventOccurrence = occurrence;
73005152
BH
164 }
165
166 /**
167 * Set the execution end event occurrence
abbdd66a 168 *
73005152
BH
169 * @param occurrence the end event occurrence to set
170 */
171 public void setEndOccurrence(int occurrence) {
eb63f5ff 172 fEndEventOccurrence = occurrence;
73005152
BH
173 }
174
175 @Override
176 public void draw(IGC context) {
177 int x = getX();
178 int y = getY();
179 int width = getWidth();
180 int height = getHeight();
eb63f5ff
BH
181 IColor tempFillColor = null;
182 IColor tempStrokeColor = null;
73005152 183
3145ec83 184 ISDPreferences pref = SDViewPref.getInstance();
abbdd66a 185
73005152
BH
186 // The execution occurrence is selected
187 // if the owning lifeline is selected
eb63f5ff 188 if (fLifeline.isSelected() || isSelected()) {
3145ec83
BH
189 context.setBackground(pref.getBackGroundColorSelection());
190 context.setForeground(pref.getForeGroundColorSelection());
73005152
BH
191 } else {
192 tempFillColor = setUnselectedFillColor(context);
193 }
3145ec83 194 if (pref.useGradienColor()) {
73005152 195 context.fillGradientRectangle(x, y, width, height, false);
df0b8ff4 196 } else {
73005152 197 context.fillRectangle(x, y, width, height);
df0b8ff4 198 }
73005152
BH
199 tempStrokeColor = setUnselectedStrokeColor(context);
200 context.drawRectangle(x, y, width, height);
201 if (tempFillColor != null) {
202 tempFillColor.dispose();
73005152
BH
203 }
204 if (tempStrokeColor != null) {
205 tempStrokeColor.dispose();
73005152 206 }
df0b8ff4 207 if (hasFocus()) {
73005152 208 drawFocus(context);
df0b8ff4 209 }
73005152
BH
210 super.drawChildenNodes(context);
211 }
212
213 /**
214 * Rewrite this method in your extension in order to support customized fill colors
abbdd66a 215 *
a0a88f65 216 * @param context Graphics context
73005152
BH
217 * @return IColor
218 */
219 protected IColor setUnselectedFillColor(IGC context) {
3145ec83
BH
220
221 ISDPreferences pref = SDViewPref.getInstance();
222
223 if (pref.useGradienColor()) {
224 context.setGradientColor(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
225 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME));
df0b8ff4 226 } else {
3145ec83 227 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
df0b8ff4 228 }
73005152
BH
229 return null;
230 }
231
232 /**
233 * Rewrite this method in your extension in order to support customized stroke colors
abbdd66a 234 *
a0a88f65 235 * @param context Graphics context
73005152
BH
236 * @return IColor
237 */
238 protected IColor setUnselectedStrokeColor(IGC context) {
3145ec83 239 context.setForeground(SDViewPref.getInstance().getForeGroundColor(ISDPreferences.PREF_EXEC));
73005152
BH
240 return null;
241 }
242
243 @Override
244 public String getArrayId() {
245 return EXEC_OCC_TAG;
246 }
247
248 @Override
249 public boolean positiveDistanceToPoint(int x, int y) {
df0b8ff4 250 if (getY() + getHeight() > y) {
73005152 251 return true;
df0b8ff4 252 }
73005152
BH
253 return false;
254 }
255
256 @Override
257 public boolean isVisible(int x, int y, int width, int height) {
258 if ((getLifeline() != null) && (getLifeline().isVisible(x, y, width, height))) {
259 int ly = getY();
260 int lh = getHeight();
df0b8ff4 261 if (ly >= y && ly < y + height) {
73005152 262 return true;
df0b8ff4
BH
263 }
264 if (ly + lh > y && ly + lh <= y + height) {
73005152 265 return true;
df0b8ff4
BH
266 }
267 if ((ly < y) && (ly + lh > y + height)) {
73005152 268 return true;
df0b8ff4 269 }
73005152
BH
270 }
271 return false;
272 }
273}
This page took 0.050016 seconds and 5 git commands to generate.