import objectdraw.*;
import java.awt.*;
import javax.swing.*;

/**
 * Draw and drag around a bullseye to demonstrate 
 * recursive drawing.
 */
public class BullsEyeController extends WindowController {
        private JSlider sizeSlider;
        
        private static final int INIT_SIZE = 32;
        private static final int MIN_SIZE = 24;
        private static final int MAX_SIZE = 1024;
        
        private BullsEyeInterface eye;
        
        private boolean dragging = false;
        private Location lastPt;
        
        public void begin() {
                sizeSlider = new JSlider(JSlider.HORIZONTAL, MIN_SIZE, MAX_SIZE, INIT_SIZE);
                sizeSlider.setMajorTickSpacing(BullsEyeInterface.RING_GAP);
                sizeSlider.setSnapToTicks(true);
                Container contentPane = getContentPane();
                contentPane.add(sizeSlider, BorderLayout.SOUTH);
                contentPane.validate();
        }
        
        
        
        public void onMouseClick(Location pt) {
                double radius = sizeSlider.getValue();
                eye = new BullsEyeRing(pt,radius,canvas);
        }
        
        
        
        public void onMousePress(Location pt) {
                if (eye != null) {
                        dragging = eye.contains(pt);
                        lastPt = pt;
                } else {
                        dragging = false;
                }
                
        }
        
        public void onMouseDrag(Location pt){
                if (dragging) {
                        eye.move(pt.getX() - lastPt.getX(),
                                 pt.getY() - lastPt.getY());
                        lastPt = pt;
                }
        }
}
