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

// -*-Mode: Java-*- 
// $Id: SimpleUtteranceRecognizer.java,v 1.11 2003/03/06 00:40:47 moltmans Exp $
// SimpleUtteranceRecognizer.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Maintainer: Michael Oltmans <moltmans@ai.mit.edu> 
// Copyright: Copyright (C) 1999 by Michael Oltmans 
// Created: <Thu Aug 19 21:39:35 1999> 
// Time-stamp: <2000-03-13 00:00:41 moltmans> 
// Keywords: 
package rec.core.speech;

import java.util.*;

import rec.sys.*;
import rec.core.*;
import rec.core.widgets.*;
import rec.util.*;

/**
 * This is a convenient wrapper for making simple recognizers of
 * utterances that don't require any reasoning and don't perform
 * complex actions.  They also never redo an action once it is undone.
 *
 * Just give it the tag to recognize and implement:
 *   performAction that will be called every time the widget is elected.
 *   performUndo   will get called to undo the performAction
 **/
public abstract class SimpleUtteranceRecognizer extends Recognizer
  implements Command
{
  /** the tag this recognizes **/
  private String m_Tag;
  
  /** the tag to recognize **/
  public SimpleUtteranceRecognizer( String tag )
  {
    m_Tag = tag;
  }

//    /** the action to perform when elected **/
//    public abstract void performAction( Surface s );
  
//    /** the action that will undo the performAction  **/
//    public abstract void performUndo( Surface s );
    
  public boolean recognize( Surface s, Widget w )
  {
    WUtterance utterance = (WUtterance)w;

    if ( utterance.hasTag( m_Tag ) ) {
      Widget widget = new WCommand( this, m_Tag );
      s.replaceWidget( w, widget );
	
      return true;
    }

    return false;
  }

  public Iterator getInputTypes()
  {
    return WUtterance.getUtteranceTypes();
  }

  public Iterator getOutputTypes()
  {
    Vector v = new Vector();

    v.addElement( "rec.core.widgets.WCommand" );

    return( v.iterator() );
  }

}

