home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 9.4 KB | 332 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.
-
-
- @(#)CheckboxNb.java 0.00 05-Jan-96
-
- An implementation of Notebook using CheckboxTabBar.
-
- Authors:
-
- rphall Rick Hall
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/CheckboxNb.java 3 1/22/96 10:24p Rphall $
-
- History:
-
- 0.00 05-Jan-96 rphall Initial Creation
- 0.01 23-Feb-96 Ted S. Changes to PaperView Interface
-
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.CheckboxTabBar;
- import pj.awt.Divider;
- import pj.awt.Notebook;
- import pj.awt.Page;
- import pj.awt.PageStack;
- import pj.awt.StringTabSpec;
-
- import collections.ImplementationError;
- import java.awt.BorderLayout;
- import java.awt.Panel;
- import java.lang.String;
-
- /**
- * An implementation of Notebook using CheckboxTabBar.
- *
- * @see pj.awt.CheckboxTabBar
- * @version 0.00 05-Jan-96
- * @author rphall
- */
- public class CheckboxNb extends Page implements Notebook
- {
-
- /*
- * Note: most navigational operations are implemented via page()
- * in order to guarantee that divider tabs are properly selected.
- */
-
- // --- Public constructors
-
- /**
- * Create an empty notebook.
- */
- public CheckboxNb()
- {
- setLayout(new BorderLayout(/*hgap*/5,/*vgap*/0));
- stack = new PageStack();
- tabbar = new CheckboxTabBar(this);
- add("Center",stack);
- add("East",tabbar);
- }
-
- /**
- * Create a notebook with the specified pages.
- * @param pages An array of pages and dividers.
- */
- public CheckboxNb(Page[] pages)
- {
- this();
- for (int i=0; i<pages.length; i++)
- appendPage(pages[i]);
- firstPage();
- }
-
- // --- Public operations: modification
-
- /**
- * Append a page as the last page in a notebook.
- * If name specifies a page that is a divider, the a notebook
- * guarantees that the divider will appear as "tabbed" in the
- * notebook if the tab specification of the divider is an
- * instance of StringTabSpec. (Otherwise the divider is treated
- * as an ordinary page.)
- *
- * @param page The page to be added.
- * @param ImplementationError thrown if the tab specification of a
- * divider is not
- */
- public void appendPage(Page page)
- {
- stack.appendPage(page);
- if (page instanceof Divider
- && ((Divider)page).getTabSpec() instanceof StringTabSpec )
- {
- Divider d = (Divider)page;
- StringTabSpec sts = (StringTabSpec)d.getTabSpec();
- tabbar.appendTab(sts);
- }
-
- } // appendPage
-
- // --- Public operations: count
-
- /**
- * @return The count of pages in this notebook.
- */
- public int countPages()
- { return stack.countPages(); }
-
- // --- Public operations: sequential access
-
- /**
- * Make the first page topmost in a stack of pages.
- * If the first page is a divider, a notebook should
- * guarantee that the tab associated with the divider appears selected.
- * If the notebook contains no pages, this operation does nothing.
- */
- public void firstPage()
- {
- page( stack.firstPage().getName() );
- // Goto the first view of the current page.
- stack.page().firstView();
- }
-
- /**
- * Make the next page (after the currently visible page)
- * topmost in a stack of pages.
- * If the next page is a divider, a notebook should
- * guarantee that the tab associated with the divider appears selected.
- * If the last page is already displayed, this operation does nothing.
- */
- public void nextPage()
- {
- page( stack.nextPage().getName() );
- // Goto the first view of the current page.
- stack.page().firstView();
-
- }
-
- /**
- * Make the last page topmost in a stack of pages.
- * If last page is a divider, a notebook should
- * guarantee that the tab associated with the divider appears selected.
- * If the notebook contains no pages, this operation does nothing.
- */
- public void lastPage()
- {
- page( stack.lastPage().getName() );
- // Goto the last view of the current page.
- // When calling this, the intention is probably to see the last PJ screen.
- System.out.println( "Lastview" );
- stack.page().lastView();
- }
-
- /**
- * Make the previous page (before the currently visible page)
- * topmost in a stack of pages.
- * If the previous page is a divider, a notebook should
- * guarantee that the tab associated with the divider appears selected.
- * If the first page is already displayed, this operation does nothing.
- */
- public void previousPage()
- {
- page( stack.previousPage().getName() );
- // Goto the first view of the current page.
- stack.page().firstView();
- }
-
- // --- Public operations: non-sequential access
-
- /**
- * Display a page as topmost in a stack of other pages.
- * If name specifies a page that is a divider, a notebook should
- * guarantee that the tab associated with the divider appears selected.
- * If no page exists with the specified name, this operation
- * does nothing.
- * @param name The name of the page to display.
- */
- public void page(String name)
- {
- Page p = stack.page(name);
- if (p instanceof Divider)
- {
- Divider d = (Divider)p;
- StringTabSpec sts = (StringTabSpec)d.getTabSpec();
- tabbar.selectTab(sts.strTabName);
- }
- if (p instanceof Notebook)
- {
- ((Notebook)p).firstPage();
- }
- // Goto the first view of the current page.
- stack.page().firstView();
-
- } // page
-
- /**
- * @return The number of views in an implementation instance.
- */
- public int countViews()
- {
- return countPages();
- }
-
- // --- Public operations: sequential access
-
- /**
- * 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();
- }
-
- /**
- * 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't do a next on the current view, then got to the next view
- // 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();
- }
- else
- {
- // For tab notebook allow wrap around.
- firstPage();
- }
- }
-
- return bRet;
- }
-
- /**
- * Make the last view the current view.
- */
- public void lastView()
- {
- super.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;
-
- System.out.println( "CheckboxNb::prevView()" );
-
- // init
- bRet = true;
-
- // If we can not do a prev on the current view, then got to the prev page
- // in the notebook - 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() )
- {
- // Show our prev view, in this case the next tab.
- previousPage();
- }
- else
- {
- // For Tabs allow wrap around.
- lastPage();
- }
- }
-
- return bRet;
- }
-
- // --- Public operations: non-sequential access
-
- /**
- * Make a specific view the current view.
- * @param idx The index of the view to display.
- */
- public void view(int idx)
- {
- super.view( idx );
- }
-
- // --- Public operations: count
-
-
- // --- Private operations
-
-
- // --- Private attributes
-
-
- /** The pages displayed to the user */
- PageStack stack;
-
- /** The tab bar */
- CheckboxTabBar tabbar;
-
- } // CheckboxNb
-