import java.awt.*;

/**
 * Double Buffering is handled here
 *
 * @author Selim Mimaroglu
 * @version 1.0
 *
 */
public class DoubleBufferHandler {


    /**
     * Set the double buffered component
     */
    public DoubleBufferHandler(DoubleBufferedComponent com) {
	this.comp = com;
    }

    /**
     * set size, change size of the component
     * @param dim new Dimension of the component
     */ 
    final public void setSize(Dimension dim) {
	d = dim;
	im = comp.createImage(d.width, d.height);
	offscreen = im.getGraphics();
    }

    /**
     * redraw the component, its's first drawn offscreen
     * @param g Graphics of the component
     */
    final public void update(Graphics g) {
	if (im == null) {
	    setSize(comp.getSize());
	}

	comp.paintFrame(offscreen);
	g.drawImage(im, 0, 0, null);
    }

    /**
     * Double buffering will be done on this component 
     */
    protected DoubleBufferedComponent comp;

    /** 
     * Dimension of this component 
     */
    protected Dimension d;
    
    /**
     * Image im for offscreen 
     */
    protected Image im;

    /**
     * offscreen graphics
     */
    protected Graphics offscreen;
}













