home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / headlineview.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  10.0 KB  |  300 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.     @(#)HeadlineView.java  0.01 22-Jan-96
  15.  
  16.         A PageView for the Front Page and ThisJustIn headlines.
  17.  
  18.     Authors:
  19.  
  20.         rphall   Rick Hall
  21.         jlee     James Lee
  22.  
  23.     Version Ident:
  24.  
  25.         $Header: /PjJavaClient/src/pj/awt/HeadlineView.java 13    3/22/96 11:53p Jlee $
  26.  
  27.     History:
  28.  
  29.         0.01 01-Jan-96  rphall      Initial Creation
  30.              22-Jan-96  rphall      Conversion from a DividerView to a PageView
  31.                                     for use within HeadlineSectionView
  32.              13-Feb-96  jlee        Replaced GridBagLayout with PjHdlViewLayout for pnlView
  33.              21-Feb-96  jlee        Used Courier font for the each column's font
  34.               1-Mar-96  Ted S.      Added icons to the page, to make it look a little more PJish.
  35.              12-Mar-96  jlee        Used PjFinals for font info used in text
  36.              21-Mar-96  jlee        Added personal news counting
  37.              26-Mar-96  jlee        Change in ObsvrLabel
  38.              26-Mar-96  Ted S.      Added images from PJ to make it prettier.
  39.  
  40. ---------------------------------------------------------------------------*/
  41.  
  42. package pj.awt;
  43.  
  44. import pj.awt.Column;
  45. import pj.awt.ObsvrLabel;
  46. import pj.awt.PageView;
  47. import pj.awt.PjHdlViewLayout;
  48. import pj.awt.PjImages;
  49. import pj.awt.PjPageSpec;
  50. import pj.awt.PjFinals;
  51. import pj.awt.PjStr;
  52. import pj.awt.StoryList;
  53. import pj.awt.GifCanvas;
  54.  
  55. import collections.Assertable;
  56. import collections.ImplementationError;
  57. import java.awt.Button;
  58. import java.awt.BorderLayout;
  59. import java.awt.Component;
  60. import java.awt.FlowLayout;
  61. import java.awt.Font;
  62. import java.awt.GridBagConstraints;
  63. import java.awt.GridBagLayout;
  64. import java.awt.Insets;
  65. import java.awt.Label;
  66. import java.awt.Panel;
  67. import java.awt.Graphics;
  68. import java.awt.Dimension;
  69. import java.awt.Color;
  70. import pj.io.Paper;
  71.  
  72. /**
  73.  * A PageView for Front Page and ThisJustIn headlines.
  74.  *
  75.  * @see PageView
  76.  * @version 0.01 22-Jan-96
  77.  * @author  rphall
  78. */
  79. public class HeadlineView extends PageView implements Assertable
  80.     {
  81.     // --- Instance variables
  82.     private Column      colLeft;
  83.     private Column      colRight;
  84.     private StoryList   slNews;
  85.     private Paper       paper;
  86.  
  87.     private Button      btnBusFin;
  88.     private Button      btnWWide;
  89.     private ObsvrLabel  olblPNews;
  90.  
  91.     private int         idxIcon;// Which icon to display, PJ front page or TJI.
  92.     private int         idxTextImage;  // Which text gif to show, "Whats news" or "This just in.."
  93.  
  94.     // --- Class variables
  95.     static  final String strBusFin = "Business and Finance";
  96.     static  final String strWWide  = "World-Wide";
  97.     static  final String strPNews  = "Personal News";
  98.  
  99.     // --- Public constructors
  100.  
  101.     /**
  102.      * A general-purpose constructor that uses preassembled
  103.      * components.
  104.      * @param t A title component.
  105.      * @param left A left-hand column.
  106.      * @param right A right-hand column.
  107.      * @param list A story list.
  108.      * @param name  The page name for a headline view
  109.      * @param paper The paper being observed.
  110.     */
  111.     public HeadlineView( Label t, Column left, Column right,
  112.             StoryList list, String pagename, Paper p)
  113.         {
  114.         super(pagename);
  115.  
  116.         Label cPageTitle = t;
  117.         colLeft = left;
  118.         colRight = right;
  119.         slNews = list;
  120.         paper = p;
  121.         idxIcon = PjImages.idxFrontPage;
  122.         idxTextImage = PjImages.idxWhatsNewsText;
  123.  
  124.         olblPNews = new ObsvrLabel( strPNews, Paper.idFPNews );
  125.         olblPNews.setFont( PjFinals.fntColumnLabel );
  126.         paper.section( Paper.idFPNews ).addObserver( olblPNews );
  127.  
  128.         initialLayout();
  129.         } // HeadlineView constructor
  130.  
  131.     /**
  132.      * A specialized constructor for a HeadlineView that
  133.      * requires specific page names.
  134.      * @param name  The page name for either for the
  135.      * Front Page headlines ( PjNbSpec.pagename[PjNbSpec.idxFPHdlines] )
  136.      * or the ThisJustIn headlines ( PjNbSpec.pagename[PjNbSpec.idxFPHdlines] )
  137.      * @param paper The paper being observed.
  138.     */
  139.     public HeadlineView(String pagename, Paper p)
  140.         {
  141.         super(pagename);
  142.         paper = p;
  143.  
  144.         if  ( pagename.equals(PjStr.pageFPHdlines) )
  145.             {
  146.             // Create Front Page components
  147.             colLeft = new Column(Paper.idFPBusFin,paper);
  148.             colRight = new Column(Paper.idFPWorld,paper);
  149.             olblPNews = new ObsvrLabel(strPNews + ": 0 Stories from the Wall Street Journal", Paper.idFPNews );
  150.             olblPNews.setFont( PjFinals.fntColumnLabel );
  151.             paper.section( Paper.idFPNews ).addObserver( olblPNews );
  152.             slNews = new StoryList(Paper.idFPNews,paper);
  153.             idxIcon = PjImages.idxFrontPage;
  154.             idxTextImage = PjImages.idxWhatsNewsText;
  155.             }
  156.  
  157.         else if
  158.             ( pagename.equals( PjStr.pageTJIHdlines) )
  159.             {
  160.             // Create ThisJustIn components
  161.             colLeft = new Column(Paper.idTJIBusFin,paper);
  162.             colRight = new Column(Paper.idTJIWorld,paper);
  163.             olblPNews = new ObsvrLabel( strPNews + ": 0 Stories from the Wall Street Journal", paper.idTJINews );
  164.             olblPNews.setFont( PjFinals.fntColumnLabel );
  165.             paper.section( Paper.idTJINews ).addObserver( olblPNews );
  166.             slNews = new StoryList(Paper.idTJINews,paper);
  167.             idxIcon = PjImages.idxTJI;
  168.             idxTextImage = PjImages.idxThisJustInText;
  169.             }
  170.         else
  171.             {
  172.             // Bad page specification
  173.             assert(false);
  174.             }
  175.  
  176.         colLeft.setFont( PjFinals.fntUnfColumnPlain );
  177.         colRight.setFont( PjFinals.fntUnfColumnPlain );
  178.         slNews.setFont( PjFinals.fntUnfColumnPlain );
  179.  
  180.  
  181.         initialLayout();
  182.         System.out.println("Debug-HeadlineView:constructed");
  183.         } // HeadlineView constructor
  184.  
  185.     // --- Public operations
  186.  
  187.     /**
  188.      * @return The number (one) of views in a HeadlineView.
  189.     */
  190.     public int countViews()
  191.         {
  192.         return 1;
  193.         }
  194.  
  195.     /**
  196.      * Raise an exception if predicate is false.
  197.      * @see collections.Assertable
  198.     */
  199.     public void assert(boolean predicate) throws ImplementationError
  200.         {
  201.         ImplementationError.assert(this, predicate);
  202.         }
  203.  
  204.     // --- Private operations
  205.  
  206.     private void initialLayout()
  207.         {
  208.         Panel pnlTop = new Panel();
  209.         layoutTopPanel(pnlTop);
  210.  
  211.         Panel pnlLeft = new Panel();
  212.         btnBusFin = new Button(strBusFin);
  213.         btnBusFin.setFont( PjFinals.fntColumnLabel );
  214.         layoutColPanel(pnlLeft,btnBusFin,colLeft);
  215.  
  216.         Panel pnlRight = new Panel();
  217.         btnWWide = new Button(strWWide);
  218.         btnWWide.setFont( PjFinals.fntColumnLabel );
  219.         layoutColPanel(pnlRight,btnWWide,colRight);
  220.  
  221.         Panel pnlBottom = new Panel();
  222.         layoutColPanel(pnlBottom,olblPNews,slNews);
  223.  
  224.         layoutPanels(pnlTop,pnlLeft,pnlRight,pnlBottom);
  225.  
  226.         } // initialLayout
  227.  
  228.     private void layoutTopPanel(Panel pnl)
  229.         {
  230.         PjImages Imgs;
  231.         Imgs = new PjImages();
  232.         // A panel to hold stuff that goes top left.
  233.         Panel pnlTopLeft = new Panel();
  234.         pnlTopLeft.setLayout( new FlowLayout( FlowLayout.LEFT ));
  235.  
  236.         // The top panel has stuf on one row aligned left
  237.         //  and stuff beneath it centered.  So border layout is handy.
  238.         pnl.setLayout( new BorderLayout() );
  239.  
  240.         // Add icon & PJ logo - they go in the top left
  241.         pnlTopLeft.add( new GifCanvas(Imgs.imagespecs()[ idxIcon ].getImage() ));
  242.         pnlTopLeft.add( new GifCanvas(Imgs.imagespecs()[ PjImages.idxPjLogo ].getImage() ));
  243.  
  244.         pnl.add( "North", pnlTopLeft );
  245.         // add the page title
  246.         Panel pnlTitle = new LineThroughPanel();
  247.         pnlTitle.add( new GifCanvas(Imgs.imagespecs()[ idxTextImage ].getImage() ) );
  248.         pnl.add("Center", pnlTitle);
  249.         }
  250.  
  251.     private void layoutColPanel(Panel pnl, Component cmp, Component col)
  252.         {
  253.         pnl.setLayout( new BorderLayout( 0, 2 ) );
  254.  
  255.         pnl.add("North", cmp);
  256.         pnl.add("Center", col);
  257.         } // layoutColPanel
  258.  
  259.     private void layoutPanels( Panel pnlTop, Panel pnlLeft, Panel pnlRight, Panel pnlBottom)
  260.         {
  261.         GridBagLayout gridbag = new GridBagLayout();
  262.         setLayout(gridbag);
  263.  
  264.         // Title panel
  265.         GridBagConstraints gbc = new GridBagConstraints();
  266.         gbc.fill = GridBagConstraints.HORIZONTAL;
  267.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  268.         gridbag.setConstraints(pnlTop, gbc);
  269.         add(pnlTop);
  270.  
  271.         // View panel
  272.         Panel pnlView = new Panel();
  273.         pnlView.setLayout( new PjHdlViewLayout( 2, 0 ) );
  274.         pnlView.add( pnlLeft );
  275.         pnlView.add( pnlRight );
  276.         pnlView.add( pnlBottom );
  277.  
  278.         gbc.weightx = 1.0;
  279.         gbc.weighty = 1.0;
  280.         gbc.fill = GridBagConstraints.BOTH;
  281.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  282.         gridbag.setConstraints(pnlView, gbc);
  283.         add(pnlView);
  284.         } // layoutPanels
  285.     } // HeadlineView
  286.  
  287.  
  288. // A panel with a horizontal line through the center of it.
  289. class LineThroughPanel extends Panel
  290.     {
  291.     public LineThroughPanel()
  292.         {}
  293.  
  294.     public void paint( Graphics g )
  295.         {
  296.         // Draw a line all the way across.
  297.         g.drawLine( 0, size().height/2, size().width, size().height/2 );
  298.         }
  299.     }
  300.