Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2006 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
4 | * | |
73005152 BH |
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 | |
73005152 BH |
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; | |
df0b8ff4 | 17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
73005152 BH |
18 | |
19 | /** | |
df0b8ff4 BH |
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> | |
73005152 | 25 | * |
df0b8ff4 | 26 | * @version 1.0 |
73005152 | 27 | * @author sveyrier |
73005152 BH |
28 | */ |
29 | public class Stop extends GraphNode { | |
30 | ||
df0b8ff4 BH |
31 | // ------------------------------------------------------------------------ |
32 | // Constants | |
33 | // ------------------------------------------------------------------------ | |
73005152 BH |
34 | /** |
35 | * The graphNode ID | |
36 | */ | |
37 | public static final String STOP = "STOP"; //$NON-NLS-1$ | |
df0b8ff4 BH |
38 | |
39 | // ------------------------------------------------------------------------ | |
40 | // Attributes | |
41 | // ------------------------------------------------------------------------ | |
42 | /** | |
43 | * The owning lifeline on which the stop appears | |
44 | */ | |
eb63f5ff | 45 | protected Lifeline fLifeline = null; |
73005152 BH |
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 | */ | |
eb63f5ff | 51 | protected int fEventOccurrence = 0; |
73005152 | 52 | |
df0b8ff4 BH |
53 | // ------------------------------------------------------------------------ |
54 | // Methods | |
55 | // ------------------------------------------------------------------------ | |
56 | ||
57 | /* | |
58 | * (non-Javadoc) | |
59 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX() | |
60 | */ | |
73005152 BH |
61 | @Override |
62 | public int getX() { | |
eb63f5ff | 63 | if (fLifeline == null) { |
73005152 | 64 | return 0; |
df0b8ff4 | 65 | } |
eb63f5ff | 66 | return fLifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.STOP_WIDTH / 2; |
73005152 BH |
67 | } |
68 | ||
df0b8ff4 BH |
69 | /* |
70 | * (non-Javadoc) | |
71 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY() | |
72 | */ | |
73005152 BH |
73 | @Override |
74 | public int getY() { | |
eb63f5ff | 75 | if (fLifeline == null) { |
73005152 | 76 | return 0; |
df0b8ff4 | 77 | } |
eb63f5ff | 78 | return fLifeline.getY() + fLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fEventOccurrence - Metrics.STOP_WIDTH / 2; |
73005152 BH |
79 | } |
80 | ||
df0b8ff4 BH |
81 | /* |
82 | * (non-Javadoc) | |
83 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth() | |
84 | */ | |
73005152 BH |
85 | @Override |
86 | public int getWidth() { | |
eb63f5ff | 87 | if (fLifeline == null) { |
73005152 | 88 | return 0; |
df0b8ff4 | 89 | } |
73005152 BH |
90 | return Metrics.STOP_WIDTH; |
91 | } | |
92 | ||
df0b8ff4 BH |
93 | /* |
94 | * (non-Javadoc) | |
95 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight() | |
96 | */ | |
73005152 BH |
97 | @Override |
98 | public int getHeight() { | |
eb63f5ff | 99 | if (fLifeline == null) { |
73005152 | 100 | return 0; |
df0b8ff4 | 101 | } |
73005152 BH |
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) { | |
eb63f5ff | 111 | fLifeline = theLifeline; |
73005152 BH |
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) { | |
eb63f5ff | 120 | fEventOccurrence = occurrence; |
73005152 BH |
121 | } |
122 | ||
df0b8ff4 BH |
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 | */ | |
73005152 BH |
127 | @Override |
128 | public void draw(IGC context) { | |
129 | // Set the appropriate color depending if the graph node if selected or not | |
eb63f5ff | 130 | if (fLifeline.isSelected()) { |
73005152 BH |
131 | context.setForeground(Frame.getUserPref().getBackGroundColorSelection()); |
132 | context.setLineWidth(Metrics.SELECTION_LINE_WIDTH); | |
133 | int lastWidth = context.getLineWidth(); | |
134 | context.setLineWidth(9); | |
135 | // Draw a cross on the lifeline | |
136 | context.drawLine(getX(), getY(), getX() + getWidth(), getY() + getHeight()); | |
137 | context.drawLine(getX() + getWidth(), getY(), getX(), getY() + getHeight()); | |
138 | // restore the context | |
139 | context.setLineWidth(lastWidth); | |
140 | context.setBackground(Frame.getUserPref().getBackGroundColorSelection()); | |
141 | context.setForeground(Frame.getUserPref().getForeGroundColorSelection()); | |
142 | } else { | |
143 | context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_LIFELINE)); | |
144 | context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_LIFELINE)); | |
145 | } | |
146 | int lastWidth = context.getLineWidth(); | |
147 | context.setLineWidth(3); | |
148 | // Draw a cross on the lifeline | |
149 | context.drawLine(getX(), getY(), getX() + getWidth(), getY() + getHeight()); | |
150 | context.drawLine(getX() + getWidth(), getY(), getX(), getY() + getHeight()); | |
151 | // restore the context | |
152 | context.setLineWidth(lastWidth); | |
153 | } | |
154 | ||
155 | /* | |
156 | * (non-Javadoc) | |
157 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId() | |
158 | */ | |
159 | @Override | |
160 | public String getArrayId() { | |
161 | return STOP; | |
162 | } | |
163 | ||
164 | /* | |
165 | * (non-Javadoc) | |
166 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int) | |
167 | */ | |
168 | @Override | |
169 | public boolean contains(int x, int y) { | |
73005152 BH |
170 | return false; |
171 | } | |
172 | } |