Search in sources :

Example 1 with Lifeline

use of net.sf.sdedit.diagram.Lifeline in project abstools by abstools.

the class SequenceElement method computePadding.

private void computePadding() {
    int main = diagram.mainLifelineWidth;
    int sub = diagram.subLifelineWidth;
    Lifeline left = leftEndpoint.getLifeline();
    if (left != null) {
        Lifeline rightMost = left.getRightmost();
        if (left == rightMost) {
            leftPadding = 0;
        } else if (rightMost.getDirection() == Direction.CENTER) {
            leftPadding = main + (left.getSideLevel() - 1) * sub;
        } else if (left.getDirection() == Direction.LEFT) {
            leftPadding = main + (left.getSideLevel() - 1) * sub + rightMost.getSideLevel() * sub;
        } else {
            leftPadding = (rightMost.getSideLevel() - left.getSideLevel()) * sub;
        }
    } else {
        leftPadding = 0;
    }
    Lifeline right = rightEndpoint.getLifeline();
    if (right != null) {
        Lifeline leftMost = right.getLeftmost();
        if (right == leftMost) {
            rightPadding = 0;
        } else if (leftMost.getDirection() == Direction.CENTER) {
            rightPadding = main + (right.getSideLevel() - 1) * sub;
        } else if (right.getDirection() == Direction.RIGHT) {
            rightPadding = main + (right.getSideLevel() - 1) * sub + leftMost.getSideLevel() * sub;
        } else {
            rightPadding = (leftMost.getSideLevel() - right.getSideLevel()) * sub;
        }
    } else {
        rightPadding = 0;
    }
}
Also used : Lifeline(net.sf.sdedit.diagram.Lifeline)

Example 2 with Lifeline

use of net.sf.sdedit.diagram.Lifeline in project abstools by abstools.

the class TextHandler method nextObjectIntern.

private Lifeline nextObjectIntern() throws SyntaxError {
    if (currentLine == null) {
        throw new IllegalStateException("nothing to read");
    }
    if (currentLine.indexOf(':') == -1) {
        throw new SyntaxError(this, "not a valid object declaration - ':' missing");
    }
    String[] parts = Grep.parse("(\\/?.+?):([^\\[\\]]+?)\\s*(\\[.*?\\]|)\\s*(\".*\"|)", currentLine);
    if (parts == null || parts.length != 4) {
        String msg;
        if (currentLine.indexOf('.') >= 0) {
            msg = "not a valid object declaration, perhaps you forgot to " + "enter an empty line before the message section";
        } else {
            msg = "not a valid object declaration";
        }
        throw new SyntaxError(this, msg);
    }
    currentLine = null;
    String name = parts[0];
    String type = parts[1];
    String flags = parts[2];
    String label = parts[3];
    if (!label.equals("")) {
        label = label.substring(1, label.length() - 1);
    }
    boolean anon = flags.indexOf('a') >= 0;
    boolean role = flags.indexOf('r') >= 0;
    boolean active = flags.indexOf('v') >= 0;
    boolean process = flags.indexOf('p') >= 0;
    boolean hasThread = flags.indexOf('t') >= 0;
    boolean autoDestroy = flags.indexOf('x') >= 0;
    boolean external = flags.indexOf('e') >= 0;
    Lifeline lifeline;
    if (external && !process) {
        throw new SyntaxError(this, "only processes can be declared external");
    }
    if (name.startsWith("/")) {
        if (type.equals("Actor") || process) {
            throw new SyntaxError(this, "processes and actors must be visible");
        }
        if (hasThread) {
            throw new SyntaxError(this, "invisible objects cannot have their own thread");
        }
        lifeline = new Lifeline(name.substring(1), type, label, false, anon, role, active, false, false, autoDestroy, external, diagram);
    } else {
        if (type.equals("Actor")) {
            if (anon) {
                throw new SyntaxError(this, "actors cannot be anonymous");
            }
        }
        if ((type.equals("Actor") || process) && hasThread) {
            throw new SyntaxError(this, "actors cannot have their own thread");
        }
        if ((type.equals("Actor") || process) && autoDestroy) {
            throw new SyntaxError(this, "actors cannot be (automatically) destroyed");
        }
        lifeline = new Lifeline(parts[0], parts[1], label, true, anon, role, active, process, hasThread, autoDestroy, external, diagram);
    }
    int cmt = rawLine.indexOf("#!");
    if (cmt >= 0 && cmt + 2 < rawLine.length() - 1) {
        String annotation = rawLine.substring(cmt + 2).trim();
        annotations.put(lifeline, annotation);
    }
    return lifeline;
}
Also used : SyntaxError(net.sf.sdedit.error.SyntaxError) Lifeline(net.sf.sdedit.diagram.Lifeline)

