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

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.*;

public class SimRopeRecognizer extends Recognizer
{
    public SimRopeRecognizer()
    {
    }

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

    public boolean recognize( Surface s, Widget w )
    {
	if(w instanceof WLine){
	    WLine l = (WLine )w;
	    
	     WSimRope rope = ((SimulateSurface)s).makeSimRope(l);
	    s.replaceWidget( l, rope );
	    
	    return true;
	}

	if(w instanceof WComplex){
	    WComplex c = (WComplex)w;

	    ///closed shapes are not ropes
	    if(c.getStartPoint().includes(c.getEndPoint(), 10)){
		return false;
	    }
	    
	    WSimRope rope = ((SimulateSurface)s).makeSimRope(c);
	    s.replaceWidget( c, rope );
	    
	    return true;
	}

	return false;
      
    }
    public Iterator getInputTypes()
    {
	Vector v = new Vector();
	
	v.addElement( "rec.core.widgets.WComplex" );
	v.addElement( "rec.core.widgets.WLine" );

	return( v.iterator() );
    }
    
    public Iterator getOutputTypes()
    {
	Vector v = new Vector();
	
	v.addElement( "rec.simulate.widgets.WSimRope" );
	
	return( v.iterator() );
    }
}
