Search in sources :

Example 46 with Path2D

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

the class DummySizeIcon method makeStar.

public Path2D makeStar(int r1, int r2, int vc) {
    double or = Math.max(r1, r2);
    double ir = Math.min(r1, r2);
    double agl = 0d;
    double add = Math.PI / vc;
    Path2D p = new Path2D.Double();
    p.moveTo(or, 0d);
    for (int i = 0; i < vc * 2 - 1; i++) {
        agl += add;
        double r = i % 2 == 0 ? ir : or;
        p.lineTo(r * Math.cos(agl), r * Math.sin(agl));
    }
    p.closePath();
    AffineTransform at = AffineTransform.getRotateInstance(-Math.PI / 2d, or, 0d);
    return new Path2D.Double(p, at);
}
Also used : Path2D(java.awt.geom.Path2D) AffineTransform(java.awt.geom.AffineTransform)

Example 47 with Path2D

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

the class WithoutArrowButtonScrollBarUI method paintBorder.

@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // // TEST: WindowsLookAndFeel
    // if (c instanceof JPopupMenu) {
    // Container top = ((JPopupMenu) c).getTopLevelAncestor();
    // if (top instanceof JWindow) {
    // Composite cmp = g2.getComposite();
    // g2.setComposite(AlphaComposite.Clear);
    // g2.setPaint(new Color(0x0, true));
    // g2.clearRect(x, y, width, height);
    // g2.setComposite(cmp);
    // }
    // }
    double r = ARC;
    double w = width - 1d;
    double h = height - 1d;
    Path2D p = new Path2D.Double();
    p.moveTo(x, y);
    p.lineTo(x, y + h - r);
    p.quadTo(x, y + h, x + r, y + h);
    p.lineTo(x + w - r, y + h);
    p.quadTo(x + w, y + h, x + w, y + h - r);
    p.lineTo(x + w, y);
    p.closePath();
    // Area round = new Area(p);
    g2.setPaint(c.getBackground());
    g2.fill(p);
    g2.setPaint(c.getForeground());
    g2.draw(p);
    g2.setPaint(c.getBackground());
    g2.drawLine(x + 1, y, x + width - 2, y);
    g2.dispose();
}
Also used : Path2D(java.awt.geom.Path2D)

Example 48 with Path2D

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

the class LineNumberView method paintIcon.

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.translate(x, y);
    if (c instanceof AbstractButton && ((AbstractButton) c).getModel().isRollover()) {
        g2.setPaint(rolloverColor);
    } else {
        g2.setPaint(arrowColor);
    }
    float w2 = getIconWidth() / 2f;
    float h2 = getIconHeight() / 2f;
    float tw = w2 / 3f;
    float th = h2 / 6f;
    g2.setStroke(new BasicStroke(w2 / 2f));
    Path2D p = new Path2D.Float();
    p.moveTo(w2 - tw, h2 + th);
    p.lineTo(w2, h2 - th);
    p.lineTo(w2 + tw, h2 + th);
    g2.draw(p);
    g2.dispose();
}
Also used : Path2D(java.awt.geom.Path2D)

Example 49 with Path2D

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

the class CheckBoxIcon method paintIcon.

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    if (!(c instanceof AbstractButton)) {
        return;
    }
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.translate(x, y);
    g2.setPaint(Color.DARK_GRAY);
    float s = Math.min(getIconWidth(), getIconHeight()) * .05f;
    float w = getIconWidth() - s - s;
    float h = getIconHeight() - s - s;
    float gw = w / 8f;
    float gh = h / 8f;
    g2.setStroke(new BasicStroke(s));
    g2.draw(new Rectangle2D.Float(s, s, w, h));
    AbstractButton b = (AbstractButton) c;
    if (b.getModel().isSelected()) {
        g2.setStroke(new BasicStroke(3f * s));
        Path2D p = new Path2D.Float();
        p.moveTo(x + 2f * gw, y + .5f * h);
        p.lineTo(x + .4f * w, y + h - 2f * gh);
        p.lineTo(x + w - 2f * gw, y + 2f * gh);
        g2.draw(p);
    }
    g2.dispose();
}
Also used : Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D)

Example 50 with Path2D

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

the class ArrowIcon method paintIcon.

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    // // NimbusLookAndFeel
    // Container parent = SwingUtilities.getUnwrappedParent(c);
    // if (parent instanceof JMenuBar) {
    // return;
    // }
    Graphics2D g2 = (Graphics2D) g.create();
    if (c instanceof AbstractButton && ((AbstractButton) c).getModel().isSelected()) {
        g2.setPaint(Color.WHITE);
    } else {
        g2.setPaint(Color.GRAY);
    }
    double w = getIconWidth() / 2d;
    Path2D p = new Path2D.Double();
    p.moveTo(0d, 0d);
    p.lineTo(w, w);
    p.lineTo(0d, getIconHeight());
    p.closePath();
    g2.translate(x, y);
    g2.fill(p);
    g2.dispose();
}
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