
import java.awt.*;
import java.io.*;
import java.util.*;

class Rectangle extends Figure {
    int _width;
    int _height;

    Rectangle( String color, int x0, int y0, int width, int height ) {
	super( color, x0, y0 );
	
	_width = width;
	_height = height;
    }
    
    public void resize( int x0, int y0, int x1, int y1 ) {
	if ( x0 > x1 ) { int tmp = x0; x0 = x1; x1 = tmp; }
	if ( y0 > y1 ) { int tmp = y0; y0 = y1; y1 = tmp; }
	_x0 = x0;
	_y0 = y0;
	_width = x1 - x0;
	_height = y1 - y0;
    }

    public void paint( Graphics g ) {
	g.setColor( getColor() );      
	g.fillRect( getX0(), getY0(), _width, _height );
    }

    public String toString() {
	String s = "Rectangle|";
        s += super.toString();
	s += _width + "|" + _height +"\n";
	return s;
    }

    Rectangle( StringTokenizer t ) {
	super( t );

	Integer i = new Integer( t.nextToken() );
	_width = i.intValue();
	
	i = new Integer( t.nextToken() );
	_height = i.intValue();
    }

    // Return true if figure is selected using these coordinates
    public boolean isSelected( int x0, int y0 ) {
	if ( x0 >= _x0 && x0 < _x0 + _width && 
	     y0 >= _y0 && y0 < _y0 + _height ) {
	    return true;
	}
	else {
	    return false;
	}
    }

    // Return true if figure is selected using these coordinates
    public boolean isInBox( int x0, int y0, int width, int height ) {
	if ( x0 <= _x0 && x0 + width >= _x0 + _width && 
	     y0 <= _y0 && y0 + height >= _y0 + _height ) {
	    return true;
	}
	else {
	    return false;
	}
    }

    public void paintSelected( Graphics g ) {
	g.setColor( Color.blue.brighter() );
	g.drawRect( _x0-2, _y0-2, 4, 4 );
	g.drawRect( _x0+_width-2, _y0+_height-2, 4, 4 );
	g.drawRect( _x0+_width-2, _y0-2, 4, 4 );
	g.drawRect( _x0-2, _y0+_height-2, 4, 4 );
    }

    public int getMinX() {
	return _x0;
    }

    public int getMaxX() {
	return _x0 + _width;
    }

    public int getMinY() {
	return _y0;
    }

    public int getMaxY() {
	return _y0 + _height;
    }


}


