home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 8.5 KB | 308 lines |
- /*---------------------------------------------------------------------------
-
- Written by the Personal Journal developers of Dow Jones & Company, Inc.
-
- Dow Jones makes no representations or warranties about
- the suitability of this software, either express or
- implied, including but not limited to the implied warranties
- of merchantability, fitness for a particular purpose,
- or non-infringement. Dow Jones will not be liable for
- any damages suffered by a user as a result of using,
- modifying or distributing this software or its derivatives.
-
-
- @(#)Section.java 0.00 22-Jan-96
-
- A divider that contains pages.
-
- Authors:
-
- rphall Rick Hall
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/Section.java 2 1/22/96 10:24p Rphall $
-
- History:
-
- 0.00 22-Jan-96 rphall Initial Creation
- 0.01 1-Mar-96 Ted S. Overide nextView etc. because a section
- is a thing with a stack of pages, that
- need to be shown in succession. Note
- that each of those pages can in turn
- have a bunch of views. But that won't
- change this code any.
- 0.02 14-Mar-96 Ted S. Added countviews().
- 0.03 26-Mar-96 Ted S. Since, in general there is one page per view,
- I made the section return the current view as
- the current page. If a derived section
- doesnt' like this, it can override it.
-
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.Divider;
- import pj.awt.Notebook;
- import pj.awt.Page;
- import pj.awt.PageStack;
- import pj.awt.TabSpec;
-
- import java.awt.GridBagLayout;
- import java.awt.GridBagConstraints;
- import java.awt.Insets;
-
-
- /**
- * A divider that contains pages. Said differently, a Section is
- * tabbed page that acts as a sub-notebook within a notebook.
- * <P>
- * A section has a cursor into the pages that it contains. The cursor
- * marks the "current", or "topmost", page in the section. If the
- * section is showing, the current page is the one that will be visible
- * to a user. The cursor is moved implicitly by first-, next-, last- and
- * previous- page operations.
- *
- * @see pj.awt.Divider
- * @see pj.awt.Notebook
- * @version 0.00 22-Jan-96
- * @author rphall
- */
- public class Section extends Divider implements Notebook
- {
-
-
- // --- Instance variables
-
- /** The pages displayed to a user */
- PageStack stack;
-
- // --- Public constructors
-
- /**
- * Construct a Section with a given tab specification.
- * @param tab A specification for the tab that should be
- * associated with this page.
- */
- public Section(TabSpec tab)
- {
- super(tab);
- stack = new PageStack();
-
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- setLayout( gridbag );
-
- gbc.fill = GridBagConstraints.BOTH;
- gbc.insets = new Insets( 2, 7, 2, 7 );
- gbc.weightx = 1;
- gbc.weighty = 1;
- gridbag.setConstraints( stack, gbc );
-
- add(stack);
- }
-
- // --- Public operations
-
- /**
- * Append a page as the last page in a section.
- * A section ignores any distinction between pages and dividers.
- * Dividers are not tabbed within a section.
- *
- * @param page The page to be added.
- */
- public void appendPage(Page page)
- {
- stack.appendPage(page);
- }
-
- /**
- * @return The count of pages in this section.
- */
- public int countPages()
- {
- return stack.countPages();
- }
-
- /**
- * Make the first page topmost in a section.
- * If the section contains no pages, this operation does nothing.
- */
- public void firstPage()
- {
- stack.firstPage();
- }
-
- /**
- * Make the next page (after the current page) topmost in a stack of
- * pages. If the last page is already topmost, this operation does
- * nothing.
- */
- public void nextPage()
- {
- stack.nextPage();
- }
-
- /**
- * Make the last page topmost in a stack of pages.
- * If the section contains no pages, this operation does nothing.
- */
- public void lastPage()
- {
- stack.lastPage();
- }
-
- /**
- * Make the previous page (before the current page) topmost in a stack
- * of pages. If the first page is already topmost, this operation does
- * nothing.
- */
- public void previousPage()
- {
- stack.previousPage();
- }
-
- /**
- * Display a specific page as topmost in a stack of pages.
- * If no page exists with the specified name, this operation
- * does nothing.
- * @param name The name of the page to make topmost.
- */
- public void page(String name)
- {
- stack.page(name);
- }
-
-
-
- /**
- * @return The number of pages. Each page may have its own set of views.
- but that is up to each page. This section is only aware of how
- many pages it has.
- */
- public int countViews()
- {
- return countPages();
- }
-
-
- /**
- * Make the first view the current view.
- */
- public void firstView()
- {
- // Always call the parents method, because it keeps track of where we are.
- super.firstView();
- firstPage();
-
- // Goto the first view in that page.
- stack.page().firstView();
- }
-
- /**
- * Make the next view (after the current view) the current view.
- * a false return means you have hit the end.
- */
- public boolean nextView()
- {
- boolean bRet;
-
- // init
- bRet = true;
-
- // If we can not do a next on the current view, then got to the next page
- // in the notebook - A view can be made up of another bunch of views.
- if ( stack.page().nextView() == false )
- {
- // Make sure we can do another next,
- // if not return false.
- if ( super.nextView() )
- {
- // Show our next view, in this case the next tab.
- nextPage();
- // Goto the first view in that page.
- stack.page().firstView();
- }
- else
- {
- bRet = false;
- }
- }
-
- return bRet;
- }
-
- /**
- * Make the last view the current view.
- */
- public void lastView()
- {
- super.lastView();
-
- // Goto the last view in the page we are about to switch to.
- stack.getPage( countViews() ).lastView();
-
- lastPage();
- }
-
- /**
- * Make the previous view (before current view) the current view.
- * a false return means you have hit the end.
- */
- public boolean previousView()
- {
- boolean bRet;
-
- // init
- bRet = true;
-
- // If we can not do a prev on the current view, then got to the prev page
- // in the section - A view can be made up of another bunch of views.
- if ( stack.page().previousView() == false )
- {
- // Make sure we can do another next,
- // if not return false.
- if ( super.previousView() )
- {
- // Goto the last view in the page we are about to switch to.
- stack.getPage( currView() - 1 ).lastView();
-
- // Show our prev view, in this case the prev page.
- previousPage();
- }
- else
- {
- bRet = false;
- }
- }
-
-
- return bRet;
- }
-
-
-
- /**
- * Make a specific view the current view.
- * @param idx The index of the view to display.
- */
- public void view(int idx)
- {
- super.view( idx );
- }
-
- /**
- * Get the index of the current view.
- * @return The index of the view being displayed.
- */
- public int currView()
- {
- return stack.currPage();
- }
-
-
-
-
-
- } // Section
-