Search in sources :

Example 41 with GeneralPath

use of java.awt.geom.GeneralPath in project vcell by virtualcell.

the class RuleParticipantEdgeDiagramShape method paintSelf.

@Override
public void paintSelf(Graphics2D g2D, int parentOffsetX, int parentOffsetY) {
    // draw cubic spline with horizontal reactant-end (p' = 0) at reaction
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    CubicCurve2D.Double cubicCurve = getCurve();
    // render curve (make CatalystShapes draw with a dashed line)
    g2D.setColor(forgroundColor);
    if (getLineStyle() == LINE_STYLE_DASHED) {
        Stroke oldStroke = g2D.getStroke();
        g2D.setStroke(DASHED_STROKE);
        g2D.draw(cubicCurve);
        g2D.setStroke(oldStroke);
    } else {
        g2D.draw(cubicCurve);
    }
    int arrowDirection = 0;
    if (this instanceof ProductPatternEdgeDiagramShape) {
        arrowDirection = 1;
    }
    if (this instanceof ReactantPatternEdgeDiagramShape) {
        arrowDirection = -1;
    }
    if (arrowDirection == 1) {
        double arcLength = integrateArcLength(cubicCurve, 0.0, 1.0, 10);
        double centerT = getParameterAtArcLength(cubicCurve, 0.0, 1.0, arcLength / 2, 20);
        Point2D center = evaluate(cubicCurve, centerT);
        double backT = intersectWithCircle(cubicCurve, centerT, 1.0, center.getX(), center.getY(), 4);
        Point2D back = evaluate(cubicCurve, backT);
        double frontT = intersectWithCircle(cubicCurve, centerT, 0.0, center.getX(), center.getY(), 4);
        Point2D front = evaluate(cubicCurve, frontT);
        GeneralPath arrow = getArrow(front, back, 7);
        g2D.fill(arrow);
    }
    if (arrowDirection == -1) {
        double arcLength = integrateArcLength(cubicCurve, 0.0, 1.0, 10);
        double centerT = getParameterAtArcLength(cubicCurve, 0.0, 1.0, arcLength / 2 + 2, 20);
        Point2D center = evaluate(cubicCurve, centerT);
        double backT = intersectWithCircle(cubicCurve, centerT, 0.0, center.getX(), center.getY(), 4);
        Point2D back = evaluate(cubicCurve, backT);
        double frontT = intersectWithCircle(cubicCurve, centerT, 1.0, center.getX(), center.getY(), 4);
        Point2D front = evaluate(cubicCurve, frontT);
        GeneralPath arrow = getArrow(front, back, 7);
        g2D.fill(arrow);
    }
    // draw label
    if (getLabel() != null && getLabel().length() > 0) {
        g2D.drawString(getLabel(), (start.x + end.x) / 2, (start.y + end.y) / 2);
    }
    return;
}
Also used : Stroke(java.awt.Stroke) GeneralPath(java.awt.geom.GeneralPath) Point2D(java.awt.geom.Point2D) CubicCurve2D(java.awt.geom.CubicCurve2D) Point(java.awt.Point)

Example 42 with GeneralPath

use of java.awt.geom.GeneralPath in project vcell by virtualcell.

the class EdgeShape method getArrow.

