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

// -*-Mode: Java-*- 
// $Id: TranscriberAgent.java,v 1.3 2003/03/06 00:40:48 moltmans Exp $
// TranscriberAgent.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Maintainer: Michael Oltmans <moltmans@ai.mit.edu> 
// Copyright: Copyright (C) 1999 by Michael Oltmans 
// Created: <Tue Jul 20 16:47:35 1999> 
// Time-stamp: <1999-09-12 17:50:55 moltmans> 
// Keywords: 

package rec.annotate.transcript;

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

import rec.agent.*;
import rec.util.*;
import speech.*;
import speech.tools.*;

public class TranscriberAgent extends SpeechAgent
  implements Transcriber, ModuleListener
{
  protected Transcript m_Transcript;
  protected Sketch m_Sketch;
  protected RemoteModule m_SketchModule;
  protected ModuleListener m_SketchListener;

  public TranscriberAgent( ) throws RemoteException
  {
    m_Transcript = new Transcript( );

    AppGrammar g = loadGrammar( );
    makeAlwaysActive( g );

    // get the sketch agent
    m_Sketch = (Sketch)reliesOn( "rec.agent.Sketch" );

    ModuleMaker mm = new ModuleMaker( "rec.annotate.transcript.SketchTranscriberModule" );

    // we are the one to ring for an update from the sketch
    m_SketchListener = this;
    m_SketchModule = m_Sketch.installModule( mm, m_SketchListener );
  }

  public Transcript getTranscript( ) throws RemoteException
  {
    return m_Transcript;
  }
  
  public Object ring( Object o )
  {
    TranscriptItem item = ( TranscriptItem ) o;
    
    Console.writeln( "Transcript Agent was rung with: " + o );
    m_Transcript.addEntry( item );
    return null;
  }

  public void acceptedTagsResult( Hashtable tags ) throws RemoteException 
  {
    if ( tags.containsKey( "ask" ) ) {
      Console.writeln( "Asking for the transcript: " );
      m_Transcript.printTranscript( );
    }
    else
      Console.writeln( "Transcriber accepted tags: " + tags );
  }
}

  
