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 $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
;
15 import java
.util
.Comparator
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IGC
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.ISDPreferences
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SortSyncMessageComparator
;
24 * A SyncMessage is a synchronous message which appear at the same event occurrence on both lifeline ends (sender and
26 * A Sync message is usually drawn horizontally.<br>
36 * SyncMessage message = new SyncMessage();
37 * // Create a new event occurrence on each lifeline
38 * lifeline1.getNewOccurrenceIndex();
39 * lifeline2.getNewOccurrenceIndex();
40 * // Set the message sender and receiver
41 * message.setStartLifeline(lifeLine1);
42 * message.setEndLifline(lifeline2);
43 * message.setName("Message label");
44 * // add the message to the frame
45 * frame.addMessage(message);
48 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
52 public class SyncMessage
extends BaseMessage
implements ITimeRange
{
55 * The associated message return
57 protected SyncMessageReturn messageReturn
;
60 * The time when the message occurs
62 protected ITmfTimestamp eventTime
= new TmfTimestamp();
64 public static final String SYNC_MESS_TAG
= "SyncMessage"; //$NON-NLS-1$
66 protected boolean hasTime
= false;
68 public SyncMessage() {
69 prefId
= ISDPreferences
.PREF_SYNC_MESS
;
73 * Ensure both lifelines have the same event occurrence (the greater found on each lifeline)
75 protected void syncLifelinesEventOccurrence() {
76 if ((getStartLifeline() != null) && (getEndLifeline() != null)) {
78 if (getStartLifeline().getEventOccurrence() > getEndLifeline().getEventOccurrence())
79 newIndex
= getStartLifeline().getEventOccurrence();
81 newIndex
= getEndLifeline().getEventOccurrence();
82 getStartLifeline().setCurrentEventOccurrence(newIndex
);
83 getEndLifeline().setCurrentEventOccurrence(newIndex
);
84 setEventOccurrence(getStartLifeline().getEventOccurrence());
89 * Set the lifeLine from which the message has been sent.<br>
90 * A new event occurrence will be created on this lifeLine.<br>
91 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
92 * event occurrence on each lifeline (the greater value will be used).<br>
93 * This synchronization is only done if the end lifeline has already been set.
95 * @param lifeline the message sender
97 public void autoSetStartLifeline(Lifeline lifeline
) {
98 lifeline
.getNewEventOccurrence();
99 setStartLifeline(lifeline
);
103 * Set the lifeLine which has receiver the message.<br>
104 * A new EventOccurence will be create on this lifeLine.<br>
105 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
106 * event occurrence on each lifeline (the greater value will be used).<br>
107 * This synchronization is only done if the start lifeline has already been set.
109 * @param lifeline the message receiver
111 public void autoSetEndLifeline(Lifeline lifeline
) {
112 lifeline
.getNewEventOccurrence();
113 setEndLifeline(lifeline
);
117 * Set the lifeLine which has receiver the message.<br>
118 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
119 * event occurrence on each lifeline (the greater value will be used).<br>
120 * This synchronization is only done if the start lifeline has already been set.
122 * @param lifeline the message receiver
125 public void setStartLifeline(Lifeline lifeline
) {
126 super.setStartLifeline(lifeline
);
127 if ((getEndLifeline() == null)) {
128 setEventOccurrence(getStartLifeline().getEventOccurrence());
130 syncLifelinesEventOccurrence();
134 * Set the lifeLine which has receiver the message.<br>
135 * SyncMessage must occur at the same event occurrence on both lifelines, this method is responsible to synchronize the
136 * event occurrence on each lifeline (the greater value will be used).<br>
137 * This synchronization is only done if the start lifeline has already been set.
139 * @param lifeline the message receiver
142 public void setEndLifeline(Lifeline lifeline
) {
143 super.setEndLifeline(lifeline
);
144 if ((getStartLifeline() == null)) {
145 setEventOccurrence(getEndLifeline().getEventOccurrence());
147 syncLifelinesEventOccurrence();
151 * Set the event occurrence when this message occurs.<br>
153 * @param occurrence the event occurrence to assign to this message.<br>
154 * @see Lifeline Lifeline for more event occurence details
157 protected void setEventOccurrence(int occurrence
) {
158 startEventOccurrence
= occurrence
;
159 endEventOccurrence
= occurrence
;
163 * Set the message return associated with this message.
165 * @param message the message return to associate
167 protected void setMessageReturn(SyncMessageReturn message
) {
168 messageReturn
= message
;
172 * Returns the syncMessageReturn associated to this syncMessage
174 * @return the message return
176 public SyncMessageReturn
getMessageReturn() {
177 return messageReturn
;
181 * Set the time when the message occurs
183 * @param time the time when the message occurs
185 public void setTime(ITmfTimestamp time
) {
186 eventTime
= time
.clone();
188 if (getStartLifeline() != null && getStartLifeline().getFrame() != null)
189 getStartLifeline().getFrame().setHasTimeInfo(true);
190 else if (getEndLifeline() != null && getEndLifeline().getFrame() != null)
191 getEndLifeline().getFrame().setHasTimeInfo(true);
195 * Returns the time when the message begin
200 public ITmfTimestamp
getEndTime() {
205 * Returns the time when the message end
210 public ITmfTimestamp
getStartTime() {
215 public boolean hasTimeInfo() {
220 public void draw(IGC context
) {
223 // Draw it selected?*/
225 context
.setBackground(Frame
.getUserPref().getBackGroundColor(prefId
));
226 context
.setForeground(Frame
.getUserPref().getForeGroundColor(prefId
));
232 public boolean isVisible(int x
, int y
, int width
, int height
) {
233 if (getY() > y
+ height
+
234 // take into account the message name drawn above the arrow
235 Metrics
.MESSAGES_NAME_SPACING
+ Metrics
.getMessageFontHeigth())
238 // UML2 lost/found message visibility special case
239 // Others visibility cases are perform in the ***common*** case
240 if ((endLifeline
== null && startLifeline
!= null) || (endLifeline
!= null && startLifeline
== null)) {
241 if (x
+ width
> getX() + getWidth() && x
< getX() + getWidth())
244 // ***Common*** syncMessages visibility
245 return super.isVisible(x
, y
, width
, height
);
249 public Comparator
<GraphNode
> getComparator() {
250 return new SortSyncMessageComparator();
254 public String
getArrayId() {
255 return SYNC_MESS_TAG
;
259 public boolean positiveDistanceToPoint(int x
, int y
) {