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

// -*-Mode: Java-*- 
// $Id: Notebook.java,v 1.2 2003/03/06 00:40:43 moltmans Exp $
// Notebook.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Mon May 08 12:51:55 2000> 
// Time-stamp: <2000-05-13 17:33:16 moltmans> 
package rec.annotate.rules;

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

/**
 * This holds the annotation objects in a hashtable so that they can
 * be referenced by the widgets they relate to.
 **/
public class Notebook 
{
  private JTRE m_jtre;
  private Surface m_surface;

  public Notebook( Surface s )
  {
    m_surface = s;
    m_jtre = new JTRE( "Annotation Notebook" );
    FactBrowser browser = new FactBrowser( m_jtre );
  }

//    public Widget fetchWidget( String name ) 
//    {
//      return 
//    }

//    public String fetchName( Widget obj )
//    {
//      return (String)m_WidgetsToNames.get( obj );
//    }

  public void assertDesign()
  {
    Iterator it = m_surface.getSurfaceWidgets().iterator();
    Object o;

    while( it.hasNext() ) {
      o = it.next();
      if ( o instanceof WSimBody ) {
	Body body = new Body( m_surface, (WSimBody)o,
			      ((WSimBody)o).getEnglishName() );
	assume( body, "drawn body" ); 
      }
    }
  }
  
  public void addRule( Surface s, AnnotateRule rule )
  {
    rule.setSurface( s );
    m_jtre.insertRule( rule );
  }
  

  public void assert( Annotation a, String reason,
		      LinkedList  antecedents )
  {
    m_jtre.assert( a, reason, antecedents );
  }

  public void assume( Annotation a, String reason )
  {
    m_jtre.assume( a, reason );
  }

  public void retract( Annotation a, String reason )
  {
    m_jtre.retract( a, reason );
  }

  /**
   * This needs to be called after a round of assertions are made.
   **/
  public void updateNotes() 
  {
    m_jtre.runRules();
    //    Console.writeln( m_jtre.rulesToString() );
    //    Console.writeln( m_jtre.factsToString() );

  }
  

}
