Search in sources :

Example 71 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class LevelXing method drawEditControls.

public void drawEditControls(Graphics2D g2) {
    Point2D pt = getCoordsCenter();
    g2.setColor(defaultTrackColor);
    g2.draw(layoutEditor.trackControlPointRectAt(pt));
    pt = getCoordsA();
    if (getConnectA() == null) {
        g2.setColor(Color.magenta);
    } else {
        g2.setColor(Color.blue);
    }
    g2.draw(layoutEditor.trackControlPointRectAt(pt));
    pt = getCoordsB();
    if (getConnectB() == null) {
        g2.setColor(Color.red);
    } else {
        g2.setColor(Color.green);
    }
    g2.draw(layoutEditor.trackControlPointRectAt(pt));
    pt = getCoordsC();
    if (getConnectC() == null) {
        g2.setColor(Color.magenta);
    } else {
        g2.setColor(Color.blue);
    }
    g2.draw(layoutEditor.trackControlPointRectAt(pt));
    pt = getCoordsD();
    if (getConnectD() == null) {
        g2.setColor(Color.red);
    } else {
        g2.setColor(Color.green);
    }
    g2.draw(layoutEditor.trackControlPointRectAt(pt));
}
Also used : Point2D(java.awt.geom.Point2D)

Example 72 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class TrackSegment method getBounds.

/**
     * @return the bounds of this track segment
     */
public Rectangle2D getBounds() {
    Rectangle2D result;
    Point2D ep1 = layoutEditor.getCoords(getConnect1(), getType1());
    result = new Rectangle2D.Double(ep1.getX(), ep1.getY(), 0, 0);
    Point2D ep2 = layoutEditor.getCoords(getConnect2(), getType2());
    result.add(ep2);
    return result;
}
Also used : Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D)

Example 73 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class TrackSegment method drawDashed.

// drawHidden(Graphics2D g2)
public void drawDashed(Graphics2D g2, boolean mainline) {
    if ((!isHidden()) && getDashed() && (mainline == getMainline())) {
        setColorForTrackBlock(g2, getLayoutBlock());
        float trackWidth = layoutEditor.setTrackStrokeWidth(g2, mainline);
        if (getArc()) {
            calculateTrackSegmentAngle();
            Stroke originalStroke = g2.getStroke();
            Stroke drawingStroke = new BasicStroke(trackWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 9 }, 0);
            g2.setStroke(drawingStroke);
            g2.draw(new Arc2D.Double(getCX(), getCY(), getCW(), getCH(), getStartadj(), getTmpAngle(), Arc2D.OPEN));
            g2.setStroke(originalStroke);
        } else if (getBezier()) {
            Stroke originalStroke = g2.getStroke();
            Stroke drawingStroke = new BasicStroke(trackWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 9 }, 0);
            g2.setStroke(drawingStroke);
            Point2D pt1 = layoutEditor.getCoords(getConnect1(), getType1());
            Point2D pt2 = layoutEditor.getCoords(getConnect2(), getType2());
            int cnt = bezierControlPoints.size();
            Point2D[] points = new Point2D[cnt + 2];
            points[0] = pt1;
            for (int idx = 0; idx < cnt; idx++) {
                points[idx + 1] = bezierControlPoints.get(idx);
            }
            points[cnt + 1] = pt2;
            MathUtil.drawBezier(g2, points);
            g2.setStroke(originalStroke);
        } else {
            Point2D end1 = layoutEditor.getCoords(getConnect1(), getType1());
            Point2D end2 = layoutEditor.getCoords(getConnect2(), getType2());
            double delX = end1.getX() - end2.getX();
            double delY = end1.getY() - end2.getY();
            double cLength = Math.hypot(delX, delY);
            // note: The preferred dimension of a dash (solid + blank space) is
            //         5 * the track width - about 60% solid and 40% blank.
            int nDashes = (int) (cLength / ((trackWidth) * 5.0));
            if (nDashes < 3) {
                nDashes = 3;
            }
            double delXDash = -delX / ((nDashes) - 0.5);
            double delYDash = -delY / ((nDashes) - 0.5);
            double begX = end1.getX();
            double begY = end1.getY();
            for (int k = 0; k < nDashes; k++) {
                g2.draw(new Line2D.Double(new Point2D.Double(begX, begY), new Point2D.Double(begX + (delXDash * 0.5), begY + (delYDash * 0.5))));
                begX += delXDash;
                begY += delYDash;
            }
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Point2D(java.awt.geom.Point2D) Arc2D(java.awt.geom.Arc2D)

Example 74 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class TrackSegment method getCentreSeg.

public Point2D getCentreSeg() {
    Point2D result = MathUtil.zeroPoint2D();
    if ((null != connect1) && (null != connect2)) {
        // get the end points
        Point2D ep1 = layoutEditor.getCoords(getConnect1(), getType1());
        Point2D ep2 = layoutEditor.getCoords(getConnect2(), getType2());
        if (getCircle()) {
            //TODO: do something here?
            //} else if (getArc()) {
            //TODO: do something here?
            result = center;
        } else if (getBezier()) {
            //compute result Bezier point for (t == 0.5);
            // copy all the control points (including end points) into an array
            int len = bezierControlPoints.size() + 2;
            Point2D[] points = new Point2D[len];
            points[0] = ep1;
            for (int idx = 1; idx < len - 1; idx++) {
                points[idx] = getBezierControlPoint(idx - 1);
            }
            points[len - 1] = ep2;
            // calculate midpoints of all points (len - 1 order times)
            for (int idx = len - 1; idx > 0; idx--) {
                for (int jdx = 0; jdx < idx; jdx++) {
                    points[jdx] = MathUtil.midPoint(points[jdx], points[jdx + 1]);
                }
            }
            result = points[0];
        } else {
            result = MathUtil.midPoint(ep1, ep2);
        }
        center = result;
    }
    return result;
}
Also used : Point2D(java.awt.geom.Point2D)

Example 75 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class TrackSegment method addBezierControlPointBefore.

private void addBezierControlPointBefore(int index) {
    Point2D addPoint = getBezierControlPoint(index);
    if (index > 0) {
        addPoint = MathUtil.midPoint(getBezierControlPoint(index - 1), addPoint);
    } else {
        Point2D ep1 = layoutEditor.getCoords(getConnect1(), getType1());
        addPoint = MathUtil.midPoint(ep1, addPoint);
    }
    bezierControlPoints.add(index, addPoint);
    layoutEditor.redrawPanel();
    layoutEditor.setDirty();
}
Also used : Point2D(java.awt.geom.Point2D)

Aggregations

Point2D (java.awt.geom.Point2D)193 Color (java.awt.Color)22 Rectangle2D (java.awt.geom.Rectangle2D)20 RadialGradientPaint (java.awt.RadialGradientPaint)19 Graphics2D (java.awt.Graphics2D)18 Point (java.awt.Point)18 Paint (java.awt.Paint)17 Line2D (java.awt.geom.Line2D)12 AffineTransform (java.awt.geom.AffineTransform)11 Rectangle (java.awt.Rectangle)9 BasicStroke (java.awt.BasicStroke)8 Stroke (java.awt.Stroke)8 Ellipse2D (java.awt.geom.Ellipse2D)8 BufferedImage (java.awt.image.BufferedImage)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 Element (org.jdom2.Element)6 GradientPaint (java.awt.GradientPaint)5 Arc2D (java.awt.geom.Arc2D)5 GeneralPath (java.awt.geom.GeneralPath)5