/**  ImageIOViewer Class
   * @version 1.0  12 June 2000
   * @author Lawrence Rodrigues
   **/
package app;
import java.io.*;
import java.rmi.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.image.*;
import com.vistech.rmi.*;
import javax.media.imageio.*;
import javax.media.imageio.stream.*;

/** An RMI client application that lists and displays buffered images loaded
  * by an RMI server.
  * @version 1.0 12 june 2000
  * @author Lawrence Rodrigues
  **/
public class ImageIOViewer extends AWTImageViewer{

   public ImageIOViewer(){
      setTitle("Remote Image IO Viewer");
   }

   public void load(String filename) throws RemoteException{
      byte[] buffer = loader.loadImageAsBytes(filename);
      ByteArrayInputStream bis = new   ByteArrayInputStream(buffer);
      BufferedImage img =  readAsBufferedImage(bis);
      imCanvas.setImage(img);
      imCanvas.repaint();
   }

   public BufferedImage readAsBufferedImage(InputStream is) {
      try {
      ImageInputStream mis = new FileCacheImageInputStream(is, new File("temp"));
      BufferedImage im = ImageIO.read(mis);
      return im;
     } catch(Exception e) {
       return null;
     }
   }
   public static void main(String args[]){
      ImageIOViewer fc = new ImageIOViewer();
   }
}

