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

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	LineRecognizer.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
//              Adapted from code written by Luke Weisman.
//              luke@ai.mit.edu
//
// DATE:	Jun 98
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:	Drawing recognition
//
// HISTORY:     Jun 98  archon  created
//
//              Sep 98  archon
//              Modified to fit with new recognition model.
//
//              Nov 98  archon
//              Now aware of new rec.geo package.
//
////////////////////////////////////////////////////////////////////////////////

package rec.core.recognizers;

import edu.mit.sketch.toolkit.SimpleClassifier;
import java.awt.*;
import java.util.*;
import rec.core.widgets.*;
import rec.geo.*;
import rec.sys.*;
import rec.util.*;
import edu.mit.sketch.geom.Line;

public class ToolkitLineRecognizer extends Recognizer
{

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

  public ToolkitLineRecognizer()
  {
  }

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

  public boolean recognize( Surface s, Widget w )
  {
    rec.sys.Squiggle st = (rec.sys.Squiggle)w;

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

    SimpleClassifier c = st.getClassifier();

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

    if ( c.isLine() ) {

      //      Console.writeln( "line online" );
      Line line = c.getLineApproximation();
      WLine l = new WLine( new GPoint( line.getX1(), line.getY1() ),
			   new GPoint( line.getX2(), line.getY2() ) );

      s.replaceWidget( st, l );

      return( true );
    }

    return( false );
  }

  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.WLine" );

    return( v.iterator() );
  }
}

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