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

class Figure extends ListNode {

    // Color of this figure
    String _color;
    
    // Position of the figure
    int _x0;
    int _y0;
    
    // Colors allowed
    static final String [] palette = { "Red", "Green", "Blue", "Black", 
			      "White", "Yellow", "Orange", 
			      "Cyan", "Magenta", "Pink" };

    static final Color [] colorPalette = {
	Color.red, Color.green, Color.blue, Color.black,
	Color.white, Color.yellow, Color.orange, Color.cyan, Color.magenta,
	Color.pink
    };

    // Get color of figure as string
    public String getStringColor() {
	return _color;
    }

    // Get color of figure as Color object
    Color getColor() {
	for ( int i=0; i < palette.length; i++ ) {
	    if ( palette[i].equals( _color ) ) {
		return colorPalette[i];
	    }
	}
	return Color.black;
    }

    // Parent constructor
    Figure( String color, int x0, int y0 ) {
	_color = color;
	_x0 = x0;
	_y0 = y0;
    }

    // Get color of figure
    public void setColor( String color) {
	_color = color;
    }

    // Set position of figure
    public void setPosition( int x0, int y0 ) {
	_x0 = x0;
	_y0 = y0;
    }
    
    // Set position of figure
    public void changePosition( int dx, int dy ) {
	_x0 += dx;
	_y0 += dy;
    }
    
    // Get position x0
    public int getX0() {
	return _x0;
    }
    
    // Get position y0
    public int getY0() {
	return _y0;
    }
    
    // Paint method. It will be overriden by subclasses
    public void paint( Graphics g ) {
    }
    
    public String toString() {
	return _color + "|" + _x0 + "|" + _y0 + "|";
    }
    
    // Parent constructor
    Figure( StringTokenizer t ) {
	// Set color
	_color = t.nextToken();
	
	Integer i = new Integer( t.nextToken() );
	_x0 = i.intValue();
	
	i = new Integer( t.nextToken() );
	_y0 = i.intValue();
    }

    // Return true if figure is selected using these coordinates
    public boolean isSelected( int x0, int y0 ) {
	return false;
    }

    public void paintSelected( Graphics g ) {
    }

    // Return true if figure is inside this box
    public boolean isInBox( int x0, int y0, int width, int height ) {
	return false;
    }

    public void resize( int x0, int y0, int x1, int y1 ) {
	_x0 = x0;
	_y0 = y0;
    }

    public int getMinX() {
	return _x0;
    }

    public int getMaxX() {
	return _x0;
    }

    public int getMinY() {
	return _y0;
    }

    public int getMaxY() {
	return _y0;
    }
}
