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

// $Id: FastRecognizer.java,v 1.5 2003/03/06 00:40:40 moltmans Exp $
// Time-stamp: <2000-03-11 18:59:36 moltmans>
package rec.sys;


////////////////////////////////////////////////////////////////////////////////
//
// FILE:	FastRecognizer.java
//
// AUTHOR:      Manoj & Luke
//              luke@ai.mit.edu, archon@ai.mit.edu
//
// DATE:        September, 1998
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:	Drawing recognition
//
// HISTORY:     September, 1998
//              MDM
//              modified to fit with new recognition model
//
////////////////////////////////////////////////////////////////////////////////


import java.io.*;
import java.util.*;


/**
 * These are the recognizers that can respond to each point added to
 * a stroke in realtime.
 */
public abstract class FastRecognizer extends Recognizer 
{
  
  public final int WANT = 1;
  public final int UNSURE = 0;
  public final int DONT_WANT = -1;

  /**
   * This allows the fast recognizer to be used as a normal
   * one.
   */
  public final boolean recognize( Surface s, Widget w )
  {
    if( want( s, (Squiggle)w, true ) == WANT )
      return( recognize( s, (Squiggle)w, true ) );

    return( false );
  }

  /**
   * This is called with every point added to the stroke.  If the 
   * rec returns WANT it gets full control of all added points,
   * UNSURE makes no comment, and DONT_WANT stops all calls.
   * 
   * DONT_WANT is not absolutely needed.  UNSURE works as well.
   */
  public abstract int want( Surface s, Squiggle st, boolean ending );
  
  /** 
   * This is called when the stroke is about to begin.  This allows
   * for the reset and cleanup necessary, since sometimes no cleanup
   * gets handed to a FR when it is returning UNSURE values.
   */
  public void reset()
  {
  }

  /**
   * This is only called if the recognizer previously returned true on
   * a want() call.
   *
   * @param last   If this is the last call, since the user lifted the
   *               mouse.
   */
  public abstract boolean recognize( Surface s, Squiggle st, boolean last );

  /**
   * @return an Iterator of types of Widget's that the
   *     FastRecognizer analyzes.
   */
  public final Iterator getInputTypes()
  {
    Vector v = new Vector();

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

    return( v.iterator() );
  }

  /**
   * @return an Iterator of types of Widget's that the
   *     FastRecognizer outputs.
   */
  public abstract Iterator getOutputTypes();
}

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