// CS134 demo - class to create graphic representation of a T-shirt.

import objectdraw.*;
import java.awt.*;

	// A class to represent dirty shirts for laundry program
public class Tshirt {

	// overall size of the shirt
private static final double SIZE = 3;

	// Size of sleeves
private static final double SLEEVE_WIDTH = 30*SIZE;
private static final double SLEEVE_HEIGHT = 6*SIZE;

	// Size of body
private static final double BODY_WIDTH = 18*SIZE;
private static final double BODY_HEIGHT = 22*SIZE;
private static final double BODY_INSET = 6*SIZE; 
	
	// Size of neck
private static final double NECK_WIDTH = 9*SIZE;
private static final double NECK_HEIGHT = 2*SIZE;	
private static final double NECK_INSET = 10.5*SIZE;
	
	// Filled regions of shirt
private FilledRect body, sleeves;
private FilledOval neck;

	// "Trim" on perimeter of shirt
private FramedRect sleeveTrim, bodyTrim;
private FramedOval neckTrim;

	// Current color of the shirt
private Color hue;

  	// Random number generator used to select next object
private RandomIntGenerator generator = new RandomIntGenerator(0,255);

	// Create a new shirt at the specified location.
public Tshirt( double x, double y,  DrawingCanvas canvas )
{
		// Construct background trim
	sleeveTrim = new FramedRect( x, y + SIZE, SLEEVE_WIDTH, SLEEVE_HEIGHT, canvas );
	bodyTrim = new FramedRect( x + BODY_INSET, y + SIZE, BODY_WIDTH, BODY_HEIGHT, canvas );
	
		// construct interior (except neck)
	sleeves = new FilledRect( x+1, y+SIZE+1, SLEEVE_WIDTH-1, SLEEVE_HEIGHT-1, canvas );
	body = new FilledRect( x+BODY_INSET+1, y+SIZE+1, BODY_WIDTH-1, BODY_HEIGHT-1, canvas );

		// add nect and nect trim
	neck = new FilledOval( x + NECK_INSET, y, NECK_WIDTH, NECK_HEIGHT, canvas );
	neckTrim = new FramedOval( x + NECK_INSET, y, NECK_WIDTH, NECK_HEIGHT, canvas );
	
		// Shirt should start out white.
	body.setColor(Color.white);
	neck.setColor(Color.white);
	sleeves.setColor(Color.white);
	
	setColor ();
}

	// Move shirt relative to its current location
public void move( double x, double y )
{
	body.move(x,y);
	neck.move(x,y);
	sleeves.move(x,y);
	bodyTrim.move(x,y);
	sleeveTrim.move(x,y);
	neckTrim.move(x,y);
}

	// Move shirt to a new position
public void moveTo( double x, double y )
{
	this.move( x - sleeves.getBounds().getX(), y - neck.getBounds().getY() );
}

	// test if shirt contains point
public boolean contains( Location point )
{
	return body.contains(point) || 
	       sleeves.contains(point) || 
	       neck.contains(point);
}

public void hide () {
	body.hide ();
	sleeves.hide();
	neck.hide();
	bodyTrim.hide ();
	sleeveTrim.hide ();
	neckTrim.hide ();
}

	// pick a new random color for the shirt
private void setColor( )
{
	hue = new Color( generator.nextValue(),
	                 generator.nextValue(),
	                 generator.nextValue()
	               );

	body.setColor(hue);
	neck.setColor(hue);
	sleeves.setColor(hue);
}

	// get the sum of the components of the shirt's color
public int colorValue(  )
{
	return hue.getRed() + hue.getBlue() + hue.getGreen();
}

}