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

The following examples show how to use java.awt.geom.Path2D#append() . 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: VisualCreditComponent.java    From workcraft with MIT License 6 votes vote down vote up
@Override
public Shape getShape() {
    Path2D shape = new Path2D.Double();

    shape.moveTo(-0.5 * SIZE, -0.4 * SIZE);
    shape.lineTo(-0.5 * SIZE, +0.4 * SIZE);
    shape.lineTo(+0.5 * SIZE, +0.4 * SIZE);
    shape.lineTo(+0.5 * SIZE, -0.4 * SIZE);
    shape.closePath();

    shape.moveTo(0.0, -0.4 * SIZE);
    shape.lineTo(0.0, +0.4 * SIZE);

    double tokenSize = SIZE / 10.0;
    for (int i = 0; i < 4; i++) {
        shape.append(new Ellipse2D.Double(-0.2 * SIZE - 0.5 * tokenSize, -0.5 * tokenSize, tokenSize, tokenSize), false);
        shape.append(new Ellipse2D.Double(+0.2 * SIZE - 0.5 * tokenSize, -0.5 * tokenSize, tokenSize, tokenSize), false);
        tokenSize /= 3.0;
    }

    return shape;
}
 
Example 2
Source File: DividerPolygon.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void paint(Graphics2D g, int width) {
  GraphicsUtil.setupAntialiasing(g);


  if (!myApplied) {
    Shape upperCurve = makeCurve(width, myStart1, myStart2, true);
    Shape lowerCurve = makeCurve(width, myEnd1, myEnd2, false);

    Path2D path = new Path2D.Double();
    path.append(upperCurve, true);
    path.append(lowerCurve, true);
    g.setColor(myColor);
    g.fill(path);

    g.setColor(DiffUtil.getFramingColor(myColor));
    g.draw(upperCurve);
    g.draw(lowerCurve);
  }
  else {
    g.setColor(myColor);
    g.draw(makeCurve(width, myStart1 + 1, myStart2 + 1, true));
    g.draw(makeCurve(width, myStart1 + 2, myStart2 + 2, true));
    g.draw(makeCurve(width, myEnd1 + 1, myEnd2 + 1, false));
    g.draw(makeCurve(width, myEnd1 + 2, myEnd2 + 2, false));
  }
}
 
Example 3
Source File: FlatUIUtils.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
private static void paintComponentBorderImpl( Graphics2D g, int x, int y, int width, int height,
	float focusWidth, float lineWidth, float arc )
{
	float x1 = x + focusWidth;
	float y1 = y + focusWidth;
	float width1 = width - focusWidth * 2;
	float height1 = height - focusWidth * 2;
	float arc2 = arc - (lineWidth * 2);

	Shape r1 = createComponentRectangle( x1, y1, width1, height1, arc );
	Shape r2 = createComponentRectangle(
		x1 + lineWidth, y1 + lineWidth,
		width1 - lineWidth * 2, height1 - lineWidth * 2, arc2 );

	Path2D border = new Path2D.Float( Path2D.WIND_EVEN_ODD );
	border.append( r1, false );
	border.append( r2, false );
	g.fill( border );
}
 
