@Override
    public void draw(Graphics2D graphics, Shape clipShape) {
        if (layoutChanged) changeLayout();
        
        // if damagedArea is not null, only draw inside the area
        Shape drawArea;
        if (damagedArea != null) {
            // transform the coordinates of the damaged area
            drawArea = new BoundaryRectangle(damagedArea.x + x, 
                    damagedArea.y + y, damagedArea.width, damagedArea.height);
        } else {
            // drawArea = clipShape;
            drawArea = getBoundingBox();
        }
        graphics.setClip(drawArea);
        
        // draw all the children
        for (GraphicalObject child : children) {
            Rectangle r = child.getBoundingBox();
            int oldX = r.x, oldY = r.y;
            // transform the coordinates
            child.moveTo(x + oldX, y + oldY);
            child.draw(graphics, drawArea);
            // change the coordinates back
            child.moveTo(oldX, oldY);
        }
        
        // reset the damaged area after drawing
        damagedArea = null;
        
        if ((selected || interimSelected) && selectionFeedback) {
            Rectangle r = new Rectangle(x, y, width - 1, height - 1);
            Rectangle r1 = new Rectangle(r.x, r.y, 4, 4);
            Rectangle r2 = new Rectangle(r.x, r.y + r.height - 3, 4, 4);
            Rectangle r3 = new Rectangle(r.x + r.width - 3, r.y, 4, 4);
            Rectangle r4 = new Rectangle(r.x + r.width - 3, 
                    r.y + r.height - 3, 4, 4);
            graphics.setStroke(new BasicStroke(1));
            if (selected && !interimSelected) {
                graphics.setColor(Color.darkGray);
                graphics.draw(r);
                graphics.fill(r1);
                graphics.fill(r2);
                graphics.fill(r3);
                graphics.fill(r4);
            } else if (interimSelected) {
                graphics.setColor(Color.lightGray);
                graphics.draw(r);
                graphics.fill(r1);
                graphics.fill(r2);
                graphics.fill(r3);
                graphics.fill(r4);
            }
        }
    }