Search in sources :

Example 1 with GLink

use of org.antlr.xjlib.appkit.gview.object.GLink in project antlrworks by antlr.

the class GDOTImporterDOT method createGraphEdge.

public GElement createGraphEdge(String[] tokens) throws IOException {
    //  DOT -> foo_bar [pos="e,65,36 65,72 65,64 65,55 65,46"];
    //   0  12     3   4 5 6               7                 8 9
    //  DOT -> A [label=foo, pos="e,153,33 119,88 124,78 129,65 136,54 139,49 142,45 146,40", lp="146,62"];
    //   0  12 3 4 5   6 7 8  9 10     11
    String sourceName = tokens[0];
    String targetName = tokens[3];
    String labelName = null;
    Vector2D labelPosition = null;
    Vector2D[] points = null;
    int index = 4;
    while (index < tokens.length - 1) {
        index++;
        if (tokens[index].equals("label")) {
            // Label name
            labelName = tokens[index += 2];
        } else if (tokens[index].equals("lp")) {
            // Label position
            String[] lpos = parseTokens(tokens[index += 2]);
            labelPosition = new Vector2D(Float.parseFloat(lpos[0]), height - Float.parseFloat(lpos[2]));
        } else if (tokens[index].equals("pos")) {
            // Edge control points
            points = parseControlPoints(tokens[index += 2]);
        } else if (tokens[index].equals(";"))
            break;
    }
    GElement source = graph.findElementWithLabel(sourceName);
    GElement target = graph.findElementWithLabel(targetName);
    GLink link = new GLink(source, GElementCircle.ANCHOR_CENTER, target, GElementCircle.ANCHOR_CENTER, GLink.SHAPE_BEZIER, labelName, 0);
    if (points == null) {
        System.err.println("No points for " + sourceName + ", " + targetName + ", " + tokens.length);
        for (int i = 0; i < tokens.length; i++) {
            String token = tokens[i];
            System.out.println(token);
        }
    }
    link.setBezierControlPoints(points);
    link.setBezierLabelPosition(labelPosition);
    return link;
}
Also used : Vector2D(org.antlr.xjlib.appkit.gview.base.Vector2D) GElement(org.antlr.xjlib.appkit.gview.object.GElement) GLink(org.antlr.xjlib.appkit.gview.object.GLink)

Example 2 with GLink

use of org.antlr.xjlib.appkit.gview.object.GLink in project antlrworks by antlr.

the class GDOTImporterPlain method createGraphEdge.

public GElement createGraphEdge(String[] tokens) {
    //  0    1     2  3 4
    //  edge start n1 7 1.153 8.556 1.125 8.417 1.097 8.236 1.111 8.083 1.111 8.042 1.125 8.014 1.125 7.972
    //  g 1.194 8.194 solid black
    //  edge rule foo 4 0.375 1.000 0.375 0.889 0.375 0.764 0.375 0.639 solid black
    int controlCount = (int) Float.parseFloat(tokens[3]);
    Vector2D[] points = new Vector2D[controlCount];
    for (int index = 0; index < controlCount; index++) {
        points[index] = new Vector2D(Float.parseFloat(tokens[4 + index * 2]) * factor, (height - Float.parseFloat(tokens[4 + index * 2 + 1])) * factor);
    }
    int labelIndex = 3 + 2 * controlCount + 1;
    String label = null;
    Vector2D labelPosition = null;
    if (isFloatString(tokens[labelIndex + 1])) {
        // Apparently there is a label because there is a float coordinate
        label = tokens[labelIndex];
        labelPosition = new Vector2D(Float.parseFloat(tokens[labelIndex + 1]) * factor, (height - Float.parseFloat(tokens[labelIndex + 2])) * factor);
    }
    GElement source = graph.findElementWithLabel(tokens[1]);
    GElement target = graph.findElementWithLabel(tokens[2]);
    GLink link = new GLink(source, GElementCircle.ANCHOR_CENTER, target, GElementCircle.ANCHOR_CENTER, GLink.SHAPE_BEZIER, label, 0);
    link.setBezierControlPoints(points);
    link.setBezierLabelPosition(labelPosition);
    return link;
}
Also used : Vector2D(org.antlr.xjlib.appkit.gview.base.Vector2D) GElement(org.antlr.xjlib.appkit.gview.object.GElement) GLink(org.antlr.xjlib.appkit.gview.object.GLink)

