use of net.sf.sdedit.message.Message in project abstools by abstools.
the class Diagram method getLifelines.
private Set<Lifeline> getLifelines(int thread) {
Set<Lifeline> lifelines = new HashSet<Lifeline>();
Lifeline firstCaller = first.get(thread);
if (!firstCaller.isAlwaysActive()) {
lifelines.add(firstCaller);
}
for (Message msg : threadStacks.get(thread)) {
lifelines.add(msg.getCaller());
if (msg.getCallee() != null) {
lifelines.add(msg.getCallee());
}
}
return lifelines;
}
use of net.sf.sdedit.message.Message in project abstools by abstools.
the class Diagram method finish.
void finish(int thread) {
LinkedList<Message> threadStack = threadStacks.get(thread);
while (threadStack != null && !threadStack.isEmpty()) {
Message answer = threadStack.removeLast();
sendAnswer(answer);
}
Lifeline firstLifeline = first.get(thread);
if (firstLifeline != null) {
firstLifeline.finish();
if (firstLifeline.getRoot() != firstLifeline) {
firstLifeline.dispose();
}
}
}
use of net.sf.sdedit.message.Message in project abstools by abstools.
the class LoopArrow method init.
private void init() {
Message message = getMessage();
Configuration conf = message.getConfiguration();
xExtent = conf.getSelfMessageHorizontalSpace();
setWidth(diagram.messagePadding + xExtent + diagram.subLifelineWidth + textWidth());
isAnswer = message instanceof AnswerToSelf;
from = message.getCaller().getView();
to = message.getCallee().getView();
if (getAlign() == Direction.LEFT) {
// loop arrows on the left must have a left neighbour
setLeftEndpoint(message.getCallee().getLeftNeighbour().getView());
if (message.getCaller().getSideLevel() < message.getCallee().getSideLevel()) {
setRightEndpoint(message.getCaller().getView());
} else {
setRightEndpoint(message.getCallee().getView());
}
} else {
int p = message.getCallee().getPosition();
if (p < message.getDiagram().getNumberOfLifelines() - 1 && message.getDiagram().getLifelineAt(p + 1).isAlive()) {
setRightEndpoint(message.getCallee().getRightNeighbour().getView());
} else {
setRightEndpoint(message.getDiagram().getPaintDevice().getRightBound());
}
if (message.getCaller().getSideLevel() < message.getCallee().getSideLevel()) {
setLeftEndpoint(message.getCaller().getView());
} else {
setLeftEndpoint(message.getCallee().getView());
}
}
}
use of net.sf.sdedit.message.Message in project abstools by abstools.
the class MessageProcessor method findCaller.
/**
* Returns the Lifeline representation of the caller as specified by the
* given MessageData and sets the current thread to the thread that was used
* in order to activate the Lifeline.
*
* @param data
* @return the Lifeline representation of the caller
* @throws SemanticError
* @precondition caller is not an actor
*/
private Lifeline findCaller() throws SemanticError {
final String callerName = data.getCaller();
if (callerIsActor()) {
/*
* When multithreading is disabled and an actor sends a message,
* finish all ongoing activities.
*/
if (!diagram.isThreaded()) {
diagram.finish();
}
return rootCaller;
}
final String mnemonic = data.getCallerMnemonic();
/*
* If lineToBeFound is not null, we just look for it, ignoring level and
* thread specification of the MessageData.
*/
Lifeline lineToBeFound = null;
if (!mnemonic.equals("")) {
lineToBeFound = diagram.getLifelineByMnemonic(data.getCaller(), mnemonic);
if (lineToBeFound == null) {
throw new SemanticError(provider, "There is no lifeline named \"" + data.getCaller() + "\" associated to mnemonic \"" + mnemonic + "\"");
}
}
final LinkedList<Message> currentStack = diagram.currentStack();
if (currentStack == null) {
throw new SemanticError(provider, "Thread " + callerThread + " has died");
}
if (callerThread == 0 && currentStack.isEmpty() && diagram.firstCaller() == null) {
/*
* The message described by MessageData is the first that occurs on
* the thread 0, no object is yet active. So set the caller active
* and declare it the first caller.
*/
diagram.setFirstCaller(rootCaller);
rootCaller.setActive(true);
return rootCaller;
}
/*
* This number counts how often we have seen a lifeline with the same
* name, but with a wrong level (or not equal to lineToBeFound), as
* senders of answers on the stack.
*/
int occured = 0;
while (!currentStack.isEmpty()) {
final Message theAnswer = currentStack.getLast();
if (lineToBeFound != null) {
if (theAnswer.getCaller() == lineToBeFound) {
return lineToBeFound;
}
} else if (theAnswer.getCaller().getName().equals(data.getCaller())) {
// followers)
if (occured == data.getLevel()) {
return theAnswer.getCaller();
}
occured++;
}
/*
* All answers that have non matching lifelines as senders are
* popped from the stack and the answer is added to the diagram,
* thus, an arrow representation will appear.
*/
currentStack.removeLast();
diagram.sendAnswer(theAnswer);
}
if (diagram.firstCaller() != null && diagram.firstCaller().getName().equals(callerName)) {
/*
* We have not yet seen the lifeline we are looking for, the last
* chance is that it is the first caller on the thread.
*/
if (occured == data.getLevel()) {
return diagram.firstCaller();
}
/*
* This chance was also missed, we add 1 to occured in order to
* count the occurence as first caller.
*/
occured++;
}
throw objectNotFound(occured, lineToBeFound);
}
use of net.sf.sdedit.message.Message in project abstools by abstools.
the class NoteManager method computeArrowAssociations.
public void computeArrowAssociations() {
for (Note description : notes) {
List<Message> msgs = messageAssociation.get(description.getNumber());
if (msgs != null) {
for (Message msg : msgs) {
// note to this.
if (msg.getArrow() != null) {
description.addTarget(msg.getArrow().getAnchor());
}
}
}
List<Pair<Lifeline, Integer>> pairs = eventAssociation.get(description.getNumber());
if (pairs != null) {
for (Pair<Lifeline, Integer> pair : pairs) {
int x = pair.getFirst().getView().getLeft() + pair.getFirst().getView().getWidth() / 2;
Point p = new Point(x, pair.getSecond());
description.addTarget(p);
}
}
}
}
Aggregations