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
.event
.TmfTimestamp
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IGC
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.ISDPreferences
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SortSyncMessageComparator
;
23 * A SyncMessage is a synchronous message which appear at the same event occurrence on both lifeline ends (sender and
25 * A Sync message is usually drawn horizontally.<br>
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("Message label");
43 * // add the message to the frame
44 * frame.addMessage(message);
47 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
51 public class SyncMessage
extends BaseMessage
implements ITimeRange
{
54 * The associated message return
56 protected SyncMessageReturn messageReturn
;
59 * The time when the message occurs
61 protected TmfTimestamp eventTime
= new TmfTimestamp();
63 public static final String SYNC_MESS_TAG
= "SyncMessage"; //$NON-NLS-1$
65 protected boolean hasTime
= false;
67 public SyncMessage() {
68 prefId
= ISDPreferences
.PREF_SYNC_MESS
;
72 * Ensure both lifelines have the same event occurrence (the greater found on each lifeline)
74 protected void syncLifelinesEventOccurrence() {
75 if ((getStartLifeline() != null) && (getEndLifeline() != null)) {
77 if (getStartLifeline().getEventOccurrence() > getEndLifeline().getEventOccurrence())
78 newIndex
= getStartLifeline().getEventOccurrence();
80 newIndex
= getEndLifeline().getEventOccurrence();
81 getStartLifeline().setCurrentEventOccurrence(newIndex
);
82 getEndLifeline().setCurrentEventOccurrence(newIndex
);
83 setEventOccurrence(getStartLifeline().getEventOccurrence());
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.
94 * @param lifeline the message sender
96 public void autoSetStartLifeline(Lifeline lifeline
) {
97 lifeline
.getNewEventOccurrence();
98 setStartLifeline(lifeline
);
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.
108 * @param lifeline the message receiver
110 public void autoSetEndLifeline(Lifeline lifeline
) {
111 lifeline
.getNewEventOccurrence();
112 setEndLifeline(lifeline
);
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.
121 * @param lifeline the message receiver
124 public void setStartLifeline(Lifeline lifeline
) {
125 super.setStartLifeline(lifeline
);
126 if ((getEndLifeline() == null)) {
127 setEventOccurrence(getStartLifeline().getEventOccurrence());
129 syncLifelinesEventOccurrence();
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.
138 * @param lifeline the message receiver
141 public void setEndLifeline(Lifeline lifeline
) {
142 super.setEndLifeline(lifeline
);
143 if ((getStartLifeline() == null)) {
144 setEventOccurrence(getEndLifeline().getEventOccurrence());
146 syncLifelinesEventOccurrence();
150 * Set the event occurrence when this message occurs.<br>
152 * @param occurrence the event occurrence to assign to this message.<br>
153 * @see Lifeline Lifeline for more event occurence details
156 protected void setEventOccurrence(int occurrence
) {
157 startEventOccurrence
= occurrence
;
158 endEventOccurrence
= occurrence
;
162 * Set the message return associated with this message.
164 * @param message the message return to associate
166 protected void setMessageReturn(SyncMessageReturn message
) {
167 messageReturn
= message
;
171 * Returns the syncMessageReturn associated to this syncMessage
173 * @return the message return
175 public SyncMessageReturn
getMessageReturn() {
176 return messageReturn
;
180 * Set the time when the message occurs
182 * @param time the time when the message occurs
184 public void setTime(TmfTimestamp time
) {
185 eventTime
= time
.clone();
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);
194 * Returns the time when the message begin
199 public TmfTimestamp
getEndTime() {
204 * Returns the time when the message end
209 public TmfTimestamp
getStartTime() {
214 public boolean hasTimeInfo() {
219 public void draw(IGC context
) {
222 // Draw it selected?*/
224 context
.setBackground(Frame
.getUserPref().getBackGroundColor(prefId
));
225 context
.setForeground(Frame
.getUserPref().getForeGroundColor(prefId
));
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())
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())
243 // ***Common*** syncMessages visibility
244 return super.isVisible(x
, y
, width
, height
);
248 public Comparator
<GraphNode
> getComparator() {
249 return new SortSyncMessageComparator();
253 public String
getArrayId() {
254 return SYNC_MESS_TAG
;
258 public boolean positiveDistanceToPoint(int x
, int y
) {