////////////////////////////////////////////////////////////////////////////////
//																			  //
// AUTHOR:      Tevfik Metin Sezgin	                        				  //
//				Massachusetts Institute of Technology						  //
//				Department of Electrical Engineering and Computer Science	  //
//				Artificial Intelligence Laboratory							  //
//																			  //
// E-MAIL:		mtsezgin@ai.mit.edu, mtsezgin@mit.edu						  //
//																			  //
// COPYRIGHT:   Tevfik Metin Sezgin                    						  //
//              All rights reserved. This code can not be copied, modified,   //
//              or distributed in whole or partially without the written 	  //
//				permission of the author. Also see the COPYRIGHT file.		  //
//																			  //
////////////////////////////////////////////////////////////////////////////////

/** 
  * 
  * See the end of the file for the log of changes.
  * 
  * $Author: mtsezgin $
  * $Date: 2000/06/03 01:52:34 $   
  * $Revision: 1.4 $
  * $Headers$
  * $Id: Paintable.java,v 1.4 2000/06/03 01:52:34 mtsezgin Exp $     
  * $Name:  $   
  * $Locker:  $
  * $Source: /mit/mtsezgin/CVS/Repository/REC/Paintable.java,v $
  *  
  **/


/**
  *
  * This object implements StrokeDataFactory
  *
  **/

class      StrokeDataReader
implements StrokeDataFactory
{
	/**
	 * The last available position
	 **/
    private int available_position = 0;


	/**
	 * Points are put into this buffer when addPoint method is 
	 * called.
	 **/
    private Point points_buffer[];


    /**
    *
    * The constructor.
    *
    **/
    public StrokeDataReader( int max_data_points )
    {
		points_buffer = new Point[max_data_points];
	}
	
	
   /**
    *
    * Add a point.
	* Throws an array index out of bound exception if more points
	* than the max_data_points are added.
    *
    **/
    public void
    addPoint( Point point )
	{
		if ( ( available_position > 0 ) && 
		     ( point.getTimeStamp() == 
			   points_buffer[available_position-1].getTimeStamp() ) ) {
			System.out.println( available_position + " redundant time stamp!" );
			return;
		}
        System.out.print( available_position + ", " );
		points_buffer[available_position] = point;
		available_position++;
	}

  
    /**
    *
    * Return the StrokeData collected by this reader
    *
    **/
    public StrokeData
    getStrokeData()
	{
		Point data[] = new Point[available_position];

		for ( int i=0; i<data.length; i++ ) {
			data[i] = points_buffer[i];
		}

        System.out.println( "available_position = " + available_position );
        System.out.println( "data.length        = " + data.length        );
				
		long time_difference = data[data.length-1].getTimeStamp() - 
							   data[0].getTimeStamp();
        System.out.println( "\n\nRead " + data.length + " points in " +
                            time_difference + " milliseconds" );
        System.out.println( "This is " + ((1000*data.length)/time_difference ) +
                            " points per second" );

		return new StrokeData( data );
	}

  
    /**
    *
    * Reset
    *
    **/
    public void
    reset()
	{
		available_position = 0;
	}


    /**
    *
    * Return the StrokeData collected by this reader
    *
    **/
    public boolean
    hasSufficientData()
	{
		return ( available_position > 4 );
	}
}

/**
  *
  * $Log: Paintable.java,v $
  * Revision 1.4  2000/06/03 01:52:34  mtsezgin
  * *** empty log message ***
  *
  * Revision 1.3  2000/04/28 04:45:04  mtsezgin
  *
  * Now each GeometricObject keeps the mouse input that was previously
  * discarded. User can switch between seeing the recognized mode and
  * the raw mode. setDataPoints( Polygon points ) and getDataPoints()
  * are added to GeometricObject, and all the implementors are modified
  * accordingly.
  *
  * Revision 1.2  2000/04/11 01:41:45  mtsezgin
  * *** empty log message ***
  *
  * Revision 1.1  2000/04/11 00:41:47  mtsezgin
  *
  * Now the whole package succesfully parses a motor.
  *
  *
  **/
