home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / pjframe.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  6.5 KB  |  253 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.     Written by the Personal Journal developers of Dow Jones & Company, Inc.
  4.  
  5.     Dow Jones makes no representations or warranties about
  6.     the suitability of this software, either express or
  7.     implied, including but not limited to the implied warranties
  8.     of merchantability, fitness for a particular purpose,
  9.     or non-infringement.  Dow Jones will not be liable for
  10.     any damages suffered by a user as a result of using,
  11.     modifying or distributing this software or its derivatives.
  12.  
  13.  
  14.     @(#)PjFrame.java  0.00 15-Jan-95
  15.  
  16.         A MainFrame customized for Personal Journal.
  17.  
  18.     Authors:
  19.  
  20.         rphall   Rick Hall
  21.         lning    Lindee Ning
  22.         jlee     James Lee
  23.  
  24.     Version Ident:
  25.  
  26.         $Header$
  27.  
  28.     History:
  29.  
  30.         15-Jan-95   rphall  Initial Creation
  31.         08-Mar-96   lning   Added action() in order to pass the command
  32.                             from selecting the menuitem.
  33.                             Also use PjNbSpec to difine the menuitems in
  34.                             "Contents" menu in order to bind them to corresponding pages.
  35.         21-Mar-96   jlee    Changed the frame title from "Personal Journal" to "Web Street Journal"
  36.         26-Mar-96   Ted S.  Changed it back, the Lawyers said "Personal Journal" is OK.
  37.         28-Mar-96   jlee    Added setAboutBoxImage
  38.         29-Mar-96   jlee    Got rid of setAboutBoxImage and changed the way adBox is created.
  39. ---------------------------------------------------------------------------*/
  40.  
  41. package pj.awt;
  42.  
  43. import pj.awt.AboutDialog;
  44. import pj.awt.MainFrame;
  45. import pj.awt.PjNbSpec;
  46.  
  47. import java.awt.Event;
  48. import java.awt.Image;
  49. import java.awt.Menu;
  50. import java.awt.MenuBar;
  51. import java.awt.MenuItem;
  52. import java.lang.String;
  53.  
  54. class PjMenuItem extends MenuItem
  55.     {
  56.  
  57.     // --- Instance variables
  58.  
  59.     String  m_itemData;
  60.     String  label;
  61.  
  62.     // --- Public constructor
  63.  
  64.     public PjMenuItem(String label, String itemData)
  65.         {
  66.         super(label);
  67.         m_itemData = itemData;
  68.         }
  69.  
  70.     // --- Public operations
  71.  
  72.     public String getItemData()
  73.         {
  74.         return m_itemData;
  75.         } // getItemData()
  76.  
  77.     } // PjMenuItem
  78.  
  79.  
  80. class PjMenuBar extends MenuBar
  81.     {
  82.  
  83.     // --- Class variables
  84.  
  85.     /** File menu */
  86.     public static final String strFile = "File";
  87.  
  88.     /** Edit menu */
  89.     //public static final String strEdit = "Edit";
  90.  
  91.     /** Contents menu */
  92.     public static final String strCtnt = "Contents";
  93.  
  94.     /** File Connect */
  95.     //public static final String strFileConnect = "Connect";
  96.  
  97.     /** File SaveAs */
  98.     //public static final String strFileSaveAs = "Save As...";
  99.  
  100.     /** File Print */
  101.     //public static final String strFilePrint = "Print...";
  102.  
  103.     /** File Printer Setup */
  104.     //public static final String strFilePrinter = "Printer Setup...";
  105.  
  106.     /** File Exit */
  107.     public static final String strFileExit = "Exit";
  108.  
  109.     /** Edit Copy */
  110.     //public static final String strEditCopy = "Copy";
  111.  
  112.     /** Edit SelectAll */
  113.     //public static final String strEditSelect = "Select All";
  114.  
  115.     /** Help */
  116.     public static final String strHelp = "Help";
  117.  
  118.     /** Help About Personal Journal... */
  119.     public static final String strHelpAbout = "About Personal Journal...";
  120.  
  121.  
  122.     private static final String astrMenuFile = strFileExit;
  123.  
  124.     /*
  125.     private static final String[] astrMenuEdit =
  126.         {
  127.         strEditCopy,strEditSelect
  128.         };
  129.     */
  130.  
  131.     // --- Public constructors
  132.  
  133.     public PjMenuBar()
  134.         {
  135.         Menu m;
  136.         Menu rootmenu;
  137.  
  138.         m = new Menu(strFile,/*tearOff*/true);
  139.         m.add( new MenuItem(astrMenuFile) );
  140.  
  141.         add(m);
  142.  
  143.         m = new Menu(strCtnt,/*tearOff*/true);
  144.  
  145.         PjNbSpec nbs = new PjNbSpec();
  146.         for (int i=0; i<nbs.mainmenustring.length; i++)
  147.             {
  148.             if(nbs.substrings[i] != null)
  149.                 {
  150.                 rootmenu = new Menu(nbs.mainmenustring[i],/*tearOff*/true);
  151.                 for (int j=0; j<nbs.substrings[i].length; j++)
  152.                     rootmenu.add( new PjMenuItem((nbs.substrings[i])[j],(nbs.subnames[i])[j]) );
  153.  
  154.                 m.add( rootmenu );
  155.                 }
  156.             else
  157.                 m.add( new PjMenuItem(nbs.mainmenustring[i],nbs.mainmenuname[i]) );
  158.             }  // for
  159.  
  160.         add(m);
  161.  
  162.         m = new Menu(strHelp,/*tearOff*/true);
  163.         m.add( new MenuItem( strHelpAbout ) );
  164.  
  165.         add(m);
  166.         setHelpMenu( m );
  167.  
  168.         } // PjMenuBar constructor
  169.  
  170.     } // PjMenuBar
  171.  
  172.  
  173.  
  174. /**
  175.  *  A MainFrame customized for Personal Journal.
  176.  *
  177.  *  @see        pj.awt.MainFrame
  178.  *  @version    0.00 15-Jan-95
  179.  *  @author     rphall
  180. */
  181. public class PjFrame extends MainFrame
  182.     {
  183.  
  184.     // --- Class variables
  185.  
  186.     /** Frame title */
  187.     public static final String strPjFrameTitle = "Personal Journal";
  188.  
  189.  
  190.     // --- Instance variables
  191.     private PjImages    piPjImages = null;
  192.     private AboutDialog adBox = null;
  193.  
  194.  
  195.     // --- Public constructors
  196.  
  197.     /**
  198.      *  Construct a PjFrame.
  199.     */
  200.     public PjFrame()
  201.         { this((PjImages)null); }
  202.  
  203.     /**
  204.      *  Construct a PjFrame.
  205.     */
  206.     public PjFrame( PjImages piImages )
  207.         {
  208.         super(strPjFrameTitle);
  209.  
  210.         piPjImages = piImages;
  211.         setMenuBar(new PjMenuBar());
  212.         System.out.println("Debug-PjFrame:constructed");
  213.         }
  214.     
  215.  
  216.  
  217.     // --- Public operations
  218.  
  219.     /**
  220.      *  Catch the action from menubar and pass it down
  221.     */
  222.     public boolean action(Event evt, Object arg)
  223.         {
  224.         if ( evt.target instanceof MenuItem )
  225.             {
  226.             if ( PjMenuBar.strFileExit.equals(((MenuItem)(evt.target)).getLabel()) )
  227.                 {
  228.                 dispose();
  229.                 return true;
  230.                 }
  231.             else
  232.             if ( PjMenuBar.strHelpAbout.equals( ((MenuItem)(evt.target)).getLabel()) )
  233.                 {
  234.                 if ( (adBox == null) || (adBox != null && !adBox.isVisible()) )
  235.                     {
  236.                     adBox = new AboutDialog( this, "About Personal Journal", true );//modal dialog box
  237.                     adBox.Initialize( piPjImages );
  238.                     return true;
  239.                     }
  240.                 }
  241.             }
  242.         else
  243.             return false;
  244.  
  245.         int count = countComponents();
  246.  
  247.         for(int i = 0; i < count; i++)
  248.             getComponent(i).handleEvent(evt);
  249.  
  250.         return true;
  251.         }
  252.     }; // PjFrame
  253.