Example 4
Source File: MyLineBorder.java    From training with MIT License 6 votes vote down vote up
/**
 * 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
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);

        RoundRectangle2D.Float outer = new RoundRectangle2D.Float(x, y, width, height, radius, radius);
        RoundRectangle2D.Float inner = new RoundRectangle2D.Float(x + thickness, y + thickness, width - thickness * 2, height - thickness * 2, 10, 10);

        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
 
Example 5
Source File: DiffDrawUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void drawCurveTrapezium(@Nonnull Graphics2D g,
                                      int x1, int x2,
                                      int start1, int end1,
                                      int start2, int end2,
                                      @Nullable Color fillColor,
                                      @Nullable Color borderColor) {
  Shape upperCurve = makeCurve(x1, x2, start1, start2, true);
  Shape lowerCurve = makeCurve(x1, x2, end1 + 1, end2 + 1, false);
  Shape lowerCurveBorder = makeCurve(x1, x2, end1, end2, false);

  if (fillColor != null) {
    Path2D path = new Path2D.Double();
    path.append(upperCurve, true);
    path.append(lowerCurve, true);

    g.setColor(fillColor);
    g.fill(path);
  }

  if (borderColor != null) {
    g.setColor(borderColor);
    g.draw(upperCurve);
    g.draw(lowerCurveBorder);
  }
}
 
Example 6
Source File: ShapeSerializationWrapper.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
public Shape create() {
	int windingRule = ((Number) map.get(KEY_WINDING_RULE)).intValue();
	String pathStr = (String) map.get(KEY_PATH);
	Path2D returnValue = new Path2D.Double(windingRule);
	returnValue.append(ShapeStringUtils.createPathIterator(pathStr), false);

	// offer more targeted classes if possible:

	Rectangle rect = ShapeUtils.getRectangle(returnValue);
	if (rect != null)
		return rect;
	Rectangle2D rect2D = ShapeUtils.getRectangle2D(returnValue);
	if (rect2D != null)
		return rect2D;

	return returnValue;
}
 
Example 7
Source File: FlatFileViewHardDriveIcon.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintIcon( Component c, Graphics2D g ) {
	/*
		<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
		  <path fill="#6E6E6E" fill-rule="evenodd" d="M2,6 L14,6 L14,10 L2,10 L2,6 Z M12,8 L12,9 L13,9 L13,8 L12,8 Z M10,8 L10,9 L11,9 L11,8 L10,8 Z"/>
		</svg>
	*/

	Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
	path.append( new Rectangle2D.Float( 2, 6, 12, 4 ), false );
	path.append( new Rectangle2D.Float( 12, 8, 1, 1 ), false );
	path.append( new Rectangle2D.Float( 10, 8, 1, 1 ), false );
	g.fill( path );
}
 
Example 8
Source File: LineBorder.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * 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
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);

        Shape outer;
        Shape inner;

        int offs = this.thickness;
        int size = offs + offs;
        if (this.roundedCorners) {
            float arc = .2f * offs;
            outer = new RoundRectangle2D.Float(x, y, width, height, offs, offs);
            inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
        }
        else {
            outer = new Rectangle2D.Float(x, y, width, height);
            inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
        }
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
 
Example 9
Source File: LineBorder.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);

        Shape outer;
        Shape inner;

        int offs = this.thickness;
        int size = offs + offs;
        if (this.roundedCorners) {
            float arc = .2f * offs;
            outer = new RoundRectangle2D.Float(x, y, width, height, offs, offs);
            inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
        }
        else {
            outer = new Rectangle2D.Float(x, y, width, height);
            inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
        }
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
 
Example 10
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 11
Source File: DarculaSpinnerBorder.java    From consulo with Apache License 2.0 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();
  Rectangle r = new Rectangle(x, y, width, height);
  JBInsets.removeFrom(r, JBUI.insets(1));

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

    g2.translate(r.x, r.y);

    float lw = LW.getFloat();
    float bw = BW.getFloat();
    float arc = COMPONENT_ARC.getFloat();

    Object op = ((JComponent)c).getClientProperty("JComponent.outline");
    if (c.isEnabled() && op != null) {
      paintOutlineBorder(g2, r.width, r.height, arc, true, isFocused(c), Outline.valueOf(op.toString()));
    }
    else {
      if (isFocused(c)) {
        paintFocusBorder(g2, r.width, r.height, arc, true);
      }

      Path2D border = new Path2D.Float(Path2D.WIND_EVEN_ODD);
      border.append(new RoundRectangle2D.Float(bw, bw, r.width - bw * 2, r.height - bw * 2, arc, arc), false);
      arc = arc > lw ? arc - lw : 0.0f;
      border.append(new RoundRectangle2D.Float(bw + lw, bw + lw, r.width - (bw + lw) * 2, r.height - (bw + lw) * 2, arc, arc), false);

      g2.setColor(getOutlineColor(c.isEnabled(), isFocused(c)));
      g2.fill(border);
    }
  }
  finally {
    g2.dispose();
  }
}
 
