Search in sources :

Example 36 with Path2D

use of java.awt.geom.Path2D in project triplea by triplea-game.

the class MapRouteDrawer method drawCurvedPath.

/**
 * Draws a smooth curve through the given array of points
 *
 * <p>
 * This algorithm is called Spline-Interpolation
 * because the Apache-commons-math library we are using here does not accept
 * values but {@code f(x)=y} with x having to increase all the time
 * the idea behind this is to use a parameter array - the so called index
 * as x array and splitting the points into a x and y coordinates array.
 * </p>
 *
 * <p>
 * Finally those 2 interpolated arrays get unified into a single {@linkplain Point2D} array and drawn to the Map
 * </p>
 *
 * @param graphics The {@linkplain Graphics2D} Object to be drawn on
 * @param points The Knot Points for the Spline-Interpolator aka the joints
 */
private void drawCurvedPath(final Graphics2D graphics, final Point2D[] points) {
    final double[] index = createParameterizedIndex(points);
    final PolynomialSplineFunction xcurve = splineInterpolator.interpolate(index, getValues(points, Point2D::getX));
    final double[] xcoords = getCoords(xcurve, index);
    final PolynomialSplineFunction ycurve = splineInterpolator.interpolate(index, getValues(points, Point2D::getY));
    final double[] ycoords = getCoords(ycurve, index);
    final List<Path2D> paths = routeCalculator.getAllNormalizedLines(xcoords, ycoords);
    for (final Path2D path : paths) {
        drawTransformedShape(graphics, path);
    }
    // draws the Line to the Cursor on every possible screen, so that the line ends at the cursor no matter what...
    final List<Point2D[]> finishingPoints = routeCalculator.getAllPoints(new Point2D.Double(xcoords[xcoords.length - 1], ycoords[ycoords.length - 1]), points[points.length - 1]);
    final boolean hasArrowEnoughSpace = points[points.length - 2].distance(points[points.length - 1]) > ARROW_LENGTH;
    for (final Point2D[] finishingPointArray : finishingPoints) {
        drawTransformedShape(graphics, new Line2D.Double(finishingPointArray[0], finishingPointArray[1]));
        if (hasArrowEnoughSpace) {
            drawArrow(graphics, finishingPointArray[0], finishingPointArray[1]);
        }
    }
}
Also used : Point2D(java.awt.geom.Point2D) Path2D(java.awt.geom.Path2D) PolynomialSplineFunction(org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction) Line2D(java.awt.geom.Line2D)

Example 37 with Path2D

use of java.awt.geom.Path2D in project Digital by hneemann.

the class GraphicSwing method drawPolygon.

@Override
public void drawPolygon(Polygon p, Style style) {
    applyStyle(style);
    Path2D path = new GeneralPath();
    // CHECKSTYLE.OFF: ModifiedControlVariable
    for (int i = 0; i < p.size(); i++) {
        if (i == 0) {
            path.moveTo(p.get(i).getXFloat(), p.get(i).getYFloat());
        } else {
            if (p.isBezierStart(i)) {
                path.curveTo(p.get(i).getXFloat(), p.get(i).getYFloat(), p.get(i + 1).getXFloat(), p.get(i + 1).getYFloat(), p.get(i + 2).getXFloat(), p.get(i + 2).getYFloat());
                i += 2;
            } else
                path.lineTo(p.get(i).getXFloat(), p.get(i).getYFloat());
        }
    }
    if (p.isClosed())
        path.closePath();
    if (style.isFilled() && p.isClosed())
        gr.fill(path);
    if (style.getThickness() > 0)
        gr.draw(path);
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Path2D(java.awt.geom.Path2D)

Example 38 with Path2D

use of java.awt.geom.Path2D in project Activiti by Activiti.

the class DefaultProcessDiagramCanvas method drawTextAnnotation.

public void drawTextAnnotation(String id, String text, GraphicInfo graphicInfo) {
    int x = (int) graphicInfo.getX();
    int y = (int) graphicInfo.getY();
    int width = (int) graphicInfo.getWidth();
    int height = (int) graphicInfo.getHeight();
    Font originalFont = g.getFont();
    Stroke originalStroke = g.getStroke();
    g.setFont(ANNOTATION_FONT);
    Path2D path = new Path2D.Double();
    x += .5;
    int lineLength = 18;
    path.moveTo(x + lineLength, y);
    path.lineTo(x, y);
    path.lineTo(x, y + height);
    path.lineTo(x + lineLength, y + height);
    path.lineTo(x + lineLength, y + height - 1);
    path.lineTo(x + 1, y + height - 1);
    path.lineTo(x + 1, y + 1);
    path.lineTo(x + lineLength, y + 1);
    path.closePath();
    g.draw(path);
    int boxWidth = width - (2 * ANNOTATION_TEXT_PADDING);
    int boxHeight = height - (2 * ANNOTATION_TEXT_PADDING);
    int boxX = x + width / 2 - boxWidth / 2;
    int boxY = y + height / 2 - boxHeight / 2;
    if (text != null && !text.isEmpty()) {
        drawMultilineAnnotationText(text, boxX, boxY, boxWidth, boxHeight);
    }
    // restore originals
    g.setFont(originalFont);
    g.setStroke(originalStroke);
    // set element's id
    g.setCurrentGroupId(id);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) Path2D(java.awt.geom.Path2D) Point(java.awt.Point) Paint(java.awt.Paint) Font(java.awt.Font)

Example 39 with Path2D

use of java.awt.geom.Path2D in project java-swing-tips by aterai.

the class ArrowToggleButtonBarCellIcon method makeShape.

protected Shape makeShape(Container parent, Component c, int x, int y) {
    int w = c.getWidth() - 1;
    int h = c.getHeight() - 1;
    double h2 = Math.round(h * .5);
    double w2 = TH;
    Path2D p = new Path2D.Double();
    p.moveTo(0d, 0d);
    p.lineTo(w - w2, 0d);
    p.lineTo(w, h2);
    p.lineTo(w - w2, h);
    p.lineTo(0d, h);
    if (!Objects.equals(c, parent.getComponent(0))) {
        p.lineTo(w2, h2);
    }
    p.closePath();
    return AffineTransform.getTranslateInstance(x, y).createTransformedShape(p);
}
Also used : Path2D(java.awt.geom.Path2D)

Example 40 with Path2D

use of java.awt.geom.Path2D in project java-swing-tips by aterai.

the class Arrow method makeArrowHead.

protected Path2D makeArrowHead(Dimension size) {
    Path2D path = new Path2D.Double();
    double t = size.height;
    double w = size.width * .5;
    path.moveTo(0d, -w);
    path.lineTo(t, 0d);
    path.lineTo(0d, w);
    path.closePath();
    return path;
}
Also used : Path2D(java.awt.geom.Path2D)

Aggregations

Path2D (java.awt.geom.Path2D)126 Point2D (java.awt.geom.Point2D)20 Area (java.awt.geom.Area)16 Rectangle2D (java.awt.geom.Rectangle2D)13 Shape (java.awt.Shape)9 Point (java.awt.Point)8 Line2D (java.awt.geom.Line2D)8 PathIterator (java.awt.geom.PathIterator)8 ArrayList (java.util.ArrayList)8 AffineTransform (java.awt.geom.AffineTransform)7 GeneralPath (java.awt.geom.GeneralPath)7 Color (java.awt.Color)6 Graphics2D (java.awt.Graphics2D)6 Paint (java.awt.Paint)6 ShapeRoi (ij.gui.ShapeRoi)5 BasicStroke (java.awt.BasicStroke)4 RadialGradientPaint (java.awt.RadialGradientPaint)4 Point2D_F64 (georegression.struct.point.Point2D_F64)3 RoundRectangle2D (java.awt.geom.RoundRectangle2D)3 Vector2D (de.gurkenlabs.litiengine.util.geom.Vector2D)2