public Shape transform(Shape shape){
  Rectangle2D bounds=shape.getBounds2D();
  Point2D center=new Point2D.Double(bounds.getCenterX(),bounds.getCenterY());
  Point2D newCenter=transform(center);
  double dx=newCenter.getX() - center.getX();
  double dy=newCenter.getY() - center.getY();
  AffineTransform at=AffineTransform.getTranslateInstance(dx,dy);
  return at.createTransformedShape(shape);
}

public Shape transform ( Shape shape ) { Rectangle2D bounds = shape . getBounds2D ( ) ; Point2D center = new Point2D . Double ( bounds . getCenterX ( ) , bounds . getCenterY ( ) ) ; Point2D newCenter = transform ( center ) ; double dx = newCenter . getX ( ) - center . getX ( ) ; double dy = newCenter . getY ( ) - center . getY ( ) ; AffineTransform at = AffineTransform . getTranslateInstance ( dx , dy ) ; return at . createTransformedShape ( shape ) ; }
return the supplied shape , translated to the coordinates that result from calling transform on its center
