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

package rec.fsm;

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	DoubleArrowFixer.java.java
//
// AUTHOR:      Luke Weisman
//              luke@ai.mit.edu
//
// DATE:	June, 1998
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:	Drawing recognition system
//
////////////////////////////////////////////////////////////////////////////////


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

public class DoubleArrowFixer extends Aligner
   implements Registerable
{

  public DoubleArrowFixer()
  {
  }

  /////////////////////////////////////////////////////////////////////////////
  
  /**
   * Each new stroke generated gets put into the pipe here.
   *     It will remove and add objects to the 'out' target
   *     as it deems fit.
   *
   * @return a boolean if changes were made.
   */
  public boolean recognize( Surface s, Widget w )
  {
    if ( !s.isRegistered( this, w ) ) 
      s.register( this, w );

    return false;
  }

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

    v.addElement( "rec.fsm.Edge" );

    return( v.iterator() );
  }

  public Iterator getOutputTypes()
  {
    return getInputTypes();
  }



  // the register stuff
  public void removed( Widget w )
  {
  }

  /**
   * Called when ow is replaced by nw.
   */
  public void replaced( Widget ow, Widget nw )
  {
  }

  public void replaced( Widget ow, Collection nw )
  {
  }


  /***
   * Called when w has been altered.
   *
   * @param w  The Widget after it has been altered.
   * @param t  The Transition that affected that Widget.
   */
  public void altered( Widget w, Transition t )
  {
    Edge ed = (Edge)w;
    //Console.writeln( "Looking at arrowheads." );
    if ( ed.full() && ed.hasArrowhead( true ) && ed.hasArrowhead( false ) )
      {
	Edge ned = new Edge( ed );
	ed.removeArrowhead( true );
	ned.removeArrowhead( false );
	
	// add new edge, rerecognize.
	ed.surf.addWidget( ned, true );
      }
  }

}

////////////////////////////////////////////////////////////////////////////////
