//[part1.
package visual.statik.sampled;


import java.awt.Image;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;


import app.*;
import io.*;


/**
 * An example that illustrates the rendering of
 * sampled static visual content
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class   ImageCanvasApp
       extends AbstractMultimediaApp
{
    /**
     * Default Constructor
     *
     */
    public ImageCanvasApp()
    {
       super();    
    }


    /**
     * This method is called just before the main window
     * is first made visible
     */
    public void init()
    {
//]part1.
//[part2a.
       Image                     image;
//]part2a.
       ImageCanvas               canvas;
       InputStream               is;       
       JPanel                    contentPane;       
//[part2b.
       ResourceFinder            finder;
       String                    name;
       
       // Get the file name
       name   = rootPaneContainer.getParameter("0");
       if (name == null) 
          name = "/visual/statik/sampled/scribble.gif";

       // Construct a ResourceFinder
       finder = ResourceFinder.createInstance();          

       // Read the image
       image  = null;       
       try
       {
          is = finder.findInputStream(name);
          if (is != null) 
          {
             image = ImageIO.read(is);
             is.close();             
          }
       }
       catch (IOException io)
       {
          // image will be null
       }
//]part2b.
//[part3.

       // Create the component that will render the image
       canvas      = new ImageCanvas(image);
       canvas.setBounds(0,
                        0,
                        image.getWidth(null),
                        image.getHeight(null));

       // Add the ImageCanvas to the main window
       contentPane = (JPanel)rootPaneContainer.getContentPane();
       contentPane.add(canvas);
    }
}
//]part3.
