Search in sources :

Example 6 with Lifeline

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

the class TextHandler method getNote.

/**
 * If there is a note specified at the current line and the subsequent
 * lines, a {@linkplain Note} representation is returned, otherwise
 * <tt>null</tt>
 *
 * @return a note, if one is specified at the current position in text,
 *         otherwise <tt>null</tt>
 */
public Note getNote() 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("\\s*(\\*|\\+)(\\d+)\\s*(.+)", currentLine);
    if (parts == null) {
        return null;
    }
    boolean consuming = parts[0].equals("+");
    int number = -1;
    try {
        number = Integer.parseInt(parts[1]);
    } catch (NumberFormatException nfe) {
    /* empty */
    }
    if (number < 0) {
        throw new SyntaxError(this, "bad note number: " + parts[1]);
    }
    String obj = parts[2];
    Lifeline line = diagram.getLifeline(obj);
    if (line == null) {
        throw new SyntaxError(this, obj + " does not exist");
    }
    int oldBegin = lineBegin;
    int oldEnd = lineEnd;
    line = line.getRightmost();
    List<String> desc = new LinkedList<String>();
    boolean more;
    do {
        if (!advance(false)) {
            lineBegin = oldBegin;
            lineEnd = oldEnd;
            throw new SyntaxError(this, "The note is not closed.");
        }
        more = !currentLine.trim().equals(parts[0] + parts[1]);
    } while (more && desc.add(currentLine));
    if (desc.size() == 0) {
        lineBegin = oldBegin;
        lineEnd = oldEnd;
        throw new SyntaxError(this, "The note is empty.");
    }
    String[] noteText = desc.toArray(new String[0]);
    URI link = null;
    if (noteText.length == 1) {
        String linkString = noteText[0].trim();
        if (linkString.startsWith("link:")) {
            try {
                linkString = linkString.substring(5).trim();
                link = new URI(linkString);
                if (link.getPath() == null) {
                    throw new SyntaxError(this, "Empty path in URI: " + linkString);
                }
                noteText[0] = link.getPath();
            } catch (URISyntaxException e) {
                throw new SyntaxError(this, "Bad URI syntax: " + e.getMessage());
            }
        }
    }
    Note note = new Note(line, number, noteText, consuming);
    note.setLink(link);
    return note;
}
Also used : Lifeline(net.sf.sdedit.diagram.Lifeline) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) LinkedList(java.util.LinkedList) SyntaxError(net.sf.sdedit.error.SyntaxError) Note(net.sf.sdedit.drawable.Note)

Example 7 with Lifeline

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

the class ExportMapAction method generateMapFile.

private void generateMapFile(Diagram diagram, TextHandler textHandler, String mapName, File target) throws IOException {
    String encoding = ConfigurationManager.getGlobalConfiguration().getFileEncoding();
    FileOutputStream fos = new FileOutputStream(target);
    OutputStreamWriter osw = new OutputStreamWriter(fos, encoding);
    PrintWriter pw = new PrintWriter(osw);
    pw.println("<!-- Generated by Quick Sequence Diagram Editor -->");
    pw.println("<!-- encoding: " + encoding + " -->");
    pw.println("<!-- You may append '#!href=\"<url>\"' to an object declaration\nin order to set" + " the 'href' attribute of an AREA tag -->");
    pw.println("<map id=\"" + mapName + "\" name=\"" + mapName + "\">");
    for (Lifeline lifeline : diagram.getAllLifelines()) {
        String annotation = textHandler.getAnnotation(lifeline);
        String file = lifeline.getName();
        if (annotation != null) {
            String[] href = Grep.parse("^.*?href=\"(.*?)\".*$", annotation);
            if (href != null) {
                file = href[0];
            }
        }
        Drawable drawable = lifeline.getHead();
        int x1 = drawable.getLeft();
        int y1 = drawable.getTop();
        int x2 = drawable.getRight();
        int y2 = drawable.getBottom();
        String coords = x1 + "," + y1 + "," + x2 + "," + y2;
        pw.println("  <area shape=\"rect\" coords=\"" + coords + "\"" + " href=\"" + file + "\"/>");
    }
    pw.println("</map>");
    pw.flush();
    pw.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) Lifeline(net.sf.sdedit.diagram.Lifeline) Drawable(net.sf.sdedit.drawable.Drawable) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Example 8 with Lifeline

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

the class BroadcastMessage method updateView.

@Override
public void updateView() {
    if (getData().getBroadcastType() == FIRST) {
        getDiagram().getPaintDevice().announce(getConfiguration().getSpaceBeforeActivation() + 3 + Arrow.getInnerHeight(this) + diagram.arrowSize / 2);
        extendLifelines(getConfiguration().getSpaceBeforeActivation() + 3);
    }
    Arrow arrow;
    if (getCaller().getPosition() < getCallee().getPosition()) {
        arrow = new BroadcastArrow(this, Direction.RIGHT, v());
    } else {
        arrow = new BroadcastArrow(this, Direction.LEFT, v());
    }
    setArrow(arrow);
    if (getData().getBroadcastType() == LAST) {
        extendLifelines(arrow.getInnerHeight());
        for (Lifeline callee : otherCallees) {
            if (!callee.isAlwaysActive() && isActivating()) {
                callee.setActive(true);
            }
        }
        if (!getCallee().isAlwaysActive() && isActivating()) {
            getCallee().setActive(true);
        }
    }
    getDiagram().getPaintDevice().addSequenceElement(arrow);
}
Also used : Arrow(net.sf.sdedit.drawable.Arrow) BroadcastArrow(net.sf.sdedit.drawable.BroadcastArrow) Lifeline(net.sf.sdedit.diagram.Lifeline) BroadcastArrow(net.sf.sdedit.drawable.BroadcastArrow)

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