home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / afc11 / JNotepad / src / JNotePadFrame.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  4.4 KB  |  127 lines

  1. //
  2. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  3. //
  4. /**
  5. *  JNotePadFrame
  6. *    
  7. *    Main frame class for JNotepad. 
  8. *    This class implements a frame window for JNotepad. Fills the frame 
  9. *    with all the controls needed, and handles closing the app. 
  10. *
  11. *    @version 1.0, 7/9/97
  12. */
  13.  
  14. import java.awt.*;
  15. import java.awt.event.*;
  16. import java.io.*;
  17.  
  18. import com.ms.ui.*;
  19.  
  20. class JNotePadFrame extends UIFrame implements IConstants{
  21.     protected JNoteMenubar menuBar;                    // JNotepad's menu bar
  22.     protected JNoteToolbar toolBar;                    // JNotepad's tool bar
  23.     protected JNoteTabFileViewer tabFileView;        // JNotepad's tab view - where all the files are kept
  24.     protected String loadedFileName = null;            // name of initial file to load
  25. /**
  26.  *    JNotePadFrame constructor.    
  27.  *
  28.  *    @param title Frame window caption
  29.  *     @param    filename    Name of initial file to load
  30.  */
  31.     public JNotePadFrame(String title, String filename){
  32.         super (title);
  33.         // create new icon for JNotepad
  34.         loadFrameIcon(ResourceIDs.IDS_JNOTEPADICON);
  35.         // create the Settings object, which allows classes to store user
  36.         // configurable option information in. Load in its data file.
  37.         JNoteAppSettings.init("JNotepad.ini");
  38.         JNoteAppSettings.load();
  39.         // Create a CommandFeature. This object handles all of the command
  40.         // processing in the application.
  41.         JNoteCommandFeature commandFeature = new JNoteCommandFeature();
  42.         JNoteAppCommandFeature.init(commandFeature, commandFeature);
  43.         // create menu bar
  44.         menuBar = new JNoteMenubar(null, JNotePad.getResources(), IDR_MENUBAR);
  45.         menuBar.addWordWrapSubmenu(JNotePad.loadString(ResourceIDs.IDS_WORDWRAPMENU));
  46.         // create a toolbar
  47.         toolBar = new JNoteToolbar(JNoteAppletObject.getApplet());
  48.         toolBar.loadButtons(JNotePad.getResources());
  49.         // Create tabbed file viewer
  50.         // This will hold the files and edit controls        
  51.         tabFileView = new JNoteTabFileViewer(this, menuBar, commandFeature, commandFeature);
  52.         // initialize the CommandFeature. We pass it the final destination
  53.         // of all commands.
  54.         commandFeature.init(tabFileView, tabFileView);
  55.         // add talkers to the CommandFeature. These objects will be listened to
  56.         // by the CommandFeature for command selection events.
  57.         commandFeature.addTalker(menuBar);
  58.         commandFeature.addTalker(toolBar);
  59.         // create a blank file or load in a current file
  60.         if (filename == null)
  61.             tabFileView.newFile();
  62.         else
  63.             tabFileView.addNewFileTab(null, filename);
  64.         // activate the CommandFeature.
  65.         commandFeature.register();
  66.         // Create a bandbox and put the menu bar and the toolbar inside it.
  67.         // Set this bandbox as the header component in the frame.
  68.         UIBandBox bandBox = new UIBandBox();
  69.         bandBox.add(menuBar);
  70.         bandBox.add(toolBar);
  71.         setMenuBar(bandBox);
  72.         // add the tabbed file viewer
  73.         add(tabFileView, "center");
  74.         // must show before resizing otherwise insets() doesn't
  75.         // work right
  76.         show();
  77.         hide();
  78.         // resize
  79.         resize(getInsets().left + getInsets().right  + 600,
  80.             getInsets().top  + getInsets().bottom + 400);        
  81.     }
  82. /**
  83.  *    Sets the icon for this frame window.
  84.  *
  85.  *    @param    stringID    The ID of the string which contains the name of the image to load.
  86.  */
  87.     protected void loadFrameIcon(int stringID){
  88.         String imgName = JNotePad.loadString(stringID);
  89.         if (imgName != null){
  90.             // no need for a mediatracker since we won't be displaying it right away
  91.             Image im = Toolkit.getDefaultToolkit().getImage(imgName);
  92.             if (im != null){
  93.                 getFrame().setIconImage(im);                
  94.             }
  95.         }        
  96.     }
  97. /**
  98.  *    Handles window events. The only one handled is Event.WINDOW_DESTROY,
  99.  *    which signals that the window is to be closed. This is handled by a 
  100.  *    call to closeWindow(). All other events are handled by the superclass.
  101.  * 
  102.  *    @param evt Event that the window is to handle
  103.  */      
  104.     public boolean handleEvent(Event evt){
  105.         switch (evt.id){
  106.             // Application shutdown (e.g. user chooses Close from the system menu).
  107.         case Event.WINDOW_DESTROY:
  108.             // if the tab file view says its okay to close the app
  109.             // (all files have been saved, and the user hasn't cancelled),
  110.             // then close the window.
  111.             if (tabFileView.closingApp()){
  112.                 closeWindow();
  113.             }return true;
  114.         default:
  115.             return super.handleEvent(evt);
  116.         }             
  117.     }
  118. /**
  119.  *    Closes the window after saving the app settings (settingsObj).
  120.  */
  121.     public void closeWindow(){
  122.         JNoteAppSettings.save();    
  123.         // !!! dispose();
  124.         setVisible(false);
  125.         System.exit(0);
  126.     }
  127. }