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 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;
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,
@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(); }
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); g.setColor(portTypeColor(input.getType())); g.setStroke(CONNECTION_STROKE); paintConnectionLine(g, (int) topLeft.getX(), (int) topLeft.getY(), r.x + portX + 4, r.y - 2);
final GeneralPath path = new GeneralPath(); final double xp = pt.getX() + x; final double yp = pt.getY() + y; visible.ensureVisible(xp, yp); if (first) { path.moveTo((float) xp, (float) yp); } else { path.lineTo((float) xp, (float) yp); path.closePath(); g2d.fill(path); } else if (back!=null) { g2d.setColor(mapper.getMappedColor(back)); DriverRectangleG2d.managePattern(param, g2d); g2d.fill(path); g2d.setColor(mapper.getMappedColor(param.getColor())); DriverLineG2d.manageStroke(param, g2d); g2d.draw(path);
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); } }
Graphics2D g2 = (Graphics2D) g; int x2Points[] = {0, 100, 0, 100}; //these are the X coordinates int y2Points[] = {0, 50, 50, 0}; //these are the Y coordinates GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, x2Points.length); polyline.moveTo (x2Points[0], y2Points[0]); for (int index = 1; index < x2Points.length; index++) { polyline.lineTo(x2Points[index], y2Points[index]); }; g2.draw(polyline);
void _extendPath(GeneralPath gp) { if (points.size() == 0) return; Point pt = points.get(0); Point ctrl1, ctrl2; gp.moveTo(pt.x, pt.y); int pointCount = getPointCount(); for (int i = 1; i < pointCount; i++) { pt = points.get(i); if (pt.isLineTo()) { gp.lineTo(pt.x, pt.y); } else if (pt.isCurveTo()) { ctrl1 = points.get(i - 2); ctrl2 = points.get(i - 1); gp.curveTo(ctrl1.x, ctrl1.y, ctrl2.x, ctrl2.y, pt.x, pt.y); } } if (closed) gp.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;
@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(); }
/** * 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); } }
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(); 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;
public static Shape createStar(int arms, Point center, double rOuter, double rInner) { double angle = Math.PI / arms; GeneralPath path = new GeneralPath(); for (int i = 0; i < 2 * arms; i++) { double r = (i & 1) == 0 ? rOuter : rInner; Point2D.Double p = new Point2D.Double(center.x + Math.cos(i * angle) * r, center.y + Math.sin(i * angle) * r); if (i == 0) path.moveTo(p.getX(), p.getY()); else path.lineTo(p.getX(), p.getY()); } path.closePath(); return path; }
/** * Creates a shape representing a point. * * @param point * the location of the point * @return a shape */ public Shape createPoint(Point2D point) { GeneralPath path = new GeneralPath(); path.moveTo((float) (point.getX()), (float) (point.getY() - size / 2)); path.lineTo((float) (point.getX() + size / 2), (float) (point.getY() + size / 2)); path.lineTo((float) (point.getX() - size / 2), (float) (point.getY() + size / 2)); path.lineTo((float) (point.getX()), (float) (point.getY() - size / 2)); return path; }