Search in sources :

Example 1 with Vector2D

use of org.antlr.xjlib.appkit.gview.base.Vector2D 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 Vector2D

use of org.antlr.xjlib.appkit.gview.base.Vector2D in project antlrworks by antlr.

the class GDOTImporterDOT method parseControlPoints.

public Vector2D[] parseControlPoints(String s) throws IOException {
    // e,56,216 51,34 43,44 33,58 29,72 15,118 20,134 36,180 39,190 45,199 50,208
    List<Vector2D> points = new ArrayList<Vector2D>();
    Vector2D endPoint = null;
    String[] pts = parseTokens(s);
    int index = -1;
    while (++index < pts.length) {
        if (pts[index].equals("e")) {
            // Arrow at the end
            if (index + 2 >= pts.length) {
                System.err.println(String.format("Expected x arrow position at %d but reached the end at %d", index + 2, pts.length));
                continue;
            }
            if (index + 4 >= pts.length) {
                System.err.println(String.format("Expected y arrow position at %d but reached the end at %d", index + 4, pts.length));
                continue;
            }
            String x = pts[index += 2];
            String y = pts[index += 2];
            endPoint = new Vector2D(Float.parseFloat(x), height - Float.parseFloat(y));
        } else if (isFloatString(pts[index]) && index + 2 < pts.length && isFloatString(pts[index + 2])) {
            // Assume pair of numbers
            if (index + 2 >= pts.length) {
                System.err.println(String.format("Expected y position at %d but reached the end at %d", index + 2, pts.length));
                continue;
            }
            String x = pts[index];
            String y = pts[index += 2];
            points.add(new Vector2D(Float.parseFloat(x), height - Float.parseFloat(y)));
        }
    }
    if (endPoint != null)
        points.add(endPoint);
    Vector2D[] p = new Vector2D[points.size()];
    for (int i = 0; i < points.size(); i++) {
        p[i] = points.get(i);
    }
    return p;
}
Also used : Vector2D(org.antlr.xjlib.appkit.gview.base.Vector2D) ArrayList(java.util.ArrayList)

Example 3 with Vector2D

use of org.antlr.xjlib.appkit.gview.base.Vector2D 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 4 with Vector2D

use of org.antlr.xjlib.appkit.gview.base.Vector2D in project antlrworks by antlr.

the class SArrow method draw.

public void draw(Graphics g) {
    if (direction == null || anchor == null)
        return;
    Vector2D v = direction.copy();
    v.setLength(length);
    v.rotate(angle * 0.5);
    g.drawLine((int) anchor.getX(), (int) anchor.getY(), (int) (anchor.getX() + v.getX()), (int) (anchor.getY() + v.getY()));
    v.rotate(-angle);
    g.drawLine((int) anchor.getX(), (int) anchor.getY(), (int) (anchor.getX() + v.getX()), (int) (anchor.getY() + v.getY()));
}
Also used : Vector2D(org.antlr.xjlib.appkit.gview.base.Vector2D)

Example 5 with Vector2D

use of org.antlr.xjlib.appkit.gview.base.Vector2D in project antlrworks by antlr.

the class SLinkBezier method relToAbs.

public Vector2D relToAbs(Vector2D p, int mode) {
    if (selfLoop) {
        return start.add(p);
    } else {
        Vector2D nz = end.sub(start);
        double f = nz.length() / originalZLength;
        double lb = p.getX();
        double lc = p.getY();
        if (mode == MODE_END) {
            // End-point is always at the same relative position
            return end.add(originalEndPointOffset);
        } else {
            if (mode == MODE_NOSTRETCH)
                f = 1;
            Vector2D nb = nz.normalize().setLength(f * lb);
            Vector2D nc = nz.copy().rotate(-90).normalize().setLength(lc);
            return start.add(nb.add(nc));
        }
    }
}
Also used : Vector2D(org.antlr.xjlib.appkit.gview.base.Vector2D)

Aggregations

Vector2D (org.antlr.xjlib.appkit.gview.base.Vector2D)40 GElement (org.antlr.xjlib.appkit.gview.object.GElement)2 GLink (org.antlr.xjlib.appkit.gview.object.GLink)2 QuadCurve2D (java.awt.geom.QuadCurve2D)1 ArrayList (java.util.ArrayList)1