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

// -*-Mode: Java-*- 
// $Id: EditModeModule.java,v 1.6 2003/03/06 00:40:40 moltmans Exp $
// EditModeModule.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Wed Sep 15 15:44:11 1999> 
// Time-stamp: <2000-03-14 18:07:56 moltmans> 
package rec.sys;

import java.util.*;
import rec.util.*;

/**
 * This is a basic module that must be given an argument which
 * will be passed on to its recognizers.  This is how selection mode
 * can be implemented.
 **/
public class EditModeModule extends BasicModule
{
  private Object m_Arg;
  private HashSet m_EditMode;

  public EditModeModule( String name, HashSet editMode )
  {
    super( name );
    m_Arg = null;
    m_EditMode = new HashSet( editMode );
  }

  public void enable() 
  {
    Assert.error( "Must provide an argument to enable a ModeRecognizerModule" );
  }

  public void enable( Object arg )
  {
    setModeArg( arg );
    super.enable();
  }

  public void disable()
  {
    m_Arg = null;
    super.disable();
  }
  
  public void setModeArg( Object arg ) 
  {
    m_Arg = arg;

    Iterator it = getAllRecognizers();
    Object o = null;
    
    while ( it.hasNext() ) {
      o = it.next();
      if ( o instanceof EditModeRecognizer ) {
	Console.writeln( "setModeArg of " + o + " to " + arg );
	((EditModeRecognizer)o).setModeArg( arg );
      }
    }

    it = getReasoners();
    while ( it.hasNext() ) {
      o = it.next();
      if ( o instanceof EditModeReasoner )
	((EditModeReasoner)o).setModeArg( arg );
    }
  }  
}


