home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / checkboxnb.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  9.4 KB  |  332 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.     @(#)CheckboxNb.java  0.00 05-Jan-96
  15.  
  16.         An implementation of Notebook using CheckboxTabBar.
  17.  
  18.     Authors:
  19.  
  20.         rphall   Rick Hall
  21.  
  22.     Version Ident:
  23.  
  24.         $Header: /PjJavaClient/src/pj/awt/CheckboxNb.java 3     1/22/96 10:24p Rphall $
  25.  
  26.     History:
  27.  
  28.         0.00 05-Jan-96  rphall      Initial Creation
  29.         0.01 23-Feb-96  Ted S.      Changes to PaperView Interface
  30.  
  31. ---------------------------------------------------------------------------*/
  32.  
  33. package pj.awt;
  34.  
  35. import pj.awt.CheckboxTabBar;
  36. import pj.awt.Divider;
  37. import pj.awt.Notebook;
  38. import pj.awt.Page;
  39. import pj.awt.PageStack;
  40. import pj.awt.StringTabSpec;
  41.  
  42. import collections.ImplementationError;
  43. import java.awt.BorderLayout;
  44. import java.awt.Panel;
  45. import java.lang.String;
  46.  
  47. /**
  48.  * An implementation of Notebook using CheckboxTabBar.
  49.  *
  50.  * @see     pj.awt.CheckboxTabBar
  51.  * @version 0.00 05-Jan-96
  52.  * @author  rphall
  53. */
  54. public class CheckboxNb extends Page implements Notebook
  55.     {
  56.  
  57.     /*
  58.      * Note: most navigational operations are implemented via page()
  59.      * in order to guarantee that divider tabs are properly selected.
  60.     */
  61.  
  62.     // --- Public constructors
  63.  
  64.     /**
  65.      * Create an empty notebook.
  66.     */
  67.     public CheckboxNb()
  68.         {
  69.         setLayout(new BorderLayout(/*hgap*/5,/*vgap*/0));
  70.         stack = new PageStack();
  71.         tabbar = new CheckboxTabBar(this);
  72.         add("Center",stack);
  73.         add("East",tabbar);
  74.         }
  75.  
  76.     /**
  77.      * Create a notebook with the specified pages.
  78.      * @param pages An array of pages and dividers.
  79.     */
  80.     public CheckboxNb(Page[] pages)
  81.         {
  82.         this();
  83.         for (int i=0; i<pages.length; i++)
  84.             appendPage(pages[i]);
  85.         firstPage();
  86.         }
  87.  
  88.     // --- Public operations: modification
  89.  
  90.     /**
  91.      * Append a page as the last page in a notebook.
  92.      * If name specifies a page that is a divider, the a notebook
  93.      * guarantees that the divider will appear as "tabbed" in the
  94.      * notebook if the tab specification of the divider is an
  95.      * instance of StringTabSpec. (Otherwise the divider is treated
  96.      * as an ordinary page.)
  97.      *
  98.      * @param page  The page to be added.
  99.      * @param ImplementationError thrown if the tab specification of a
  100.      * divider is not 
  101.     */
  102.     public void appendPage(Page page)
  103.         {
  104.         stack.appendPage(page);
  105.         if (page instanceof Divider
  106.             && ((Divider)page).getTabSpec() instanceof StringTabSpec )
  107.             {
  108.             Divider d = (Divider)page;
  109.             StringTabSpec sts = (StringTabSpec)d.getTabSpec();
  110.             tabbar.appendTab(sts);
  111.             }
  112.  
  113.         } // appendPage
  114.  
  115.     // --- Public operations: count
  116.  
  117.     /**
  118.      * @return The count of pages in this notebook.
  119.     */
  120.     public int countPages()
  121.         { return stack.countPages(); }
  122.  
  123.     // --- Public operations: sequential access
  124.  
  125.     /**
  126.      * Make the first page topmost in a stack of pages.
  127.      * If the first page is a divider, a notebook should
  128.      * guarantee that the tab associated with the divider appears selected.
  129.      * If the notebook contains no pages, this operation does nothing.
  130.     */
  131.     public void firstPage()
  132.         {
  133.         page( stack.firstPage().getName() ); 
  134.         // Goto the first view of the current page.
  135.         stack.page().firstView();
  136.         }
  137.  
  138.     /**
  139.      * Make the next page (after the currently visible page)
  140.      * topmost in a stack of pages.
  141.      * If the next page is a divider, a notebook should
  142.      * guarantee that the tab associated with the divider appears selected.
  143.      * If the last page is already displayed, this operation does nothing.
  144.     */
  145.     public void nextPage()
  146.         { 
  147.         page( stack.nextPage().getName() ); 
  148.         // Goto the first view of the current page.
  149.         stack.page().firstView();
  150.  
  151.         }
  152.  
  153.     /**
  154.      * Make the last page topmost in a stack of pages.
  155.      * If last page is a divider, a notebook should
  156.      * guarantee that the tab associated with the divider appears selected.
  157.      * If the notebook contains no pages, this operation does nothing.
  158.     */
  159.     public void lastPage()
  160.         { 
  161.         page( stack.lastPage().getName() ); 
  162.         // Goto the last view of the current page.
  163.         // When calling this, the intention is probably to see the last PJ screen.
  164.         System.out.println( "Lastview" );
  165.         stack.page().lastView();
  166.         }
  167.  
  168.     /**
  169.      * Make the previous page (before the currently visible page)
  170.      * topmost in a stack of pages.
  171.      * If the previous page is a divider, a notebook should
  172.      * guarantee that the tab associated with the divider appears selected.
  173.      * If the first page is already displayed, this operation does nothing.
  174.     */
  175.     public void previousPage()
  176.         { 
  177.         page( stack.previousPage().getName() ); 
  178.         // Goto the first view of the current page.
  179.         stack.page().firstView();  
  180.         }
  181.  
  182.     // --- Public operations: non-sequential access
  183.  
  184.     /**
  185.      * Display a page as topmost in a stack of other pages.
  186.      * If name specifies a page that is a divider, a notebook should
  187.      * guarantee that the tab associated with the divider appears selected.
  188.      * If no page exists with the specified name, this operation
  189.      * does nothing.
  190.      * @param name The name of the page to display.
  191.     */
  192.     public void page(String name)
  193.         {
  194.         Page p = stack.page(name);
  195.         if (p instanceof Divider)
  196.             {
  197.             Divider d = (Divider)p;
  198.             StringTabSpec sts = (StringTabSpec)d.getTabSpec();
  199.             tabbar.selectTab(sts.strTabName);
  200.             }
  201.         if (p instanceof Notebook)
  202.             {
  203.             ((Notebook)p).firstPage();
  204.             }
  205.         // Goto the first view of the current page.
  206.         stack.page().firstView();
  207.  
  208.         } // page
  209.      
  210.     /**
  211.      * @return The number of views in an implementation instance.
  212.     */
  213.     public int countViews()
  214.         {
  215.         return countPages();
  216.         }
  217.  
  218.     // --- Public operations: sequential access
  219.  
  220.     /**
  221.      * Make the first view the current view.
  222.     */
  223.     public void firstView()
  224.         {
  225.         // Always call the parents method, because it keeps track of where we are.
  226.         super.firstView();
  227.         firstPage();
  228.         }
  229.  
  230.     /**
  231.      * Make the next view (after the current view) the current view.
  232.      *  a false return means you have hit the end.
  233.     */
  234.     public boolean nextView()
  235.         {
  236.         boolean bRet;
  237.  
  238.         // init
  239.         bRet = true;
  240.  
  241.         // If we can't do a next on the current view, then got to the next view
  242.         // in the notebook  - A view can be made up of another bunch of views.
  243.         if ( stack.page().nextView() == false )
  244.             {
  245.             // Make sure we can do another next, 
  246.             //  if not return false.
  247.             if ( super.nextView() )
  248.                 {
  249.                 // Show our next view, in this case the next tab.
  250.                 nextPage();                
  251.                 }        
  252.             else
  253.                 {
  254.                 // For tab notebook allow wrap around.
  255.                 firstPage();
  256.                 }
  257.             }
  258.                                
  259.         return bRet;
  260.         }
  261.  
  262.     /**
  263.      * Make the last view the current view.
  264.     */
  265.     public void lastView()
  266.         {
  267.         super.lastView();
  268.         lastPage();
  269.         }
  270.  
  271.     /**
  272.      * Make the previous view (before current view) the current view.
  273.      *  a false return means you have hit the end.
  274.     */
  275.     public boolean previousView()
  276.         {
  277.         boolean bRet;
  278.  
  279.         System.out.println( "CheckboxNb::prevView()" );
  280.  
  281.         // init
  282.         bRet = true;
  283.  
  284.         // If we can not do a prev on the current view, then got to the prev page
  285.         // in the notebook  - A view can be made up of another bunch of views.
  286.         if ( stack.page().previousView() == false )
  287.             {
  288.             // Make sure we can do another next, 
  289.             //  if not return false.
  290.             if ( super.previousView() )
  291.                 {
  292.                 // Show our prev view, in this case the next tab.
  293.                 previousPage();                
  294.                 }        
  295.             else
  296.                 {
  297.                 // For Tabs allow wrap around.
  298.                 lastPage();
  299.                 }
  300.             }       
  301.         
  302.         return bRet;        
  303.         }
  304.  
  305.     // --- Public operations: non-sequential access
  306.      
  307.     /**
  308.      * Make a specific view the current view.
  309.      * @param idx The index of the view to display.
  310.     */
  311.     public void view(int idx)
  312.         {
  313.         super.view( idx );
  314.         }
  315.  
  316.      // --- Public operations: count
  317.  
  318.  
  319.     // --- Private operations
  320.  
  321.  
  322.     // --- Private attributes
  323.  
  324.  
  325.     /** The pages displayed to the user */
  326.     PageStack   stack;
  327.  
  328.     /** The tab bar */
  329.     CheckboxTabBar  tabbar;
  330.  
  331.     } // CheckboxNb
  332.