Java Code Examples for java.awt.geom.Path2D#quadTo()

The following examples show how to use java.awt.geom.Path2D#quadTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override protected Shape makeShape(Container parent, Component c, int x, int y) {
  double r = 4d;
  double w = c.getWidth() - 1d;
  double h = c.getHeight() - 1d;
  double h2 = h * .5;
  Path2D p = new Path2D.Double();
  p.moveTo(w - h2, 0d);
  p.quadTo(w, 0d, w, h2);
  p.quadTo(w, 0d + h, w - h2, h);
  if (c == parent.getComponent(0)) {
    // :first-child
    p.lineTo(r, h);
    p.quadTo(0d, h, 0d, h - r);
    p.lineTo(0d, r);
    p.quadTo(0d, 0d, r, 0d);
  } else {
    p.lineTo(0d, h);
    p.quadTo(h2, h, h2, h2);
    p.quadTo(h2, 0d, 0d, 0d);
  }
  p.closePath();
  return AffineTransform.getTranslateInstance(x, y).createTransformedShape(p);
}
 
Example 2
Source File: FlatUIUtils.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a filled rounded rectangle shape and allows specifying the radius of each corner.
 */
public static Shape createRoundRectanglePath( float x, float y, float width, float height,
	float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight )
{
	if( arcTopLeft <= 0 && arcTopRight <= 0 && arcBottomLeft <= 0 && arcBottomRight <= 0 )
		return new Rectangle2D.Float( x, y, width, height );

	// limit arcs to min(width,height)
	float maxArc = Math.min( width, height ) / 2;
	arcTopLeft = (arcTopLeft > 0) ? Math.min( arcTopLeft, maxArc ) : 0;
	arcTopRight = (arcTopRight > 0) ? Math.min( arcTopRight, maxArc ) : 0;
	arcBottomLeft = (arcBottomLeft > 0) ? Math.min( arcBottomLeft, maxArc ) : 0;
	arcBottomRight = (arcBottomRight > 0) ? Math.min( arcBottomRight, maxArc ) : 0;

	float x2 = x + width;
	float y2 = y + height;

	Path2D rect = new Path2D.Float();
	rect.moveTo( x2 - arcTopRight, y );
	rect.quadTo( x2, y, x2, y + arcTopRight );
	rect.lineTo( x2, y2 - arcBottomRight );
	rect.quadTo( x2, y2, x2 - arcBottomRight, y2 );
	rect.lineTo( x + arcBottomLeft, y2 );
	rect.quadTo( x, y2, x, y2 - arcBottomLeft );
	rect.lineTo( x, y + arcTopLeft );
	rect.quadTo( x, y, x + arcTopLeft, y );
	rect.closePath();

	return rect;
}
 
Example 3
Source File: ShapeUtilitiesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link ShapeUtilities#toPrimitive(Shape)}.
 */
@Test
public void testToPrimitive() {
    final Path2D path = new Path2D.Double();
    path.moveTo(4, 5);
    path.lineTo(7, 9);
    Shape p = ShapeUtilities.toPrimitive(path);
    assertInstanceOf("toPrimitive", Line2D.class, p);
    assertEquals("P1", new Point2D.Double(4, 5), ((Line2D) p).getP1());
    assertEquals("P2", new Point2D.Double(7, 9), ((Line2D) p).getP2());

    path.reset();
    path.moveTo(4, 5);
    path.quadTo(6, 7, 8, 5);
    p = ShapeUtilities.toPrimitive(path);
    assertInstanceOf("toPrimitive", QuadCurve2D.class, p);
    assertEquals("P1",     new Point2D.Double(4, 5), ((QuadCurve2D) p).getP1());
    assertEquals("CtrlPt", new Point2D.Double(6, 7), ((QuadCurve2D) p).getCtrlPt());
    assertEquals("P2",     new Point2D.Double(8, 5), ((QuadCurve2D) p).getP2());

    path.reset();
    path.moveTo(4, 5);
    path.curveTo(6, 7, 8, 6, 9, 4);
    p = ShapeUtilities.toPrimitive(path);
    assertInstanceOf("toPrimitive", CubicCurve2D.class, p);
    assertEquals("P1",     new Point2D.Double(4, 5), ((CubicCurve2D) p).getP1());
    assertEquals("CtrlP1", new Point2D.Double(6, 7), ((CubicCurve2D) p).getCtrlP1());
    assertEquals("CtrlP2", new Point2D.Double(8, 6), ((CubicCurve2D) p).getCtrlP2());
    assertEquals("P2",     new Point2D.Double(9, 4), ((CubicCurve2D) p).getP2());
}
 
