import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Point;

import java.awt.image.ImageObserver;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;

class AnimationRule
{
	private Rectangle clips[][];
	private Point	  offsets[][];
	private long      times[];
	public  int       current_clip;


    /**
     *  The constructor
     */
    public AnimationRule()
    {
		clips        = new Rectangle[0][0];
		offsets      = new Point[0][0];
		times        = new long[0];
		current_clip = 0;
    }


    /**
     *  Test if the pixel is transparent. White pixels are 
	 *  assumed to be transparent.
     */
    public void
	appendClips( Rectangle clip[], long time, Point offset[] )
    {
		Rectangle modified_clips[][] = 
			new Rectangle[clips.length+1][0];
		Point modified_offsets[][] = 
			new Point[offsets.length+1][0];
		long modified_times[]   = 
			new long[times.length+1];
		
		for ( int i=0; i<clips.length; i++ ) {
			modified_clips[i]   = clips[i];
			modified_offsets[i] = offsets[i];
			modified_times[i]   = times[i];
		}
		
		modified_clips[modified_clips.length-1]   = clip;
		modified_offsets[modified_clips.length-1] = offset;
		modified_times[modified_times.length-1]   = time;
		
	    clips   = modified_clips;
	    offsets = modified_offsets;
	    times   = modified_times;
    }


    /**
     *  Get the offsets
     */
    public Point[]
	getCurrentOffsets()
    {
		return offsets[current_clip];
	}


    /**
     *  Get the current clip.
     */
    public Rectangle[]
	getCurrentClips()
    {
		return clips[current_clip];
	}


    /**
     *  Get the delay for the current clip
     */
    public long
	getCurrentDelay()
    {
		return times[current_clip];
	}


    /**
     *  Point to the next clip
     */
    public void
	next()
    {
		current_clip = (current_clip+1)%clips.length;
	}
}
