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

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	ClickRecognizer.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.
//
//              Mar 99  archon
//              Sharpened the click resolution.
//
///////////////////////////////////////////////////////////////////////////////

package rec.core.recognizers;

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

public class ClickRecognizer extends Recognizer
{
  public static boolean isClick( rec.sys.Squiggle s )
  {
    if( s.getNumberOfPoints() <= 2 || s.getLength() < 8.0 )
      return( true );

    return( false );
  }

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

  public ClickRecognizer()
  {
  }

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

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

    if( isClick( st ) ) {

      //Console.writeln( "click online" );

      WClick c = new WClick( st.getLocation().getCenter() );

      s.replaceWidget( w, c );

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

    return( v.iterator() );
  }
}

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