home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 10.0 KB | 300 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.
-
-
- @(#)HeadlineView.java 0.01 22-Jan-96
-
- A PageView for the Front Page and ThisJustIn headlines.
-
- Authors:
-
- rphall Rick Hall
- jlee James Lee
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/HeadlineView.java 13 3/22/96 11:53p Jlee $
-
- History:
-
- 0.01 01-Jan-96 rphall Initial Creation
- 22-Jan-96 rphall Conversion from a DividerView to a PageView
- for use within HeadlineSectionView
- 13-Feb-96 jlee Replaced GridBagLayout with PjHdlViewLayout for pnlView
- 21-Feb-96 jlee Used Courier font for the each column's font
- 1-Mar-96 Ted S. Added icons to the page, to make it look a little more PJish.
- 12-Mar-96 jlee Used PjFinals for font info used in text
- 21-Mar-96 jlee Added personal news counting
- 26-Mar-96 jlee Change in ObsvrLabel
- 26-Mar-96 Ted S. Added images from PJ to make it prettier.
-
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.Column;
- import pj.awt.ObsvrLabel;
- import pj.awt.PageView;
- import pj.awt.PjHdlViewLayout;
- import pj.awt.PjImages;
- import pj.awt.PjPageSpec;
- import pj.awt.PjFinals;
- import pj.awt.PjStr;
- import pj.awt.StoryList;
- import pj.awt.GifCanvas;
-
- import collections.Assertable;
- import collections.ImplementationError;
- import java.awt.Button;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.FlowLayout;
- import java.awt.Font;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import java.awt.Label;
- import java.awt.Panel;
- import java.awt.Graphics;
- import java.awt.Dimension;
- import java.awt.Color;
- import pj.io.Paper;
-
- /**
- * A PageView for Front Page and ThisJustIn headlines.
- *
- * @see PageView
- * @version 0.01 22-Jan-96
- * @author rphall
- */
- public class HeadlineView extends PageView implements Assertable
- {
- // --- Instance variables
- private Column colLeft;
- private Column colRight;
- private StoryList slNews;
- private Paper paper;
-
- private Button btnBusFin;
- private Button btnWWide;
- private ObsvrLabel olblPNews;
-
- private int idxIcon;// Which icon to display, PJ front page or TJI.
- private int idxTextImage; // Which text gif to show, "Whats news" or "This just in.."
-
- // --- Class variables
- static final String strBusFin = "Business and Finance";
- static final String strWWide = "World-Wide";
- static final String strPNews = "Personal News";
-
- // --- Public constructors
-
- /**
- * A general-purpose constructor that uses preassembled
- * components.
- * @param t A title component.
- * @param left A left-hand column.
- * @param right A right-hand column.
- * @param list A story list.
- * @param name The page name for a headline view
- * @param paper The paper being observed.
- */
- public HeadlineView( Label t, Column left, Column right,
- StoryList list, String pagename, Paper p)
- {
- super(pagename);
-
- Label cPageTitle = t;
- colLeft = left;
- colRight = right;
- slNews = list;
- paper = p;
- idxIcon = PjImages.idxFrontPage;
- idxTextImage = PjImages.idxWhatsNewsText;
-
- olblPNews = new ObsvrLabel( strPNews, Paper.idFPNews );
- olblPNews.setFont( PjFinals.fntColumnLabel );
- paper.section( Paper.idFPNews ).addObserver( olblPNews );
-
- initialLayout();
- } // HeadlineView constructor
-
- /**
- * A specialized constructor for a HeadlineView that
- * requires specific page names.
- * @param name The page name for either for the
- * Front Page headlines ( PjNbSpec.pagename[PjNbSpec.idxFPHdlines] )
- * or the ThisJustIn headlines ( PjNbSpec.pagename[PjNbSpec.idxFPHdlines] )
- * @param paper The paper being observed.
- */
- public HeadlineView(String pagename, Paper p)
- {
- super(pagename);
- paper = p;
-
- if ( pagename.equals(PjStr.pageFPHdlines) )
- {
- // Create Front Page components
- colLeft = new Column(Paper.idFPBusFin,paper);
- colRight = new Column(Paper.idFPWorld,paper);
- olblPNews = new ObsvrLabel(strPNews + ": 0 Stories from the Wall Street Journal", Paper.idFPNews );
- olblPNews.setFont( PjFinals.fntColumnLabel );
- paper.section( Paper.idFPNews ).addObserver( olblPNews );
- slNews = new StoryList(Paper.idFPNews,paper);
- idxIcon = PjImages.idxFrontPage;
- idxTextImage = PjImages.idxWhatsNewsText;
- }
-
- else if
- ( pagename.equals( PjStr.pageTJIHdlines) )
- {
- // Create ThisJustIn components
- colLeft = new Column(Paper.idTJIBusFin,paper);
- colRight = new Column(Paper.idTJIWorld,paper);
- olblPNews = new ObsvrLabel( strPNews + ": 0 Stories from the Wall Street Journal", paper.idTJINews );
- olblPNews.setFont( PjFinals.fntColumnLabel );
- paper.section( Paper.idTJINews ).addObserver( olblPNews );
- slNews = new StoryList(Paper.idTJINews,paper);
- idxIcon = PjImages.idxTJI;
- idxTextImage = PjImages.idxThisJustInText;
- }
- else
- {
- // Bad page specification
- assert(false);
- }
-
- colLeft.setFont( PjFinals.fntUnfColumnPlain );
- colRight.setFont( PjFinals.fntUnfColumnPlain );
- slNews.setFont( PjFinals.fntUnfColumnPlain );
-
-
- initialLayout();
- System.out.println("Debug-HeadlineView:constructed");
- } // HeadlineView constructor
-
- // --- Public operations
-
- /**
- * @return The number (one) of views in a HeadlineView.
- */
- public int countViews()
- {
- return 1;
- }
-
- /**
- * Raise an exception if predicate is false.
- * @see collections.Assertable
- */
- public void assert(boolean predicate) throws ImplementationError
- {
- ImplementationError.assert(this, predicate);
- }
-
- // --- Private operations
-
- private void initialLayout()
- {
- Panel pnlTop = new Panel();
- layoutTopPanel(pnlTop);
-
- Panel pnlLeft = new Panel();
- btnBusFin = new Button(strBusFin);
- btnBusFin.setFont( PjFinals.fntColumnLabel );
- layoutColPanel(pnlLeft,btnBusFin,colLeft);
-
- Panel pnlRight = new Panel();
- btnWWide = new Button(strWWide);
- btnWWide.setFont( PjFinals.fntColumnLabel );
- layoutColPanel(pnlRight,btnWWide,colRight);
-
- Panel pnlBottom = new Panel();
- layoutColPanel(pnlBottom,olblPNews,slNews);
-
- layoutPanels(pnlTop,pnlLeft,pnlRight,pnlBottom);
-
- } // initialLayout
-
- private void layoutTopPanel(Panel pnl)
- {
- PjImages Imgs;
- Imgs = new PjImages();
- // A panel to hold stuff that goes top left.
- Panel pnlTopLeft = new Panel();
- pnlTopLeft.setLayout( new FlowLayout( FlowLayout.LEFT ));
-
- // The top panel has stuf on one row aligned left
- // and stuff beneath it centered. So border layout is handy.
- pnl.setLayout( new BorderLayout() );
-
- // Add icon & PJ logo - they go in the top left
- pnlTopLeft.add( new GifCanvas(Imgs.imagespecs()[ idxIcon ].getImage() ));
- pnlTopLeft.add( new GifCanvas(Imgs.imagespecs()[ PjImages.idxPjLogo ].getImage() ));
-
- pnl.add( "North", pnlTopLeft );
- // add the page title
- Panel pnlTitle = new LineThroughPanel();
- pnlTitle.add( new GifCanvas(Imgs.imagespecs()[ idxTextImage ].getImage() ) );
- pnl.add("Center", pnlTitle);
- }
-
- private void layoutColPanel(Panel pnl, Component cmp, Component col)
- {
- pnl.setLayout( new BorderLayout( 0, 2 ) );
-
- pnl.add("North", cmp);
- pnl.add("Center", col);
- } // layoutColPanel
-
- private void layoutPanels( Panel pnlTop, Panel pnlLeft, Panel pnlRight, Panel pnlBottom)
- {
- GridBagLayout gridbag = new GridBagLayout();
- setLayout(gridbag);
-
- // Title panel
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pnlTop, gbc);
- add(pnlTop);
-
- // View panel
- Panel pnlView = new Panel();
- pnlView.setLayout( new PjHdlViewLayout( 2, 0 ) );
- pnlView.add( pnlLeft );
- pnlView.add( pnlRight );
- pnlView.add( pnlBottom );
-
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pnlView, gbc);
- add(pnlView);
- } // layoutPanels
- } // HeadlineView
-
-
- // A panel with a horizontal line through the center of it.
- class LineThroughPanel extends Panel
- {
- public LineThroughPanel()
- {}
-
- public void paint( Graphics g )
- {
- // Draw a line all the way across.
- g.drawLine( 0, size().height/2, size().width, size().height/2 );
- }
- }
-