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

// $Id: SimPolyFromPolyRecognizer.java,v 1.7 2003/03/06 00:40:41 moltmans Exp $
// Time-stamp: <2000-03-11 18:59:37 moltmans>
package rec.simulate.recognizers;


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

// This is code written by Luke Weisman, with small modifications
// by Christine Alvarado

public class SimPolyFromPolyRecognizer extends Recognizer
{
  public final static double BREAK = 20.0;

  public SimPolyFromPolyRecognizer()
  {
  }

  /////////////////////////////////////////////////////////////////////////////

  public boolean recognize( Surface s, Widget w )
  {
    WPolygon pi = (WPolygon)w;

    int sides = pi.numSides();
    Widget q = null;

    if ( pi instanceof WRectangle ){
	
	WRectangle wr = new WRectangle( (WQuadrilateral) pi );
	q =  ((SimulateSurface)s).makeSimRect( wr );
	
    }
    
    else if (pi instanceof WQuadrilateral){

	WQuadrilateral sq = new WQuadrilateral( pi );
	q = ((SimulateSurface)s).makeSimQuad( sq );
	
    }
    else {
	
	q = ((SimulateSurface)s).makeSimPolygon( pi );
    }
    

    s.replaceWidget( w, q );

    return( true );
  }

  public Iterator getInputTypes()
  {
    Vector v = new Vector();

    v.addElement( "rec.core.widgets.WPolygon" );
    v.addElement( "rec.core.widgets.WRectangle" );
    v.addElement( "rec.core.widgets.WQuadrilateral" );

    return( v.iterator() );
  }

  public Iterator getOutputTypes()
  {
    Vector v = new Vector();

    v.addElement( "rec.simulate.widgets.WSimPolygon" );

    return( v.iterator() );
  }
}

////////////////////////////////////////////////////////////////////////////////
