home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / marketview.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  7.9 KB  |  286 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.     @(#)MarketView.java  0.00 01-Jan-96
  15.  
  16.         A DividerView for the Front Page and ThisJustIn headlines.
  17.  
  18.  
  19.     Authors:
  20.  
  21.         rphall   Rick Hall
  22.  
  23.  
  24.     Version Ident:
  25.  
  26.         $Header$
  27.  
  28.  
  29.     History:
  30.  
  31.         0.00 01-Jan-96  rphall      Initial Creation
  32.         0.01 3-Mar-96   Ted S.      Added market icons.
  33.             27-Mar-96   jlee        Changed "Currencies && Bonds" to "Currencies and Bonds"
  34.  
  35. ---------------------------------------------------------------------------*/
  36.  
  37. package pj.awt;
  38.  
  39. import pj.awt.Column;
  40. import pj.awt.DividerView;
  41. import pj.awt.PjImages;
  42. import pj.awt.PjPageSpec;
  43. import pj.awt.PjStr;
  44. import pj.awt.StoryList;
  45. import pj.io.Paper;
  46.  
  47. import collections.Assertable;
  48. import collections.ImplementationError;
  49. import java.awt.Button;
  50. import java.awt.Component;
  51. import java.awt.FlowLayout;
  52. import java.awt.GridBagConstraints;
  53. import java.awt.GridBagLayout;
  54. import java.awt.Label;
  55. import java.awt.Panel;
  56.  
  57. /**
  58.  * A DividerView for Front Page and ThisJustIn headlines.
  59.  *
  60.  * @see DividerView
  61.  * @version 0.00 01-Jan-96
  62.  * @author  rphall
  63. */
  64. public class MarketView extends DividerView implements Assertable
  65.     {
  66.  
  67.     // --- Class variables
  68.  
  69.     private static final String strDjia     = "Dow Jones Industrial Average";
  70.     private static final String strStkIdx   = "Stock Indexes";
  71.     private static final String strWrap     = "Market News";
  72.     private static final String strExTrs    = "Currencies and Bonds";
  73.  
  74.     // --- Instance variables
  75.  
  76.     private Component cPageTitle;
  77.     private Column    colDjia;
  78.     private Column    colStkIdx;
  79.     private Paper     paper;
  80.  
  81.     private Label     lblDjia;
  82.     private Label     lblStkIdx;
  83.     private Button    btnWrap;
  84.     private Button    btnExTrs;
  85.  
  86.  
  87.     // --- Public constructors
  88.  
  89.     /**
  90.      * A general-purpose constructor that uses preassembled
  91.      * components.
  92.      * @param t A title component.
  93.      * @param djia A Dow Jones Industrial Average column.
  94.      * @param stkidx A Stock Indexes column.
  95.      * @param pagespec A specification for the page.
  96.      * @param paper The paper being observed.
  97.     */
  98.     public MarketView( Component t, Column djia, Column stkidx,
  99.             PjPageSpec pagespec, Paper p)
  100.         {
  101.         super(pagespec.tabspec);
  102.  
  103.         cPageTitle = t;
  104.         colDjia = djia;
  105.         colStkIdx = stkidx;
  106.         paper = p;
  107.  
  108.         initialLayout();
  109.  
  110.         } // MarketView constructor
  111.  
  112.     /**
  113.      * A specialized constructor for a MarketView that uses
  114.      * a page specification.
  115.      * @param pagespec  A page specification, either for the
  116.      * Front Page headlines or the ThisJustIn headlines.
  117.      * @param paper The paper being observed.
  118.     */
  119.     public MarketView(PjPageSpec pagespec, Paper paper)
  120.         {
  121.         super(pagespec.tabspec);
  122.  
  123.         if  ( pagespec.strPageName.equals(PjStr.pageMrk) )
  124.             {
  125.             // Create Markets Page components
  126.             cPageTitle = new Label("Markets");
  127.             colDjia = new Column(Paper.idMrkDjia,paper);
  128.             colStkIdx = new Column(Paper.idMrkStkIdx,paper);
  129.             }
  130.  
  131.         else
  132.             {
  133.             // Bad page specification
  134.             assert(false);
  135.             }
  136.  
  137.         initialLayout();
  138.  
  139.         } // MarketView constructor
  140.  
  141.     // --- Public operations
  142.  
  143.     /**
  144.      * @return The number (one) of views in a MarketView.
  145.     */
  146.     public int countViews()
  147.         {
  148.         return 1;
  149.         }
  150.  
  151.     /**
  152.      * Raise an exception if predicate is false.
  153.      * @see collections.Assertable
  154.     */
  155.     public void assert(boolean predicate) throws ImplementationError
  156.         {
  157.         ImplementationError.assert(this, predicate);
  158.         }
  159.  
  160.     // --- Private operations
  161.  
  162.     private void initialLayout()
  163.         {
  164.         Panel pnlTop = new Panel();
  165.         layoutTopPanel(pnlTop);
  166.  
  167.         Panel pnlTopData = new Panel();
  168.         lblDjia = new Label(strDjia);
  169.         layoutArrayPanel(pnlTopData,lblDjia,colDjia);
  170.  
  171.         Panel pnlBtmData = new Panel();
  172.         lblStkIdx = new Label(strStkIdx);
  173.         layoutArrayPanel(pnlBtmData,lblStkIdx,colStkIdx);
  174.  
  175.         Panel pnlBtn = new Panel();
  176.         btnWrap = new Button(strWrap);
  177.         btnExTrs = new Button(strExTrs);
  178.         layoutBtnPanel(pnlBtn,btnWrap,btnExTrs);
  179.  
  180.         layoutPanels(pnlTop,pnlTopData,pnlBtmData,pnlBtn);
  181.  
  182.         } // initialLayout
  183.  
  184.     private void layoutTopPanel(Panel pnl)
  185.         {
  186.         PjImages Imgs;
  187.         Imgs = new PjImages();
  188.  
  189.         // allign evrything to the left like in VB PJ.
  190.         pnl.setLayout( new FlowLayout( FlowLayout.LEFT ) );
  191.  
  192.         // Add the little market icon
  193.         // fixme: Determine if bull or bear should be used.
  194.         pnl.add( new GifCanvas(Imgs.imagespecs()[ PjImages.idxBull ].getImage() ));
  195.         pnl.add( new Label( "hey" ));
  196.  
  197.         // add the page title "Market..."
  198.         pnl.add(cPageTitle);
  199.         }
  200.  
  201.     private void layoutArrayPanel(Panel pnl, Component lbl, Component col)
  202.         {
  203.         GridBagLayout gridbag = new GridBagLayout();
  204.         pnl.setLayout(gridbag);
  205.  
  206.         GridBagConstraints gbc = new GridBagConstraints();
  207.         gbc.weightx = 1.0;
  208.         gbc.weighty = 1.0;
  209.  
  210.         gbc.fill = GridBagConstraints.HORIZONTAL;
  211.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  212.  
  213.         gridbag.setConstraints(lbl, gbc);
  214.         pnl.add(lbl);
  215.  
  216.         gbc.fill = GridBagConstraints.BOTH;
  217.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  218.         gridbag.setConstraints(col, gbc);
  219.         pnl.add(col);
  220.  
  221.         } // layoutArrayPanel
  222.  
  223.     private void layoutBtnPanel(Panel pnl, Component btnLeft, Component btnRight)
  224.         {
  225.         GridBagLayout gridbag = new GridBagLayout();
  226.         pnl.setLayout(gridbag);
  227.  
  228.         GridBagConstraints gbc = new GridBagConstraints();
  229.         gbc.weightx = 1.0;
  230.         gbc.weighty = 1.0;
  231.  
  232.         gbc.fill = GridBagConstraints.HORIZONTAL;
  233.         gbc.gridwidth = GridBagConstraints.RELATIVE;
  234.  
  235.         gridbag.setConstraints(btnLeft, gbc);
  236.         pnl.add(btnLeft);
  237.  
  238.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  239.         gridbag.setConstraints(btnRight, gbc);
  240.         pnl.add(btnRight);
  241.  
  242.         } // layoutBtnPanel
  243.  
  244.     private void layoutPanels( Panel pnlTop,
  245.             Panel pnlTopData, Panel pnlBtmData, Panel pnlBtn)
  246.         {
  247.         GridBagLayout gridbag = new GridBagLayout();
  248.         setLayout(gridbag);
  249.  
  250.         // Top panel
  251.         GridBagConstraints gbc = new GridBagConstraints();
  252.  
  253.         gbc.fill = GridBagConstraints.BOTH;
  254.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  255.  
  256.         gridbag.setConstraints(pnlTop, gbc);
  257.         add(pnlTop);
  258.  
  259.         // Top panel of data
  260.         gbc = new GridBagConstraints();
  261.         gbc.weightx = 1.0;
  262.  
  263.         gbc.fill = GridBagConstraints.BOTH;
  264.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  265.  
  266.         gridbag.setConstraints(pnlTopData, gbc);
  267.         add(pnlTopData);
  268.  
  269.         // Bottom panel of data
  270.         gridbag.setConstraints(pnlBtmData, gbc);
  271.         add(pnlBtmData);
  272.  
  273.         // Bottom panel
  274.         gbc = new GridBagConstraints();
  275.         gbc.fill = GridBagConstraints.BOTH;
  276.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  277.  
  278.         gridbag.setConstraints(pnlBtn, gbc);
  279.         add(pnlBtn);
  280.  
  281.         } // layoutPanels
  282.  
  283.  
  284.  
  285.     } // MarketView
  286.