// (c) MIT 2003.  All rights reserved.

package rec.house;


import java.awt.*;
import java.util.*;
import rec.core.*;
import rec.util.*;
import rec.sys.*;

public class AutoNamer extends Recognizer
{
  int cur_name = 0;

  double ave_size;
  int tot_regions;

  public AutoNamer()
  {
  }
  
  /**
   * Each new stroke generated gets put into the pipe here.  It will
   * remove and add objects to the 'out' target as it deems fit.
   *
   * @return true if changes were made
   */
  public boolean recognize( Surface s, Widget w )
  {
    final Region n = (Region)w;

    if ( n.name == null )
      {
	String the_name = null;

	double a = n.area();
	ave_size = ( ave_size * tot_regions + a ) / (tot_regions+1);
	tot_regions++;

	if ( tot_regions > 3 )
	  {
	    if ( a < ( ave_size / 2 ) )
	      the_name = "closet";
	    //	    else if ( a < ave_size ) 
	    //	      the_name = "bathroom";
	    else
	      the_name = "region " + cur_name++;
	  }
	else
	  the_name = "region " + cur_name++;
	

	Console.writeln( "Naming Region " + the_name );

	n.setName( the_name );

	return false; // we are not wanting to rerecognize anything.
      }
    else
      return false;
  }
  
  public Iterator getInputTypes()
  {
    Vector v = new Vector();
    
    v.addElement( "rec.house.Region" );
    
    return v.iterator();
  }

  public Iterator getOutputTypes() 
  {
    Vector v = new Vector();
    v.addElement( "rec.house.Region" );

    return v.iterator();
  }


}
