home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / pjadview.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  5.2 KB  |  172 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.     @(#)PjAdView.java   0.00 16-Jan-96
  15.  
  16.         A PageView that displays an advertisement.
  17.  
  18.     Authors:
  19.  
  20.         jlee        James Lee
  21.         rphall      Rick Hall
  22.  
  23.     Version Ident:
  24.  
  25.         $Header: /PjJavaClient/src/pj/awt/PjAdView.java 4     1/24/96 1:34a Rphall $
  26.  
  27.     History:
  28.  
  29.         16-Jan-96    rphall      Initial Creation
  30.         22-Jan-96    jlee        Changes made according to modified Ad specification.
  31.         7 -Feb-96    jlee        Replaced GridBagLayout with a custom layout:PjAdViewLayout
  32.         12-Mar-96    jlee        Used LineTextBox class for Ad Text Box
  33.         21-Mar-96    jlee        Finished the link button so that it can actually show the URL document
  34. ---------------------------------------------------------------------------*/
  35.  
  36. package pj.awt;
  37.  
  38. import pj.applet.PjLauncher;
  39.  
  40. import pj.awt.GifCanvas;
  41. import pj.awt.LineTextBox;
  42. import pj.awt.Panel3D;
  43. import pj.awt.PjAdSpec;
  44. import pj.awt.PjAdViewLayout;
  45. import pj.awt.PjFinals;
  46.  
  47. import java.awt.Button;
  48. import java.awt.Component;
  49. import java.awt.Event;
  50. import java.awt.Font;
  51. import java.awt.GridBagConstraints;
  52. import java.awt.GridBagLayout;
  53. import java.awt.Panel;
  54. import java.awt.Container;
  55. import java.awt.Color;
  56. import java.awt.Insets;
  57. import java.net.URL;
  58. import java.net.MalformedURLException;
  59.  
  60. /**
  61.  * A PageView that displays an advertisement.
  62.  * An advertisement consists of a GIF image, some text, and an
  63.  * optional URL link to the advertiser's homepage.
  64.  * <P>
  65.  * The current layout(custom layout:PjAdViewLayout) places the image to
  66.  * the left and the ad text to the right.
  67.  * The url, if present, is below the text.
  68.  * <pre>
  69.  *      ____________________________________________
  70.  *      |                   |                       |
  71.  *      |  Image            |        Text           |
  72.  *      |                   |                       |
  73.  *      |___________________|_______________________|
  74.  *      |________________URL________________________|
  75.  *
  76.  * </pre>
  77.  * FIXME: change this hard-coded layout to a configurable layout.
  78.  *
  79.  * @version    0.00 17-Jan-96
  80.  * @author     rphall, jlee
  81. */
  82. public class PjAdView extends Panel3D
  83.     {
  84.  
  85.     // --- Instance variables
  86.  
  87.     /** The specification for this ad */
  88.     private PjAdSpec adspec;
  89.  
  90.     /** A canvas displaying the ad image */
  91.     private GifCanvas gcImage;
  92.  
  93.     /** A word-wrapped display of the ad text */
  94.     private LineTextBox ltbCopy;
  95.  
  96.     /** A Button that somehow displays the home page of the ad */
  97.     private Button btnUrl;
  98.  
  99.     // --- Public constructor
  100.  
  101.     /**
  102.      * Construct an advertisement
  103.      * @param pas A specification for the advertisement.
  104.     */
  105.     public PjAdView(PjAdSpec pas)
  106.         {
  107.         adspec = pas;
  108.         Panel pnlAdView = new Panel();
  109.         add( pnlAdView );
  110.  
  111.         // get image and add to this instance
  112.         gcImage = new GifCanvas( pas.getImage() );
  113.  
  114.         // get copy and add to this instance
  115.         ltbCopy = new LineTextBox( 0 );
  116.         ltbCopy.setFont( PjFinals.fntAdTextPlain );
  117.         ltbCopy.setText( pas.getCopy() );
  118.  
  119.         // get link and add to this instance
  120.         btnUrl = new Button();
  121.         btnUrl.setForeground( Color.blue );
  122.         btnUrl.setLabel( pas.getLinkTitle() );
  123.  
  124.         // use GridBagLayout to layout image, copy, and link button
  125.         layoutAdPanel( pnlAdView, gcImage, ltbCopy, btnUrl );
  126.         }
  127.  
  128.  
  129.     // --- Public operations
  130.  
  131.     public boolean action(Event e, Object arg)
  132.         {
  133.         boolean bHandled = false;
  134.  
  135.         if ( e.target instanceof Button )//user clicked more button
  136.             {
  137.             URL u = null;
  138.             try
  139.                 {
  140.                 u = new URL( adspec.getLink().toString() );// toString() used to double check the validity of URL
  141.                 }
  142.             catch( MalformedURLException m )
  143.                 {
  144.                 System.out.println( "Debug-PjAdView-action:MalformedURLException");
  145.                 }
  146.  
  147.             System.out.println( "Debug-PjAdView-action:u=" + u);
  148.             PjLauncher.getPjApplet().getAppletContext().showDocument( adspec.getLink() );
  149.             bHandled = true;
  150.             }
  151.  
  152.         return bHandled;
  153.         } // action
  154.  
  155.     // --- Private operations
  156.  
  157.     private void layoutAdPanel(Container pnl, Component gcImage, Component ltbCopy, Component btnUrl)
  158.         {
  159.         PjAdViewLayout avLayout = new PjAdViewLayout();
  160.         pnl.setLayout(avLayout);
  161.  
  162.         // Components should be added in the following order.
  163.         pnl.add( ltbCopy );
  164.         pnl.add( btnUrl );
  165.         pnl.add( gcImage );
  166.  
  167.         } // layoutAdPanel
  168.  
  169.  
  170.  
  171.     } // PjAdView
  172.