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

package rec.core.recognizers;

import edu.mit.sketch.geom.Approximation;
import edu.mit.sketch.geom.Point;
import edu.mit.sketch.geom.Polygon;
import edu.mit.sketch.geom.GeneralPath;
import edu.mit.sketch.toolkit.SimpleClassifier;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Vector;
import rec.core.widgets.WPolyLine;
import rec.core.widgets.WComplex;
import rec.geo.GPoint;
import rec.sys.Recognizer;
import rec.sys.Squiggle;
import rec.sys.Surface;
import rec.sys.Widget;
import rec.util.Assert;


public class ToolkitComplexRecognizer extends Recognizer
{
  
  public boolean recognize( Surface s, Widget w )
  {
    Squiggle squiggle = (Squiggle)w;
    double length = squiggle.getLength();

    //    Console.writeln( "line recognizer activated" );

    SimpleClassifier c = squiggle.getClassifier();

    // the classifier may be null if there was not enough data for it to operate
    if( c == null ) {
      return false;
    }

    if( ! c.isComplex() ) {
      return false;      
    }

    GeneralPath generalPath = c.getComplexApproximation();
    Assert.notNull( generalPath, "The classifier returned a null complex approximation" );

    WComplex complex = new WComplex( generalPath, length );
    s.replaceWidget( squiggle, complex, true );

    return true;
  }

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

    v.addElement( "rec.sys.Squiggle" );

    return( v.iterator() );
  }

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

    v.addElement( "rec.core.widgets.WComplex" );

    return( v.iterator() );
  }
  
}// ToolkitFacitedLineBreakerRecognizer

