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

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	RotateTransition.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
// DATE:	08-XX-98
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:	Drawing recognition
//
// HISTORY:     09-XX-98 archon
//              Modified to fit with new recognition model
//
//              11-15-98 archon
//              Now aware of new rec.geo package
//
////////////////////////////////////////////////////////////////////////////////

package rec.core;

import rec.util.*;
import rec.geo.*;
import rec.sys.*;

public class RotateTransition extends AlterTransition
{
  public RotateTransition( Surface s, VisibleWidget targetWidget, GPoint center,
			   double angle )
  {
    super( s, targetWidget );

    m_PointOfRotation = new GPoint( center );
    m_AngleRotated = angle;
  }

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

  public GPoint getPointOfRotation()
  {
    return( new GPoint( m_PointOfRotation ) );
  }

  public double getAngleRotated()
  {
    return( m_AngleRotated );
  }

  public void doUndo()
  {
    ((VisibleWidget)getTargetWidget()).rotate( m_PointOfRotation, -1.0 * m_AngleRotated );

    getSurface().alterWidget( getTargetWidget(),
			      (AlterTransition)getRedoTransition() );
  }

  public Transition makeRedoTransition()
  {
    return( new RotateTransition( getSurface(),
				  (VisibleWidget)getTargetWidget(),
				  m_PointOfRotation,
				  ( -1.0 * m_AngleRotated ) ) );
  }

  // an extension of luke's little hack.  this is not the way to do
  // this, but it's what you get when you try to simplify something
  // complicated without structure breaking down.
  public void doDo()
  {
    getRedoTransition().undo();
  }
  
  public String name()
  {
    return "rotate";
  }


  public String getAction()
  {
    return "rotates object " + m_TargetWidget + " by " + m_AngleRotated;
  }
  //////////////////////////////////////////////////////////////////////////////

  private GPoint m_PointOfRotation;
  private double m_AngleRotated;
}

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