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

  1. /*---------------------------------------------------------------------------
  2.     Written by the Personal Journal developers of Dow Jones & Company, Inc.
  3.  
  4.     Dow Jones makes no representations or warranties about
  5.     the suitability of this software, either express or
  6.     implied, including but not limited to the implied warranties
  7.     of merchantability, fitness for a particular purpose,
  8.     or non-infringement.  Dow Jones will not be liable for
  9.     any damages suffered by a user as a result of using,
  10.     modifying or distributing this software or its derivatives.
  11.  
  12.  
  13.     @(#)PjFrame.java  0.00 15-Jan-95
  14.  
  15.         A MainFrame customized for Personal Journal.
  16.  
  17.     Authors:
  18.  
  19.         jlee     James Lee
  20.         Ted S.   Ted Skolnick
  21.  
  22.     Version Ident:
  23.  
  24.         $Header:$
  25.  
  26.     History:
  27.  
  28.         27-Mar-96   jlee    Initial Creation
  29.         28-Mar-96   jlee    Added initBoxText
  30.         28-Mar-96   Ted S.  Added some more text.
  31.         29-Mar-96   jlee    Changed old Initialize() to Initialize( PjImages )
  32. ---------------------------------------------------------------------------*/
  33.  
  34. package pj.awt;
  35.  
  36. import pj.awt.GifCanvas;
  37. import pj.awt.Panel3D;
  38. import pj.awt.PjFinals;
  39. import pj.awt.PjImages;
  40. import pj.awt.TextCanvas;
  41.  
  42. import java.awt.Button;
  43. import java.awt.Canvas;
  44. import java.awt.Color;
  45. import java.awt.Component;
  46. import java.awt.Container;
  47. import java.awt.Dimension;
  48. import java.awt.Dialog;
  49. import java.awt.Event;
  50. import java.awt.Font;
  51. import java.awt.FontMetrics;
  52. import java.awt.Graphics;
  53. import java.awt.GridBagConstraints;
  54. import java.awt.GridBagLayout;
  55. import java.awt.Frame;
  56. import java.awt.Image;
  57. import java.awt.Insets;
  58. import java.awt.LayoutManager;
  59. import java.awt.Panel;
  60. import java.awt.Rectangle;
  61. import java.lang.String;
  62.  
  63.  
  64. class AboutDialog extends Dialog
  65.     {
  66.     // --- Public constructors
  67.     public AboutDialog( Frame frmParent, String strTitle, boolean bModal )
  68.         {
  69.         super( frmParent, strTitle, bModal );
  70.         }
  71.  
  72.  
  73.     // --- Public functions
  74.     public void Initialize( PjImages piImages )
  75.         {
  76.         GifCanvas   gcAboutBox = null;
  77.         Image       iPjLogo = null;
  78.         PjImages    iPjImages = null;
  79.  
  80.         setResizable( false );
  81.         setLayout( new AboutBoxLayout( 0, 3 ) );
  82.  
  83.         if ( piImages != null )
  84.             iPjLogo = piImages.imagespecs()[piImages.idxPjLogo].getImage();
  85.  
  86.         if ( iPjLogo != null )
  87.             gcAboutBox = new GifCanvas( iPjLogo );
  88.         else
  89.             {
  90.             System.out.println("Error-AboutDialog-Initialize:About Box Image is null!");
  91.             dispose();
  92.             return;
  93.             }
  94.  
  95.         add( gcAboutBox );
  96.  
  97.         Panel3D   pnl3dText = new Panel3D();
  98.             TextCanvas tcvText = new TextCanvas();
  99.             pnl3dText.add( tcvText );
  100.         add( pnl3dText );
  101.  
  102.         Button btnOk = new Button("OK");
  103.         add( btnOk );
  104.  
  105.         pack();
  106.         show();
  107.         resize( PjFinals.dimAboutDialogSize );
  108.  
  109.         initBoxText( tcvText );
  110.         }
  111.  
  112.     private void initBoxText( TextCanvas tcvText )
  113.         {
  114.         // 0: PLAIN font, 1: BOLD font 2: ITALIC font
  115.         tcvText.addText( "", 0 );
  116.         tcvText.addText( "Personal Journal (Java Implementation) Version 1.0(Build0329)", 1 );
  117.         tcvText.addText( "", 0 );
  118.         tcvText.addText( "Dow Jones & Company, Inc.", 1 );
  119.         tcvText.addText( "", 0 );
  120.         tcvText.addText( "Personal Journal gives you a quick read of selected", 1 );
  121.         tcvText.addText( "Wall Street Journal editiorial, business and world-wide", 1 );
  122.         tcvText.addText( "news plus the news that's most important to you.", 1 );
  123.         tcvText.addText( "", 0 );
  124.         tcvText.addText( "Develped by:", 1 );
  125.         tcvText.addText( "   Laura Bertrand, Mark Bukovec, Richard Hall, James Lee", 1 );
  126.         tcvText.addText( "   Lindee Ning, Alka Rao, Nimesh Shah, Ted Skolnick", 1 );
  127.         tcvText.addText( "", 0 );
  128.         tcvText.addText( "Thanks to:", 1 );
  129.         tcvText.addText( "   Amy Katz, Keith Tuskey  for their help.", 1 );
  130.         }
  131.  
  132.  
  133.     /**
  134.      *  Handle an event.  A AboutDialog will handle Event.WINDOW_DESTROY,
  135.      *  and delegate other events to its superclass, Frame.
  136.      *  @param evt      An event targeted at the frame.
  137.      *  @return         True if the frame handled the event, false otherwise.
  138.     */
  139.     public boolean handleEvent( Event evt )
  140.         {
  141.         switch ( evt.id )
  142.             {
  143.             case Event.WINDOW_DESTROY:
  144.                 dispose();
  145.                 return true;
  146.             case Event.ACTION_EVENT:
  147.                 if ( evt.target instanceof Button )
  148.                     {
  149.                     dispose();
  150.                     return true;
  151.                     }
  152.                 break;
  153.             default:
  154.                 break;
  155.             }//switch
  156.  
  157.         return false;
  158.         } // handleEvent
  159.     }// AboutDialog
  160.  
  161. /*---------------------------------------------------------------------------
  162.  
  163.     Written by the Personal Journal developers of Dow Jones & Company, Inc.
  164.  
  165.     Dow Jones makes no representations or warranties about
  166.     the suitability of this software, either express or
  167.     implied, including but not limited to the implied warranties
  168.     of merchantability, fitness for a particular purpose,
  169.     or non-infringement.  Dow Jones will not be liable for
  170.     any damages suffered by a user as a result of using,
  171.     modifying or distributing this software or its derivatives.
  172.  
  173.  
  174.     @(#)AboutBoxLayout.java   0.00 8-Feb-96
  175.  
  176.         A AboutBoxLayout that manages the eaual size buttons layout.
  177.  
  178.     Authors:
  179.  
  180.         jlee        James Lee
  181.  
  182.     Version Ident:
  183.  
  184.         $Header:$
  185.  
  186.     History:
  187.  
  188.          27-Mar-96    jlee   Initial creation.
  189. ---------------------------------------------------------------------------*/
  190.  
  191. /**
  192.  * AboutBoxLayout is used to layout equal size buttons in a panel.
  193.  * @version     0.00, 8/2/96
  194.  * @author      James Lee
  195.  */
  196. class AboutBoxLayout implements LayoutManager
  197.     {
  198.  
  199.     // Instance variables
  200.  
  201.     private int   hgap;
  202.     private int   vgap;
  203.  
  204.     private       Rectangle recLast  = new Rectangle(0, 0, 0, 0);
  205.  
  206.  
  207.     // --- Public constructors
  208.     /**
  209.      * Constructs a new Flow Layout with a centered alignment.
  210.      * Default value for hgap and vgap is 0.
  211.      */
  212.     public AboutBoxLayout()
  213.         {
  214.         this(0, 0);
  215.         }
  216.  
  217.     /**
  218.      * Constructs a new Flow Layout with the specified alignment and gap
  219.      * values.
  220.      * @param hgap the horizontal gap variable
  221.      * @param vgap the vertical gap variable
  222.      */
  223.     public AboutBoxLayout(int hgap, int vgap)
  224.         {
  225.         this.hgap = hgap;
  226.         this.vgap = vgap;
  227.         }
  228.  
  229.     // --- Public operations
  230.     /**
  231.      * Adds the specified component to the layout. Not used by this class.
  232.      * @param name the name of the component
  233.      * @param comp the the component to be added
  234.      */
  235.     public void addLayoutComponent(String name, Component comp)
  236.         {
  237.         }
  238.  
  239.     /**
  240.      * Removes the specified component from the layout. Not used by
  241.      * this class.
  242.      * @param comp the component to remove
  243.      */
  244.     public void removeLayoutComponent(Component comp)
  245.         {
  246.         }
  247.  
  248.     /**
  249.      * Returns the preferred dimensions for this layout given the components
  250.      * in the specified target container.
  251.      * @param target the component which needs to be laid out
  252.      * @see Container
  253.      * @see #minimumLayoutSize
  254.      */
  255.     public Dimension preferredLayoutSize(Container target)
  256.         {
  257.         return PjFinals.dimAboutDialogSize;
  258.         }
  259.  
  260.     /**
  261.      * Returns the minimum dimensions needed to layout the components
  262.      * contained in the specified target container.
  263.      * @param target the component which needs to be laid out
  264.      * @see #preferredLayoutSize
  265.      */
  266.     public Dimension minimumLayoutSize(Container target)
  267.         {
  268.         return PjFinals.dimAboutDialogSize;
  269.         }
  270.  
  271.  
  272.     /**
  273.      * Lays out the container. This method will actually reshape the
  274.      * components in the target in order to satisfy the constraints of
  275.      * the PjAdViewLayout object.
  276.      * @param target the specified component being laid out.
  277.      * @see Container
  278.      */
  279.     public void layoutContainer(Container target)
  280.         {
  281.         Insets insets = target.insets();
  282.         Rectangle rec = target.bounds();
  283.  
  284.         if ( target.isValid() &&
  285.             rec.x == recLast.x && rec.y == recLast.y &&
  286.             rec.width == recLast.width && rec.height == recLast.height  )
  287.  
  288.             return;
  289.         else
  290.             recLast = rec;
  291.  
  292.         int maxwidth = rec.width - (insets.left + insets.right);
  293.         int maxheight = rec.height - (insets.top + insets.bottom + vgap*2);
  294.         int nmembers = target.countComponents();
  295.  
  296.         int x;
  297.  
  298.         for (int i = 0 ; i < nmembers ; i++)
  299.             {
  300.             Component m = target.getComponent(i);
  301.  
  302.             if ( m.isVisible() )
  303.                 switch ( i )
  304.                     {
  305.                     case 0://image
  306.                         x = (maxwidth - PjFinals.dimAboutBoxImage.width) / 2 + insets.left;
  307.                         m.move( x , insets.top );
  308.                         break;
  309.                     case 1://panel
  310.                         m.reshape( insets.left, insets.top + vgap + PjFinals.dimAboutBoxImage.height,
  311.                                    maxwidth, maxheight - PjFinals.dimOKButton.height - PjFinals.dimAboutBoxImage.height );
  312.                         break;
  313.                     case 2://button
  314.                         x = (maxwidth - PjFinals.dimOKButton.width) / 2  + insets.left;
  315.                         m.reshape( x, insets.top + maxheight - PjFinals.dimOKButton.height + vgap,
  316.                                    PjFinals.dimOKButton.width, PjFinals.dimOKButton.height );
  317.                         break;
  318.                     default:
  319.                         break;
  320.                     }
  321.             }
  322.         }
  323.  
  324.     /**
  325.      * Returns the String representation of this AboutBoxLayout's values.
  326.      */
  327.     public String toString()
  328.         {
  329.         return  getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]";
  330.         }
  331.     }
  332.