/*
 * Created on Apr 12, 2003
 *
 * To change this generated comment go to 
 * Window>Preferences>Java>Code Generation>Code Template
 */
package jdraw.figures;

import java.awt.event.*;
import java.awt.*;

import jdraw.framework.*;

/**
 * This tool defines a mode for drawing rectangles.
 *
 * @see Figure
 *
 * @author  Christoph Denzler
 * @version 1.0, 12.4.03
 */
public class RectangleTool extends AbstractTool {
	
	private Point anchor = null;
	private jdraw.figures.Rectangle rubberband = null;
	
	public RectangleTool(DrawEditor e ) {
		super(e);
	}

	/**
	 * Activates the Rectangle Mode. There will be a
	 * specific menu added to the menu bar that provides settings for
	 * Rectangle attributes
	 */
	public void activate() {
		getView().setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
		getEditor().showStatus("Rectangle Mode");
	}

	/**
	 * Initializes a new Rectangle object by setting an anchor
	 * point where the mouse was pressed. A new Rectangle 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 jdraw.figures.Rectangle(x, y, 0, 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));
		java.awt.Rectangle r = rubberband.getBounds();
		getEditor().showStatus("w: "+ r.width + ", h: " + r.height);
	}

	/**
	 * 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("");
	}

}
