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 / Stop.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
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
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
15
16 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
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 * <p>
22 * It is the UML2 stop graphical representation in the sequence diagram viewer.
23 * This draw a cross on the lifeline. The stop y coordinate depend on the event occurrence when it appears.
24 * A stop is never drawn it is assigned to a lifeline.
25 * </p>
26 *
27 * @version 1.0
28 * @author sveyrier
29 */
30 public class Stop extends GraphNode {
31
32 // ------------------------------------------------------------------------
33 // Constants
34 // ------------------------------------------------------------------------
35 /**
36 * The graphNode ID
37 */
38 public static final String STOP = "STOP"; //$NON-NLS-1$
39
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43 /**
44 * The owning lifeline on which the stop appears
45 */
46 protected Lifeline fLifeline = null;
47 /**
48 * This basically represents the time when the stop occurs on the owning Lifeline
49 *
50 * @see Lifeline Lifeline for more event occurence details
51 */
52 protected int fEventOccurrence = 0;
53
54 // ------------------------------------------------------------------------
55 // Methods
56 // ------------------------------------------------------------------------
57
58 /*
59 * (non-Javadoc)
60 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX()
61 */
62 @Override
63 public int getX() {
64 if (fLifeline == null) {
65 return 0;
66 }
67 return fLifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.STOP_WIDTH / 2;
68 }
69
70 /*
71 * (non-Javadoc)
72 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY()
73 */
74 @Override
75 public int getY() {
76 if (fLifeline == null) {
77 return 0;
78 }
79 return fLifeline.getY() + fLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fEventOccurrence - Metrics.STOP_WIDTH / 2;
80 }
81
82 /*
83 * (non-Javadoc)
84 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth()
85 */
86 @Override
87 public int getWidth() {
88 if (fLifeline == null) {
89 return 0;
90 }
91 return Metrics.STOP_WIDTH;
92 }
93
94 /*
95 * (non-Javadoc)
96 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight()
97 */
98 @Override
99 public int getHeight() {
100 if (fLifeline == null) {
101 return 0;
102 }
103 return Metrics.STOP_WIDTH;
104 }
105
106 /**
107 * Set the lifeline on which the stop must be draw
108 *
109 * @param theLifeline The the stop owing lifeline
110 */
111 public void setLifeline(Lifeline theLifeline) {
112 fLifeline = theLifeline;
113 }
114
115 /**
116 * Set the event occurrence when this stop appears
117 *
118 * @param occurrence the eventOccurence to assign to the stop
119 */
120 public void setEventOccurrence(int occurrence) {
121 fEventOccurrence = occurrence;
122 }
123
124 /*
125 * (non-Javadoc)
126 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
127 */
128 @Override
129 public void draw(IGC context) {
130
131 ISDPreferences pref = SDViewPref.getInstance();
132
133 // Set the appropriate color depending if the graph node if selected or not
134 if (fLifeline.isSelected()) {
135 context.setForeground(pref.getBackGroundColorSelection());
136 context.setLineWidth(Metrics.SELECTION_LINE_WIDTH);
137 int lastWidth = context.getLineWidth();
138 context.setLineWidth(9);
139 // Draw a cross on the lifeline
140 context.drawLine(getX(), getY(), getX() + getWidth(), getY() + getHeight());
141 context.drawLine(getX() + getWidth(), getY(), getX(), getY() + getHeight());
142 // restore the context
143 context.setLineWidth(lastWidth);
144 context.setBackground(pref.getBackGroundColorSelection());
145 context.setForeground(pref.getForeGroundColorSelection());
146 } else {
147 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_LIFELINE));
148 context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_LIFELINE));
149 }
150 int lastWidth = context.getLineWidth();
151 context.setLineWidth(3);
152 // Draw a cross on the lifeline
153 context.drawLine(getX(), getY(), getX() + getWidth(), getY() + getHeight());
154 context.drawLine(getX() + getWidth(), getY(), getX(), getY() + getHeight());
155 // restore the context
156 context.setLineWidth(lastWidth);
157 }
158
159 /*
160 * (non-Javadoc)
161 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
162 */
163 @Override
164 public String getArrayId() {
165 return STOP;
166 }
167
168 /*
169 * (non-Javadoc)
170 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int)
171 */
172 @Override
173 public boolean contains(int x, int y) {
174 return false;
175 }
176 }
This page took 0.036287 seconds and 5 git commands to generate.