final Shape s = builder.getProduct();
System.out.println(s.accept(new Size()) + " basic shapes");
// calculate the bounding box
final Location b = s.accept(new BoundingBox());
final Rectangle r = (Rectangle) b.getChild();
// draw it in a frame centered around the bounding box
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final int padding = 20;
@SuppressWarnings("serial")
JPanel p = new JPanel() {
@Override
public void paintComponent(Graphics g) {
g.translate(-b.getX() + padding, -b.getY() + padding);
s.accept(new Draw(g));
s.accept(new BoundingBox()).accept(new Draw(g));
}
};
p.setPreferredSize(new Dimension(r.getWidth() + 2 * padding, r.getHeight() + 2 * padding));
f.setContentPane(p);
f.pack();
f.setVisible(true);
// now draw the same complex group of shapes.impl.composite by hand