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

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

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


    /**
     *  The constructor
     */
    public AnimationRule()
    {
		clips        = new Rectangle[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 )
    {
		Rectangle modified_clips[][] = 
			new Rectangle[clips.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_times[i] = times[i];
		}
		
		modified_clips[modified_clips.length-1] = clip;
		modified_times[modified_times.length-1] = time;
		
	    clips = modified_clips;
	    times = modified_times;
    }


    /**
     *  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;
	}
}
