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

// -*-Mode: Java-*- 
// $Id: SketchTranscriberModule.java,v 1.3 2003/03/06 00:40:48 moltmans Exp $
// TranscriptModule.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Maintainer: Michael Oltmans <moltmans@ai.mit.edu> 
// Copyright: Copyright (C) 1999 by Michael Oltmans 
// Created: <Fri Jul 16 16:06:11 1999> 
// Time-stamp: <1999-09-12 17:48:27 moltmans> 
// Keywords: 

package rec.annotate.transcript;

import rec.agent.*;
import rec.sys.*;
import rec.util.*;

import java.util.*;
import java.rmi.*;

/**
 * This class spies on the sketch system and tells the Transcript
 * agent when the sketch is modified.
 **/
public class SketchTranscriberModule extends RemoteModuleImpl
  implements Registerable
{

  public SketchTranscriberModule( ModuleListener parent ) throws RemoteException
  {
    super( parent );
    Console.writeln( "Constructed TranscriptModule connected to " + parent );
  }

  private void tellPop( TranscriptItem item )
  {
    try {
      Console.writeln( "Telling pop: " + item );
      parent.ring( item );
    }
    catch ( RemoteException e ) {
      e.printStackTrace( );
    }
  }

  public boolean recognizeWidget( Surface s, Widget w ) 
  {
    s.register( this, w );
    tellPop( new TranscriptItem( w, TranscriptItem.ADDED ) );
    return false;
  }

  public void removed( Widget w )
  {
    tellPop( new TranscriptItem( w, TranscriptItem.REMOVED ) );
  }

  public void replaced( Widget ow, Widget nw )
  {
    tellPop( new TranscriptItem( ow, nw, TranscriptItem.REPLACED ) );
  }

  public void replaced( Widget ow, Collection nws )
  {
    Iterator it = nws.iterator();
    while( it.hasNext() )
      replaced( ow, (Widget)it.next() );
  }

  public void altered( Widget w, Transition t )
  {
    tellPop( new TranscriptItem( w, TranscriptItem.ALTERED ) );
  }

}

      


  
