import java.awt.Color;
import java.io.*;
import java.util.Scanner;
import java.util.Vector;

/**
 * A class that can be used to retrieve Color objects
 * by name (using the W3C names defined in
 * http://www.w3.org/TR/2003/CR-css3-color-20030514/ )
 */
public class ColorFinder
{
   // private Color[]        colors;       
   // private String[]       names;
      private Vector colors;
		private Vector names;

    /**
     * Default Constructor
     */
    public ColorFinder() throws IOException
    {
       Color          value;       
       int            blue, green, red;       
       Scanner        in;
       String         key;
       
       
      // colors = new Color[147];
      // names  = new String[147];
         colors = new Vector();    // or   colors = new Vector (147);
			names = new Vector ();    // or   names = new Vector (147);    
		 
       in = new Scanner(new File("colors.txt"));

       for (int i=0; in.hasNext(); i++)
       {
          key       = in.next();
          red       = in.nextInt();
          green     = in.nextInt();
          blue      = in.nextInt();
          value     = new Color(red, green, blue);          

         // names[i]  = key;
         // colors[i] = value;
			names.add(key);
			colors.add(value);          
       }
    }


    /**
     * Get the Color with the given name/description
     *
     * @param   description  The name/description of the Color
     * @return               The Color (or null if no such name exists)
     */
    public Color getColor(String description)
    {
       Color           result;
       String 			  key; 
       result = null;
       for (int i = 0; i < names.size() && result == null; i++)
		 {   key = (String) names.elementAt(i);
			 if (description.equals(key))
			 {
			   result = (Color) colors.elementAt(i);
			 }
       }
       return result;       
    }
    
}
