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

// -*-Mode: Java-*- 
// $Id: WAnnotation.java,v 1.2 2003/03/06 00:40:43 moltmans Exp $
// WAnnotation.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Thu Feb 24 15:54:50 2000> 
// Time-stamp: <2000-04-12 21:43:53 moltmans> 
package rec.annotate.widgets;

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


/**
 * This class is for annotation widgets.
 * Since most annotations are primarly wrappers around annotation objects
 **/
public abstract class WAnnotation extends Widget
{
  protected Annotation m_annotation;
  protected AnnotationNotebook m_notebook;

  public abstract void performAction( Surface s );
  public abstract void undoAction( Surface s );
  public abstract WAnnotation makeAnnotationWidget( Annotation a,
						    AnnotationNotebook book );

  public WAnnotation( Annotation annotation, AnnotationNotebook book )
  {
    m_annotation = annotation;
    m_notebook = book;
  }

  public Annotation getAnnotation() 
  {
    return m_annotation;
  }

  public AnnotationNotebook getNotebook()
  {
    return m_notebook;
  }

  public void makeDefaultSuitcase( Surface s )
  {
    DoTransition dt = new DoTransition(s) {
      public void doDo( )
      {
	m_annotation.updateNotebook();
	m_notebook.addEvent( m_annotation );
	performAction( m_Surface );

	// this is now done in the notebook
//  	Iterator ents = m_annotation.getEntities().iterator();
//  	while( ents.hasNext() ) {
//  	  Entity e = (Entity)ents.next();
//  	  e.updateBindings( m_notebook );
//  	  m_notebook.addAnnotation( e.getWidget(), m_annotation );
//  	}
	
	DebugWindow.addLine( "Annotations", m_annotation.describe() );
	DebugWindow.addParagraph( "Annotations" );
      }

      public void doUndo()
      {
	DebugWindow.addLine( "MO", "undo annotation" );
    
//  	m_annotation.retractUpdate();
//  	undoAction( m_Surface );

//  	Iterator ents = m_annotation.getEntities().iterator();
//  	while( ents.hasNext() ) {
//  	  Entity e = (Entity)ents.next();
//  	  e.retractBindings( m_notebook );
//  	  m_notebook.removeAnnotation( e.getWidget(), m_annotation );
//  	}

//  	DebugWindow.addLine( "Annotations",
//  			     "Retract:\n" + m_annotation.describe() );
      }

      public String getAction( )
      {
	return "Annotate: " + m_annotation.describe();
      }
    };
    addToSuitcase( dt );
  }

}
  


