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

// -*-Mode: Java-*- 
// $Id: UtteranceFrame.java,v 1.5 2003/03/06 00:40:39 moltmans Exp $
// UtteranceFrame.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Thu Feb 24 18:15:21 2000> 
// Time-stamp: <2001-09-11 15:03:16 moltmans> 
package rec.ui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.util.*;
import rec.sys.WUtterance;

/**
 * This class provides a mechanism for displaying utterances as they
 * are spoken.  This is in keeping with the explicit feed back
 * paradigm.
 **/
public class UtteranceFrame extends Frame
{
  private JTextPane m_pane;
  private JScrollBar m_scrollBar;
  private DefaultStyledDocument m_doc;
  private String m_title;
  private AttributeSet m_attr;
  
  public UtteranceFrame() 
  {
    super( "Recent Utterances");

    m_doc = new DefaultStyledDocument();
    m_pane = new JTextPane(m_doc);

    JScrollPane scrollPane = new JScrollPane( m_pane );
    m_scrollBar = scrollPane.getVerticalScrollBar();

    setLayout(new BorderLayout());
    add( scrollPane, BorderLayout.CENTER );

    m_pane.setEditable( false );
    SimpleAttributeSet m_attr = new SimpleAttributeSet();
    StyleConstants.setFontFamily(m_attr, "courier");
    StyleConstants.setFontSize(m_attr, 12);

    try {
      m_doc.insertString( m_doc.getLength(),
			  "I have heard the following", m_attr );
    }
    catch ( BadLocationException ble ) {
    }

    WindowListener wl = new WindowAdapter() {
      public void windowClosing( WindowEvent e ) {
	dispose();
      }
    };

    addWindowListener( wl );
  }

//    public void show() 
//    {
//      m_pane.display( m_content );
//      super.show();
//    }
  

  public void addUtterance( WUtterance utterance ) 
  {
    try {
      m_doc.insertString( m_doc.getLength(), utterance.getTags().getText(),
			  m_attr );
      m_scrollBar.setValue( m_scrollBar.getMaximum() );
    }
    catch ( BadLocationException ble ) {
    }
  }
}
