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