/** Modified version of program written by Java: An Eventful Approach
 *  authors - draw a single NestedRects object in the center of the
 *  canvas when run as a main program.  Russell C. Bjork 3/20/08
 */
import objectdraw.*;
import java.awt.*;

// creates a set of NestedRects and allows them to be dragged or removed
// according to the action of the mouse
public class NestedRectsController extends WindowController {

    // Added main method and begin method for demonstration - RCB
    
    public static void main(String [] args) {
        NestedRectsController controller = new NestedRectsController();
        controller.startController();
    }
    public void begin() {
        
        rects = new NestedRects((canvas.getWidth() - WIDTH)/2, 
                                 (canvas.getHeight() - HEIGHT)/2,
                                 WIDTH,
                                 HEIGHT,
                                 canvas);
    }
    
    // dimensions of NestedRects
    private static final double WIDTH = 200,
                                HEIGHT = 100;

    private NestedRects rects;

    // draw a new set of NestedRects where the mouse was pressed
    public void onMousePress(Location point) {
        rects = new NestedRects( point.getX(), point.getY(), 
                                 WIDTH, HEIGHT, canvas );
    }

    // move the rects with the mouse
    public void onMouseDrag(Location point) {
        rects.moveTo(point.getX(), point.getY());
    }
    
    // remove the rects from the canvas
    public void onMouseRelease(Location point) {
        rects.removeFromCanvas();
    }    
}
