/*******************************************************************

  Class:	CS6600, Graphics
  Author:	Yury Izrailevsky
	
  Assignment 1 - Paint program


  This file contains the implementation of Y_Rectange class.
*******************************************************************/

import java.awt.*;

public class Y_Rectangle extends Rectangle implements YI_Figures
{
    //------------------ Data members -----------------------
    Color fColor = Color.black;
    boolean fFillIn = false;


    //--------------------- METHODS --------------------------
    public Y_Rectangle(Color color, boolean f, int px, int py)
    {
	fColor = color;
	fFillIn = f;
	x = px;
	y = py;
	height = width = 0;
    }

    // overrides interface function
    public int whatFigureAmI() {return YI_Figures.FT_RECTANGLE;}
    
    // overrides interface draw()
    public int draw(Graphics g)
    {
	// draw with native color 
	Color old_color = g.getColor();
	g.setColor(fColor);
	
	if (fFillIn){
	    g.fillRect(x, y, width, height);
	}
	else {
	    g.drawRect(x, y, width, height);
	}// end else
	
	// restore old color
	g.setColor(old_color);

	return E.OK;
	
    }// end of draw()


    // for rubber-band purposes
    public int drawWhite(Graphics g)
    {
	// draw with native color 
	Color old_color = g.getColor();
	g.setColor(Color.white);
	
	if (fFillIn){
	    g.fillRect(x, y, width, height);
	}
	else {
	    g.drawRect(x, y, width, height);
	}// end else
	
	// restore old color
	g.setColor(old_color);

	return E.OK;

    }// end of drawWhite()
    
    // override interface setColor
    public int setColor(Color color)
    {
	fColor = color;
	return E.OK;
    }

    // override interface setFillIn
    public int setFillIn(boolean mode)
    {
	fFillIn = mode;
	return E.OK;
    }

    // implemet scalePoint
    // scales all points by a certain value
    public void scalePoints(double coef)
    {
	x = (int)(x * coef);
	y = (int)(y * coef);
	width = (int)(width * coef);
	height = (int)(height * coef);
    }

}// end of Y_Rectangle implementation

