home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 11.0 KB | 387 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.
-
-
- @(#)SportsSection.java 0.00 26-Jan-96
-
- A SectionView for the Sports.
-
- Authors:
-
- jlee James Lee
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/SportsSection.java 6 3/22/96 11:13p Jlee $
-
- History:
-
- 0.00 14-Jan-96 jlee Initial Creation
- 0.01 1-Mar-96 Ted S. Added sports icons to the page,
- to make it look a little more PJish.
- 27-Mar-96 jlee Changed "Highligh&ts" and "Sc&ores" to "Highlights" and "Scores"
-
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.Column;
- import pj.awt.PageView;
- import pj.awt.PjListLayout;
- import pj.awt.PjPageSpec;
- import pj.awt.PjFinals;
- import pj.awt.PjStr;
- import pj.awt.SectionView;
- import pj.io.MalformedPaperStoryException;
- import pj.io.Paper;
- import pj.io.PaperStory;
- import pj.net.RemoteImage;
-
- import collections.Assertable;
- import collections.ImplementationError;
- import java.awt.Button;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.FlowLayout;
- import java.awt.Font;
- import java.awt.GridBagLayout;
- import java.awt.GridBagConstraints;
- import java.awt.Insets;
- import java.awt.Label;
- import java.awt.Panel;
-
-
- /**
- * A SectionView for Sports.
- *
- * @see DividerView
- * @version 0.00 14-Jan-96
- * @author jlee
- */
- public class SportsSection extends SectionView implements Assertable
- {
-
-
- // --- Class variables
- /**
- * Labels for the buttons and page names.
- */
- static final String strTitleScores = "Scoreboard";
- static final String strTitleHighlights = "Sports";
- static final String strLblHighlights = "Highlights";
- static final String strBtnScores = "Scores";
- static final String strBtnHighlights = "Highlights";
-
- // --- Instance variables
-
- private PageView pvScores;
- private PageView pvHighlights;
- private Paper paper;
-
-
-
- // --- Public constructors
-
- /**
- * A general-purpose constructor that uses preassembled
- * components.
- * @param scores A PageView for scores.
- * @param scores A PageView for highlights.
- * @param pagespec A specification for the page.
- * @param paper The paper being observed.
- */
- public SportsSection( PageView scores, PageView highlights, PjPageSpec pagespec, Paper p)
- {
- super(pagespec.tabspec);
-
- pvScores = scores;
- pvHighlights = highlights;
- paper = p;
-
- initialLayout();
-
- } // SportsSection constructor
-
- /**
- * A specialized constructor for a SportsSection that uses
- * a page specification.
- * @param pagespec A page specification, either for the Sports.
- * @param pas A PjAdSpec object.
- * @param p The paper being observed.
- */
- public SportsSection( PjPageSpec pagespec, PjAdSpec pas, Paper p )
- {
- super(pagespec.tabspec);
- paper = p;
-
- // Column pages creation
- if ( pagespec.strPageName.equals( PjStr.pageSpHilite) )
- {
- pvScores = new SportsViewScores(pas, paper);
- pvHighlights = new SportsViewHighlights( paper );
- }
- else
- {
- // Bad page specification
- assert(false);
- }
-
- initialLayout();
-
- System.out.println("Debug-SportsSection:constructed");
- } // SportsSection constructor
-
- // --- Public operations
- /**
- * @return The number (one) of views in a SportsSection.
- */
- public int countViews()
- {
- int num = 0;
- num += pvScores.countViews();
- num += pvHighlights.countViews();
- return num;
- }
-
- /**
- * Handles events
- *
- * @param evt An Event object
- * @return true if the event's handled, false otherwise.
- */
- public boolean handleEvent(Event evt)
- {
- boolean bHandled = false;
-
- switch (evt.id)
- {
- default:
- bHandled = super.handleEvent(evt);
- break;
- } // switch
-
- return bHandled;
- } // handleEvent
-
- /**
- * Handles ACTION_EVENT. Specifically, when you click one of those regions in
- * the Sports map, it'll generate this action event, which will be eventually handled here.
- *
- * @param e An Event object
- * @param arg An String object which is the name of the hot area which user cliked on.
- * @return true if further event handling's neccessary, false otherwise.
- */
- public boolean action(Event e, Object arg)
- {
- boolean bHandled = false;
-
- if ( strBtnScores.equals( arg ) )
- {
- bHandled = true;
- stack.page(strTitleScores);
- }
- else if ( strBtnHighlights.equals( arg ) )
- {
- bHandled = true;
- stack.page(strTitleHighlights);
- }
-
- 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( pvScores != null );
- assert( pvHighlights != null );
- assert( paper != null );
-
- appendPage(pvScores );
- appendPage(pvHighlights );
- }
-
-
-
- } // SportsSection
-
-
- /**
- * A helper class that creates a view of scores
- */
- class SportsViewScores extends PageView
- {
-
- // --- Public constructors
-
- public SportsViewScores(PjAdSpec pas, Paper paper)
- {
- super(SportsSection.strTitleScores);
-
- // Create Sports Page components
- Label lblPageTitle = new Label(SportsSection.strTitleScores);
- lblPageTitle.setFont( PjFinals.fntSectionBigTitle );
-
- Button btnHighlights = new Button(SportsSection.strBtnHighlights);
- btnHighlights.setFont( PjFinals.fntColumnLabel );
-
- Column colScores = new Column(Paper.idSpScores, paper);
- colScores.setFont( PjFinals.fntUnfColumnPlain );
- PjAdView pjav = new PjAdView(pas);
-
- Panel pnlScores = new Panel();
- pnlScores.setLayout( new PjListLayout( PjListLayout.RIGHT ) );
- pnlScores.add( btnHighlights );
- pnlScores.add( colScores );
-
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- 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 ) );
-
- // Sports icon
- PjImages Imgs = new PjImages();
-
- // Add the little sports score icon.
- pnlHeader.add( new GifCanvas(Imgs.imagespecs()[ PjImages.idxScores ].getImage() ) );
-
- // Add the title
- pnlHeader.add( lblPageTitle );
-
- // Add the header panel with its contents to the page.
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gbc.anchor=GridBagConstraints.WEST;
- gridbag.setConstraints(pnlHeader,gbc);
- add( pnlHeader );
-
- //Scores panel
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pnlScores,gbc);
- add(pnlScores);
-
- //Adview
- gbc.insets = new Insets( 2, 0, 0, 0 );//placing 2 pixel gap betwwen upeer panel and this.
- gbc.weighty = 0.0;
- gridbag.setConstraints(pjav,gbc);
- add(pjav);
-
- } // constructor
-
- // --- Public operations
-
- public int countViews()
- {
- return 1;
- }
-
- } // SportsViewScores
-
-
- /**
- * A helper class that creates a view of highlights
- */
- class SportsViewHighlights extends PageView
- {
-
- // --- Public constructors
-
- public SportsViewHighlights(Paper paper)
- {
- super(SportsSection.strTitleHighlights);
-
- // Create Portfolio Page components
- Label lblPageTitle = new Label(SportsSection.strTitleHighlights);
- lblPageTitle.setFont( PjFinals.fntSectionBigTitle );
-
- Label lblHighlights = new Label( SportsSection.strLblHighlights );
- Button btnScores = new Button(SportsSection.strBtnScores);
-
- lblHighlights.setFont( PjFinals.fntColumnLabel );
- btnScores.setFont( PjFinals.fntColumnLabel );
-
- Column colSpHilite = new Column(Paper.idSpHilite, paper);
- colSpHilite.setFont( PjFinals.fntUnfColumnPlain );
-
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
-
- 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 ) );
-
- // Sports icon
- PjImages Imgs = new PjImages();
-
- // Add the little sports icon.
- pnlHeader.add( new GifCanvas(Imgs.imagespecs()[ PjImages.idxSports ].getImage() ) );
-
- // Add the title "sports"
- pnlHeader.add( lblPageTitle );
-
- // Add the header panel with its contents to the page.
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gbc.anchor=GridBagConstraints.WEST;
- gridbag.setConstraints(pnlHeader,gbc);
- add( pnlHeader );
-
- //Label
- gbc.weightx = 1.0;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.gridwidth=GridBagConstraints.RELATIVE;
- gridbag.setConstraints(lblHighlights,gbc);
- add( lblHighlights );
-
- //Button
- gbc.weightx = 0.0;
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gridbag.setConstraints(btnScores,gbc);
- add( btnScores );
-
- //Hightlights panel
- gbc.insets = new Insets( 2, 0, 0, 0 );//placing 2 pixel gap betwwen upeer panel and this.
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
-
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth=GridBagConstraints.REMAINDER;
-
- gridbag.setConstraints(colSpHilite,gbc);
- add(colSpHilite);
-
- } // constructor
-
- // --- Public operations
-
- public int countViews()
- {
- return 1;
- }
-
- } //SportsViewHighlights
-