home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / sportssection.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  11.0 KB  |  387 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.     @(#)SportsSection.java  0.00 26-Jan-96
  15.  
  16.         A SectionView for the Sports.
  17.  
  18.     Authors:
  19.  
  20.         jlee    James Lee
  21.  
  22.     Version Ident:
  23.  
  24.         $Header: /PjJavaClient/src/pj/awt/SportsSection.java 6     3/22/96 11:13p Jlee $
  25.  
  26.     History:
  27.  
  28.         0.00 14-Jan-96  jlee      Initial Creation
  29.         0.01 1-Mar-96   Ted S.    Added sports icons to the page,
  30.                                   to make it look a little more PJish.
  31.             27-Mar-96   jlee      Changed "Highligh&ts" and "Sc&ores" to "Highlights" and "Scores"
  32.  
  33. ---------------------------------------------------------------------------*/
  34.  
  35. package pj.awt;
  36.  
  37. import pj.awt.Column;
  38. import pj.awt.PageView;
  39. import pj.awt.PjListLayout;
  40. import pj.awt.PjPageSpec;
  41. import pj.awt.PjFinals;
  42. import pj.awt.PjStr;
  43. import pj.awt.SectionView;
  44. import pj.io.MalformedPaperStoryException;
  45. import pj.io.Paper;
  46. import pj.io.PaperStory;
  47. import pj.net.RemoteImage;
  48.  
  49. import collections.Assertable;
  50. import collections.ImplementationError;
  51. import java.awt.Button;
  52. import java.awt.Component;
  53. import java.awt.Event;
  54. import java.awt.FlowLayout;
  55. import java.awt.Font;
  56. import java.awt.GridBagLayout;
  57. import java.awt.GridBagConstraints;
  58. import java.awt.Insets;
  59. import java.awt.Label;
  60. import java.awt.Panel;
  61.  
  62.  
  63. /**
  64.  * A SectionView for Sports.
  65.  *
  66.  * @see DividerView
  67.  * @version 0.00 14-Jan-96
  68.  * @author  jlee
  69. */
  70. public class SportsSection extends SectionView implements Assertable
  71.     {
  72.  
  73.  
  74.     // --- Class variables
  75.     /**
  76.       * Labels for the buttons and page names.
  77.      */
  78.     static final String strTitleScores     = "Scoreboard";
  79.     static final String strTitleHighlights = "Sports";
  80.     static final String strLblHighlights   = "Highlights";
  81.     static final String strBtnScores       = "Scores";
  82.     static final String strBtnHighlights   = "Highlights";
  83.  
  84.     // --- Instance variables
  85.  
  86.     private PageView pvScores;
  87.     private PageView pvHighlights;
  88.     private Paper    paper;
  89.  
  90.  
  91.  
  92.     // --- Public constructors
  93.  
  94.     /**
  95.      * A general-purpose constructor that uses preassembled
  96.      * components.
  97.      * @param scores A PageView for scores.
  98.      * @param scores A PageView for highlights.
  99.      * @param pagespec A specification for the page.
  100.      * @param paper The paper being observed.
  101.     */
  102.     public SportsSection( PageView scores, PageView highlights, PjPageSpec pagespec, Paper p)
  103.         {
  104.         super(pagespec.tabspec);
  105.  
  106.         pvScores = scores;
  107.         pvHighlights = highlights;
  108.         paper = p;
  109.  
  110.         initialLayout();
  111.  
  112.         } // SportsSection constructor
  113.  
  114.     /**
  115.      * A specialized constructor for a SportsSection that uses
  116.      * a page specification.
  117.      * @param pagespec  A page specification, either for the Sports.
  118.      * @param pas A PjAdSpec object.
  119.      * @param p The paper being observed.
  120.     */
  121.     public SportsSection( PjPageSpec pagespec, PjAdSpec pas, Paper p )
  122.         {
  123.         super(pagespec.tabspec);
  124.         paper = p;
  125.  
  126.         // Column pages creation
  127.         if ( pagespec.strPageName.equals( PjStr.pageSpHilite) )
  128.             {
  129.             pvScores = new SportsViewScores(pas, paper);
  130.             pvHighlights = new SportsViewHighlights( paper );
  131.             }
  132.         else
  133.             {
  134.             // Bad page specification
  135.             assert(false);
  136.             }
  137.  
  138.         initialLayout();
  139.  
  140.         System.out.println("Debug-SportsSection:constructed");
  141.         } // SportsSection constructor
  142.  
  143.     // --- Public operations
  144.     /**
  145.      * @return The number (one) of views in a SportsSection.
  146.      */
  147.     public int countViews()
  148.         {
  149.         int num = 0;
  150.         num += pvScores.countViews();
  151.         num += pvHighlights.countViews();
  152.         return num;
  153.         }
  154.  
  155.     /**
  156.      * Handles events
  157.      *
  158.      * @param evt An Event object
  159.      * @return true if the event's handled, false otherwise.
  160.      */
  161.     public boolean handleEvent(Event evt)
  162.         {
  163.         boolean bHandled = false;
  164.  
  165.         switch (evt.id)
  166.             {
  167.             default:
  168.                 bHandled = super.handleEvent(evt);
  169.                 break;
  170.             } // switch
  171.  
  172.         return bHandled;
  173.         } // handleEvent
  174.  
  175.     /**
  176.      * Handles ACTION_EVENT. Specifically, when you click one of those regions in
  177.      * the Sports map, it'll generate this action event,  which will be eventually handled here.
  178.      *
  179.      * @param e An Event object
  180.      * @param arg An String object which is the name of the hot area which user cliked on.
  181.      * @return true if further event handling's neccessary, false otherwise.
  182.      */
  183.     public boolean action(Event e, Object arg)
  184.         {
  185.         boolean bHandled = false;
  186.  
  187.         if ( strBtnScores.equals( arg ) )
  188.             {
  189.             bHandled = true;
  190.             stack.page(strTitleScores);
  191.             }
  192.         else if ( strBtnHighlights.equals( arg ) )
  193.             {
  194.             bHandled = true;
  195.             stack.page(strTitleHighlights);
  196.             }
  197.  
  198.         return bHandled;
  199.         } // action
  200.  
  201.     /**
  202.      * Raise an exception if predicate is false.
  203.      * @see collections.Assertable
  204.     */
  205.     public void assert(boolean predicate) throws ImplementationError
  206.         {
  207.         ImplementationError.assert(this, predicate);
  208.         }
  209.  
  210.     // --- Private operations
  211.  
  212.     private void initialLayout()
  213.         {
  214.         assert( pvScores != null );
  215.         assert( pvHighlights  != null );
  216.         assert( paper != null );
  217.  
  218.         appendPage(pvScores );
  219.         appendPage(pvHighlights );
  220.         }
  221.  
  222.  
  223.  
  224.     } // SportsSection
  225.  
  226.  
  227. /**
  228.  * A helper class that creates a view of scores
  229. */
  230. class SportsViewScores extends PageView
  231.     {
  232.  
  233.     // --- Public constructors
  234.  
  235.     public SportsViewScores(PjAdSpec pas, Paper paper)
  236.         {
  237.         super(SportsSection.strTitleScores);
  238.  
  239.         // Create Sports Page components
  240.         Label lblPageTitle = new Label(SportsSection.strTitleScores);
  241.         lblPageTitle.setFont( PjFinals.fntSectionBigTitle );
  242.  
  243.         Button btnHighlights = new Button(SportsSection.strBtnHighlights);
  244.         btnHighlights.setFont( PjFinals.fntColumnLabel );
  245.  
  246.         Column colScores = new Column(Paper.idSpScores, paper);
  247.         colScores.setFont( PjFinals.fntUnfColumnPlain );
  248.         PjAdView pjav = new PjAdView(pas);
  249.  
  250.         Panel    pnlScores    = new Panel();
  251.         pnlScores.setLayout( new PjListLayout( PjListLayout.RIGHT ) );
  252.         pnlScores.add( btnHighlights );
  253.         pnlScores.add( colScores );
  254.  
  255.         GridBagLayout gridbag   = new GridBagLayout();
  256.         GridBagConstraints gbc  = new GridBagConstraints();
  257.         setLayout(gridbag);
  258.  
  259.         // Create a panel to hold the icon and the text for page title.
  260.         Panel pnlHeader = new Panel();
  261.         pnlHeader.setLayout( new FlowLayout( FlowLayout.LEFT ) );
  262.  
  263.          // Sports icon
  264.         PjImages Imgs = new PjImages();
  265.  
  266.         // Add the little sports score icon.
  267.         pnlHeader.add( new GifCanvas(Imgs.imagespecs()[ PjImages.idxScores ].getImage() ) );
  268.  
  269.         // Add the title
  270.         pnlHeader.add( lblPageTitle );
  271.  
  272.         // Add the header panel with its contents to the page.
  273.         gbc.gridwidth=GridBagConstraints.REMAINDER;
  274.         gbc.anchor=GridBagConstraints.WEST;
  275.         gridbag.setConstraints(pnlHeader,gbc);
  276.         add( pnlHeader );
  277.  
  278.         //Scores panel
  279.         gbc.weighty = 1.0;
  280.         gbc.fill = GridBagConstraints.BOTH;
  281.         gbc.gridwidth=GridBagConstraints.REMAINDER;
  282.         gridbag.setConstraints(pnlScores,gbc);
  283.         add(pnlScores);
  284.  
  285.         //Adview
  286.         gbc.insets = new Insets( 2, 0, 0, 0 );//placing 2 pixel gap betwwen upeer panel and this.
  287.         gbc.weighty = 0.0;
  288.         gridbag.setConstraints(pjav,gbc);
  289.         add(pjav);
  290.  
  291.         } // constructor
  292.  
  293.     // --- Public operations
  294.  
  295.     public int countViews()
  296.         {
  297.         return 1;
  298.         }
  299.  
  300.     } // SportsViewScores
  301.  
  302.  
  303. /**
  304.  * A helper class that creates a view of highlights
  305. */
  306. class SportsViewHighlights extends PageView
  307.     {
  308.  
  309.     // --- Public constructors
  310.  
  311.     public SportsViewHighlights(Paper paper)
  312.         {
  313.         super(SportsSection.strTitleHighlights);
  314.  
  315.         // Create Portfolio Page components
  316.         Label lblPageTitle = new Label(SportsSection.strTitleHighlights);
  317.         lblPageTitle.setFont( PjFinals.fntSectionBigTitle );
  318.  
  319.         Label lblHighlights = new Label( SportsSection.strLblHighlights );
  320.         Button btnScores = new Button(SportsSection.strBtnScores);
  321.  
  322.         lblHighlights.setFont( PjFinals.fntColumnLabel );
  323.         btnScores.setFont( PjFinals.fntColumnLabel );
  324.  
  325.         Column colSpHilite = new Column(Paper.idSpHilite, paper);
  326.         colSpHilite.setFont( PjFinals.fntUnfColumnPlain );
  327.  
  328.         GridBagLayout gridbag   = new GridBagLayout();
  329.         GridBagConstraints gbc  = new GridBagConstraints();
  330.  
  331.         setLayout(gridbag);
  332.  
  333.  
  334.          // Create a panel to hold the icon and the text for page title.
  335.         Panel pnlHeader = new Panel();
  336.         pnlHeader.setLayout( new FlowLayout( FlowLayout.LEFT ) );
  337.  
  338.          // Sports icon
  339.         PjImages Imgs = new PjImages();
  340.  
  341.         // Add the little sports icon.
  342.         pnlHeader.add( new GifCanvas(Imgs.imagespecs()[ PjImages.idxSports ].getImage() ) );
  343.  
  344.         // Add the title "sports"
  345.         pnlHeader.add( lblPageTitle );
  346.  
  347.         // Add the header panel with its contents to the page.
  348.         gbc.gridwidth=GridBagConstraints.REMAINDER;
  349.         gbc.anchor=GridBagConstraints.WEST;
  350.         gridbag.setConstraints(pnlHeader,gbc);
  351.         add( pnlHeader );
  352.  
  353.         //Label
  354.         gbc.weightx = 1.0;
  355.         gbc.fill = GridBagConstraints.HORIZONTAL;
  356.         gbc.gridwidth=GridBagConstraints.RELATIVE;
  357.         gridbag.setConstraints(lblHighlights,gbc);
  358.         add( lblHighlights );
  359.  
  360.         //Button
  361.         gbc.weightx = 0.0;
  362.         gbc.gridwidth=GridBagConstraints.REMAINDER;
  363.         gridbag.setConstraints(btnScores,gbc);
  364.         add( btnScores );
  365.  
  366.         //Hightlights panel
  367.         gbc.insets = new Insets( 2, 0, 0, 0 );//placing 2 pixel gap betwwen upeer panel and this.
  368.         gbc.weightx = 1.0;
  369.         gbc.weighty = 1.0;
  370.  
  371.         gbc.fill = GridBagConstraints.BOTH;
  372.         gbc.gridwidth=GridBagConstraints.REMAINDER;
  373.  
  374.         gridbag.setConstraints(colSpHilite,gbc);
  375.         add(colSpHilite);
  376.  
  377.         } // constructor
  378.  
  379.     // --- Public operations
  380.  
  381.     public int countViews()
  382.         {
  383.         return 1;
  384.         }
  385.  
  386.     } //SportsViewHighlights
  387.