Search in sources :

Example 1 with Anchor2D

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

the class GElement method setAnchor.

public void setAnchor(String key, Vector2D position, Vector2D direction) {
    Anchor2D anchor = getAnchor(key);
    if (anchor == null) {
        anchor = new Anchor2D();
        anchors.put(key, anchor);
    }
    anchor.setPosition(position);
    anchor.setDirection(direction);
}
Also used : Anchor2D(org.antlr.xjlib.appkit.gview.base.Anchor2D)

Example 2 with Anchor2D

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

the class GElement method getAnchorClosestToPoint.

public Anchor2D getAnchorClosestToPoint(Point p) {
    double smallest_distance = Integer.MAX_VALUE;
    Anchor2D closest_anchor = null;
    for (Anchor2D anchor : anchors.values()) {
        double dx = anchor.position.getX() - p.x;
        double dy = anchor.position.getY() - p.y;
        double d = Math.sqrt(dx * dx + dy * dy);
        if (d < smallest_distance) {
            smallest_distance = d;
            closest_anchor = anchor;
        }
    }
    return closest_anchor;
}
Also used : Anchor2D(org.antlr.xjlib.appkit.gview.base.Anchor2D)

Example 3 with Anchor2D

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

Anchor2D (org.antlr.xjlib.appkit.gview.base.Anchor2D)3 GElement (org.antlr.xjlib.appkit.gview.object.GElement)1 GLink (org.antlr.xjlib.appkit.gview.object.GLink)1