
/*
 * @(#) AppFrame.java 1.0 96/12/26 
 * Copyright (c) 1996 Larry Rodrigues
 */
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;

    public class AppFrame extends Frame{

       private int width, height;
       String str;
       Locale curLocale;
       String copyRight, author;
       String helpMidText, helpBoxTitle;
       String aboutMidText, aboutBoxTitle;
       MenuItem open, exit,save, saveAs, print, help, about;

       protected String curDataFile;

       public static void main(String arg[]){
          Image icon = Toolkit.getDefaultToolkit().getImage("manning.jpg");
          AppFrame app = new AppFrame(400, 300);
          Image scIcon =  icon.getScaledInstance(16,16,Image.SCALE_FAST);
          app.setIconImage(scIcon);
          app.show();
       }
       public AppFrame(){
          createGUI();
       }

       public AppFrame(int wid, int ht){
          setTitle("");
          width = wid;
          height = ht;
          setLocale(Locale.US);
          createGUI();
          setSize(width,height);
       }

       protected void createGUI(){
          setBackground(Color.lightGray);
          WindowEventHandler winAda = new WindowEventHandler();
          addWindowListener(winAda);
          AppMenuBar AppMenuBar = new AppMenuBar();
          setMenuBar((MenuBar)AppMenuBar);
       }
       /** Implementing WindowListener
         */
       class WindowEventHandler extends WindowAdapter{
           public void windowClosed(WindowEvent e){
              dispose();
              //System.exit(0);
           }
           public void windowClosing(WindowEvent e){
              dispose();
              //System.exit(0);
           }
       }

       public void open(){

       }
       public void saveAs(){
       }

       public void save(){

   
       }
       public void quit(){
          dispose();
       }
       public class AppMenuBar extends MenuBar {
          Vector menus = new Vector();

          public AppMenuBar(){
             createGUI();
             createHelpMenu();
          }

          public void createGUI(){
             createFileMenu();
          }
          public Menu createFileMenu() {
             Menu fileMenu = new Menu("File");
            
             open = new MenuItem("Open");
             open.addActionListener(new OpenAdapter());

             save = new MenuItem("Save");
             save.addActionListener(new SaveAdapter());
    
             saveAs = new MenuItem("Save As");
             saveAs.addActionListener(new SaveAsAdapter());
             exit = new MenuItem("Exit");
             MenuItem printSetup = new MenuItem("Print Setup");
             exit.addActionListener(
               new ActionListener(){
                  public void actionPerformed(ActionEvent e){
                     quit();
                 }
               }
             ); 
             //fileMenu.add(open);
             //fileMenu.add(save);
             //fileMenu.add(saveAs);
             //fileMenu.addSeparator();
             fileMenu.add(exit);
             add(fileMenu);
             return fileMenu;
         }

      public Menu createHelpMenu() {
         help = new MenuItem("Help");
         HelpAdapter hlpA = new HelpAdapter();
         help.addActionListener(hlpA);
         about = new MenuItem("About");
         AboutAdapter abtA = new AboutAdapter();
         about.addActionListener(abtA);
         Menu helpMenu = new Menu("Help");
         helpMenu.add(help);
         helpMenu.add(about);
         add(helpMenu);
         return helpMenu;
      }

      public Menu createLocaleMenu(){
         LocaleAdapter usL = new LocaleAdapter(Locale.US);
         MenuItem us = new MenuItem("US");
         us.addActionListener(usL);
         MenuItem uk = new MenuItem("UK");
         LocaleAdapter ukL = new LocaleAdapter(Locale.UK);
         uk.addActionListener(ukL);

         MenuItem france = new MenuItem("French");
         LocaleAdapter frL = new LocaleAdapter(Locale.FRENCH);
         france.addActionListener(frL);

         MenuItem germany = new MenuItem("German");
         LocaleAdapter gerL = new LocaleAdapter(Locale.GERMAN);
         germany.addActionListener(gerL);
         Menu localeMenu = new Menu("Locale");
         localeMenu.add(us);
         localeMenu.add(uk);
         localeMenu.add(france);
         localeMenu.add(germany);
         add(localeMenu);
         menus.addElement(localeMenu);
         return localeMenu;
      }

      public Menu createPrintMenu(){
         print = new MenuItem("Print");
         PrintAdapter pa = new PrintAdapter();
         print.addActionListener(pa);
         MenuItem printSetup = new MenuItem("Print Setup");
         Menu printMenu = new Menu("Print");
         printMenu.add(print);
         menus.addElement(printMenu);
         add(printMenu);
         return printMenu;
      }

      public void addMenus(Vector menus){
         for(Enumeration e = menus.elements();e.hasMoreElements();){
             add((Menu)(e.nextElement()));
         }
      }
      class PrintSetupAdapter implements ActionListener{
         public void actionPerformed(ActionEvent e){
            PrintJob pr = 
            Toolkit.getDefaultToolkit().getPrintJob(AppFrame.this, "Print", null);
            Graphics printG = pr.getGraphics();
            printG.setColor(Color.black);
            printAll(printG);
            printG.dispose();
            pr.end();
         }
     }

     class PrintAdapter implements ActionListener{
         public void actionPerformed(ActionEvent e){
            PrintJob pr = 
            Toolkit.getDefaultToolkit().getPrintJob(AppFrame.this, "Print", null);
            Graphics printG = pr.getGraphics();
            printAll(printG);
            printG.dispose();
            pr.end();
         }

     }

     class LocaleAdapter implements ActionListener{
         Locale locale;
         public LocaleAdapter(Locale loc){
            locale = loc;      
         } 
         public void actionPerformed(ActionEvent e){
            //setLocale(locale); 
         }
      }

      class HelpAdapter implements ActionListener{
         MessageBox helpBox;
         public void actionPerformed(ActionEvent e){
            String topString = new String("Help \n");
            String midString = new String("Currently no help available \n");
            helpBox = new MessageBox(AppFrame.this,256,256,helpBoxTitle,topString+midString, false); 

            helpBox.addActionListener(
               new ActionListener() {
                  public void actionPerformed(ActionEvent e){
                     helpBox.dispose();
                  }
               }
            );

            helpBox.show();
         }

      }
      class AboutAdapter implements ActionListener{
         MessageBox aboutBox;
         public void actionPerformed(ActionEvent e){
            String topString = new String("Image Viewer Version 1.0 \n");
            String midString = new String("Author: Lawrence Rodrigues \n");
            aboutBox = new MessageBox(AppFrame.this,256,256,aboutBoxTitle,topString+midString, false); 
            aboutBox.addActionListener(
               new ActionListener() {
                  public void actionPerformed(ActionEvent e){
                     aboutBox.dispose();
                  }
               }
            );
            aboutBox.setTitle(" About");
            aboutBox.show();
         }
       }

       class OpenAdapter implements ActionListener{
          public void actionPerformed(ActionEvent e){
             open();
          }
       }

       
       class SaveAdapter implements ActionListener{
          public void actionPerformed(ActionEvent e){
             save();
          }
       }
    
       class SaveAsAdapter implements ActionListener{
          public void actionPerformed(ActionEvent e){
             saveAs();
          }
       }

    }  //End of AppMenuBar class
}
