/* @(#) ImageBrowser.java 1.1 99/11/20
 * Copyright (c) 1999 Lawrence Rodrigues
 */
package com.vistech.imageviewer;
import java.io.*;
import java.beans.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.lang.reflect.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.*;
import com.vistech.util.*;
import com.vistech.events.*;
import com.vistech.imageloader.*;
import com.sun.image.codec.jpeg.*;

/** The ImageBrowser class displays multiple images in a single frame.
 * @version 1.0  20 Nov 1999
 * @author Lawrence Rodrigues
 **/
public class ImageBrowser extends com.vistech.util.ApplicationFrame{
   protected MultiImageLoader il;
   protected String saveFileName = null;
   protected ViewerPanel viewer;
   public ImageBrowser() {
      createUI();
      saveFileName = "ImageLoaderGUI.jpg";
   }

   protected void setAboutStrings() {
      setAboutString(" JPEG Image Browser \n Version 1.0 \n"+
                        "Author: Lawrence Rodrigues\n");
      setAboutTitle("Image Browser");
   }

   private void createUI() {
      setAboutStrings();
      il = new MultiImageLoader();
      il.setLoadButtonLabel("Launch Image Browser");
      il.addImageLoadedListener(
          new ImageLoadedListener() {
             public void imageLoaded(ImageLoadedEvent e) {
                Image[] imset = e.getImages();
                displayImage(imset);
                il.setLoadButtonLabel("Load Images");
             }
          });
      this.getContentPane().add(il);
      this.setSize(il.getPreferredSize().width+30, il.getPreferredSize().height+50);
   }

   public void save() {
     /* if(saveFileName == null) saveAs();
      Graphics g = this.getContentPane().getGraphics();
      Container contpane = this.getContentPane();
      JpegUtil.saveComponentAsJPEG(il,this.getContentPane(), saveFileName);
      contpane.add(il);
      this.validate(); */
   }

   public void saveAs() {
    /*  String filename = JpegUtil.launchFileDialog();
      if(filename != null){
         saveFileName = filename;
         save();
      }*/
   }

   public void displayImage(Image[] imset) {
      if(viewer == null) {
         viewer = new ViewerPanel();
         viewer.setTitle("Image Browser");
         viewer.addWindowListener(
           new WindowAdapter() {
           public void windowClosing(WindowEvent e){
             System.exit(0);
          }
         });
      }
      viewer.setImageSet(imset);
      viewer.show();
      viewer.repaint();
  }

  public static void  main(String[] args){
     ImageBrowser ib = new ImageBrowser();
     ib.setTitle("Image Browser");
     ib.show();
  }
}