home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 23.7 KB | 785 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.
-
-
- @(#)TabNotebook.java 0.00 05-Jan-96
-
- An implementation of Notebook using NotebookTabBar.
-
- Authors:
-
- rphall Rick Hall
- jlee James Lee
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/TabNotebook.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
- 4-Mar-96 jlee Major change: got rid of Checkbox, replaced custom made Tab
- cleaned up the functionality according the change.
- changed class name from "CheckboxNb" to "TabNotebook"
- changed class name from "CheckboxTabBar" to "NotebookTabBar"
- changed class name from "CheckboxTab" to "NotebookTab"
- placed NotebookTabBar[CheckboxTabBar]
- and NotebookTab[CheckboxTab] in this file instead in separate files.
- 12-Mar-96 jlee Changed layout to make small gap at the bottom.
- 21-Mar-96 Ted S. Update the view index on goto page by name. So when user clicks
- on a tab, the notebook updates which view it is on.
- 25-Mar-96 jlee Modified layoutCOntainer so that it dosn't repeat the same layout change.
- 26-mAR-96 Ted S. Changes to get rid of screen flashing and keep better track
- of the current view.
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.Divider;
- import pj.awt.Notebook;
- import pj.awt.NotebookTabBar;
- import pj.awt.Page;
- import pj.awt.PageStack;
- import pj.awt.PjFinals;
- import pj.awt.StringTabSpec;
-
- import collections.ImplementationError;
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Panel;
- import java.awt.Rectangle;
- import java.lang.String;
- import java.lang.Thread;
-
- /**
- * An implementation of Notebook using NotebookTabBar.
- *
- * @see pj.awt.NotebookTabBar
- * @version 0.00 05-Jan-96
- * @author rphall
- */
- public class TabNotebook extends Page implements Notebook
- {
-
- /*
- * Note: most navigational operations are implemented via page()
- * in order to guarantee that divider tabs are properly selected.
- */
-
-
- // --- Instance variables
-
- /** The pages displayed to the user */
- protected PageStack stack;
-
- /** The tab bar */
- NotebookTabBar tabbar;
-
- // --- Public constructors
-
- /**
- * Create an empty notebook.
- */
- public TabNotebook()
- {
- setLayout( new TabNbPanelLayout( 2, 5 ) );
-
- add( new Notebook3DBorder( Notebook3DBorder.EAST ) );
- add( new Notebook3DBorder( Notebook3DBorder.WEST ) );
- add( new Notebook3DBorder( Notebook3DBorder.NORTH ) );
- add( new Notebook3DBorder( Notebook3DBorder.SOUTH ) );
-
- stack = new PageStack();
- tabbar = new NotebookTabBar(this);
-
- add( tabbar );
- add( stack );
- System.out.println("Debug-TabNotebook:constructed");
- }
-
- /**
- * Create a notebook with the specified pages.
- * @param pages An array of pages and dividers.
- */
- public TabNotebook(Page[] pages)
- {
- this();
-
- for (int i=0; i<pages.length; i++)
- appendPage(pages[i]);
-
- firstPage();
- }
-
- // --- Public operations
-
- /**
- * 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
-
-
- /**
- * @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()
- {
- String name = stack.firstPage().getName();
-
- page( name );
-
- // Goto the first view of the current page.
- stack.page().firstView();
- tabbar.selectTab( name );
- }
-
- /**
- * 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()
- {
- String name = stack.nextPage().getName();
-
- page( name );
-
- // Goto the first view of the current page.
- stack.page().firstView();
- tabbar.selectTab( name );
-
- }
-
- /**
- * 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()
- {
- String name = stack.lastPage().getName();
-
- //page( name );
- tabbar.selectTab( name );
- }
-
- /**
- * 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()
- {
- String name = stack.previousPage().getName();
-
- //page( name );
- tabbar.selectTab( name );
- }
-
-
-
- /**
- * 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();
- //((Notebook)p).page(name);
- }
-
- // 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();
- }
-
-
-
- /**
- * 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();
- // 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 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() )
- {
- // 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 next tab.
- previousPage();
- }
- else
- {
- // For Tabs allow wrap around.
- lastView();
- }
- }
-
- 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.PageNameToIndex( stack.page().getName() );
- }
-
- } // TabNotebook
-
-
- /*---------------------------------------------------------------------------
-
- 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.
-
-
- @(#)Notebook3DBorder.java 0.00 2-Mar-96
-
- Notebook3DBorder that implements 3D border line.
-
- Authors:
-
- jlee James Lee
-
- Version Ident:
-
- $Header$
-
- History:
-
- 2-Mar-96 jlee Initial creation.
-
- ---------------------------------------------------------------------------*/
-
- /**
- * Notebook3DBorder is used to mimic 3D effect as a line.
- * @version 0.00, 2-Mar-96
- * @author James Lee
- */
- class Notebook3DBorder extends Canvas
- {
-
- // --- Class variables
-
- public static final int EAST = 1;
- public static final int WEST = 2;
- public static final int NORTH = 3;
- public static final int SOUTH = 4;
-
-
-
- // --- Instance variables
-
- private int n3dLinePanelWidth;
- private int n3dLinePanelHeight;
- private int nDirection;
-
-
- // --- Public constructors
- /**
- * Constructs a Notebook3DBorder.
- */
- public Notebook3DBorder( int nDir )
- {
- nDirection = nDir;
- }
-
- // --- Public operations
- /**
- * Paint the canvas with 3D line based on the direction.
- */
- public void paint(Graphics g)
- {
- int i;
-
- switch ( nDirection )
- {
- case EAST:
- for ( i = 4; i < 6; i++ )
- {
- g.setColor( Color.white );
- g.drawLine( n3dLinePanelWidth - i, 0, n3dLinePanelWidth - i, n3dLinePanelHeight );
- }
- break;
-
- case WEST:
- for ( i = 4; i < 6; i++ )
- {
- g.setColor( Color.gray );
- g.drawLine( i, n3dLinePanelHeight, i, 0 );
- }
- break;
-
- case NORTH:
- for ( i = 4; i < 6; i++ )
- {
- g.setColor( Color.gray );
- g.drawLine( 0, i, n3dLinePanelWidth, i );
- }
- break;
-
- case SOUTH:
- for ( i = 0; i < 4; i++ )
- {
- g.setColor( Color.white );
- g.drawLine( n3dLinePanelWidth, n3dLinePanelHeight - i, 0, n3dLinePanelHeight - i );
- }
- break;
- }//switch
- }
-
- /**
- * Overides reshape funxtion so that we can catch size change.
- */
- public synchronized void reshape(int x, int y, int width, int height)
- {
- n3dLinePanelWidth = width;
- n3dLinePanelHeight = height;
-
- super.reshape(x, y, width, height);
-
- repaint();
- }
-
- }//Notebook3DBorder
-
- /*---------------------------------------------------------------------------
-
- 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.
-
-
- @(#)TabNbPanelLayout.java 0.00 5-Feb-96
-
- TabNbPanelLayout that manages Tabs Panel layout.
-
- Authors:
-
- jlee James Lee
-
- Version Ident:
-
- $Header$
-
- History:
-
- 2-Mar-96 jlee Initial creation.
-
- ---------------------------------------------------------------------------*/
-
- /**
- * TabNbPanelLayout is used to layout Tabs panel and 3D lines in a panel.
- * @version 0.00, 2-Mar-96
- * @author James Lee
- */
- class TabNbPanelLayout implements LayoutManager
- {
-
- // --- Instance variables
-
- private int hgap;
- private int vgap;
-
- private int PanelWidth;
- private int PanelHeight;
-
- private Rectangle recLast = new Rectangle(0, 0, 0, 0);
-
- /**
- * Constructs a new TabNbPanelLayout.
- * Default value for hgap and vgap is 0.
- */
- public TabNbPanelLayout()
- {
- this(0, 0);
- }
-
- /**
- * Constructs a new TabNbPanelLayout with the specified gap values.
- * @param hgap the horizontal gap variable
- * @param vgap the vertical gap variable
- */
- public TabNbPanelLayout(int hgap, int vgap)
- {
- this.hgap = hgap;
- this.vgap = vgap;
- }
-
- /**
- * Adds the specified component to the layout. Not used by this class.
- * @param name the name of the component
- * @param comp the the component to be added
- */
- public void addLayoutComponent(String name, Component comp)
- {
- }
-
- /**
- * Removes the specified component from the layout. Not used by
- * this class.
- * @param comp the component to remove
- */
- public void removeLayoutComponent(Component comp)
- {
- }
-
- /**
- * Returns the preferred dimensions for this layout given the components
- * in the specified target container.
- * @param target the component which needs to be laid out
- * @see Container
- * @see #minimumLayoutSize
- */
- public Dimension preferredLayoutSize(Container target)
- {
- Dimension dim = new Dimension(0, 0);
- int nmembers = target.countComponents();
-
- for (int i = 0 ; i < nmembers ; i++)
- {
- Component m = target.getComponent(i);
-
- if (m.isVisible())
- {
- Dimension d = m.preferredSize();
- dim.height += d.height;
- dim.width += d.width;
-
- if (i > 0)
- {
- dim.width += hgap;
- dim.height += vgap;
- }
- }
- } // for
-
- dim.height /= 3;
- dim.width /= 4;
-
- Insets insets = target.insets();
- dim.width += insets.left + insets.right + hgap*2;
- dim.height += insets.top + insets.bottom + vgap*2;
-
- return dim;
- }
-
- /**
- * Returns the minimum dimensions needed to layout the components
- * contained in the specified target container.
- * @param target the component which needs to be laid out
- * @see #preferredLayoutSize
- */
- public Dimension minimumLayoutSize(Container target)
- {
- Dimension dim = new Dimension(0, 0);
- int nmembers = target.countComponents();
-
- for (int i = 0 ; i < nmembers ; i++)
- {
- Component m = target.getComponent(i);
-
- if (m.isVisible())
- {
- Dimension d = m.minimumSize();
- dim.height += d.height;
- dim.width += d.width;
-
- if (i > 0)
- {
- dim.width += hgap;
- dim.height += vgap;
- }
- }
- }// for
-
- dim.height /= 3;
- dim.width /= 4;
-
- Insets insets = target.insets();
- dim.width += insets.left + insets.right + hgap*2;
- dim.height += insets.top + insets.bottom + vgap*2;
-
- return dim;
- }
-
-
- /**
- * Lays out the container. This method will actually reshape the
- * components in the target in order to satisfy the constraints of
- * the TabNbPanelLayout object.
- * @param target the specified component being laid out.
- * @see Container
- */
- public void layoutContainer(Container target)
- {
- Thread.currentThread().setPriority( Thread.MAX_PRIORITY );
-
- Insets insets = target.insets();
- Rectangle rec = target.bounds();
-
- if ( target.isValid() &&
- rec.x == recLast.x && rec.y == recLast.y &&
- rec.width == recLast.width && rec.height == recLast.height )
- return;
- else
- recLast = rec;
-
- PanelWidth = rec.width;
- PanelHeight = rec.height;
-
- int nBorderMargin = 4;
- int nBorderWidth = 6;
-
- int tabWidth = (rec.width - nBorderMargin * 2) / 6;
- int tabHeight = PjFinals.nTab3DHeight;
-
- int nStatusBarWidth1 = ( rec.width - nBorderMargin * 2 ) * 21 / 28;
- int nStatusBarWidth2 = rec.width - nBorderMargin * 2 - nStatusBarWidth1 - hgap - 1;
- int nBottomOffset = PjFinals.nStatusBarHeight + 4;
-
- int nmembers = target.countComponents();
-
- for (int i = 0 ; i < nmembers ; i++)
- {
- Component m = target.getComponent(i);
-
- if ( m.isVisible() )
- {
- if ( i < 4 )
- {
- switch ( i )
- {
- case 0://East 3d Border
- m.reshape( rec.width - nBorderWidth - 1, nBorderWidth,
- nBorderWidth + 1,
- rec.height - tabHeight - nBorderWidth - nBottomOffset - vgap );
- break;
- case 1://West 3d Border
- m.reshape( 0, nBorderMargin,
- nBorderWidth - 1,
- rec.height - tabHeight - nBorderWidth - nBottomOffset - vgap );
- break;
- case 2://North 3d Border
- m.reshape( nBorderMargin, 0, rec.width - nBorderMargin - nBorderWidth,
- nBorderWidth + 1 );
- break;
- case 3://South 3d Border
- m.reshape( nBorderWidth,
- rec.height - 2 - tabHeight - nBottomOffset - vgap,
- rec.width - nBorderMargin - nBorderWidth, 2 );
- break;
- }//switch
- } //if
- else
- if ( i == 4 ) //TabBar
- m.reshape( nBorderMargin, rec.height - tabHeight - nBottomOffset - vgap,
- rec.width - nBorderMargin * 2, tabHeight );
- else
- if ( i == 5 ) //Center notebook
- {
- m.reshape( nBorderWidth + 2, 36 + nBorderWidth + 2, rec.width - (nBorderWidth + 2) * 2,
- rec.height - tabHeight - (nBorderWidth + 2) * 2 - 36 - nBottomOffset - vgap );
- m.validate();
- }
- else
- if ( i == 6 ) //Ticker
- m.reshape( nBorderWidth + 2, nBorderWidth + 2,
- rec.width - (nBorderWidth + 2) * 2, 36 );
- else
- if ( i == 7 ) //Status bar 1
- m.reshape( nBorderMargin, rec.height - nBottomOffset,
- nStatusBarWidth1, PjFinals.nStatusBarHeight );
- else
- if ( i == 8 ) //Status bar 2
- m.reshape( nBorderMargin + nStatusBarWidth1 + hgap,
- rec.height - nBottomOffset,
- nStatusBarWidth2,
- PjFinals.nStatusBarHeight );
- }//if
- }//for
- }
-
- /**
- * Returns the String representation of this TabNbPanelLayout's values.
- */
- public String toString()
- {
- return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]" +
- "[width=" + PanelWidth + ",height=" + PanelHeight + "]";
- }
-
- }//TabNbPanelLayout
-