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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations