/**  BufferedImageViewer Class
   * @version 1.0  12 June 2000
   * @author Lawrence Rodrigues
   **/
package app;
import java.io.*;
import java.rmi.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
import com.vistech.rmi.*;

/** 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 BufferedImageViewer extends AWTImageViewer{

   public BufferedImageViewer(){
      setTitle("Java 2D Image Viewer");
   }

   public void load(String filename) throws RemoteException{
      if(filename.endsWith(".jpg")  || filename.endsWith(".jpeg") ||
         filename.endsWith(".JPG")  || filename.endsWith(".JPEG")){
         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 {
         JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(is);
         BufferedImage bi = decoder.decodeAsBufferedImage();
         return bi;
      } catch(Exception e) {
         System.out.println(e);
         return null;
      }
   }

   public static void main(String args[]){
      BufferedImageViewer fc = new BufferedImageViewer();
  }
}
