
/*
 * @(#) ApplicationFrame.java 1.0 98/20/5 
 * Copyright (c) 1998 Larry Rodrigues
 */
    package vis.util;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.event.*;
    /**
      * Provides a skeleton application frame for applications.
      * @version 1.0  20 May 1998
      * @author Lawrence Rodrigues
      */
    public class ApplicationFrame extends JFrame{
       private int width, height;
       String str;
       Locale curLocale;
       String copyRight, author;
       String helpMidText, helpBoxTitle;
       String aboutMidText, aboutBoxTitle;
       JMenuItem open, exit,save, saveAs, print, help, about;
       JMenu lookAndFeel;
       protected String curDataFile;
       public Container contentPane;

       public static void main(String arg[]){
          ApplicationFrame app = new ApplicationFrame(400, 300);
          app.show();
       }

       /**
         * Constructor sets default locale and creates GUI.
         */
       public ApplicationFrame(){
          contentPane = this.getContentPane();
          setLocale(Locale.US);
          createGUI();
       }

       /**
         *  Constructor when used in applications.
         *  @param wid the width of the frame.
         *  @param ht the height of the frame.
         */
       public ApplicationFrame(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();
          setJMenuBar((JMenuBar)AppMenuBar);
       }

       /**
         *
         * @param the locale.
         */
       public void setLocale(Locale loc){
          String resource = new String("USResource.msg");
          if(loc ==  Locale.GERMAN){
             resource = new String("GermanResource.msg");
          }

          if(loc ==  Locale.FRENCH){
             resource = new String("FrenchResource.msg");
          }
          if(loc ==  Locale.UK){
             resource = new String("UKResource.msg");
          }
          if(loc ==  Locale.US){
             resource = new String("USResource.msg");
          }

          Properties prop = new Properties();
          try{
              FileInputStream file = new FileInputStream(resource);
              PropertyResourceBundle  msg = new PropertyResourceBundle(file);
              copyRight = (String)msg.handleGetObject("m1");
              author = (String)msg.handleGetObject("m2");
              aboutBoxTitle = (String)msg.handleGetObject("m3"); 
              helpBoxTitle = (String)msg.handleGetObject("m4");
              helpMidText = (String)msg.handleGetObject("m6"); 
              aboutMidText = (String)msg.handleGetObject("m5"); 

          }catch(IOException e){};

       }

       public void updateUI(){
          SwingUtilities.updateComponentTreeUI(contentPane);
       }

       /**
         * Implementing WindowListener
         *
         */
       class WindowEventHandler extends WindowAdapter{
           public void windowClosed(WindowEvent e){
              dispose();
           }
       }

       public void open(){

       }
       public void saveAs(){
       }

       public void save(){

   
       }
       public void quit(){
          dispose();
       }

       public class AppMenuBar extends JMenuBar {
          Vector menus = new Vector();

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

          public void createGUI(){
             createFileMenu();
             createPrintMenu();
          }
          public JMenu createFileMenu() {
             JMenu fileMenu = new JMenu("File");
            
             open = new JMenuItem("Open");
             open.addActionListener(new OpenAdapter());
             save = new JMenuItem("Save");
             save.addActionListener(new SaveAdapter());

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

      public JMenu createHelpMenu() {
         help = new JMenuItem("Help");
         help.addActionListener(
            new ActionListener() {
               public void actionPerformed(ActionEvent e){
                  JOptionPane.showMessageDialog(ApplicationFrame.this, 
                  " Under Construction",
                  "Help", 
                  JOptionPane.INFORMATION_MESSAGE);
               }
            }
         );

         about = new JMenuItem("About");
         about.addActionListener(
            new ActionListener() {
               public void actionPerformed(ActionEvent e){
                  JOptionPane.showMessageDialog(ApplicationFrame.this, 
                  " Jar Image Viewer \n Version 1.0 \n Author: Lawrence Rodrigues",
                  "Jar Image Viewer", 
                  JOptionPane.INFORMATION_MESSAGE);
               }
            }
         );
         JMenu helpMenu = new JMenu("Help");
         helpMenu.add(help);
         helpMenu.add(about);
         add(helpMenu);
         return helpMenu;
      }

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

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

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

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

      public void addMenus(Vector menus){
         for(Enumeration e = menus.elements();e.hasMoreElements();){
             add((JMenu)(e.nextElement()));
         }
      }
      class PrintSetupAdapter implements ActionListener{
         public void actionPerformed(ActionEvent e){
            PrintJob pr = 
            Toolkit.getDefaultToolkit().getPrintJob(ApplicationFrame.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(ApplicationFrame.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){
            ApplicationFrame.this.setLocale(locale); 
         }
      }


       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
}
