Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / SyncMessage.java
CommitLineData
73005152
BH
1/**********************************************************************
2 * Copyright (c) 2005, 2006, 2011 IBM Corporation and others.
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 * $Id: SyncMessage.java,v 1.2 2006/09/20 20:56:25 ewchan Exp $
8 *
9 * Contributors:
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
14
15import java.util.Comparator;
16
6c13869b 17import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
73005152
BH
18import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
19import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences;
20import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SortSyncMessageComparator;
21
22/**
23 * A SyncMessage is a synchronous message which appear at the same event occurrence on both lifeline ends (sender and
24 * receiver).<br>
25 * A Sync message is usually drawn horizontally.<br>
26 * <br>
27 * <br>
28 * Usage example:
29 *
30 * <pre>
31 * Frame frame;
32 * Lifeline lifeLine1;
33 * Lifeline lifeLine2;
34 *
35 * SyncMessage message = new SyncMessage();
36 * // Create a new event occurrence on each lifeline
37 * lifeline1.getNewOccurrenceIndex();
38 * lifeline2.getNewOccurrenceIndex();
39 * // Set the message sender and receiver
40 * message.setStartLifeline(lifeLine1);
41 * message.setEndLifline(lifeline2);
42 * message.setName(&quot;Message label&quot;);
43 * // add the message to the frame
44 * frame.addMessage(message);
45 * </pre>
46 *
47 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
48 * @author sveyrier
49 *
50 */
51public class SyncMessage extends BaseMessage implements ITimeRange {
52
53 /**
54 * The associated message return
55 */
56 protected SyncMessageReturn messageReturn;
57
58 /**
59 * The time when the message occurs
60 */
61 protected TmfTimestamp eventTime = new TmfTimestamp();
62
63 public static final String SYNC_MESS_TAG = "SyncMessage"; //$NON-NLS-1$
64
65 protected boolean hasTime = false;
66
67 public SyncMessage() {
68 prefId = ISDPreferences.PREF_SYNC_MESS;
69 }
70
71 /**
72 * Ensure both lifelines have the same event occurrence (the greater found on each lifeline)
73 */
74 protected void syncLifelinesEventOccurrence() {
75 if ((getStartLifeline() != null) && (getEndLifeline() != null)) {
76 int newIndex = 0;
77 if (getStartLifeline().getEventOccurrence() > getEndLifeline().getEventOccurrence())
78 newIndex = getStartLifeline().getEventOccurrence();
79 else
80 newIndex = getEndLifeline().getEventOccurrence();
81 getStartLifeline().setCurrentEventOccurrence(newIndex);
82 getEndLifeline().setCurrentEventOccurrence(newIndex);
83 setEventOccurrence(getStartLifeline().getEventOccurrence());
84 }
85 }
86
87 /**
88 * Set the lifeLine from which the message has been sent.<br>
89 * A new event occurrence will be created on this lifeLine.<br>
90 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
91 * event occurrence on each lifeline (the greater value will be used).<br>
92 * This synchronization is only done if the end lifeline has already been set.
93 *
94 * @param lifeline the message sender
95 */
96 public void autoSetStartLifeline(Lifeline lifeline) {
97 lifeline.getNewEventOccurrence();
98 setStartLifeline(lifeline);
99 }
100
101 /**
102 * Set the lifeLine which has receiver the message.<br>
103 * A new EventOccurence will be create on this lifeLine.<br>
104 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
105 * event occurrence on each lifeline (the greater value will be used).<br>
106 * This synchronization is only done if the start lifeline has already been set.
107 *
108 * @param lifeline the message receiver
109 */
110 public void autoSetEndLifeline(Lifeline lifeline) {
111 lifeline.getNewEventOccurrence();
112 setEndLifeline(lifeline);
113 }
114
115 /**
116 * Set the lifeLine which has receiver the message.<br>
117 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
118 * event occurrence on each lifeline (the greater value will be used).<br>
119 * This synchronization is only done if the start lifeline has already been set.
120 *
121 * @param lifeline the message receiver
122 */
123 @Override
124 public void setStartLifeline(Lifeline lifeline) {
125 super.setStartLifeline(lifeline);
126 if ((getEndLifeline() == null)) {
127 setEventOccurrence(getStartLifeline().getEventOccurrence());
128 } else
129 syncLifelinesEventOccurrence();
130 }
131
132 /**
133 * Set the lifeLine which has receiver the message.<br>
134 * SyncMessage must occur at the same event occurrence on both lifelines, this method is responsible to synchronize the
135 * event occurrence on each lifeline (the greater value will be used).<br>
136 * This synchronization is only done if the start lifeline has already been set.
137 *
138 * @param lifeline the message receiver
139 */
140 @Override
141 public void setEndLifeline(Lifeline lifeline) {
142 super.setEndLifeline(lifeline);
143 if ((getStartLifeline() == null)) {
144 setEventOccurrence(getEndLifeline().getEventOccurrence());
145 } else
146 syncLifelinesEventOccurrence();
147 }
148
149 /**
150 * Set the event occurrence when this message occurs.<br>
151 *
152 * @param occurrence the event occurrence to assign to this message.<br>
153 * @see Lifeline Lifeline for more event occurence details
154 */
155 @Override
156 protected void setEventOccurrence(int occurrence) {
157 startEventOccurrence = occurrence;
158 endEventOccurrence = occurrence;
159 }
160
161 /**
162 * Set the message return associated with this message.
163 *
164 * @param message the message return to associate
165 */
166 protected void setMessageReturn(SyncMessageReturn message) {
167 messageReturn = message;
168 }
169
170 /**
171 * Returns the syncMessageReturn associated to this syncMessage
172 *
173 * @return the message return
174 */
175 public SyncMessageReturn getMessageReturn() {
176 return messageReturn;
177 }
178
179 /**
180 * Set the time when the message occurs
181 *
182 * @param time the time when the message occurs
183 */
184 public void setTime(TmfTimestamp time) {
185 eventTime = time.clone();
186 hasTime = true;
187 if (getStartLifeline() != null && getStartLifeline().getFrame() != null)
188 getStartLifeline().getFrame().setHasTimeInfo(true);
189 else if (getEndLifeline() != null && getEndLifeline().getFrame() != null)
190 getEndLifeline().getFrame().setHasTimeInfo(true);
191 }
192
193 /**
194 * Returns the time when the message begin
195 *
196 * @return the time
197 */
198 @Override
199 public TmfTimestamp getEndTime() {
200 return eventTime;
201 }
202
203 /**
204 * Returns the time when the message end
205 *
206 * @return the time
207 */
208 @Override
209 public TmfTimestamp getStartTime() {
210 return eventTime;
211 }
212
213 @Override
214 public boolean hasTimeInfo() {
215 return hasTime;
216 }
217
218 @Override
219 public void draw(IGC context) {
220 if (!isVisible())
221 return;
222 // Draw it selected?*/
223 if (!isSelected()) {
224 context.setBackground(Frame.getUserPref().getBackGroundColor(prefId));
225 context.setForeground(Frame.getUserPref().getForeGroundColor(prefId));
226 }
227 super.draw(context);
228 }
229
230 @Override
231 public boolean isVisible(int x, int y, int width, int height) {
232 if (getY() > y + height +
233 // take into account the message name drawn above the arrow
234 Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth())
235 return false;
236
237 // UML2 lost/found message visibility special case
238 // Others visibility cases are perform in the ***common*** case
239 if ((endLifeline == null && startLifeline != null) || (endLifeline != null && startLifeline == null)) {
240 if (x + width > getX() + getWidth() && x < getX() + getWidth())
241 return true;
242 }
243 // ***Common*** syncMessages visibility
244 return super.isVisible(x, y, width, height);
245 }
246
247 @Override
248 public Comparator<GraphNode> getComparator() {
249 return new SortSyncMessageComparator();
250 }
251
252 @Override
253 public String getArrayId() {
254 return SYNC_MESS_TAG;
255 }
256
257 @Override
258 public boolean positiveDistanceToPoint(int x, int y) {
259 if (getY() > y)
260 return true;
261 return false;
262 }
263}
This page took 0.038187 seconds and 5 git commands to generate.