public void drawPolyline(int xPoints[], int yPoints[], int nPoints) { if(nPoints > 0) { GeneralPath generalpath = new GeneralPath(); generalpath.moveTo(xPoints[0], yPoints[0]); for(int j = 1; j < nPoints; j++) generalpath.lineTo(xPoints[j], yPoints[j]); draw(generalpath); } }
public GeneralPath makeIntoPath() { int size = getPoints().size(); if(size < 2) return null; GeneralPath path = new GeneralPath(); ShapePoint point = (ShapePoint) getPoints().get(0); path.moveTo((int) point.x, (int) point.y); for(int i = 1; i < size; i++){ point = (ShapePoint) getPoints().get(i); path.lineTo((int) point.x, (int) point.y); } if(isClosed() && size > 2){ path.closePath(); } return path; }
public Shape createStrokedShape(Shape shape) { GeneralPath result = new GeneralPath(); PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); float points[] = new float[6]; moveX = lastX = points[0]; moveY = lastY = points[1]; result.moveTo(moveX, moveY); next = 0; break;
GeneralPath gp = new GeneralPath(); gp.moveTo(r.x + NODE_WIDTH - 2, r.y + NODE_HEIGHT - 20); gp.lineTo(r.x + NODE_WIDTH - 2, r.y + NODE_HEIGHT - 2); gp.lineTo(r.x + NODE_WIDTH - 20, r.y + NODE_HEIGHT - 2); g.fill(gp);
int endX = x2; GeneralPath path = new GeneralPath(); path.moveTo(startX, y); path.lineTo(endX, y); path.lineTo(endX - ARROW_WIDTH, y - ARROW_WIDTH); path.moveTo(endX, y); path.lineTo(endX - ARROW_WIDTH, y + ARROW_WIDTH); g.draw(path); g.fillArc(startX, y - CIRCLE_WIDTH / 2, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360); g.drawString(label, startX + LABEL_OFFSET, y - LABEL_OFFSET); int endX = x2 + endingLine.getWidth(); GeneralPath path = new GeneralPath(); path.moveTo(startX, y); path.lineTo(endX, y); path.lineTo(endX + ARROW_WIDTH, y - ARROW_WIDTH); path.moveTo(endX, y); path.lineTo(endX + ARROW_WIDTH, y + ARROW_WIDTH); g.draw(path); int labelWidth = g.getFontMetrics().stringWidth(label); g.fillArc(startX - CIRCLE_WIDTH / 2, y - CIRCLE_WIDTH / 2, CIRCLE_WIDTH, CIRCLE_WIDTH, 0,
private void drawPlayPauseButton(Graphics2D g) { if (stackWindow.getAnimate()) { g.setColor(Color.black); g.setStroke(stroke); g.drawLine(3, 3, 3, 11); g.drawLine(8, 3, 8, 11); } else { g.setColor(Color.darkGray); GeneralPath path = new GeneralPath(); path.moveTo(3f, 2f); path.lineTo(10f, 7f); path.lineTo(3f, 12f); path.lineTo(3f, 2f); g.fill(path); } }
private static void paintConnectionLine(Graphics2D g, int x0, int y0, int x1, int y1) { double dy = Math.abs(y1 - y0); if (dy < GRID_CELL_SIZE) { g.drawLine(x0, y0, x1, y1); } else { double halfDx = Math.abs(x1 - x0) / 2.0; GeneralPath p = new GeneralPath(); p.moveTo(x0, y0); p.curveTo(x0, y0 + halfDx, x1, y1 - halfDx, x1, y1); g.draw(p); } }
private static GeneralPath createPathAcross() { GeneralPath p = new GeneralPath(); p.moveTo(99.936f, 21.019f); p.curveTo(99.936f, 51.019f, 78.316f, 86.931f, 51.019f, 89.745f); p.curveTo(23.721f, 92.559f, -2.012f, 75.843f, 0, 61.21f); return p; }
@Override public void appendRectangle(Point2D p0, Point2D p1, Point2D p2, Point2D p3) { currentPath.moveTo((float) p0.getX(), (float) p0.getY()); currentPath.lineTo((float) p1.getX(), (float) p1.getY()); currentPath.lineTo((float) p2.getX(), (float) p2.getY()); currentPath.lineTo((float) p3.getX(), (float) p3.getY()); currentPath.closePath(); }
public Shape createStrokedShape (Shape shape) { GeneralPath result = new GeneralPath(); PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); float points[] = new float[6]; moveX = lastX = points[0]; moveY = lastY = points[1]; result.moveTo(moveX, moveY); next = wavelength / 2; break; float y = lastY + next * dy * r; if ((phase & 1) == 0) result.lineTo(x + amplitude * dy * r, y - amplitude * dx * r); else result.lineTo(x - amplitude * dy * r, y + amplitude * dx * r); next += wavelength; phase++; lastX = thisX; lastY = thisY; if (type == PathIterator.SEG_CLOSE) result.closePath(); break;
/** * Draws a sequence of connected lines defined by * arrays of <i>x</i> and <i>y</i> coordinates. * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point. * The figure is not closed if the first point * differs from the last point. * @param xPoints an array of <i>x</i> points * @param yPoints an array of <i>y</i> points * @param nPoints the total number of points * @see java.awt.Graphics#drawPolygon(int[], int[], int) * @since JDK1.1 */ public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints){ if(nPoints > 0){ GeneralPath path = new GeneralPath(); path.moveTo(xPoints[0], yPoints[0]); for(int i=1; i<nPoints; i++) path.lineTo(xPoints[i], yPoints[i]); draw(path); } }
GeneralPath shape = new GeneralPath(); shape.moveTo(cubicCurve1.x1, cubicCurve1.y1); shape.curveTo(cubicCurve1.ctrlx1, cubicCurve1.ctrly1, cubicCurve1.ctrlx2, cubicCurve1.ctrly2, cubicCurve1.x2, cubicCurve1.y2); shape.curveTo(cubicCurve2.ctrlx1, cubicCurve2.ctrly1, cubicCurve2.ctrlx2, cubicCurve2.ctrly2, cubicCurve2.x2, cubicCurve2.y2); shape.curveTo(cubicCurve3.ctrlx1, cubicCurve3.ctrly1, cubicCurve3.ctrlx2, cubicCurve3.ctrly2, cubicCurve1.x1, cubicCurve1.y1); g2D.draw(shape); g2D.setClip(shape); // Draw an image g2D.drawImage(image, 0, 0, this);
@Override public void appendRectangle(Point2D p0, Point2D p1, Point2D p2, Point2D p3) { // to ensure that the path is created in the right direction, we have to create // it by combining single lines instead of creating a simple rectangle linePath.moveTo((float) p0.getX(), (float) p0.getY()); linePath.lineTo((float) p1.getX(), (float) p1.getY()); linePath.lineTo((float) p2.getX(), (float) p2.getY()); linePath.lineTo((float) p3.getX(), (float) p3.getY()); // close the subpath instead of adding the last line so that a possible set line // cap style isn't taken into account at the "beginning" of the rectangle linePath.closePath(); }
GlyphVector glyphVector = font.createGlyphVector(frc, text); GeneralPath result = new GeneralPath(); PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); float points[] = new float[6]; moveX = lastX = points[0]; moveY = lastY = points[1]; result.moveTo(moveX, moveY); nextAdvance = glyphVector.getGlyphMetrics(currentChar).getAdvance() * 0.5f; next = nextAdvance;
public Shape createStrokedShape (Shape shape) { GeneralPath result = new GeneralPath(); PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); float points[] = new float[6]; moveX = lastX = points[0]; moveY = lastY = points[1]; result.moveTo(moveX, moveY); next = wavelength / 2; break; float y = lastY + next * dy * r; if ((phase & 1) == 0) result.lineTo(x + amplitude * dy * r, y - amplitude * dx * r); else result.lineTo(x - amplitude * dy * r, y + amplitude * dx * r); next += wavelength; phase++; lastX = thisX; lastY = thisY; if (type == PathIterator.SEG_CLOSE) result.closePath(); break;
public Shape createStrokedShape (Shape shape) { GeneralPath result = new GeneralPath(); shape = new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(shape); PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); moveX = lastX = randomize(points[0]); moveY = lastY = randomize(points[1]); result.moveTo(moveX, moveY); next = 0; break; float x = lastX + next * dx * r; float y = lastY + next * dy * r; result.lineTo(randomize(x), randomize(y)); next += detail;
private static GeneralPath createPathCyclic() { GeneralPath p = new GeneralPath(); p.moveTo(99.936f, 51.019f); p.curveTo(99.936f, 51.019f, 78.316f, 86.931f, 51.019f, 89.745f); p.curveTo(23.721f, 92.559f, -2.012f, 75.843f, 11.082f, 61.21f); p.curveTo(4.178f, 46.576f, 34.931f, 39.565f, 62.229f, 36.751f); p.curveTo(89.526f, 33.937f, 99.936f, 51.019f, 99.936f, 51.019f); return p; } private static GeneralPath createPathAcross() {
/** * Draws a filled polygon with the given (x[i], y[i]) coordinates. * * @param x an array of all the x-coordindates of the polygon * @param y an array of all the y-coordindates of the polygon */ public void filledPolygon(double[] x, double[] y) { int n = x.length; GeneralPath path = new GeneralPath(); path.moveTo((float) scaleX(x[0]), (float) scaleY(y[0])); for (int i = 0; i < n; i++) path.lineTo((float) scaleX(x[i]), (float) scaleY(y[i])); path.closePath(); offscreen.fill(path); draw(); }
public Shape createStrokedShape (Shape shape) { GeneralPath result = new GeneralPath(); shape = new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(shape); PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS); moveX = lastX = randomize(points[0]); moveY = lastY = randomize(points[1]); result.moveTo(moveX, moveY); next = 0; break; float x = lastX + next * dx * r; float y = lastY + next * dy * r; result.lineTo(randomize(x), randomize(y)); next += detail;