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

// -*-Mode: Java-*- 
// $Id: Event.java,v 1.5 2003/03/06 00:40:49 moltmans Exp $
// Event.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Mon May 08 15:13:37 2000> 
// Time-stamp: <2000-07-19 18:19:57 moltmans> 
package rec.annotate.facts;

import java.util.*;

import rec.sys.*;
import rec.annotate.rules.*;
import rec.annotate.widgets.*;

/**
 **/
public abstract class Event extends Annotation
{
  public abstract boolean isBasedOn( Annotation a );
  public abstract Body getSubject();

  /**
   * Combine ths event with the given event and return a detailed
   * version thereof.
   **/
  public abstract Event combineWith( Event e );

  private Surface m_surface;

  public Event( Surface s, long start, long end ) 
  {
    super( start, end );
    m_surface = s;
  }

  public Surface getSurface()
  {
    return m_surface;
  }

  public boolean sameEvent( Event event )
  {
    if( sameFact( event ) )
      return true;

    // make sure they are the same type and have the same subject
    if( !getFactType().equals( event.getFactType() ) ||
	!getSubject().sameFact( event.getSubject() ) )
    {
      return false;
    }

    Notebook book = m_surface.getNotebook();
    int dist = book.numAnnotations( this, event );
    return ( Math.abs( dist ) < 2 );
  }

}
