
/*
 * @(#) FrameMenuApp.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 FrameMenuApp extends Frame{

       private int width, height;
       private String str = new String("Frame MenuBar Demo");
       private Locale curLocale;
       private String copyRight, author;
       private String helpMidText, helpBoxTitle;
       private String aboutMidText, aboutBoxTitle;

       public static void main(String arg[]){
          Image icon = Toolkit.getDefaultToolkit().getImage("wrox.gif");
          FrameMenuApp app = new FrameMenuApp(300, 300);
          Image scIcon =  icon.getScaledInstance(16,16,Image.SCALE_FAST);
          app.setIconImage(scIcon);
       }
        
       public FrameMenuApp(int wid, int ht){
           setTitle("Frame MenuBar  Example");
           width = wid;
           height = ht;
           setLocale(Locale.US);
           createUI();
   //        setSize(new Dimension(width, height));
        }

        private void createUI(){
           Panel sliderPanel = new Panel();
           sliderPanel.setLayout(new FlowLayout());
           setBackground(Color.lightGray);
           WindowEventHandler winAda = new WindowEventHandler();
           addWindowListener(winAda);
           FrameMenuBar frameMenuBar = new FrameMenuBar();
           pack();
           setMenuBar((MenuBar)frameMenuBar);
           show();
       }


      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"); 
//            System.out.println("String "+ copyRight+ aboutBoxTitle+ author+
//                                helpBoxTitle);

          }catch(IOException e){};

       }

       /**
         * Implementing WindowListener
         *
         */

        class WindowEventHandler extends WindowAdapter{

           public void windowOpened(WindowEvent e){
              System.out.println("Window Opened");
           }

           public void windowClosed(WindowEvent e){
              dispose();
              System.out.println("Window Closed");
              System.exit(0);
           }

       }

   public void quit(){
      dispose();
      System.exit(0);
   }


   public class FrameMenuBar extends MenuBar {

      public FrameMenuBar(){
         createUI();
      }

      public void createUI(){
            MenuItem help = new MenuItem("Help");
            HelpAdapter hlpA = new HelpAdapter();
            help.addActionListener(hlpA);
            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("France");
            LocaleAdapter frL = new LocaleAdapter(Locale.FRENCH);
            france.addActionListener(frL);

            MenuItem germany = new MenuItem("Germany");
            LocaleAdapter gerL = new LocaleAdapter(Locale.GERMAN);
            germany.addActionListener(gerL);

  
            MenuItem about = new MenuItem("About");
            AboutAdapter abtA = new AboutAdapter();
            about.addActionListener(abtA);

            MenuItem quit = new MenuItem("Exit");
            quit.addActionListener(
               new ActionListener(){
                  public void actionPerformed(ActionEvent e){
                     quit();
                 }
               }
            ); 

            Menu fileMenu = new Menu("File");
            fileMenu.add(quit);
            Menu localeMenu = new Menu("Locale");
            localeMenu.add(us);
            localeMenu.add(uk);
            localeMenu.add(france);
            localeMenu.add(germany);
            Menu helpMenu = new Menu("Help");
            helpMenu.add(help);

            Menu aboutMenu = new Menu("About");
            aboutMenu.add(about);

            MenuBar frameMenuBar = new MenuBar();
 	    add(fileMenu);
 	    add(localeMenu);
            add(aboutMenu);
            setHelpMenu(helpMenu);
      }


      class LocaleAdapter implements ActionListener{
         Locale locale;

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


      }

      class HelpAdapter implements ActionListener{

         OkBox helpBox;
         public void actionPerformed(ActionEvent e){

            String topString = new String(copyRight+" "+author+"\n");
            String midString = new String(helpMidText+"\n");
            helpBox = new OkBox(FrameMenuApp.this,256,256,helpBoxTitle,topString+midString, false); 

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

            helpBox.show();
         }

      }

      class AboutAdapter implements ActionListener{

         OkBox aboutBox;
         public void actionPerformed(ActionEvent e){
            String topString = new String(copyRight+" "+author+"\n");
            String midString = new String(aboutMidText+"\n");
            aboutBox = new OkBox(FrameMenuApp.this,256,256,aboutBoxTitle,topString+midString, false); 
            aboutBox.addActionListener(
               new ActionListener() {
                  public void actionPerformed(ActionEvent e){
                     aboutBox.dispose();
                  }
               }
            );
            aboutBox.show();
         }

       }
    
    }  //End of Menubar class

  
   }
