Java Code Examples for java.awt.geom.Path2D#Float

The following examples show how to use java.awt.geom.Path2D#Float . 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: DarculaComboBoxUI.java    From consulo with Apache License 2.0 6 votes vote down vote up
static Shape getArrowShape(Component button) {
  Rectangle r = new Rectangle(button.getSize());
  JBInsets.removeFrom(r, JBUI.insets(1, 0, 1, 1));

  int tW = JBUIScale.scale(9);
  int tH = JBUIScale.scale(5);
  int xU = (r.width - tW) / 2 - JBUIScale.scale(1);
  int yU = (r.height - tH) / 2 + JBUIScale.scale(1);

  Path2D path = new Path2D.Float();
  path.moveTo(xU, yU);
  path.lineTo(xU + tW, yU);
  path.lineTo(xU + tW / 2.0f, yU + tH);
  path.lineTo(xU, yU);
  path.closePath();
  return path;
}
 
Example 2
Source File: StarPolygon.java    From pumpernickel with MIT License 6 votes vote down vote up
protected Path2D createPath2D() {
	float r1 = getRadius1();
	float r2 = getRadius2();
	int k = getNumberOfPoints();

	Point2D[] points = new Point2D[2 * k];
	for (int a = 0; a < k; a++) {
		double theta1 = 2 * Math.PI / k * a - Math.PI / 2;
		double theta2 = 2 * Math.PI / k * (a + .5) - Math.PI / 2;
		points[2 * a + 0] = new Point2D.Double(r1 * Math.cos(theta1),
				r1 * Math.sin(theta1));
		points[2 * a + 1] = new Point2D.Double(r2 * Math.cos(theta2),
				r2 * Math.sin(theta2));
	}
	Path2D p = new Path2D.Float();
	p.moveTo(points[0].getX(), points[0].getY());
	for (int a = 1; a < points.length; a++) {
		p.lineTo(points[a].getX(), points[a].getY());
	}
	p.closePath();
	p.transform(AffineTransform.getTranslateInstance(getCenterX(),
			getCenterY()));
	return p;
}
 
Example 3
Source File: DarculaUIUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void paintCellEditorBorder(Graphics2D g2, Component c, Rectangle r, boolean hasFocus) {
  g2 = (Graphics2D)g2.create();
  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);

    float bw = CELL_EDITOR_BW.getFloat();

    Path2D border = new Path2D.Float(Path2D.WIND_EVEN_ODD);
    border.append(new Rectangle2D.Float(0, 0, r.width, r.height), false);
    border.append(new Rectangle2D.Float(bw, bw, r.width - bw * 2, r.height - bw * 2), false);

    Object op = ((JComponent)c).getClientProperty("JComponent.outline");
    if (op != null || hasFocus) {
      Outline outline = op == null ? Outline.focus : Outline.valueOf(op.toString());
      outline.setGraphicsColor(g2, true);
      g2.fill(border);
    }
  }
  finally {
    g2.dispose();
  }
}
 
Example 4
Source File: DrawPath.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void DrawPath(SunGraphics2D sg2d, SurfaceData sData,
                     int transX, int transY,
                     Path2D.Float p2df)
{
    tracePrimitive(target);
    target.DrawPath(sg2d, sData, transX, transY, p2df);
}
 
Example 5
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 6
Source File: LoopPipe.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        Path2D.Float p2df;
        int transX;
        int transY;
        if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
            if (s instanceof Path2D.Float) {
                p2df = (Path2D.Float)s;
            } else {
                p2df = new Path2D.Float(s);
            }
            transX = sg2d.transX;
            transY = sg2d.transY;
        } else {
            p2df = new Path2D.Float(s, sg2d.transform);
            transX = 0;
            transY = 0;
        }
        sg2d.loops.drawPathLoop.DrawPath(sg2d, sg2d.getSurfaceData(),
                                         transX, transY, p2df);
        return;
    }

    if (sg2d.strokeState == SunGraphics2D.STROKE_CUSTOM) {
        fill(sg2d, sg2d.stroke.createStrokedShape(s));
        return;
    }

    ShapeSpanIterator sr = getStrokeSpans(sg2d, s);

    try {
        fillSpans(sg2d, sr);
    } finally {
        sr.dispose();
    }
}
 
Example 7
Source File: GeneralRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void DrawPath(SunGraphics2D sg2d, SurfaceData sData,
                     int transx, int transy,
                     Path2D.Float p2df)
{
    PixelWriter pw = GeneralRenderer.createSolidPixelWriter(sg2d, sData);
    ProcessPath.drawPath(
        new PixelWriterDrawHandler(sData, pw, sg2d.getCompClip(),
                                   sg2d.strokeHint),
        p2df, transx, transy
    );
}
 
Example 8
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 9
Source File: LoopPipe.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        Path2D.Float p2df;
        int transX;
        int transY;
        if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
            if (s instanceof Path2D.Float) {
                p2df = (Path2D.Float)s;
            } else {
                p2df = new Path2D.Float(s);
            }
            transX = sg2d.transX;
            transY = sg2d.transY;
        } else {
            p2df = new Path2D.Float(s, sg2d.transform);
            transX = 0;
            transY = 0;
        }
        sg2d.loops.drawPathLoop.DrawPath(sg2d, sg2d.getSurfaceData(),
                                         transX, transY, p2df);
        return;
    }

    if (sg2d.strokeState == SunGraphics2D.STROKE_CUSTOM) {
        fill(sg2d, sg2d.stroke.createStrokedShape(s));
        return;
    }

    ShapeSpanIterator sr = getStrokeSpans(sg2d, s);

    try {
        fillSpans(sg2d, sr);
    } finally {
        sr.dispose();
    }
}
 
