/*
 * @(#)RectangleShape.java	1.0 11-Apr-07
 *
 * IIT Bombay, 
 * Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.
 */
package classes.shapes;

import java.awt.Color;
import java.awt.Graphics;

import types.Command;
import types.ShapeCoordinates;
import interfaces.CommandColleague;
import interfaces.ICommandMediator;
import interfaces.IShape;
import interfaces.IShapeVisitor;
import interfaces.IVisitable;

/**
 * Class for rectangle shape objects
 *
 * @author  Prathab, Mukesh
 * @version 1.0, 21-Mar-07
 */
public class RectangleShape extends CommandColleague implements IShape, IVisitable  {
	public ShapeCoordinates shapeCoordinates;
	public boolean isPermanentShape;
	private Color color;
	
	/**
	 * Initializes with the deafult shape coordinates and mediator object
	 * @see types.ShapeCoordinates
	 * @see interfaces.ICommandMediator
	 */
	public RectangleShape(ShapeCoordinates shapeCoordinates, ICommandMediator commandMediator) {
		super(commandMediator);
		this.shapeCoordinates = shapeCoordinates;
	}
	
	/**
	 * Draws the rectangle shape
	 * This method acts as proxy to draw the shape. The drawing command
	 * is encapsulated using <tt>Command</tt> object and sent to
	 * the command mediator (<tt>CommandContainer</tt>) object
	 * @see interfaces.IShape#drawShape()
	 * @see types.Command
	 */
	public void drawShape() {
		Command cmd = new Command();
		cmd.methodName = new String("drawRect");
		cmd.args = new String[4];
		cmd.args[0] = String.valueOf(shapeCoordinates.x);
		cmd.args[1] = String.valueOf(shapeCoordinates.y);
		cmd.args[2] = String.valueOf(shapeCoordinates.width);
		cmd.args[3] = String.valueOf(shapeCoordinates.height);
		//commandMediator.sendCommand(cmd, isPermanentShape);
		commandMediator.sendCommand(cmd);
	}
	
	/**
	 * Set the Graphics object which is responsible to draw the graphics
	 * @param g <tt>Graphics</tt> object to be set
	 * @see interfaces.IShapeDrawer#setGraphicsObject(java.awt.Graphics)
	 */
	public void setGraphicsObject(Graphics g) {
		// (proxy method)
	}

	/**
	 * Set the Command object which contains the commands to draw the shape
	 * @param command <tt>Command</tt> object to set
	 * @see interfaces.IShapeDrawer#setCommandObject(types.Command)
	 */
	public void setCommandObject(Command command) {
		// (proxy method)
	}
	
	/**
	 * Draws the shape at the specified location
	 * @param x x-coordinate
	 * @param y y-coordinate
	 * @see interfaces.IShape#drawShape(int, int)
	 */
	public void drawShape(int x, int y) {
		Command cmd = new Command();
		cmd.methodName = new String("drawRect");
		cmd.args = new String[4];
		cmd.args[0] = new String(String.valueOf(x));
		cmd.args[1] = new String(String.valueOf(y));
		cmd.args[2] = new String(String.valueOf(shapeCoordinates.width));
		cmd.args[3] = new String(String.valueOf(shapeCoordinates.height));
		commandMediator.sendCommand(cmd);
	}
	
	/**
	 * Relocate the shape at external specified location 
	 * @see interfaces.IShape#drawShape(int, int)
	 */
	public void changeShapeXYCoordinates(int x, int y) {
		this.shapeCoordinates.x = x;
		this.shapeCoordinates.y = y;
	}
	
	/**
	 * Sets whether the shape is permanent or tempory with respect to drawing
	 * @see interfaces.IShape#setAsPermanentShape(boolean)
	 */
	public void setAsPermanentShape(boolean isPermanent) {
		this.isPermanentShape = isPermanent;
	}
	
	/**
	 * Return whether the shape is permanent
	 * @return <tt>true</tt> if shape is permanent
	 * @see interfaces.IShape#IsPermanentShape()
	 */
	public boolean IsPermanentShape() {
		return isPermanentShape;
	}
	/**
	 * Creates clone of the object
	 * @return the clone of the current object
	 * @see interfaces.IShape#clone()
	 */
	public Object clone() {
		ShapeCoordinates shapeCoordinates = (ShapeCoordinates) this.shapeCoordinates.clone();
		RectangleShape clone = new RectangleShape(shapeCoordinates,this.commandMediator);
		clone.isPermanentShape = this.isPermanentShape;
		return clone;
	}
	
	/** 
	 * Sets the color attribute for the shape
	 * @see interfaces.IShape#setColor(java.awt.Color)
	 */
	public void setColor(Color color) {
		this.color = color;
	}
	/**
	 * Returns the color attribute for the shape
	 * @see interfaces.IShape#getColor()
	 */
	public Color getColor(){
		return this.color;
	}	
	/**
	 * Accepts the visitor and execute its method
	 * @see interfaces.IVisitable#accept(interfaces.IShapeVisitor)
	 */
	public void accept(IShapeVisitor shapeVisitor) {
		shapeVisitor.visit(this);
	}
}
