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

// -*-Mode: Java-*- 
// $Id: MergeMovementRule.java,v 1.2 2003/03/06 00:40:43 moltmans Exp $
// MergeMovementRule.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Mon May 01 20:43:35 2000> 
// Time-stamp: <2000-05-13 18:29:04 moltmans> 
package rec.annotate.rules;

import rec.tms.*;
import rec.sys.*;
import java.util.*;

public class MergeMovementRule extends AnnotateRule 
{
  
  public LinkedList getTriggers() 
  {
    LinkedList triggers = new LinkedList();
    triggers.add( Type.MOTION_EVENT );
    triggers.add( Type.MOTION_EVENT );
    return triggers;
  }

  /**
   * @see MotionEvent.sameEvent for details of when 2 motions are the
   *      same.
   **/
  public boolean match( LinkedList params ) 
  {
    if( params.size() == 1 )
      return true;

    MotionEvent e1 = (MotionEvent)params.get(0);
    MotionEvent e2 = (MotionEvent)params.get(1);

    return ( (e1 != e2) &&
	     e1.sameEvent( e2 ) );
  }

  public void run( Surface s, Notebook book, LinkedList params )
  {
    MotionEvent e1 = (MotionEvent)params.get(0);
    MotionEvent e2 = (MotionEvent)params.get(1);

    SameEvent fact = new SameEvent( e1, e2 );
    book.assert( fact, "same events", params );
  }

  public String toString() 
  {
    return "<Rule: MergeMovementRule>";
  }
  
}
