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

// -*-Mode: Java-*- 
// $Id: MovementGestureRecognizer.java,v 1.9 2003/03/06 00:40:49 moltmans Exp $
// MovementGestureRecognizer.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Tue Feb 15 21:16:43 2000> 
// Time-stamp: <2001-04-03 19:27:47 moltmans> 
package rec.annotate.recognizers;

import java.util.*;
import rec.sys.*;
import rec.core.widgets.*;
import rec.annotate.widgets.*;
import rec.simulate.widgets.WSimBody;

/**
 * This class recognizes movement gestures (i.e. arrows).
 **/
public class MovementGestureRecognizer extends Recognizer
{
  public boolean recognize( Surface s, Widget w )
  {
    final WSquiggleArrow arrow = (WSquiggleArrow)w;
    GeometryCalculator gc = new GeometryCalculator(s);

    // Find the closest body that contains the tail point
    // allowing for a bit of slack as well
    GeoFunction gf = new GeoFunction() {
	public boolean check(VisibleWidget vw) 
	{
	  return (vw instanceof WSimBody) &&
	    ((WSimBody)vw).contains(arrow.getTailPoint(), 30);
	}
      };
    WSimBody body =
      (WSimBody)gc.findClosestSurfaceWidgetWithCheck(arrow.getTailPoint(),
						     gf);
						   
    WMotionArrow warrow = new WMotionArrow( s, arrow, body );

    s.replaceWidget( w, warrow );
    return true;
  }

  public Iterator getInputTypes()
  {
    Vector v = new Vector();
    v.addElement( "rec.core.widgets.WSquiggleArrow" );
    return( v.iterator() );
  }

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