/*
 * Created on Apr 20, 2003
 *
 * To change this generated comment go to 
 * Window>Preferences>Java>Code Generation>Code Template
 */
package jdraw.figures;

import java.awt.*;
import java.awt.event.*;

import jdraw.framework.*;

/**
 * @author Christoph
 */
public class EllipseTool extends AbstractTool {

	private Point anchor = null;
	private Ellipse rubberband = null;
	/**
	 * @param editor
	 */
	public EllipseTool(DrawEditor editor) {
		super(editor);
	}

	/**
	 * Activates the Ellipse Mode. There will be a
	 * specific menu added to the menu bar that provides settings for
	 * Ellipse attributes
	 */
	public void activate() {
		getView().setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
		getEditor().showStatus("Ellipse Mode");
	}

	/**
	 * Initializes a new Ellipse object by setting an anchor
	 * point where the mouse was pressed. A new Ellipse is then
	 * added to the model.
	 * 
	 * @see jdraw.framework.DrawTool#mouseDown(int, int, MouseEvent)
	 */
	public void mouseDown(int x, int y, MouseEvent e) {
		anchor = new Point(x, y);
		rubberband = new Ellipse(x, y, 0);
		getView().getModel().addFigure(rubberband);
	}

	/**
	 * During a mouse drag, the Rectangle will be resized according to
	 * the mouse position. The status bar shows the current size.
	 * 
	 * @see jdraw.framework.DrawTool#mouseDrag(int, int, MouseEvent)
	 */
	public void mouseDrag(int x, int y, MouseEvent e) {
		rubberband.setBounds(anchor, new Point(x, y));
		getEditor().showStatus("w: " + rubberband.getWidth() + ", h: " + rubberband.getHeight());
	}

	/**
	 * When the user releases the mouse, the Rectangle object is
	 * updated according to the color and fill status settings.
	 * 
	 * @see jdraw.framework.DrawTool#mouseUp(int, int, MouseEvent)
	 */
	public void mouseUp(int x, int y, MouseEvent e) {
		rubberband.setBounds(anchor, new Point(x, y));
		rubberband = null;
		getEditor().showStatus("");
	}

}