Example 3 with GLink

use of org.antlr.xjlib.appkit.gview.object.GLink in project antlrworks by antlr.

the class AWTreeGraphView method addChildElement.

public void addChildElement(GElementNode parent, GElementNode child) {
    /** Get the far right position of the last child */
    double x = parent.getLastChildRightSpan();
    /** Add a gap if there is already a child otherwise use the parent left coordinate */
    if (x > 0)
        x += HORIZONTAL_GAP;
    else
        x = parent.getLeft();
    /** Set the child position */
    child.setPositionOfUpperLeftCorner(x, parent.getBottom() + VERTICAL_GAP);
    /** Create the link from the parent to this child */
    GLink link = new GLink(parent, GLink.ANCHOR_BOTTOM, child, GLink.ANCHOR_TOP, GLink.SHAPE_ELBOW, "", 0);
    link.setDraggable(DRAGGABLE);
    /** Configure the link geometry */
    SLinkElbow l = (SLinkElbow) link.getLink();
    l.setOutOffsetLength(10);
    l.getArrow().setLength(6);
    /** Add the link and the child */
    parent.addElement(link);
    parent.addElement(child);
}
Also used : SLinkElbow(org.antlr.xjlib.appkit.gview.shape.SLinkElbow) GLink(org.antlr.xjlib.appkit.gview.object.GLink)

Example 4 with GLink

use of org.antlr.xjlib.appkit.gview.object.GLink in project antlrworks by antlr.

the class GEventCreateLinkElement method updateLink.

public void updateLink(Point mouse) {
    GElement ce = delegate.eventQueryElementAtPoint(mouse);
    boolean selfLoop = ce == startElement;
    setLinkStartAnchor(startElement.getAnchor(startAnchorKey));
    if (ce == null || ce instanceof GLink) {
        setLinkEnd(Vector2D.vector(mouse), Anchor2D.DIRECTION_BOTTOM);
    } else {
        Anchor2D anchor = ce.getAnchorClosestToPoint(mouse);
        String anchorKey = ce.getAnchorKeyClosestToPoint(mouse);
        setLinkEnd(anchor.position, anchor.direction);
        if (selfLoop) {
            if (anchor.direction == Anchor2D.DIRECTION_FREE)
                linkArc.setMouse(mouse);
            else
                linkArc.setMouse(anchor.position.add(anchor.direction));
            linkArc.setEndTangentOffset(startElement.getDefaultAnchorOffset(anchorKey));
        } else {
            linkArc.setMouse(mouse);
            linkArc.setEndTangentOffset(ce.getDefaultAnchorOffset(anchorKey));
        }
        if (selfLoop && view.defaultLinkShape() == GLink.SHAPE_ELBOW && startElement.getAnchor(startAnchorKey).equals(anchor)) {
            linkElement = linkArc;
        } else if (view.defaultLinkShape() == GLink.SHAPE_ELBOW)
            linkElement = linkElbow;
        else if (view.defaultLinkShape() == GLink.SHAPE_ARC)
            linkElement = linkArc;
    }
    setLinkSelfLoop(selfLoop);
    linkElement.update();
}
Also used : Anchor2D(org.antlr.xjlib.appkit.gview.base.Anchor2D) GElement(org.antlr.xjlib.appkit.gview.object.GElement) GLink(org.antlr.xjlib.appkit.gview.object.GLink)

Aggregations

GLink (org.antlr.xjlib.appkit.gview.object.GLink)4 GElement (org.antlr.xjlib.appkit.gview.object.GElement)3 Vector2D (org.antlr.xjlib.appkit.gview.base.Vector2D)2 Anchor2D (org.antlr.xjlib.appkit.gview.base.Anchor2D)1 SLinkElbow (org.antlr.xjlib.appkit.gview.shape.SLinkElbow)1