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

// -*-Mode: JDE-*- 
// $Id: WPoint.java,v 1.5 2003/03/06 00:40:48 moltmans Exp $
// WPoint.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Fri Jun 09 17:14:04 2000> 
// Time-stamp: <2001-03-11 17:43:43 moltmans> 
package rec.annotate.widgets;

import java.awt.Graphics;
import rec.util.*;
import rec.sys.*;
import rec.geo.*;
import rec.core.widgets.*;
import rec.annotate.facts.*;
import rec.annotate.rules.*;
import rec.simulate.widgets.WSimBody;

/**
 **/
public class WPoint extends SelfDrawingWidget
{
  private GPoint m_point;
  private WPoint m_me;
  private WSimBody m_referent;

  public WPoint( Surface s, GPoint point, WSimBody body ) 
  {
    super( new GShape[] {point} );
    m_point = point;
    m_referent = body;
    setDefaultColor( "point", "annotation" );
    setEnglishName( "" );
    m_me = this;
  }
  
  public void makeDefaultSuitcase( Surface s )
  {
    //      Assert.check( m_pointFact == null,
    //  		  "Remaking Point Fact" );

    DoTransition dt = new DoTransition(s) {
      public void doDo( )
      {
	Notebook book = m_Surface.getNotebook();
	String pointSym = book.getSymbol(m_me);
	String bodySym = book.getSymbol(m_referent);
	
	book.assume( new String[] {"point", pointSym}, ":REC-SYSTEM" );
	book.assume( new String[] {"point-referent", pointSym, bodySym},
		     ":REC-SYSTEM" );
	book.assumeTimeStamp(m_me);
	book.updateNotes();
      }

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

      public String getAction( )
      {
	return "WPoint: " + m_point;
      }
    };
    super.makeDefaultSuitcase( s );
    addToSuitcase( dt );
    //    addToSuitcase( new DieTransition( s, this ) ); 
  }

  public void draw( Graphics g )
  {
    int x = (int)m_point.x;
    int y = (int)m_point.y;

    g.fillOval( x-7, y-7, 14, 14 );
  }
}