Example 12
Source File: LineBorder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);

        Shape outer;
        Shape inner;

        int offs = this.thickness;
        int size = offs + offs;
        if (this.roundedCorners) {
            float arc = .2f * offs;
            outer = new RoundRectangle2D.Float(x, y, width, height, offs, offs);
            inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
        }
        else {
            outer = new Rectangle2D.Float(x, y, width, height);
            inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
        }
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
 
Example 13
Source File: LineBorder.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);

        Shape outer;
        Shape inner;

        int offs = this.thickness;
        int size = offs + offs;
        if (this.roundedCorners) {
            float arc = .2f * offs;
            outer = new RoundRectangle2D.Float(x, y, width, height, offs, offs);
            inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
        }
        else {
            outer = new Rectangle2D.Float(x, y, width, height);
            inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
        }
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
 
Example 14
Source File: LineBorder.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);

        Shape outer;
        Shape inner;

        int offs = this.thickness;
        int size = offs + offs;
        if (this.roundedCorners) {
            int arc = offs + size;
            outer = new RoundRectangle2D.Float(x, y, width, height, arc, arc);
            inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
        }
        else {
            outer = new Rectangle2D.Float(x, y, width, height);
            inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
        }
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
 
Example 15
Source File: ShapeUtils.java    From pumpernickel with MIT License 5 votes vote down vote up
public static Shape clone(Shape shape) {
	if (shape == null)
		return null;

	if (shape instanceof RectangularShape)
		return (Shape) ((RectangularShape) shape).clone();
	if (shape instanceof Line2D)
		return (Shape) ((Line2D) shape).clone();

	PathIterator pi = shape.getPathIterator(null);
	Path2D p = new Path2D.Float(pi.getWindingRule());
	p.append(pi, false);
	return p;
}
 
Example 16
Source File: FlatUIUtils.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a not-filled rectangle shape with the given line width.
 */
public static Path2D createRectangle( float x, float y, float width, float height, float lineWidth ) {
	Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
	path.append( new Rectangle2D.Float( x, y, width, height ), false );
	path.append( new Rectangle2D.Float( x + lineWidth, y + lineWidth,
		width - (lineWidth * 2), height - (lineWidth * 2) ), false );
	return path;
}
 
Example 17
Source File: LineBorder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);

        Shape outer;
        Shape inner;

        int offs = this.thickness;
        int size = offs + offs;
        if (this.roundedCorners) {
            int arc = offs + size;
            outer = new RoundRectangle2D.Float(x, y, width, height, arc, arc);
            inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
        }
        else {
            outer = new Rectangle2D.Float(x, y, width, height);
            inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
        }
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
 
Example 18
Source File: FlatTaskPaneUI.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
@Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
	if( color == null )
		return;

	FlatUIUtils.setRenderingHints( (Graphics2D) g );

	g.setColor( color );

	float lineWidth = UIScale.scale( 1f );
	Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
	path.append( new Rectangle2D.Float( x, y, width, height ), false );
	path.append( new Rectangle2D.Float( x + lineWidth, y, width - (lineWidth * 2), height - lineWidth ), false );
	((Graphics2D)g).fill( path );
}
 
Example 19
Source File: LineBorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);

        Shape outer;
        Shape inner;

        int offs = this.thickness;
        int size = offs + offs;
        if (this.roundedCorners) {
            float arc = .2f * offs;
            outer = new RoundRectangle2D.Float(x, y, width, height, offs, offs);
            inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
        }
        else {
            outer = new Rectangle2D.Float(x, y, width, height);
            inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
        }
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
 
Example 20
Source File: ShapeUtilitiesViewer.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Append the given point to the given path.
 */
private static void addPoint(final Path2D addTo, final double x, final double y) {
    addTo.append(new Ellipse2D.Double(x - POINT_RADIUS, y - POINT_RADIUS, 2*POINT_RADIUS, 2*POINT_RADIUS), false);
}