home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / viewfactory.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  8.4 KB  |  267 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.  
  15.     @(#)ViewFactory.java  0.00 07-Jan-96
  16.  
  17.         A class of objects that create PaperViews.
  18.  
  19.  
  20.     Authors:
  21.  
  22.         rphall   Rick Hall
  23.  
  24.  
  25.     Version Ident:
  26.  
  27.         $Header$
  28.  
  29.  
  30.     History:
  31.  
  32.         0.00 07-Jan-96  rphall   Initial Creation
  33.  
  34. ---------------------------------------------------------------------------*/
  35.  
  36. package pj.awt;
  37.  
  38. import pj.awt.Column;
  39. import pj.awt.DividerView;
  40. import pj.awt.HeadlineView;
  41. import pj.awt.MarketView;
  42. import pj.awt.PjStr;
  43. import pj.awt.PageView;
  44. import pj.awt.PaperView;
  45. import pj.io.Paper;
  46.  
  47.  
  48. import collections.Assertable;
  49. import collections.ImplementationCheckable;
  50. import collections.ImplementationError;
  51. import java.awt.Label; // FIXME: remove hack
  52.  
  53. /**
  54.  * A class of objects that create PaperViews.
  55.  *
  56.  * @see        pj.awt.PaperView
  57.  * @see        pj.awt.PageView
  58.  * @see        pj.awt.DividerView
  59.  * @version    0.00 07-Jan-96
  60.  * @author     rphall
  61. */                  
  62. public class ViewFactory implements Assertable, ImplementationCheckable
  63.     {
  64.  
  65.  
  66.     // --- Instance variables
  67.  
  68.     /** The paper upon which views gaze */
  69.     protected Paper paper;
  70.  
  71.     /** Page indices */
  72.  
  73.     private final int idxFPHdlines  = 100;
  74.     private final int idxFPBusFin   = 101;
  75.     private final int idxFPWorld    = 102;
  76.     private final int idxFPNews     = 103;
  77.     private final int idxFPFlash    = 104;
  78.  
  79.     private final int idxTJIHdlines = 200;
  80.     private final int idxTJIBusFin  = 201;
  81.     private final int idxTJIWorld   = 202;
  82.     private final int idxTJINews    = 203;
  83.  
  84.     private final int idxPort       = 300;
  85.  
  86.     private final int idxMrk        = 402401;
  87.     private final int idxMrkExTrs   = 403404;
  88.     private final int idxMrkWrap    = 405;
  89.  
  90.     private final int idxSpHilite   = 501;
  91.     private final int idxSpScoresAd = 502503;
  92.  
  93.     private final int idxWth        = 600611;
  94.     private final int idxWthUSNE    = 601;
  95.     private final int idxWthUSSE    = 602;
  96.     private final int idxWthUSMW    = 603;
  97.     private final int idxWthUSWest  = 604;
  98.     private final int idxWthCanada  = 605;
  99.     private final int idxWthSouthA  = 606;
  100.     private final int idxWthEurope  = 607;
  101.     private final int idxWthMidE    = 608;
  102.     private final int idxWthAfrica  = 609;
  103.     private final int idxWthAsia    = 610;
  104.  
  105.     // --- Public constructors
  106.  
  107.     /**
  108.      * Construct a factory.
  109.     */
  110.     public ViewFactory(Paper p)
  111.         {
  112.         assert(p != null);
  113.         paper = p;
  114.         checkImplementation();
  115.         }
  116.  
  117.     // --- Public operations
  118.  
  119.     /**
  120.      * Create a page view.
  121.      * @param pagespec  A specification for the page.
  122.      * @return A PageView.
  123.      * @exception ImplementationError thrown if the pagespec
  124.      * is null or invalid.
  125.     */
  126.     public Page createPage(PjPageSpec spec)
  127.         {
  128.         Page pg = null;
  129.         int idx = (new Integer(spec.strPageName)).intValue();
  130.         switch ( idx )
  131.             {
  132.             case idxFPHdlines :
  133.                 pg = new HeadlineView(spec,paper);
  134.                 break;
  135.  
  136.             case idxFPBusFin :
  137.             case idxFPWorld :
  138.             case idxFPNews :
  139.  
  140.             case idxFPFlash :
  141.                 //pg = new Column(spec.strPageName,spec.strPageName,paper);
  142.                 pg = new PageView(spec.strPageName);
  143.                 break;
  144.  
  145.             case idxTJIHdlines :
  146.                 pg = new HeadlineView(spec,paper);
  147.                 break;
  148.  
  149.             case idxTJIBusFin :
  150.             case idxTJIWorld :
  151.  
  152.             case idxTJINews :
  153.                 //pg = new Column(spec.strPageName,spec.strPageName,paper);
  154.                 pg = new PageView(spec.strPageName);
  155.                 break;
  156.  
  157.             case idxMrk :
  158.                 pg = new MarketView(spec,paper);
  159.                 break;
  160.  
  161.             case idxMrkExTrs :
  162.                 //pg = new ExTrsView(spec,paper);
  163.                 pg = new PageView(spec.strPageName);
  164.                 break;
  165.  
  166.             case idxMrkWrap :
  167.                 //pg = new Column(spec.strPageName,spec.strPageName,paper);
  168.                 pg = new PageView(spec.strPageName);
  169.                 break;
  170.  
  171.             case idxPort :
  172.                 pg = new PortView(spec,paper);
  173.                 break;
  174.  
  175.             case idxSpHilite :
  176.                 pg = new SpHiliteView(spec,paper);
  177.                 break;
  178.  
  179.             case idxSpScoresAd :
  180.                 //pg = new SpScoresAdView(spec,paper);
  181.                 pg = new PageView(spec.strPageName);
  182.                 break;
  183.  
  184.             case idxWth :
  185.                 //pg = new WthView(spec,paper);
  186.                 pg = new DividerView(spec.tabspec);
  187.                 break;
  188.  
  189.             case idxWthUSNE :
  190.             case idxWthUSSE :
  191.  
  192.             case idxWthUSMW :
  193.             case idxWthUSWest :
  194.  
  195.             case idxWthCanada :
  196.             case idxWthSouthA :
  197.  
  198.             case idxWthEurope :
  199.             case idxWthMidE :  
  200.  
  201.             case idxWthAfrica :
  202.             case idxWthAsia :
  203.                 //pg = new Column(spec.strPageName,spec.strPageName,paper);
  204.                 pg = new PageView(spec.strPageName);
  205.                 break;
  206.  
  207.             default :
  208.                 assert(false);
  209.  
  210.             } // switch idx
  211.  
  212.         assert(pg != null);
  213.  
  214.         return pg;
  215.         } // createPage
  216.  
  217.     /**
  218.      * Raise an exception if predicate is false.
  219.      * @see collections.Assertable
  220.     */
  221.     public void assert(boolean predicate) throws ImplementationError
  222.         { 
  223.         ImplementationError.assert(this, predicate); 
  224.         }
  225.  
  226.     /**
  227.      * Raise an exception if implementation is out of sync with PjStr.
  228.      * @see PjNbSpec
  229.     */
  230.     public void checkImplementation() throws ImplementationError
  231.         {
  232.         assert( idxFPHdlines == (new Integer(PjStr.pageFPHdlines)).intValue() );
  233.         assert( idxFPBusFin == (new Integer(PjStr.pageFPBusFin)).intValue() );
  234.         assert( idxFPWorld == (new Integer(PjStr.pageFPWorld)).intValue() );
  235.         assert( idxFPNews == (new Integer(PjStr.pageFPNews)).intValue() );
  236.         assert( idxFPFlash == (new Integer(PjStr.pageFPFlash)).intValue() );
  237.  
  238.         assert( idxTJIHdlines == (new Integer(PjStr.pageTJIHdlines)).intValue() );
  239.         assert( idxTJIBusFin == (new Integer(PjStr.pageTJIBusFin)).intValue() );
  240.         assert( idxTJIWorld == (new Integer(PjStr.pageTJIWorld)).intValue() );
  241.         assert( idxTJINews == (new Integer(PjStr.pageTJINews)).intValue() );
  242.         
  243.         assert( idxMrk == (new Integer(PjStr.pageMrk)).intValue() );
  244.         assert( idxMrkExTrs == (new Integer(PjStr.pageMrkExTrs)).intValue() );
  245.         assert( idxMrkWrap == (new Integer(PjStr.pageMrkWrap)).intValue() );
  246.  
  247.         assert( idxPort == (new Integer(PjStr.pagePort)).intValue() );
  248.  
  249.         assert( idxSpHilite == (new Integer(PjStr.pageSpHilite)).intValue() );
  250.         assert( idxSpScoresAd == (new Integer(PjStr.pageSpScoresAd)).intValue() );
  251.  
  252.         assert( idxWth == (new Integer(PjStr.pageWth)).intValue() );
  253.         assert( idxWthUSNE == (new Integer(PjStr.pageWthUSNE)).intValue() );
  254.         assert( idxWthUSSE == (new Integer(PjStr.pageWthUSSE)).intValue() );
  255.         ssert( idxWthUSMW == (new Integer(PjStr.pageWthUSMW)).intValue() );
  256.         assert( idxWthUSWest == (new Integer(PjStr.pageWthUSWest)).intValue() );
  257.         ssert( idxWthCanada == (new Integer(PjStr.pageWthCanada)).intValue() );
  258.         assert( idxWthSouthA == (new Integer(PjStr.pageWthSouthA)).intValue() );
  259.         assert( idxWthEurope == (new Integer(PjStr.pageWthEurope)).intValue() );
  260.         assert( idxWthMidE == (new Integer(PjStr.pageWthMidE)).intValue() );
  261.         assert( idxWthAfrica == (new Integer(PjStr.pageWthAfrica)).intValue() );
  262.         assert( idxWthAsia == (new Integer(PjStr.pageWthAsia)).intValue() );
  263.         }
  264.  
  265.     
  266.     }; // ViewFactory
  267.