@Override
    public void resizeToChildren() {
        if (children.isEmpty()) {
            return;
        }
        // compute the width and height
        int x1, y1, x2, y2, cx1, cy1, cx2, cy2;
        ListIterator<GraphicalObject> it = children.listIterator();
        GraphicalObject next = it.next();
        Rectangle r = next.getBoundingBox();
        x1 = r.x;
        y1 = r.y;
        x2 = x1 + r.width - 1;
        y2 = y1 + r.height - 1;
        while (it.hasNext()) {
            next = it.next();
            r = next.getBoundingBox();
            cx1 = r.x;
            cy1 = r.y;
            cx2 = cx1 + r.width - 1;
            cy2 = cy1 + r.height - 1;
            if (cx2 > x2) {
                x2 = cx2;
            }
            if (cy2 > y2) {
                y2 = cy2;
            }
        }
        // resize
        width = x2;
        height = y2;
    }