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

// -*-Mode: Java-*- 
// $Id: MotionGestureRule.java,v 1.2 2003/03/06 00:40:43 moltmans Exp $
// MotionGestureRule.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Fri May 12 12:11:18 2000> 
// Time-stamp: <2000-05-12 12:23:14 moltmans> 
package rec.annotate.rules;

import java.util.*;
import rec.util.*;
import rec.tms.*;
import rec.sys.*;
import rec.simulate.widgets.*;
import rec.core.widgets.*;

/**
 * Recognize arrows indicating motions
 **/
public class MotionGestureRule extends AnnotateRule
{

  public LinkedList getTriggers() 
  {
    LinkedList triggers = new LinkedList();
    triggers.add( Type.ARROW );
    triggers.add( Type.BODY );
    return triggers;
  }

  /**
   * The rule matches when it describes a motion event
   **/
  public boolean match( LinkedList params ) 
  {
    if( params.size() < 2 ) {
      return true;
    }

    Arrow arrow = (Arrow)params.get(0);
    WSquiggleArrow warrow = arrow.getArrow();
    Body body = (Body)params.get(1);
    WSimBody wbody = body.getBody();
    DebugWindow.addLine( "JTRE", "MotionGestureRule: " + params );
    DebugWindow.addLine( "JTRE", "***contains? = " +
			 wbody.contains( warrow.getTailPoint() ) );
    return wbody.contains( warrow.getTailPoint() );
  }

  public void run( Surface s, Notebook book, LinkedList params )
  {
    Arrow arrow = (Arrow)params.get(0);
    Body body = (Body)params.get(1);
    MotionEvent event = new MotionEvent( s, body, arrow );
    book.assert( event, "motion gesture", params );
  }
}