Example 4
Source File: DarculaUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("SuspiciousNameCombination")
public static void doPaint(Graphics2D g, int width, int height, float arc, boolean symmetric) {
  float bw = UIUtil.isUnderDefaultMacTheme() ? JBUI.scale(3) : BW.getFloat();
  float lw = UIUtil.isUnderDefaultMacTheme() ? JBUI.scale(UIUtil.isRetina(g) ? 0.5f : 1.0f) : LW.getFloat();

  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, MacUIUtil.USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE);

  float outerArc = arc > 0 ? arc + bw - JBUI.scale(2f) : bw;
  float rightOuterArc = symmetric ? outerArc : JBUI.scale(6f);
  Path2D outerRect = new Path2D.Float(Path2D.WIND_EVEN_ODD);
  outerRect.moveTo(width - rightOuterArc, 0);
  outerRect.quadTo(width, 0, width, rightOuterArc);
  outerRect.lineTo(width, height - rightOuterArc);
  outerRect.quadTo(width, height, width - rightOuterArc, height);
  outerRect.lineTo(outerArc, height);
  outerRect.quadTo(0, height, 0, height - outerArc);
  outerRect.lineTo(0, outerArc);
  outerRect.quadTo(0, 0, outerArc, 0);
  outerRect.closePath();

  bw += lw;
  float rightInnerArc = symmetric ? outerArc : JBUI.scale(7f);
  Path2D innerRect = new Path2D.Float(Path2D.WIND_EVEN_ODD);
  innerRect.moveTo(width - rightInnerArc, bw);
  innerRect.quadTo(width - bw, bw, width - bw, rightInnerArc);
  innerRect.lineTo(width - bw, height - rightInnerArc);
  innerRect.quadTo(width - bw, height - bw, width - rightInnerArc, height - bw);
  innerRect.lineTo(outerArc, height - bw);
  innerRect.quadTo(bw, height - bw, bw, height - outerArc);
  innerRect.lineTo(bw, outerArc);
  innerRect.quadTo(bw, bw, outerArc, bw);
  innerRect.closePath();

  Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
  path.append(outerRect, false);
  path.append(innerRect, false);
  g.fill(path);
}
 
Example 5
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@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);
  double r = 12d;
  double w = width - 1d;
  double h = height - 1d;

  Path2D p = new Path2D.Double();
  p.moveTo(x, y + h);
  p.lineTo(x, y + r);
  p.quadTo(x, y, x + r, y);
  p.lineTo(x + w - r, y);
  p.quadTo(x + w, y, x + w, y + r);
  p.lineTo(x + w, y + h);
  p.closePath();
  Area round = new Area(p);

  // Area round = new Area(new RoundRectangle2D.Double(x, y, w, h, r, r));
  // Rectangle b = round.getBounds();
  // b.setBounds(b.x, b.y + r, b.width, b.height - r);
  // round.add(new Area(b));

  Container parent = c.getParent();
  if (Objects.nonNull(parent)) {
    g2.setPaint(parent.getBackground());
    Area corner = new Area(new Rectangle2D.Double(x, y, width, height));
    corner.subtract(round);
    g2.fill(corner);
  }
  // g2.setPaint(tp);
  // g2.fill(round);
  g2.setPaint(c.getForeground());
  g2.draw(round);
  g2.dispose();
}
 
