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

// -*-Mode: Java-*- 
// $Id: WMotionArrow.java,v 1.11 2003/03/06 00:40:48 moltmans Exp $
// WMotionArrow.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Thu May 11 15:47:12 2000> 
// Time-stamp: <2001-03-11 17:42:39 moltmans> 
package rec.annotate.widgets;

import java.awt.Graphics;
import rec.util.*;
import rec.sys.*;
import rec.core.widgets.*;
import rec.simulate.widgets.WSimBody;
import rec.annotate.rules.Notebook;
import java.awt.Rectangle;
import rec.util.DebugWindow;

/**
 * This represents the motion that a body makes as part of its
 * behavior.
 **/
public class WMotionArrow extends WSquiggleArrow {
  private WSimBody m_referent;
  private Notebook m_notebook;
  // a pointer to myself for use in inner classes
  private WMotionArrow m_me;

  public WMotionArrow( Surface s, WSquiggleArrow arrow, WSimBody body ) 
  {
    super( arrow );
    setDefaultColor( "path", "annotation" );
    setEnglishName( "" );
    m_referent = body;
    m_notebook = s.getNotebook();
    m_me = this;
  }
  
  public void makeDefaultSuitcase( Surface s ) 
  {
    //    m_arrowFact = new Arrow( s, this );
    DoTransition dt = new DoTransition(s) {
      public void doDo( )
      {
	String bodySym = m_notebook.getSymbol(m_referent);
	String arrowSym = m_notebook.getSymbol(m_me);
	m_notebook.assume(new String[] {"arrow", arrowSym}, ":REC-SYSTEM");
	m_notebook.assume(new String[] {"arrow-referent", arrowSym, bodySym},
		    ":REC-SYSTEM");
	m_notebook.assumeTimeStamp(m_me);
	m_notebook.updateNotes();
      }

      public void doUndo( )
      {
	Notebook book = m_Surface.getNotebook();
	String arrowSym = m_notebook.getSymbol(m_me);
	String bodySym = m_notebook.getSymbol(m_referent);
	m_notebook.retract( new String[] {"arrow", arrowSym}, ":REC-SYSTEM" );
	m_notebook.retract(new String[] {"arrow-referent", arrowSym, bodySym},
			  ":REC-SYSTEM");
	m_notebook.updateNotes();
      }

      public String getAction( )
      {
	return "WMotionArrow";
      }
    };
    super.makeDefaultSuitcase( s );
    addToSuitcase( dt );
  }

  public boolean passesBy(WSimBody body1, WSimBody body2) 
  {
    Rectangle bounds = body1.getBounds();
    double size = ( bounds.getWidth() + bounds.getHeight() ) / 4.0;
    return passesBy( body2.getShape(), size);
  }
}