Example 10
Source File: X11Renderer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void XDoPath(SunGraphics2D sg2d, long pXSData, long xgc,
             int transX, int transY, Path2D.Float p2df,
             boolean isFill)
{
    GraphicsPrimitive.tracePrimitive(isFill ?
                                     "X11FillPath" :
                                     "X11DrawPath");
    super.XDoPath(sg2d, pXSData, xgc, transX, transY, p2df, isFill);
}
 
Example 11
Source File: GDIRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void doShape(GDIWindowSurfaceData sData,
             Region clip, Composite comp, int color,
             int transX, int transY,
             Path2D.Float p2df, boolean isfill)
{
    GraphicsPrimitive.tracePrimitive(isfill
                                     ? "GDIFillShape"
                                     : "GDIDrawShape");
    super.doShape(sData, clip, comp, color,
                  transX, transY, p2df, isfill);
}
 
Example 12
Source File: CrashTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void paint(final Graphics2D g2d, final float size) {
    final double halfSize = size / 2.0;

    final Path2D.Float path = new Path2D.Float(WIND_NON_ZERO, 32 * 1024);

    // show cross:
    path.moveTo(0, 0);
    path.lineTo(size, size);

    path.moveTo(size, 0);
    path.lineTo(0, size);

    path.moveTo(0, 0);
    path.lineTo(size, 0);

    path.moveTo(0, 0);
    path.lineTo(0, size);

    path.moveTo(0, 0);

    double r = size;

    final int ratio = 100;
    int repeats = 1;

    int n = 0;

    while (r > 1.0) {
        repeats *= ratio;

        if (repeats > 10000) {
            repeats = 10000;
        }

        for (int i = 0; i < repeats; i++) {
            path.lineTo(halfSize - 0.5 * r + i * r / repeats,
                        halfSize - 0.5 * r);
            n++;
            path.lineTo(halfSize - 0.5 * r + i * r / repeats + 0.1,
                        halfSize + 0.5 * r);
            n++;
        }

        r -= halfSize;
    }
    System.out.println("draw : " + n + " lines.");
    g2d.draw(path);
}
 
Example 13
Source File: GDIRenderer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
native void doShape(GDIWindowSurfaceData sData,
Region clip, Composite comp, int color,
int transX, int transY,
Path2D.Float p2df, boolean isfill);
 
Example 14
Source File: OGLRenderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected void fillPath(SunGraphics2D sg2d,
                        Path2D.Float p2df, int transx, int transy)
{
    GraphicsPrimitive.tracePrimitive("OGLFillPath");
    oglr.fillPath(sg2d, p2df, transx, transy);
}
 
Example 15
Source File: X11Renderer.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
native void XDoPath(SunGraphics2D sg2d, long pXSData, long xgc,
int transX, int transY, Path2D.Float p2df,
boolean isFill);
 
Example 16
Source File: Path.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
public Path() {
	this.path2D = new Path2D.Float();
}
 
Example 17
Source File: TransformingPathConsumer2D.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
Path2DWrapper init(Path2D.Float p2d) {
    this.p2d = p2d;
    return this;
}
 
Example 18
Source File: DuctusRenderingEngine.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public FillAdapter() {
    // Ductus only supplies float coordinates so
    // Path2D.Double is not necessary here.
    path = new Path2D.Float(Path2D.WIND_NON_ZERO);
}
 
Example 19
Source File: BufferedRenderPipe.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void fill(SunGraphics2D sg2d, Shape s) {
    int transx, transy;

    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        // Here we are able to use fillPath() for
        // high-quality fills.
        Path2D.Float p2df;
        if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
            if (s instanceof Path2D.Float) {
                p2df = (Path2D.Float)s;
            } else {
                p2df = new Path2D.Float(s);
            }
            transx = sg2d.transX;
            transy = sg2d.transY;
        } else {
            p2df = new Path2D.Float(s, sg2d.transform);
            transx = 0;
            transy = 0;
        }
        fillPath(sg2d, p2df, transx, transy);
        return;
    }

    AffineTransform at;
    if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
        // Transform (translation) will be done by FillSpans (we could
        // delegate to fillPolygon() here, but most hardware accelerated
        // libraries cannot handle non-convex polygons, so we will use
        // the FillSpans approach by default)
        at = null;
        transx = sg2d.transX;
        transy = sg2d.transY;
    } else {
        // Transform will be done by the PathIterator
        at = sg2d.transform;
        transx = transy = 0;
    }

    ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d);
    try {
        // Subtract transx/y from the SSI clip to match the
        // (potentially untranslated) geometry fed to it
        Region clip = sg2d.getCompClip();
        ssi.setOutputAreaXYXY(clip.getLoX() - transx,
                              clip.getLoY() - transy,
                              clip.getHiX() - transx,
                              clip.getHiY() - transy);
        ssi.appendPath(s.getPathIterator(at));
        fillSpans(sg2d, ssi, transx, transy);
    } finally {
        ssi.dispose();
    }
}
 
Example 20
Source File: Window.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the shape of the window.
 *
 * The value returned by this method may not be the same as
 * previously set with {@code setShape(shape)}, but it is guaranteed
 * to represent the same shape.
 *
 * @return the shape of the window or {@code null} if no
 *     shape is specified for the window
 *
 * @see Window#setShape(Shape)
 * @see GraphicsDevice.WindowTranslucency
 *
 * @since 1.7
 */
public Shape getShape() {
    synchronized (getTreeLock()) {
        return shape == null ? null : new Path2D.Float(shape);
    }
}