//[skeleton1.
package visual.dynamic.sampled;

import java.awt.Graphics;


/*
 * An abstract implementation of the FrameOp interface.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public abstract class      AbstractFrameOp 
                implements FrameOp
{
    protected int             duration, first;

    
    /**
     * Explicit Value Constructor
     *
     * @param first     The first frame
     * @param duration  The duration (in frames)
     */
    public AbstractFrameOp(int first, int duration)
    {
       this.first    = first;       
       this.duration = 0;
       if (duration > 0) this.duration = duration;
    }
//]skeleton1.
//[methods1.

    /**
     * Get the index of the first frame of this FrameOp
     *
     * @return  The index of the first frame
     */
    public int getFirstFrame()
    {
       return first;       
    }
    

    /**
     * Get the index of the last frame of this FrameOp
     *
     * @return  The index of the last frame
     */
    public int getLastFrame()
    {
       return first+duration;       
    }
    

    /**
     * Has this FrameOp finished at the given frame?
     *
     * @return true if finished; false otherwise
     */
    protected boolean hasFinishedAt(int frame)
    {
       return (frame >= (first+duration-1));       
    }
    
//]methods1.
    
    

    /**
     * Apply the post-rendering portion of
     * this FrameOp
     *
     * @param g      The rendering engine
     * @param frame  The current frame number
     */
    public abstract void postRendering(Graphics g, int frame);


    /**
     * Apply the pre-rendering portion of
     * this FrameOp
     *
     * @param g      The rendering engine
     * @param frame  The current frame number
     */
    public abstract void preRendering(Graphics g, int frame);


//[methods2.

    /**
     * Should this FrameOp be applied at the given frame
     *
     * @return true if yes; false otherwise
     */
    protected boolean shouldApplyAt(int frame)
    {
       return ((frame >= first) && (frame <= (first+duration-1)));       
    }
//]methods2.
//[skeleton2.
    
}
//]skeleton2.
