home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 5.2 KB | 172 lines |
- /*---------------------------------------------------------------------------
-
- Written by the Personal Journal developers of Dow Jones & Company, Inc.
-
- Dow Jones makes no representations or warranties about
- the suitability of this software, either express or
- implied, including but not limited to the implied warranties
- of merchantability, fitness for a particular purpose,
- or non-infringement. Dow Jones will not be liable for
- any damages suffered by a user as a result of using,
- modifying or distributing this software or its derivatives.
-
-
- @(#)PjAdView.java 0.00 16-Jan-96
-
- A PageView that displays an advertisement.
-
- Authors:
-
- jlee James Lee
- rphall Rick Hall
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/PjAdView.java 4 1/24/96 1:34a Rphall $
-
- History:
-
- 16-Jan-96 rphall Initial Creation
- 22-Jan-96 jlee Changes made according to modified Ad specification.
- 7 -Feb-96 jlee Replaced GridBagLayout with a custom layout:PjAdViewLayout
- 12-Mar-96 jlee Used LineTextBox class for Ad Text Box
- 21-Mar-96 jlee Finished the link button so that it can actually show the URL document
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.applet.PjLauncher;
-
- import pj.awt.GifCanvas;
- import pj.awt.LineTextBox;
- import pj.awt.Panel3D;
- import pj.awt.PjAdSpec;
- import pj.awt.PjAdViewLayout;
- import pj.awt.PjFinals;
-
- import java.awt.Button;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Panel;
- import java.awt.Container;
- import java.awt.Color;
- import java.awt.Insets;
- import java.net.URL;
- import java.net.MalformedURLException;
-
- /**
- * A PageView that displays an advertisement.
- * An advertisement consists of a GIF image, some text, and an
- * optional URL link to the advertiser's homepage.
- * <P>
- * The current layout(custom layout:PjAdViewLayout) places the image to
- * the left and the ad text to the right.
- * The url, if present, is below the text.
- * <pre>
- * ____________________________________________
- * | | |
- * | Image | Text |
- * | | |
- * |___________________|_______________________|
- * |________________URL________________________|
- *
- * </pre>
- * FIXME: change this hard-coded layout to a configurable layout.
- *
- * @version 0.00 17-Jan-96
- * @author rphall, jlee
- */
- public class PjAdView extends Panel3D
- {
-
- // --- Instance variables
-
- /** The specification for this ad */
- private PjAdSpec adspec;
-
- /** A canvas displaying the ad image */
- private GifCanvas gcImage;
-
- /** A word-wrapped display of the ad text */
- private LineTextBox ltbCopy;
-
- /** A Button that somehow displays the home page of the ad */
- private Button btnUrl;
-
- // --- Public constructor
-
- /**
- * Construct an advertisement
- * @param pas A specification for the advertisement.
- */
- public PjAdView(PjAdSpec pas)
- {
- adspec = pas;
- Panel pnlAdView = new Panel();
- add( pnlAdView );
-
- // get image and add to this instance
- gcImage = new GifCanvas( pas.getImage() );
-
- // get copy and add to this instance
- ltbCopy = new LineTextBox( 0 );
- ltbCopy.setFont( PjFinals.fntAdTextPlain );
- ltbCopy.setText( pas.getCopy() );
-
- // get link and add to this instance
- btnUrl = new Button();
- btnUrl.setForeground( Color.blue );
- btnUrl.setLabel( pas.getLinkTitle() );
-
- // use GridBagLayout to layout image, copy, and link button
- layoutAdPanel( pnlAdView, gcImage, ltbCopy, btnUrl );
- }
-
-
- // --- Public operations
-
- public boolean action(Event e, Object arg)
- {
- boolean bHandled = false;
-
- if ( e.target instanceof Button )//user clicked more button
- {
- URL u = null;
- try
- {
- u = new URL( adspec.getLink().toString() );// toString() used to double check the validity of URL
- }
- catch( MalformedURLException m )
- {
- System.out.println( "Debug-PjAdView-action:MalformedURLException");
- }
-
- System.out.println( "Debug-PjAdView-action:u=" + u);
- PjLauncher.getPjApplet().getAppletContext().showDocument( adspec.getLink() );
- bHandled = true;
- }
-
- return bHandled;
- } // action
-
- // --- Private operations
-
- private void layoutAdPanel(Container pnl, Component gcImage, Component ltbCopy, Component btnUrl)
- {
- PjAdViewLayout avLayout = new PjAdViewLayout();
- pnl.setLayout(avLayout);
-
- // Components should be added in the following order.
- pnl.add( ltbCopy );
- pnl.add( btnUrl );
- pnl.add( gcImage );
-
- } // layoutAdPanel
-
-
-
- } // PjAdView
-