Example 3 with Lifeline

use of net.sf.sdedit.diagram.Lifeline in project abstools by abstools.

the class TextHandler method getLaterObjects.

public Collection<Lifeline> getLaterObjects() throws SyntaxError {
    ArrayList<Lifeline> laterObjects = new ArrayList<Lifeline>();
    if (!reader.markSupported()) {
        System.out.println("WARNING: reader does not support marking");
        return laterObjects;
    }
    String oldCurrentLine = currentLine;
    String oldRawLine = rawLine;
    StringBuffer oldLines = new StringBuffer();
    try {
        String line;
        do {
            line = reader.readLine();
            if (line != null) {
                if (line.startsWith("#newobj ")) {
                    currentLine = line.substring(8);
                    rawLine = currentLine;
                    laterObjects.add(nextObjectIntern());
                }
                oldLines.append(line);
                oldLines.append('\n');
            }
        } while (line != null);
        reader.close();
        reader = new BufferedReader(new StringReader(oldLines.toString()));
    } catch (IOException io) {
        io.printStackTrace();
    }
    currentLine = oldCurrentLine;
    rawLine = oldRawLine;
    return laterObjects;
}
Also used : Lifeline(net.sf.sdedit.diagram.Lifeline) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) IOException(java.io.IOException)

Example 4 with Lifeline

use of net.sf.sdedit.diagram.Lifeline in project abstools by abstools.

the class Tab method getSuggestions.

/**
 * @see net.sf.sdedit.ui.components.AutoCompletion.SuggestionProvider#getSuggestions(java.lang.String)
 */
public List<String> getSuggestions(String prefix) {
    List<String> suggestions = new LinkedList<String>();
    Diagram diag = getDiagram();
    if (diag != null) {
        for (Lifeline lifeline : diag.getAllLifelines()) {
            String name = lifeline.getName();
            if (name.startsWith(prefix)) {
                suggestions.add(name);
            }
        }
    }
    return suggestions;
}
Also used : Lifeline(net.sf.sdedit.diagram.Lifeline) LinkedList(java.util.LinkedList) Diagram(net.sf.sdedit.diagram.Diagram)

Example 5 with Lifeline

use of net.sf.sdedit.diagram.Lifeline in project abstools by abstools.

the class TextHandler method getEventAssociation.

/**
 * If the current line specifies an association of a note to the current
 * vertical position of a lifeline, this method returns a pair consisting of
 * the lifeline and the note number.
 *
 * @return a pair of a lifeline and a note number, if the current line
 *         specifies and association between the note and the lifeline,
 *         otherwise <tt>null</tt>
 */
public Pair<Lifeline, Integer> getEventAssociation() throws SyntaxError {
    if (section == 0) {
        throw new IllegalStateException("not all objects have been read");
    }
    if (currentLine == null) {
        throw new IllegalStateException("nothing to read");
    }
    String[] parts = Grep.parse("\\((\\d+)\\)\\s*(\\w+)", currentLine);
    if (parts == null) {
        return null;
    }
    int number = Integer.parseInt(parts[0]);
    String obj = parts[1];
    Lifeline line = diagram.getLifeline(obj);
    if (line == null) {
        throw new SyntaxError(this, obj + " does not exist");
    }
    return new Pair<Lifeline, Integer>(line, number);
}
Also used : SyntaxError(net.sf.sdedit.error.SyntaxError) Lifeline(net.sf.sdedit.diagram.Lifeline) Pair(net.sf.sdedit.util.Pair)

Aggregations

Lifeline (net.sf.sdedit.diagram.Lifeline)8 SyntaxError (net.sf.sdedit.error.SyntaxError)3 LinkedList (java.util.LinkedList)2 BufferedReader (java.io.BufferedReader)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Diagram (net.sf.sdedit.diagram.Diagram)1 Arrow (net.sf.sdedit.drawable.Arrow)1 BroadcastArrow (net.sf.sdedit.drawable.BroadcastArrow)1 Drawable (net.sf.sdedit.drawable.Drawable)1 Note (net.sf.sdedit.drawable.Note)1 Pair (net.sf.sdedit.util.Pair)1