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

// $Id: FlipTransition.java,v 1.4 2003/03/06 00:40:40 moltmans Exp $
// Time-stamp: <2000-03-11 18:59:36 moltmans>
package rec.sys;


////////////////////////////////////////////////////////////////////////////////
//
// FILE:	FlipTransition.java

// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:	Drawing recognition
//
//////////////////////////////////////////////////////////////////////////////


import rec.util.*;

/**
 * This is a utility Transition.  It allows for a different kind of
 * method.
 *
 * need to override doUndo() and doRedo()
 */
public abstract class FlipTransition extends Transition
{
  protected boolean flipped;

  /**
   * use this to create the FlipTransition
   */
  public FlipTransition( Surface s )
  {
    super( s );
    flipped = false;
  }

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


  /**
   * Make the transition which undoes this one and return it.
   */
  protected Transition makeRedoTransition( )
  {
    final FlipTransition internal = this;;

    Assert.check( internal.flipped == false,
		  "double flip bad" );

    FlipTransition t = new FlipTransition( getSurface() )    {
      
      public void doUndo( )
	{
	  internal.doRedo();
	}
      public void doRedo()
	{
	  internal.doUndo();
	}
      public String name()
	{
	  return internal.name();
	}

    };
    t.flipped = true;

    return t;
  }

  public Transition getFlip()
  {
    return getRedoTransition();
  }
  
  public abstract void doRedo( );

  public abstract String name();

  public String toString( )
  {
    return name() + ( flipped ? "(flip)-" : "-" ) + getId();
  }

}

