package visual.statik.sampled;

import javax.microedition.lcdui.*;

import gui.*;

/**
 * A concrete extension of a Canvas that illustrates
 * the rendering of sampled static visual content
 *
 * Changes in J2ME Version:
 *
 *    Packed int instead of Color
 * 
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0 (J2ME)
 */
public class ImageCanvas extends VisualComponent
{
    private Image       image;
    
    
    /**
     * Explicit Value Constructor
     *
     * @param image   The Image to render
     */
    public ImageCanvas(Image image)
    {
        this.image = image;
    }
    
    
    /**
     * Render this Canvas
     *
     * @param g   The rendering engine to use
     */
    public void paint(Graphics g)
    {
        int         height, x, y, width;

        // Note: The Canvas class is abstract so we don't
        // call super.paint(g)
        
        x      = g.getClipX();
        y      = g.getClipY();
        width  = g.getClipWidth();
        height = g.getClipHeight();
        
        // Note:  The background needs to be "cleared"
        g.setColor(0x00FFFFFF);
        g.fillRect(x, y, width, height);
        
        // Note: The registration point must be specified
        g.drawImage(image, 0, 0, Graphics.TOP|Graphics.LEFT);
    }
}
