home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / portview.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  6.8 KB  |  246 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.     @(#)PortView.java  0.00 01-Jan-96
  15.  
  16.         A DividerView for the Portfolio section.
  17.  
  18.     Authors:
  19.  
  20.         jlee     James Lee
  21.         rphall   Rick Hall
  22.  
  23.     Version Ident:
  24.  
  25.         $Header: /PjJavaClient/src/pj/awt/PortView.java 13    3/22/96 11:13p Jlee $
  26.  
  27.     History:
  28.  
  29.  
  30.         0.00 15-Jan-96  rphall      Initial Creation
  31.         0.01 23-Jan-96  jlee        Added PjAdSpec parameter in PortView constructor and
  32.                                     modified ad. view panel layout.
  33.         0.02 1-Mar-96   Ted S.      Added portfolio Icon to make it more PJish.
  34. ---------------------------------------------------------------------------*/
  35.  
  36. package pj.awt;
  37.  
  38. import pj.awt.ArrayFormatter;
  39. import pj.awt.Column;
  40. import pj.awt.DividerView;
  41. import pj.awt.PjAdSpec;
  42. import pj.awt.PjAdView;
  43. import pj.awt.PjImages;
  44. import pj.awt.PjListLayout;
  45. import pj.awt.PjPageSpec;
  46. import pj.awt.PjFinals;
  47. import pj.awt.PjStr;
  48. import pj.io.Paper;
  49.  
  50. import collections.Assertable;
  51. import collections.ImplementationError;
  52. import java.awt.Button;
  53. import java.awt.Component;
  54. import java.awt.FlowLayout;
  55. import java.awt.Font;
  56. import java.awt.GridBagConstraints;
  57. import java.awt.GridBagLayout;
  58. import java.awt.Label;
  59. import java.awt.Panel;
  60.  
  61.  
  62. /**
  63.  * A DividerView for the Portfolio section.
  64.  *
  65.  * @see DividerView
  66.  * @version 0.00 01-Jan-96
  67.  * @author  rphall
  68. */
  69. public class PortView extends DividerView implements Assertable
  70.     {
  71.  
  72.     // --- Class variables
  73.  
  74.     private static final String strPort="Quotes (Delayed at least 15 minutes)";
  75.  
  76.     // --- Instance variables
  77.  
  78.     private Component cPageTitle;
  79.     private Column    colPort;
  80.     private PjAdView  pjav;
  81.     private Paper     paper;
  82.  
  83.     private Label     lblPort;
  84.  
  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 port A Portfolio column.
  94.      * @param pagespec A specification for the page.
  95.      * @param pas A specification for the Portfolio ad.
  96.      * @param paper The paper being observed.
  97.     */
  98.     public PortView( Component t, Column port,
  99.                         PjPageSpec pagespec, PjAdSpec pas, Paper p)
  100.         {
  101.         super(pagespec.tabspec);
  102.  
  103.         cPageTitle = t;
  104.         colPort = port;
  105.         pjav = new PjAdView(pas);
  106.         paper = p;
  107.  
  108.         initialLayout();
  109.  
  110.         } // PortView constructor
  111.  
  112.     /**
  113.      * A specialized constructor for a PortView 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 pas A specification for the Portfolio ad.
  118.      * @param p The paper being observed.
  119.     */
  120.     public PortView(PjPageSpec pagespec, PjAdSpec pas, Paper p)
  121.         {
  122.         super(pagespec.tabspec);
  123.         paper = p;
  124.  
  125.         if  ( pagespec.strPageName.equals(PjStr.pagePort) )
  126.             {
  127.             // Create Portfolio Page components
  128.             cPageTitle = new Label("Portfolio");
  129.             cPageTitle.setFont( PjFinals.fntSectionBigTitle );
  130.  
  131.             colPort = new Column(Paper.idPortQuote,paper);
  132.             colPort.setStoryFormatter( new ArrayFormatter(Paper.idPortQuote) );
  133.             colPort.setFont( PjFinals.fntFormattedColumn );
  134.             pjav = new PjAdView(pas);
  135.             }
  136.  
  137.         else
  138.             {
  139.             // Bad page specification
  140.             assert(false);
  141.             }
  142.  
  143.         initialLayout();
  144.         System.out.println("Debug-PortView:constructed");
  145.         } // PortView constructor
  146.  
  147.     // --- Public operations
  148.  
  149.     /**
  150.      * @return The number (one) of views in a PortView.
  151.     */
  152.     public int countViews()
  153.         {
  154.         return 1;
  155.         }
  156.  
  157.     /**
  158.      * Raise an exception if predicate is false.
  159.      * @see collections.Assertable
  160.     */
  161.     public void assert(boolean predicate) throws ImplementationError
  162.         {
  163.         ImplementationError.assert(this, predicate);
  164.         }
  165.  
  166.     // --- Private operations
  167.  
  168.     private void initialLayout()
  169.         {
  170.         Panel pnlTop = new Panel();
  171.         layoutTopPanel(pnlTop);
  172.  
  173.         Panel pnlTopData = new Panel();
  174.         lblPort = new Label(strPort);
  175.         lblPort.setFont( PjFinals.fntColumnLabel );
  176.  
  177.         layoutArrayPanel(pnlTopData,lblPort,colPort);
  178.  
  179.         layoutPanels(pnlTop,pnlTopData,pjav);
  180.  
  181.         } // initialLayout
  182.  
  183.     private void layoutTopPanel(Panel pnl)
  184.         {
  185.         PjImages Imgs;
  186.         Imgs = new PjImages();
  187.  
  188.         // allign evrything to the left like in VB PJ.
  189.         pnl.setLayout( new FlowLayout( FlowLayout.LEFT ) );
  190.  
  191.         // Add the little portfolio icon
  192.         pnl.add( new GifCanvas(Imgs.imagespecs()[ PjImages.idxPortfolio ].getImage() ));
  193.  
  194.         // add the page title "Portfolio"
  195.         pnl.add(cPageTitle);
  196.         }
  197.  
  198.     private void layoutArrayPanel(Panel pnl, Component lbl, Component col)
  199.         {
  200.         PjListLayout listLayout = new PjListLayout();
  201.         pnl.setLayout(listLayout);
  202.  
  203.         // Components should added in following order.
  204.         pnl.add(lbl);
  205.         pnl.add(col);
  206.  
  207.         } // layoutArrayPanel
  208.  
  209.     private void layoutAdPanel(Panel pnl, PjAdView pjav)
  210.         {
  211.         pnl.add("Center", pjav );
  212.         } // layoutAdPanel
  213.  
  214.     private void layoutPanels( Panel pnlTop, Panel pnlTopData, Panel pnlAd)
  215.         {
  216.         GridBagLayout gridbag = new GridBagLayout();
  217.         setLayout(gridbag);
  218.  
  219.         // Top panel
  220.         GridBagConstraints gbc = new GridBagConstraints();
  221.         gbc.fill = GridBagConstraints.BOTH;
  222.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  223.         gridbag.setConstraints(pnlTop, gbc);
  224.         add(pnlTop);
  225.  
  226.         // Top panel of data
  227.         gbc = new GridBagConstraints();
  228.         gbc.weighty = 1.0;
  229.         gbc.fill = GridBagConstraints.BOTH;
  230.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  231.         gridbag.setConstraints(pnlTopData, gbc);
  232.         add(pnlTopData);
  233.  
  234.         // Ad panel
  235.         gbc = new GridBagConstraints();
  236.         gbc.fill = GridBagConstraints.BOTH;
  237.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  238.         gridbag.setConstraints(pnlAd, gbc);
  239.         add(pnlAd);
  240.  
  241.         } // layoutPanels
  242.  
  243.  
  244.  
  245.     } // PortView
  246.