home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / section.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  8.5 KB  |  308 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.     @(#)Section.java  0.00 22-Jan-96
  15.  
  16.         A divider that contains pages.
  17.  
  18.     Authors:
  19.  
  20.         rphall   Rick Hall
  21.  
  22.     Version Ident:
  23.  
  24.         $Header: /PjJavaClient/src/pj/awt/Section.java 2     1/22/96 10:24p Rphall $
  25.  
  26.     History:
  27.  
  28.         0.00 22-Jan-96  rphall      Initial Creation
  29.         0.01  1-Mar-96  Ted S.      Overide nextView etc. because a section
  30.                                         is a thing with a stack of pages, that
  31.                                         need to be shown in succession.  Note
  32.                                         that each of those pages can in turn
  33.                                         have a bunch of views. But that won't
  34.                                         change this code any.
  35.         0.02 14-Mar-96  Ted S.      Added countviews().
  36.         0.03 26-Mar-96  Ted S.        Since, in general there is one page per view,
  37.                                         I made the section return the current view as 
  38.                                         the current page.  If a derived section
  39.                                         doesnt' like this, it can override it.                
  40.  
  41. ---------------------------------------------------------------------------*/
  42.  
  43. package pj.awt;
  44.  
  45. import pj.awt.Divider;
  46. import pj.awt.Notebook;
  47. import pj.awt.Page;
  48. import pj.awt.PageStack;
  49. import pj.awt.TabSpec;
  50.  
  51. import java.awt.GridBagLayout;
  52. import java.awt.GridBagConstraints;
  53. import java.awt.Insets;
  54.  
  55.  
  56. /**
  57.  * A divider that contains pages.  Said differently, a Section is
  58.  * tabbed page that acts as a sub-notebook within a notebook.
  59.  * <P>
  60.  * A section has a cursor into the pages that it contains.  The cursor
  61.  * marks the "current", or "topmost", page in the section.  If the
  62.  * section is showing, the current page is the one that will be visible
  63.  * to a user.  The cursor is moved implicitly by first-, next-, last- and
  64.  * previous- page operations.
  65.  *
  66.  * @see     pj.awt.Divider
  67.  * @see     pj.awt.Notebook
  68.  * @version 0.00 22-Jan-96
  69.  * @author  rphall
  70. */
  71. public class Section extends Divider implements Notebook
  72.     {
  73.  
  74.  
  75.     // --- Instance variables
  76.  
  77.     /** The pages displayed to a user */
  78.     PageStack   stack;
  79.  
  80.     // --- Public constructors
  81.  
  82.     /**
  83.      * Construct a Section with a given tab specification.
  84.      * @param tab   A specification for the tab that should be
  85.      * associated with this page.
  86.     */
  87.     public Section(TabSpec tab)
  88.         {
  89.         super(tab);
  90.         stack = new PageStack();
  91.  
  92.         GridBagLayout gridbag = new GridBagLayout();
  93.         GridBagConstraints gbc = new GridBagConstraints();
  94.         setLayout( gridbag );
  95.  
  96.         gbc.fill = GridBagConstraints.BOTH;
  97.         gbc.insets = new Insets( 2, 7, 2, 7 );
  98.         gbc.weightx = 1;
  99.         gbc.weighty = 1;
  100.         gridbag.setConstraints( stack, gbc );
  101.  
  102.         add(stack);
  103.         }
  104.  
  105.     // --- Public operations
  106.  
  107.     /**
  108.      * Append a page as the last page in a section.
  109.      * A section ignores any distinction between pages and dividers.
  110.      * Dividers are not tabbed within a section.
  111.      *
  112.      * @param page  The page to be added.
  113.     */
  114.     public void appendPage(Page page)
  115.         { 
  116.         stack.appendPage(page); 
  117.         }
  118.  
  119.     /**
  120.      * @return The count of pages in this section.
  121.     */
  122.     public int countPages()
  123.         { 
  124.         return stack.countPages();               
  125.         }
  126.  
  127.     /**
  128.      * Make the first page topmost in a section.
  129.      * If the section contains no pages, this operation does nothing.
  130.     */
  131.     public void firstPage()
  132.         { 
  133.         stack.firstPage(); 
  134.         }
  135.  
  136.     /**
  137.      * Make the next page (after the current page) topmost in a stack of
  138.      * pages. If the last page is already topmost, this operation does
  139.      * nothing.
  140.     */
  141.     public void nextPage()
  142.         { 
  143.         stack.nextPage(); 
  144.         }
  145.  
  146.     /**
  147.      * Make the last page topmost in a stack of pages.
  148.      * If the section contains no pages, this operation does nothing.
  149.     */
  150.     public void lastPage()
  151.         { 
  152.         stack.lastPage(); 
  153.         }
  154.  
  155.     /**
  156.      * Make the previous page (before the current page) topmost in a stack
  157.      * of pages. If the first page is already topmost, this operation does
  158.      * nothing.
  159.     */
  160.     public void previousPage()
  161.         { 
  162.         stack.previousPage(); 
  163.         }
  164.  
  165.     /**
  166.      * Display a specific page as topmost in a stack of pages.
  167.      * If no page exists with the specified name, this operation
  168.      * does nothing.
  169.      * @param name The name of the page to make topmost.
  170.     */
  171.     public void page(String name)
  172.         { 
  173.         stack.page(name); 
  174.         }
  175.  
  176.  
  177.  
  178.       /**
  179.      * @return The number of pages.  Each page may have its own set of views. 
  180.             but that is up to each page.  This section is only aware of how 
  181.             many pages it has.
  182.     */
  183.     public int countViews()
  184.         {
  185.         return countPages();
  186.         }
  187.  
  188.  
  189.     /**
  190.      * Make the first view the current view.
  191.     */
  192.     public void firstView()
  193.         {
  194.         // Always call the parents method, because it keeps track of where we are.
  195.         super.firstView();
  196.         firstPage(); 
  197.  
  198.         // Goto the first view in that page.
  199.         stack.page().firstView(); 
  200.         }
  201.  
  202.     /**
  203.      * Make the next view (after the current view) the current view.
  204.      *  a false return means you have hit the end.
  205.     */
  206.     public boolean nextView()
  207.         {
  208.         boolean bRet;
  209.            
  210.         // init
  211.         bRet = true;
  212.  
  213.         // If we can not do a next on the current view, then got to the next page
  214.         // in the notebook  - A view can be made up of another bunch of views.
  215.         if ( stack.page().nextView() == false )
  216.             {
  217.             // Make sure we can do another next, 
  218.             //  if not return false.
  219.             if ( super.nextView() )
  220.                 {               
  221.                 // Show our next view, in this case the next tab.
  222.                 nextPage();
  223.                 // Goto the first view in that page.
  224.                 stack.page().firstView();                
  225.                 }        
  226.             else
  227.                 {
  228.                 bRet = false;
  229.                 }
  230.             }     
  231.  
  232.         return bRet;
  233.         }
  234.  
  235.     /**
  236.      * Make the last view the current view.
  237.     */
  238.     public void lastView()
  239.         {
  240.         super.lastView();
  241.  
  242.         // Goto the last view in the page we are about to switch to.
  243.         stack.getPage( countViews() ).lastView();              
  244.           
  245.         lastPage();        
  246.         }
  247.  
  248.     /**
  249.      * Make the previous view (before current view) the current view.
  250.      *  a false return means you have hit the end.
  251.     */
  252.     public boolean previousView()
  253.         {
  254.         boolean bRet;
  255.  
  256.         // init
  257.         bRet = true;
  258.  
  259.         // If we can not do a prev on the current view, then got to the prev page
  260.         // in the section  - A view can be made up of another bunch of views.
  261.         if ( stack.page().previousView() == false )
  262.             {
  263.             // Make sure we can do another next, 
  264.             //  if not return false.                        
  265.             if ( super.previousView() )
  266.                 {                
  267.                 // Goto the last view in the page we are about to switch to.
  268.                 stack.getPage( currView() - 1  ).lastView();                
  269.  
  270.                 // Show our prev view, in this case the prev page.
  271.                 previousPage();                
  272.                 }        
  273.             else
  274.                 {
  275.                 bRet = false;
  276.                 }
  277.             }
  278.  
  279.        
  280.         return bRet;     
  281.         }
  282.  
  283.     
  284.      
  285.     /**
  286.      * Make a specific view the current view.
  287.      * @param idx The index of the view to display.
  288.     */
  289.     public void view(int idx)
  290.         {
  291.         super.view( idx );
  292.         }
  293.  
  294.    /**
  295.      * Get the index of the current view.
  296.      * @return The index of the view being displayed.
  297.     */
  298.     public int currView()
  299.         {        
  300.         return stack.currPage();
  301.         } 
  302.     
  303.  
  304.  
  305.     
  306.  
  307.     } // Section
  308.