protected static GeneralPath getArrow(Point2D front, Point2D back, double width) {
    double deltaX = back.getX() - front.getX();
    double deltaY = back.getY() - front.getY();
    double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
    // take straight-line approximation for direction (given right.p1 and
    // right.p2 as end points)
    // use 10 and 30 "pixels" away for the arrowhead.
    double X1 = front.getX();
    double Y1 = front.getY();
    double X2 = front.getX() + 1.0 * deltaX;
    double Y2 = front.getY() + 1.0 * deltaY;
    double X3 = X2 + 0.5 * width * deltaY / distance;
    double Y3 = Y2 - 0.5 * width * deltaX / distance;
    double X4 = X2 - 0.5 * width * deltaY / distance;
    double Y4 = Y2 + 0.5 * width * deltaX / distance;
    GeneralPath arrow = new GeneralPath();
    arrow.moveTo((float) X1, (float) Y1);
    arrow.lineTo((float) X3, (float) Y3);
    arrow.lineTo((float) X4, (float) Y4);
    arrow.lineTo((float) X1, (float) Y1);
    arrow.setWindingRule(GeneralPath.WIND_NON_ZERO);
    return arrow;
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 43 with GeneralPath

use of java.awt.geom.GeneralPath in project vcell by virtualcell.

the class ArrowPainter method getArrow.

public static GeneralPath getArrow(Point2D front, Point2D back, double width) {
    double deltaX = back.getX() - front.getX();
    double deltaY = back.getY() - front.getY();
    double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
    double X1 = front.getX();
    double Y1 = front.getY();
    double X2 = front.getX() + 1.5 * deltaX;
    double Y2 = front.getY() + 1.5 * deltaY;
    double X3 = X2 + 0.5 * width * deltaY / distance;
    double Y3 = Y2 - 0.5 * width * deltaX / distance;
    double X4 = X2 - 0.5 * width * deltaY / distance;
    double Y4 = Y2 + 0.5 * width * deltaX / distance;
    GeneralPath arrow = new GeneralPath();
    arrow.moveTo((float) X1, (float) Y1);
    arrow.lineTo((float) X3, (float) Y3);
    arrow.lineTo((float) X4, (float) Y4);
    arrow.lineTo((float) X1, (float) Y1);
    arrow.setWindingRule(GeneralPath.WIND_NON_ZERO);
    return arrow;
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 44 with GeneralPath

use of java.awt.geom.GeneralPath in project vcell by virtualcell.

the class OverlayEditorPanelJAI method placeMarkerOverResolved.

public void placeMarkerOverResolved(CoordinateIndex ci, int starSize) {
    if (ci == null) {
        imagePane.drawStar(null);
        return;
    }
    zSlider.setValue(ci.z);
    GeneralPath generalPath = new GeneralPath();
    generalPath.moveTo((float) (ci.x - starSize), (float) ci.y);
    generalPath.lineTo((float) (ci.x + starSize), (float) ci.y);
    generalPath.moveTo((float) (ci.x), (float) (ci.y - starSize));
    generalPath.lineTo((float) (ci.x), (float) (ci.y + starSize));
    generalPath.moveTo((float) (ci.x - starSize), (float) (ci.y - starSize));
    generalPath.lineTo((float) (ci.x + starSize), (float) (ci.y + starSize));
    generalPath.moveTo((float) (ci.x - starSize), (float) (ci.y + starSize));
    generalPath.lineTo((float) (ci.x + starSize), (float) (ci.y - starSize));
    imagePane.drawStar(generalPath);
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 45 with GeneralPath

use of java.awt.geom.GeneralPath in project vcell by virtualcell.

the class WorkflowEdgeShape method paintSelf.

@Override
public void paintSelf(Graphics2D g2D, int absPosX, int absPosY) {
    super.paintSelf(g2D, absPosX, absPosY);
    // 
    if (bArrow) {
        Point startLocation = getNode1Shape().getAttachmentLocation(Shape.ATTACH_CENTER);
        startLocation.translate(getNode1Shape().getRelX(), getNode1Shape().getRelY());
        Point endLocation = getNode2Shape().getAttachmentLocation(Shape.ATTACH_CENTER);
        endLocation.translate(getNode2Shape().getRelX(), getNode2Shape().getRelY());
        double diffX = endLocation.x - startLocation.x;
        double diffY = endLocation.y - startLocation.y;
        double length = Math.sqrt(diffX * diffX + diffY * diffY);
        if (length == 0) {
            length = 1;
        }
        double arrowScale = 10 / length;
        Point front = new Point((int) (startLocation.x + diffX / 2 + diffX * arrowScale / 2), (int) (startLocation.y + diffY / 2 + diffY * arrowScale / 2));
        Point back = new Point((int) (startLocation.x + diffX / 2 - diffX * arrowScale / 2), (int) (startLocation.y + diffY / 2 - diffY * arrowScale / 2));
        GeneralPath path = getArrow(front, back, 10);
        g2D.fill(path);
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Point(java.awt.Point)

Aggregations

GeneralPath (java.awt.geom.GeneralPath)96 Point (java.awt.Point)14 AffineTransform (java.awt.geom.AffineTransform)14 PathIterator (java.awt.geom.PathIterator)14 Graphics2D (java.awt.Graphics2D)8 Rectangle2D (java.awt.geom.Rectangle2D)8 Color (java.awt.Color)7 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)6 Point2D (java.awt.geom.Point2D)6 Stroke (java.awt.Stroke)5 Area (java.awt.geom.Area)4 Shape (java.awt.Shape)3 CubicCurve2D (java.awt.geom.CubicCurve2D)3 LayoutPathImpl (sun.font.LayoutPathImpl)3 GradientPaint (java.awt.GradientPaint)2 Rectangle (java.awt.Rectangle)2 Line2D (java.awt.geom.Line2D)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 JBColor (com.intellij.ui.JBColor)1