Search in sources :

Example 16 with Vector2D

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

the class GEventDragElement method mouseDragged.

public void mouseDragged(MouseEvent e, Point mousePosition) {
    if (dragElement != null) {
        Vector2D mouse = Vector2D.vector(mousePosition);
        Vector2D position = mouse.sub(dragElementOffset);
        view.showAndAjustPositionToMagnetics(position);
        dragElement.moveToPosition(position);
        delegate.eventChangeDone();
        delegate.eventShouldRepaint();
    } else if (dragging) {
        p2 = mousePosition;
        delegate.eventMoveSelectedElements(p2.x - p1.x, p2.y - p1.y);
        p1 = p2;
        delegate.eventChangeDone();
        delegate.eventShouldRepaint();
    }
}
Also used : Vector2D(org.antlr.xjlib.appkit.gview.base.Vector2D)

Example 17 with Vector2D

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

the class GElement method drag.

public void drag(Vector2D p) {
    double dx = 0;
    double dy = 0;
    if (oldPosition == null) {
        oldPosition = new Vector2D();
    } else {
        dx = p.x - oldPosition.x;
        dy = p.y - oldPosition.y;
    }
    oldPosition.x = p.x;
    oldPosition.y = p.y;
    move(dx, dy);
}
Also used : Vector2D(org.antlr.xjlib.appkit.gview.base.Vector2D)

Example 18 with Vector2D

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

the class GElement method dragElementPosition.

public Vector2D dragElementPosition(Vector2D p) {
    Vector2D ep = p.copy();
    if (oldPosition != null) {
        ep.x += p.x - oldPosition.x;
        ep.y += p.y - oldPosition.y;
    }
    return ep;
}
Also used : Vector2D(org.antlr.xjlib.appkit.gview.base.Vector2D)

Example 19 with Vector2D

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

the class GElementArrow method setTarget.

public void setTarget(double x, double y) {
    arrow.setAnchor(x, y);
    target = new Vector2D(x, y);
    Vector2D direction = getPosition().sub(target);
    arrow.setDirection(direction);
}
Also used : Vector2D(org.antlr.xjlib.appkit.gview.base.Vector2D)

Example 20 with Vector2D

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

the class SLinkArc method update.

public void update() {
    if (selfLoop) {
        if (cubic == null)
            cubic = new CubicCurve2D.Double();
        Vector2D corde = direction.copy();
        corde.stretch(1.7);
        if (corde.length() < 100)
            corde.setLength(100);
        corde.rotate(-40);
        cubic.ctrlx1 = getStartWithOffset().getX() + corde.getX();
        cubic.ctrly1 = getStartWithOffset().getY() + corde.getY();
        corde.rotate(+80);
        cubic.ctrlx2 = getStartWithOffset().getX() + corde.getX();
        cubic.ctrly2 = getStartWithOffset().getY() + corde.getY();
        // Move the start/end point according to offset
        Vector2D v1 = new Vector2D(cubic.ctrlx1, cubic.ctrly1).sub(getStartWithOffset());
        Vector2D v2 = new Vector2D(cubic.ctrlx2, cubic.ctrly2).sub(getStartWithOffset());
        v1 = v1.normalize();
        v1.stretch(startTangentOffset);
        v2 = v2.normalize();
        v2.stretch(endTangentOffset);
        cubic.x1 = getStartWithOffset().getX() + v1.getX();
        cubic.y1 = getStartWithOffset().getY() + v1.getY();
        cubic.x2 = getEndWithOffset().getX() + v2.getX();
        cubic.y2 = getEndWithOffset().getY() + v2.getY();
        // Position of the label
        Vector2D vlabel = direction.copy();
        vlabel.setLength(vlabel.length() + 15);
        if (vlabel.length() < 75)
            vlabel.setLength(75);
        Vector2D plabel = getStartWithOffset().add(vlabel);
        label.setPosition(plabel);
        // Create the arrow at the end of the path
        arrow.setAnchor(cubic.x2, cubic.y2);
        arrow.setDirection(new Vector2D(cubic.ctrlx2 - cubic.x2, cubic.ctrly2 - cubic.y2));
        shape = cubic;
    } else {
        Vector2D middle = getEndWithOffset().sub(getStartWithOffset());
        middle.stretch(0.5);
        Vector2D height = middle.normalize();
        height.rotate(-90);
        if (flateness == 0)
            height.setLength(0.01);
        else
            height.setLength(flateness);
        Vector2D ctrl = middle.add(height);
        if (quad == null)
            quad = new QuadCurve2D.Double();
        quad.x1 = getStartWithOffset().getX();
        quad.y1 = getStartWithOffset().getY();
        quad.x2 = getEndWithOffset().getX();
        quad.y2 = getEndWithOffset().getY();
        quad.ctrlx = getStartWithOffset().getX() + ctrl.getX();
        quad.ctrly = getStartWithOffset().getY() + ctrl.getY();
        Vector2D controlPoint = new Vector2D(quad.ctrlx, quad.ctrly);
        // Move the start/end point according to offset
        Vector2D v1 = controlPoint.sub(getStartWithOffset());
        Vector2D v2 = controlPoint.sub(getEndWithOffset());
        v1 = v1.normalize();
        v1.stretch(startTangentOffset);
        v2 = v2.normalize();
        v2.stretch(endTangentOffset);
        quad.x1 = getStartWithOffset().getX() + v1.getX();
        quad.y1 = getStartWithOffset().getY() + v1.getY();
        quad.x2 = getEndWithOffset().getX() + v2.getX();
        quad.y2 = getEndWithOffset().getY() + v2.getY();
        // Position of the label
        pmiddle = new Vector2D(quad.x1 + (quad.x2 - quad.x1) * 0.5, quad.y1 + (quad.y2 - quad.y1) * 0.5);
        vlabel = new Vector2D(quad.x2 - quad.x1, quad.y2 - quad.y1).rotate(90 * (flateness < 0 ? 1 : -1));
        vlabel.setLength(Math.abs(flateness) * 0.5 + 20);
        label.setPosition(pmiddle.add(vlabel));
        // Create the arrow at the end of the path
        arrow.setAnchor(quad.x2, quad.y2);
        arrow.setDirection(controlPoint.sub(getEndWithOffset()));
        shape = quad;
    }
}
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