home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / sphiliteview.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  7.6 KB  |  279 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.     @(#)SpHiliteView.java  0.00 01-Jan-96
  15.  
  16.         A DividerView for the Sports Highlights section.
  17.  
  18.     Authors:
  19.  
  20.         rphall   Rick Hall
  21.         jlee     James Lee
  22.  
  23.     Version Ident:
  24.  
  25.         $Header$
  26.  
  27.     History:
  28.  
  29.         0.00 15-Jan-96  rphall      Initial Creation
  30.              27-Mar-96  jlee        Got rid of & from "Sc&ores"
  31. ---------------------------------------------------------------------------*/
  32.  
  33. package pj.awt;
  34.  
  35. import pj.awt.Column;
  36. import pj.awt.DividerView;
  37. import pj.awt.PjPageSpec;
  38. import pj.awt.PjStr;
  39. import pj.io.Paper;
  40.  
  41. import collections.Assertable;
  42. import collections.ImplementationError;
  43. import java.awt.Button;
  44. import java.awt.Component;
  45. import java.awt.Font;
  46. import java.awt.GridBagConstraints;
  47. import java.awt.GridBagLayout;
  48. import java.awt.Label;
  49. import java.awt.Panel;
  50. import java.awt.Insets;
  51.  
  52.  
  53. /**
  54.  * A DividerView for the Sports Highlights section.
  55.  *
  56.  * @see DividerView
  57.  * @version 0.00 01-Jan-96
  58.  * @author  rphall
  59. */
  60. public class SpHiliteView extends DividerView implements Assertable
  61.     {
  62.     // --- Class variables
  63.  
  64.     private static final String strSpHilite  ="Highlights";
  65.     private static final String strSpScore   ="Scores";
  66.  
  67.     // FIXME
  68.     //private static final URL strAdImageParam = "data/SpHiliteAdImage.gif";
  69.     //private static final URL strAdCopyParam  = "data/SpHiliteAdCopy.txt";
  70.  
  71.     // --- Instance variables
  72.  
  73.     private Component cPageTitle;
  74.     private Column    colSpHilite;
  75.     private Component cAdImage;
  76.     private Component cAdCopy;
  77.     private Paper     paper;
  78.  
  79.     private Label     lblSpHilite;
  80.     private Button    btnSpScore;
  81.  
  82.  
  83.     // --- Public constructors
  84.  
  85.     /**
  86.      * A general-purpose constructor that uses preassembled
  87.      * components.
  88.      * @param t A title component.
  89.      * @param port A Sports Highlights column.
  90.      * @param pagespec A specification for the page.
  91.      * @param paper The paper being observed.
  92.     */
  93.     public SpHiliteView(Component t,Column port,PjPageSpec pagespec,Paper p)
  94.         {
  95.         super(pagespec.tabspec);
  96.  
  97.         cPageTitle = t;
  98.         colSpHilite = port;
  99.         paper = p;
  100.  
  101.         initialLayout();
  102.  
  103.         } // SpHiliteView constructor
  104.  
  105.     /**
  106.      * A specialized constructor for a SpHiliteView that uses
  107.      * a page specification.
  108.      * @param pagespec  A page specification, either for the
  109.      * Front Page headlines or the ThisJustIn headlines.
  110.      * @param paper The paper being observed.
  111.     */
  112.     public SpHiliteView(PjPageSpec pagespec, Paper paper)
  113.         {
  114.         super(pagespec.tabspec);
  115.  
  116.         if  ( pagespec.strPageName.equals(PjStr.pageSpHilite) )
  117.             {
  118.             // Create Sports Highlights Page components
  119.             cPageTitle = new Label("Sports");
  120.  
  121.             Font lblFont = new Font("MS Sans Serif", Font.BOLD, 25 );
  122.             cPageTitle.setFont( lblFont );
  123.  
  124.             colSpHilite = new Column(Paper.idSpHilite,paper);
  125.             }
  126.  
  127.         else
  128.             {
  129.             // Bad page specification
  130.             assert(false);
  131.             }
  132.  
  133.         initialLayout();
  134.  
  135.         } // SpHiliteView constructor
  136.  
  137.     // --- Public operations
  138.  
  139.     /**
  140.      * @return The number (one) of views in a SpHiliteView.
  141.     */
  142.     public int countViews()
  143.         {
  144.         return 1;
  145.         }
  146.  
  147.     /**
  148.      * Raise an exception if predicate is false.
  149.      * @see collections.Assertable
  150.     */
  151.     public void assert(boolean predicate) throws ImplementationError
  152.         {
  153.         ImplementationError.assert(this, predicate);
  154.         }
  155.  
  156.     // --- Private operations
  157.  
  158.     private void initialLayout()
  159.         {
  160.         Font lblFont = new Font("MS Sans Serif", Font.BOLD, 8 );
  161.  
  162.         Panel pnlTop = new Panel();
  163.         layoutTopPanel(pnlTop);
  164.  
  165.         Panel pnlTopData = new Panel();
  166.         lblSpHilite = new Label(strSpHilite);
  167.         btnSpScore = new Button(strSpScore);
  168.  
  169.         lblSpHilite.setFont( lblFont );
  170.         btnSpScore.setFont( lblFont );
  171.  
  172.         layoutArrayPanel(pnlTopData,lblSpHilite,btnSpScore,colSpHilite);
  173.  
  174.         Panel pnlAd = null;
  175.         /*
  176.         Panel pnlAd = new Panel();
  177.         btnWrap = new Button(strWrap);
  178.         btnExTrs = new Button(strExTrs);
  179.         layoutAdPanel(pnlAd,btnWrap,btnExTrs);
  180.         */
  181.  
  182.         layoutPanels(pnlTop,pnlTopData,pnlAd);
  183.  
  184.         } // initialLayout
  185.  
  186.     private void layoutTopPanel(Panel pnl)
  187.         {
  188.         pnl.add(cPageTitle);
  189.         }
  190.  
  191.     private void layoutArrayPanel(Panel pnl, Component lbl, Component btn, Component col)
  192.         {
  193.         GridBagLayout gridbag = new GridBagLayout();
  194.         pnl.setLayout(gridbag);
  195.  
  196.         GridBagConstraints gbc = new GridBagConstraints();
  197.         gbc.weightx = 1.0;
  198.         gbc.fill = GridBagConstraints.HORIZONTAL;
  199.  
  200.         gbc.insets = new Insets( 20, 7, 2, 7 );
  201.         gridbag.setConstraints(lbl, gbc);
  202.         pnl.add(lbl);
  203.  
  204.         gbc.weightx = 0;
  205.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  206.         gridbag.setConstraints(btn, gbc);
  207.         pnl.add(btn);
  208.  
  209.         gbc.weightx = 1.0;
  210.         gbc.weighty = 1.0;
  211.         gbc.insets = new Insets( 0, 7, 2, 7 );
  212.  
  213.         gbc.fill = GridBagConstraints.BOTH;
  214.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  215.         gridbag.setConstraints(col, gbc);
  216.         pnl.add(col);
  217.  
  218.         } // layoutArrayPanel
  219.  
  220.     private void layoutAdPanel(Panel pnl, Component cImage, Component cCopy)
  221.         {
  222.         GridBagLayout gridbag = new GridBagLayout();
  223.         pnl.setLayout(gridbag);
  224.  
  225.         GridBagConstraints gbc = new GridBagConstraints();
  226.         gbc.weightx = 1.0;
  227.         gbc.weighty = 1.0;
  228.  
  229.         gbc.fill = GridBagConstraints.HORIZONTAL;
  230.         gbc.gridwidth = GridBagConstraints.RELATIVE;
  231.  
  232.         gridbag.setConstraints(cImage, gbc);
  233.         pnl.add(cImage);
  234.  
  235.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  236.         gridbag.setConstraints(cCopy, gbc);
  237.         pnl.add(cCopy);
  238.  
  239.         } // layoutAdPanel
  240.  
  241.     private void layoutPanels( Panel pnlTop, Panel pnlTopData, Panel pnlAd)
  242.         {
  243.         GridBagLayout gridbag = new GridBagLayout();
  244.         setLayout(gridbag);
  245.  
  246.         // Top panel
  247.         GridBagConstraints gbc = new GridBagConstraints();
  248.         gbc.fill = GridBagConstraints.BOTH;
  249.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  250.  
  251.         gridbag.setConstraints(pnlTop, gbc);
  252.         add(pnlTop);
  253.  
  254.         // Top panel of data
  255.         gbc = new GridBagConstraints();
  256.         gbc.weightx = 1.0;
  257.         gbc.weighty = 1.0;
  258.  
  259.         gbc.fill = GridBagConstraints.BOTH;
  260.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  261.  
  262.         gridbag.setConstraints(pnlTopData, gbc);
  263.         add(pnlTopData);
  264.  
  265.         /*
  266.         // Ad panel
  267.         gbc = new GridBagConstraints();
  268.         gbc.fill = GridBagConstraints.BOTH;
  269.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  270.         gridbag.setConstraints(pnlAd, gbc);
  271.         add(pnlAd);
  272.         */
  273.  
  274.         } // layoutPanels
  275.  
  276.  
  277.  
  278.     } // SpHiliteView
  279.