home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 15.2 KB | 515 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.
-
-
- @(#)HeadlineSection.java 0.00 22-Jan-96
-
- A SectionView for the Front Page and ThisJustIn headlines.
-
- Authors:
-
- rphall Rick Hall
- jlee James Lee
- Ted S. Ted Skolnick
- lning Lindee Ning
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/HeadlineSection.java 13 3/22/96 11:53p Jlee $
-
- History:
-
- 0.00 22-Jan-96 rphall Initial Creation
- 21-Feb-96 jlee Used Courier font for the each column's font
- 0.01 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.
- 14-Mar-96 Ted S. Removed CountViews(), since super handles it.
- 25-Mar-96 lning Added two buttons for viewing previous and next
- story.
- 28-Mar-96 Ted S. & L. Ning
- Reworked last revision.
- Added Prev and next buttons to the the Personal
- News column by deriving off of column, and
- making use of the View() interface.
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.Column;
- import pj.awt.HeadlineView;
- import pj.awt.Page;
- import pj.awt.PjPageSpec;
- import pj.awt.PjImages;
- import pj.awt.PjFinals;
- import pj.awt.PjStr;
- import pj.awt.SectionView;
-
- import collections.Assertable;
- import collections.ImplementationError;
- import java.awt.Button;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FlowLayout;
- import java.awt.GridBagLayout;
- import java.awt.GridBagConstraints;
- import java.awt.Label;
- import java.awt.Panel;
- import pj.io.Paper;
-
- /**
- * A SectionView for Front Page and ThisJustIn headlines.
- *
- * @see DividerView
- * @version 0.00 22-Jan-96
- * @author rphall
- */
- public class HeadlineSection extends SectionView implements Assertable
- {
-
- // --- Public constructors
-
- /**
- * A general-purpose constructor that uses preassembled
- * components.
- * @param hv A HeadlineView.
- * @param pvBF A PageView for Business and Finance stories.
- * @param pvWW A PageView for World-Wide stories.
- * @param pvPN A PageView for Personal News stories.
- * @param pagespec A specification for the page.
- * @param paper The paper being observed.
- */
- public HeadlineSection( HeadlineView hv, PageView pvBF,
- PageView pvWW, PageView pvPN, PjPageSpec pagespec, Paper p)
- {
- super(pagespec.tabspec);
-
- hvHeadlines = hv;
- pvBusFin = pvBF;
- pvWWide = pvWW;
- pvPNews = pvPN;
- paper = p;
- idxIcon = PjImages.idxFrontPage;
-
- initialLayout();
-
- firstView();
-
- } // HeadlineSection constructor
-
- /**
- * A specialized constructor for a HeadlineSection that uses
- * a page specification.
- * @param pagespec A page specification, either for the
- * Front Page headlines or the ThisJustIn headlines.
- * @param p The paper being observed.
- */
- public HeadlineSection(PjPageSpec pagespec, Paper p)
- {
- super(pagespec.tabspec);
- paper = p;
-
- if ( pagespec.strPageName.equals(PjStr.pageFPHdlines) )
- {
- pvBusFin = new Column(pgBusFin,Paper.idFPBusFin,paper);
- pvWWide = new Column(pgWWide,Paper.idFPWorld,paper);
- pvPNews = new ColumnAndButtons(pgPNews,Paper.idFPNews,paper);
- idxIcon = PjImages.idxFrontPage;
- }
-
- else if
- ( pagespec.strPageName.equals( PjStr.pageTJIHdlines) )
- {
- pvBusFin = new ColumnSingleView(pgBusFin,Paper.idTJIBusFin,paper);
- pvWWide = new ColumnSingleView(pgWWide,Paper.idTJIWorld,paper);
- pvPNews = new ColumnAndButtons(pgPNews,Paper.idTJINews,paper);
- idxIcon = PjImages.idxTJI;
- }
- else
- {
- // Bad page specification
- assert(false);
- }
-
- pvBusFin.setFont( PjFinals.fntUnfColumnPlain );
- pvWWide.setFont( PjFinals.fntUnfColumnPlain );
- pvPNews.setFont( PjFinals.fntUnfColumnPlain );
-
- hvHeadlines = new HeadlineView(pagespec.strPageName,paper);
- hvHeadlines.setName(pgHeadlines);
- initialLayout();
-
- System.out.println("Debug-HeadlineSection:constructed");
- } // HeadlineSection constructor
-
-
- public boolean handleEvent(Event evt)
- {
- boolean bHandled = false;
-
- switch (evt.id)
- {
- case Event.LIST_SELECT:
- int iStory = ((Integer)evt.arg).intValue();
- pvPNews.view(iStory);
- stack.page(pgPNews);
- bHandled = true;
- break;
- default:
- bHandled = super.handleEvent(evt);
- break;
- } // switch
-
- return bHandled;
- } // handleEvent
-
- public boolean action(Event e, Object arg)
- {
- boolean bHandled = false;
-
- if ( HeadlineView.strBusFin.equals(arg) )
- {
- bHandled = true;
- stack.page(pgBusFin);
- }
- else
- if ( HeadlineView.strWWide.equals(arg) )
- {
- bHandled = true;
- stack.page(pgWWide);
- }
- else
- if ( HeadlineView.strPNews.equals(arg) )
- {
- bHandled = true;
- if ( pvPNews.countViews() > 0 )
- {
- pvPNews.view( 0 );
- stack.page(pgPNews);
- }
- }
- else
- if ( e.target instanceof Button )//user clicked storylist selection button
- {
- int iStory = 0;
- try
- {
- iStory = Integer.parseInt( ((Button)e.target).getLabel() ) - 1;
- }
- catch ( NumberFormatException ex )
- {
- return bHandled;
- }
-
- if ( iStory >= 0)
- {
- pvPNews.view(iStory);
- stack.page(pgPNews);
- bHandled = true;
- }
- }
-
- return bHandled;
- } // action
-
- /**
- * 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()
- {
- assert( hvHeadlines != null );
- assert( pvBusFin != null );
- assert( pvWWide != null );
- assert( pvPNews != null );
- assert( paper != null );
-
- appendPage( hvHeadlines );
- appendPage( layoutPage( pvBusFin, pgBusFin ) );
- appendPage( layoutPage( pvWWide, pgWWide ) );
- appendPage( layoutPage( pvPNews, pgPNews ) );
- }
-
- private Page layoutPage( PageView pv, String name )
- {
- Font lblFont = PjFinals.fntSectionBigTitle;
-
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
-
- // Use DeferPage as the type of page to create and tell it
- // to defer View() functions to the Page passed in.
- DeferPage pnlPage = new DeferPage( name, pv );
- Label lblPage = new Label(name);
-
- lblPage.setFont( lblFont );
- pnlPage.setLayout( gridbag );
-
-
- // Create a panel to hold the icon and the text for page title.
- Panel pnlHeader = new Panel();
- pnlHeader.setLayout( new FlowLayout( FlowLayout.LEFT ) );
-
- PjImages Imgs = new PjImages();
- // Add the little icon
- pnlHeader.add( new GifCanvas(Imgs.imagespecs()[ idxIcon ].getImage() ) );
- // Add the title
- pnlHeader.add( lblPage );
-
- // Add the header panel with its contents to the page.
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gbc.anchor=GridBagConstraints.WEST;
- gridbag.setConstraints(pnlHeader,gbc);
- pnlPage.add( pnlHeader );
-
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pv, gbc);
- pnlPage.add( pv );
-
-
- return pnlPage;
- }
- // --- Private attributes
-
- private HeadlineView hvHeadlines;
- private PageView pvBusFin;
- private PageView pvWWide;
- private PageView pvPNews;
- private Paper paper;
-
- // Which icon to display, PJ front page or TJI.
- private int idxIcon;
-
- private final String pgHeadlines = "Headlines";
- private final String pgBusFin ="Business and Finance";
- private final String pgWWide = "World-Wide";
- private final String pgPNews = "Personal News";
-
- } // HeadlineSection
-
-
- /**
- * A Column containing three components: a view and two buttons and a lable
- * laid out beneath the subpanel. This is a helper class for Headline
- * views.
- * <P>
- * The layout of ColumnAndButtons is:
- * <pre>
- * -------------------
- * | |
- * | column |
- * | |
- * -------------------
- * |prev| lable |next|
- * -------------------
- * </pre>
- *
- * @version 0.00 28-Mar-96
- * @author lning & Ted S.
- */
- class ColumnAndButtons extends Column
- {
- private Button btnPrv = new Button("Previous Story");
- private Button btnNxt = new Button("Next Story");
- private Label lbStory = new Label("",Label.CENTER);
-
- // --- Public constructors
-
- /**
- * Construct a ColumnAndButtons as a standalone page.
- * @param pagename The name of the standalone page.
- * @param section The name of the observed section.
- * @param p The paper that contains the observed section.
- */
- public ColumnAndButtons(String pagename, String section, Paper p)
- {
- super(pagename,section,p);
- // Start with a clean slate, no components
- removeAll();
- // Add all the componetns I need
- iniLayout();
- updateLabel();
- }
-
- /**
- * Construct a Column as a page component.
- * @param section The name of the observed section.
- * @param paper The paper that contains the observed section.
- */
- public ColumnAndButtons(String section, Paper paper)
- {
- this(null,section,paper);
- }
-
- // --- Public operations
-
-
-
- // Handle button clicks
- public boolean action(Event e, Object arg)
- {
- boolean bHandled = false;
-
- if ( "Previous Story".equals(arg) )
- {
- previousView();
- bHandled = true;
- }
-
- else
- if ( "Next Story".equals(arg) )
- {
- nextView();
- bHandled = true;
- }
-
-
- return bHandled;
- } // action
-
- protected void iniLayout()
- {
- btnPrv.setFont( PjFinals.fntColumnLabel );
- btnNxt.setFont( PjFinals.fntColumnLabel );
- lbStory.setFont( PjFinals.fntColumnLabel );
-
- Panel pnlColumn = new Panel();
-
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- Panel pnlButtons = new Panel();
-
-
- //GridBagLayout for column and button panels.
- setLayout(gridbag);
-
- //Button panel. false: un-constrained width.
- pnlButtons.setLayout( new PjBtnLbLayout(false) );
- pnlButtons.add( btnPrv );
- pnlButtons.add( lbStory );
- pnlButtons.add( btnNxt );
-
- //Column panel
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
-
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(ltb, gbc);
- add(ltb);
-
- // Button panel
- gbc.weighty = 0;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pnlButtons,gbc);
- add(pnlButtons);
- }
-
-
-
-
- // Make sure the label # of # is correct
- private void updateLabel()
- {
- // Update the label.
- String str = Integer.toString(currView()) + " of " + Integer.toString(countViews());
- lbStory.setText(str);
-
- // Disable or enable buttons.
- btnPrv.enable( currView() > 1 );
- btnNxt.enable( currView() < countViews() );
- } //updateLabel
-
-
- /**
- * Make the first story of the observed section the current view.
- */
- public void firstView()
- {
- super.firstView();
- updateLabel();
- }
-
- /**
- * Make the next story (after the current story) the current view.
- */
- public boolean nextView()
- {
- boolean b = super.nextView();
- updateLabel();
- return b;
- }
-
- /**
- * Make the last story of the observed section the current view.
- */
- public void lastView()
- {
- super.lastView();
- updateLabel();
- }
-
- /**
- * Make the previous story (before the current story) the current view.
- */
- public boolean previousView()
- {
- boolean b = super.previousView();
- updateLabel();
- return b;
- }
-
- /**
- * Make a specific story the current view.
- * @param idx The index of the view to display.
- */
- public void view(int idx)
- {
- // fixme: view are 1 based, but the caller of this routine is
- // 0 based. That caller should be fixed to be one based, and the
- // + 1 should be removed from here.
- super.view(idx + 1);
- updateLabel();
- }
-
-
- public Dimension minimumSize()
- {
- return ltb.minimumSize();
- }
-
- public Dimension preferredSize()
- {
- return ltb.preferredSize();
- }
-
-
-
-
- } // ColumnAdnButtons
-
-
-
-
-
-