Example 6
Source File: AwtRenderingBackend.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void quadraticCurveTo(final double cpx, final double cpy,
                final double x, final double y) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("[" + id_ + "] quadraticCurveTo()");
    }

    final Path2D subPath = getCurrentSubPath();
    if (subPath != null) {
        final Point2D cp = transformation_.transform(new Point2D.Double(cpx, cpy), null);
        final Point2D p = transformation_.transform(new Point2D.Double(x, y), null);
        subPath.quadTo(cp.getX(), cp.getY(), p.getX(), p.getY());
    }
}
 
Example 7
Source File: Test7019861.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 8
Source File: GeneralPath2D.java    From javaGeom with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void updatePath(Path2D path) {
	path.quadTo(p1.x(), p1.y(), p2.x(), p2.y());
}
 
Example 9
Source File: Path2DCopyConstructor.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static Path2D addQuads(Path2D p2d) {
    for (int i = 0; i < 10; i++) {
        p2d.quadTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i);
    }
    return p2d;
}
 
Example 10
Source File: Test7019861.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 11
Source File: Path2DGrow.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void addQuad(Path2D p2d, int i) {
    p2d.quadTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i);
}
 
Example 12
Source File: Path2DCopyConstructor.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static Path2D addQuads(Path2D p2d) {
    for (int i = 0; i < 10; i++) {
        p2d.quadTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i);
    }
    return p2d;
}
 
Example 13
Source File: Test7019861.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 14
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
@Override public void paintIcon(Component c, Graphics g, int x, int y) {
  Container parent = c.getParent();
  if (Objects.isNull(parent)) {
    return;
  }
  float r = 8f;
  float w = c.getWidth();
  float h = c.getHeight() - 1f;

  Graphics2D g2 = (Graphics2D) g.create();
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

  Path2D p = new Path2D.Float();
  if (c == parent.getComponent(0)) {
    // :first-child
    p.moveTo(x, y + r);
    p.quadTo(x, y, x + r, y);
    p.lineTo(x + w, y);
    p.lineTo(x + w, y + h);
    p.lineTo(x + r, y + h);
    p.quadTo(x, y + h, x, y + h - r);
  } else if (c == parent.getComponent(parent.getComponentCount() - 1)) {
    // :last-child
    w--;
    p.moveTo(x, y);
    p.lineTo(x + w - r, y);
    p.quadTo(x + w, y, x + w, y + r);
    p.lineTo(x + w, y + h - r);
    p.quadTo(x + w, y + h, x + w - r, y + h);
    p.lineTo(x, y + h);
  } else {
    p.moveTo(x, y);
    p.lineTo(x + w, y);
    p.lineTo(x + w, y + h);
    p.lineTo(x, y + h);
  }
  p.closePath();

  Color ssc = TL;
  Color bgc = BR;
  if (c instanceof AbstractButton) {
    ButtonModel m = ((AbstractButton) c).getModel();
    if (m.isSelected() || m.isRollover()) {
      ssc = ST;
      bgc = SB;
    }
  }

  Area area = new Area(p);
  g2.setPaint(c.getBackground());
  g2.fill(area);
  g2.setPaint(new GradientPaint(x, y, ssc, x, y + h, bgc, true));
  g2.fill(area);
  g2.setPaint(BR);
  g2.draw(area);
  g2.dispose();
}
 
Example 15
Source File: Test7019861.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 16
Source File: Path2DGrow.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static void addQuad(Path2D p2d, int i) {
    p2d.quadTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i);
}
 
Example 17
Source File: Path2DCopyConstructor.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static Path2D addQuads(Path2D p2d) {
    for (int i = 0; i < 10; i++) {
        p2d.quadTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i);
    }
    return p2d;
}
 
Example 18
Source File: Test7019861.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 19
Source File: Path2DGrow.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void addQuad(Path2D p2d, int i) {
    p2d.quadTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i);
}
 
Example 20
Source File: Path2DCopyConstructor.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
static Path2D addQuads(Path2D p2d) {
    for (int i = 0; i < 10; i++) {
        p2d.quadTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i);
    }
    return p2d;
}