Search in sources :

Example 71 with Path2D

use of java.awt.geom.Path2D in project jdk8u_jdk by JetBrains.

the class Test7019861 method getPath.

private static Path2D getPath(int x, int y, int len) {
    Path2D p = new Path2D.Double();
    p.moveTo(x, y);
    p.quadTo(x + len, y, x + len, y + len);
    return p;
}
Also used : Path2D(java.awt.geom.Path2D)

Example 72 with Path2D

use of java.awt.geom.Path2D in project poi by apache.

the class TestPresetGeometries method testRead.

@Test
public void testRead() {
    Map<String, CustomGeometry> shapes = PresetGeometries.getInstance();
    assertEquals(187, shapes.size());
    for (String name : shapes.keySet()) {
        CustomGeometry geom = shapes.get(name);
        Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), new IAdjustableShape() {

            @Override
            public Guide getAdjustValue(String presetName) {
                return null;
            }
        });
        for (Path p : geom) {
            Path2D path = p.getPath(ctx);
            assertNotNull(path);
        }
    }
    // we get the same instance on further calls
    assertTrue(shapes == PresetGeometries.getInstance());
}
Also used : Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D) Test(org.junit.Test)

Example 73 with Path2D

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

the class TitledBorder2 method paintBorder.

/**
     * Paints the border for the specified component with the
     * specified position and size.
     * @param c the component for which this border is being painted
     * @param g the paint graphics
     * @param x the x position of the painted border
     * @param y the y position of the painted border
     * @param width the width of the painted border
     * @param height the height of the painted border
     */
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Border border = getBorder();
    String title = getTitle();
    if (Objects.nonNull(title) && !title.isEmpty()) {
        int edge = border instanceof TitledBorder2 ? 0 : EDGE_SPACING;
        JLabel label = getLabel(c);
        Dimension size = label.getPreferredSize();
        Insets insets = makeBorderInsets(border, c, new Insets(0, 0, 0, 0));
        int borderX = x + edge;
        int borderY = y + edge;
        int borderW = width - edge - edge;
        int borderH = height - edge - edge;
        int labelY = y;
        int labelH = size.height;
        int position = getPosition();
        switch(position) {
            case ABOVE_TOP:
                insets.left = 0;
                insets.right = 0;
                borderY += labelH - edge;
                borderH -= labelH - edge;
                break;
            case TOP:
                insets.top = edge + insets.top / 2 - labelH / 2;
                if (insets.top < edge) {
                    borderY -= insets.top;
                    borderH += insets.top;
                } else {
                    labelY += insets.top;
                }
                break;
            case BELOW_TOP:
                labelY += insets.top + edge;
                break;
            case ABOVE_BOTTOM:
                labelY += height - labelH - insets.bottom - edge;
                break;
            case BOTTOM:
                labelY += height - labelH;
                insets.bottom = edge + (insets.bottom - labelH) / 2;
                if (insets.bottom < edge) {
                    borderH += insets.bottom;
                } else {
                    labelY -= insets.bottom;
                }
                break;
            case BELOW_BOTTOM:
                insets.left = 0;
                insets.right = 0;
                labelY += height - labelH;
                borderH -= labelH - edge;
                break;
            default:
        }
        insets.left += edge + TEXT_INSET_H;
        insets.right += edge + TEXT_INSET_H;
        int labelX = x;
        int labelW = width - insets.left - insets.right;
        if (labelW > size.width) {
            labelW = size.width;
        }
        switch(getJustification(c)) {
            case LEFT:
                labelX += insets.left;
                break;
            case RIGHT:
                labelX += width - insets.right - labelW;
                break;
            case CENTER:
                labelX += (width - labelW) / 2;
                break;
            default:
        }
        if (border != null) {
            if (position != TOP && position != BOTTOM) {
                border.paintBorder(c, g, borderX, borderY, borderW, borderH);
            } else {
                Graphics g2 = g.create();
                if (g2 instanceof Graphics2D) {
                    Graphics2D g2d = (Graphics2D) g2;
                    Path2D path = new Path2D.Float();
                    path.append(new Rectangle(borderX, borderY, borderW, labelY - borderY), false);
                    path.append(new Rectangle(borderX, labelY, labelX - borderX - TEXT_SPACING, labelH), false);
                    path.append(new Rectangle(labelX + labelW + TEXT_SPACING, labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false);
                    path.append(new Rectangle(borderX, labelY + labelH, borderW, borderY - labelY + borderH - labelH), false);
                    g2d.clip(path);
                }
                border.paintBorder(c, g2, borderX, borderY, borderW, borderH);
                g2.dispose();
            }
        }
        g.translate(labelX, labelY);
        label.setSize(labelW, labelH);
        label.paint(g);
        g.translate(-labelX, -labelY);
    } else if (Objects.nonNull(border)) {
        border.paintBorder(c, g, x, y, width, height);
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 74 with Path2D

use of java.awt.geom.Path2D in project poi by apache.

the class DrawFreeformShape method computeOutlines.

protected Collection<Outline> computeOutlines(Graphics2D graphics) {
    List<Outline> lst = new ArrayList<Outline>();
    FreeformShape<?, ?> fsh = getShape();
    Path2D sh = fsh.getPath();
    AffineTransform tx = (AffineTransform) graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
    if (tx == null) {
        tx = new AffineTransform();
    }
    java.awt.Shape canvasShape = tx.createTransformedShape(sh);
    FillStyle fs = fsh.getFillStyle();
    StrokeStyle ss = fsh.getStrokeStyle();
    Path path = new Path(fs != null, ss != null);
    lst.add(new Outline(canvasShape, path));
    return lst;
}
Also used : Path(org.apache.poi.sl.draw.geom.Path) Path2D(java.awt.geom.Path2D) ArrayList(java.util.ArrayList) FillStyle(org.apache.poi.sl.usermodel.FillStyle) AffineTransform(java.awt.geom.AffineTransform) Outline(org.apache.poi.sl.draw.geom.Outline) StrokeStyle(org.apache.poi.sl.usermodel.StrokeStyle)

Example 75 with Path2D

use of java.awt.geom.Path2D in project processdash by dtuma.

the class MultiWindowCheckboxIcon method paintIcon.

public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    float scale = (float) g2.getTransform().getScaleX();
    g2.setStroke(new BasicStroke(1 / scale));
    paintFrame(g2, x + 12, y);
    paintFrame(g2, x + 16, y + 3);
    g2.setColor(boxColor);
    g2.drawRect(x + 0, y + 1, 8, 8);
    if (isChecked()) {
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(checkColor);
        g2.setStroke(new BasicStroke(scale > 1.3 ? 1.5f : 1));
        Path2D p = new Path2D.Float();
        p.moveTo(x + 2, y + 5);
        p.lineTo(x + 4, y + 7);
        p.lineTo(x + 6, y + 3);
        g2.draw(p);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Path2D(java.awt.geom.Path2D) Graphics2D(java.awt.Graphics2D)

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