home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 13.8 KB | 453 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.
-
-
- @(#)TitleList.java 0.00 09-Mar-96
-
- A list that displays personal news title list.
-
-
- Authors:
-
- jlee James Lee
-
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/TitleList.java 5 3/22/96 11:13p Jlee $
-
-
- History:
-
- 9-Mar-96 jlee Initial Creation
- 12-Mar-96 jlee Made the TextField as un-editable and white background.
- 19-Mar-96 jlee Fixed scrolling problem.
- 25-Mar-96 jlee Modified layoutCOntainer so that it dosn't repeat the same layout change.
- 26-Mar-96 jlee Made the scrollbar's routine more solid.
- 29-Mar-96 jlee Changed ScrollBar update algorithm, and added getButtonHeight() and getButtonHeight()
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.PjFinals;
-
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Font;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Panel;
- import java.awt.Rectangle;
- import java.awt.Scrollbar;
- import java.awt.TextField;
-
-
- import java.lang.String;
-
- /**
- * A custom list that displays personal news titles.
- *
- * @see TabBar
- * @version 0.00 9-Mar-96
- * @author James Lee
- */
- public class TitleList extends Panel
- {
- // --- Instance variables
- private Scrollbar m_sbTitleList = null;
- private int m_nSbTitleListPageIncrement = 0;
- private int m_nSbTitleListCurValue = 0;
- private int m_nNumberOfTitles = 0;
- private Font m_fntButton = null;
- private boolean m_bEndOfAdding = false;
- private Dimension dimTextFieldMinimumSize = new Dimension( 10, 10 );
- private TextField tfTitleList = null;
- private int nTitleListButtonHeight = 0;
-
- // --- Public constructors
-
- public TitleList()
- {
- setLayout( new TitleListLayout( 3, 3 ) );
-
- m_sbTitleList = new Scrollbar( Scrollbar.VERTICAL );
- m_sbTitleList.setBackground( Color.lightGray );
- m_sbTitleList.resize( PjFinals.nScrollbarWidth, 10 );
- m_sbTitleList.hide();
-
- add( m_sbTitleList );
- m_nNumberOfTitles = 0;
- m_fntButton = PjFinals.fntPNButton;
- System.out.println("Debug-TitleList:constructed");
-
- } // TitleList
-
- // --- Public operations
-
- public boolean isListFinishedAdding()
- {
- return m_bEndOfAdding;
- }
-
- public void addItem( String str, boolean bEndOfAdding )
- {
- if ( !bEndOfAdding )
- {
- Button b = new Button( String.valueOf( ++m_nNumberOfTitles ) );
- b.hide();
- b.setFont( m_fntButton );
-
- tfTitleList = new TextField( str );
- tfTitleList.hide();
- tfTitleList.setEditable( false );
- tfTitleList.setBackground( Color.white );
-
- add( b );
- add( tfTitleList );
- }
- else
- {
- m_bEndOfAdding = bEndOfAdding;
- getParent().getParent().getParent().invalidate();
- getParent().getParent().getParent().layout();
-
- if ( tfTitleList != null )
- dimTextFieldMinimumSize = tfTitleList.minimumSize();
- }
- }
-
- public Dimension getTextFieldMinimumSize()
- {
- return dimTextFieldMinimumSize;
- }
-
- public void setButtonHeight( int nButtonHeight )
- {
- nTitleListButtonHeight = nButtonHeight;
- }
-
- public int getButtonHeight()
- {
- return nTitleListButtonHeight;
- }
-
- public int getPageIncrement()
- {
- return m_nSbTitleListPageIncrement;
- }
-
- public void setPageIncrement( int inc )
- {
- m_nSbTitleListPageIncrement = inc;
- }
-
- public void setScbValue( int v )
- {
- m_nSbTitleListCurValue = v;
- m_sbTitleList.setValue( v );
- }
-
- public int getScbValue()
- {
- return m_nSbTitleListCurValue;
- }
-
- public void setScbActualValue( int v )
- {
- m_sbTitleList.setValue( v );
- }
-
- public boolean handleEvent(Event evt)
- {
- int v, max;
-
- switch (evt.id)
- {
- case Event.SCROLL_LINE_UP:
- v = m_nSbTitleListCurValue - 1;
- if ( v < 0 )
- v = 0;
- setScbValue( v );
- break;
- case Event.SCROLL_LINE_DOWN:
- max = m_sbTitleList.getMaximum() - m_sbTitleList.getVisible();
- v = m_nSbTitleListCurValue + 1;
- if ( v > max )
- v = max;
- setScbValue( v );
- break;
- case Event.SCROLL_PAGE_UP:
- v = m_nSbTitleListCurValue - m_nSbTitleListPageIncrement;
- if ( v < 0 )
- v = 0;
- setScbValue( v );
- break;
- case Event.SCROLL_PAGE_DOWN:
- max = m_sbTitleList.getMaximum() - m_sbTitleList.getVisible();
- v = m_nSbTitleListCurValue + m_nSbTitleListPageIncrement;
- if ( v > max )
- v = max;
- setScbValue( v );
- break;
- case Event.SCROLL_ABSOLUTE:
- max = m_sbTitleList.getMaximum() - m_sbTitleList.getVisible();
- v = m_sbTitleList.getValue();
- if ( v > max )
- v = max;
- setScbValue( v );
- break;
- default:
- return false;
- }// switch
-
- invalidate();
- layout();
-
- return true;
- }// handleEvent
-
-
- public synchronized void clear()
- {
- m_nNumberOfTitles = 0;
- removeAll();
- add( m_sbTitleList );
- }
- }//TitleList
-
- /*---------------------------------------------------------------------------
-
- 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.
-
-
- @(#)TitleListLayout.java 0.00 5-Feb-96
-
- A TitleListLayout that manages Tabs layout.
-
- Authors:
-
- jlee James Lee
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/TitleList.java 5 3/22/96 11:13p Jlee $
-
- History:
-
- 2-Mar-96 jlee Initial creation.
-
- ---------------------------------------------------------------------------*/
-
- /**
- * TitleListLayout is used to layout Tabs in a panel.
- * @version 0.00, 3/2/96
- * @author James Lee
- */
- class TitleListLayout implements LayoutManager {
-
- // --- Instance variables
- private int hgap;
- private int vgap;
-
- private int nWidth;
- private int nHeight;
-
- private int m_nSbLastVisibleSize = 0;
- private Rectangle recLast = new Rectangle(0, 0, 0, 0);
-
-
- // --- Public constructors
- /**
- * Constructs a new TitleListLayout with a centered alignment.
- * Default value for hgap and vgap is 0.
- */
- public TitleListLayout()
- {
- this(0, 0);
- }
-
- /**
- * Constructs a new TitleListLayout with the specified alignment and gap
- * values.
- * @param hgap the horizontal gap variable
- * @param vgap the vertical gap variable
- */
- public TitleListLayout(int hgap, int vgap)
- {
- this.hgap = hgap;
- this.vgap = vgap;
- }
- // --- Public operations
-
- /**
- * 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(200, (PjFinals.nTitleListButtonHeight + vgap) * 4 - vgap);
- 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(200, (PjFinals.nTitleListButtonHeight + vgap) * 4 - vgap);
- return dim;
- }
-
-
- /**
- * Lays out the container. This method will actually reshape the
- * components in the target in order to satisfy the constraints of
- * the TitleListLayout object.
- * @param target the specified component being laid out.
- * @see Container
- */
- public void layoutContainer(Container target)
- {
- Component m;
- int nSbMax = 0;
- int nSbValue = 0;
- int nSbVisibleSize = 0;
- int nButonHeight = ((TitleList)target).getButtonHeight();
- 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;
-
- nWidth = rec.width;
- nHeight = rec.height;
-
- int nmembers = target.countComponents();
-
- if ( nmembers > 0 && ((TitleList)target).isListFinishedAdding() )
- {
- m = target.getComponent(0);//Scrollbar
- m.show();
-
- if ( rec.height > 0 )
- m.reshape( rec.width - PjFinals.nScrollbarWidth, 0, PjFinals.nScrollbarWidth, rec.height );
- else
- System.out.println("Debug-TitleList-layoutContainer: Scrollbar's height is less than 1");
-
- nSbVisibleSize = (rec.height + vgap) / ( nButonHeight + vgap);
- nSbMax = (nmembers - 1) / 2;
-
- if ( nSbVisibleSize != m_nSbLastVisibleSize )
- {
- m_nSbLastVisibleSize = nSbVisibleSize;
- nSbValue = 0;
- if ( m instanceof Scrollbar )
- {
- ((Scrollbar)m).setValues( nSbValue, nSbVisibleSize, 0, nSbMax );
- ((TitleList)target).setScbValue( nSbValue );
- ((TitleList)target).setScbActualValue( nSbValue );
- ((TitleList)target).setPageIncrement( nSbVisibleSize );
- }
- }
- else
- nSbValue = ((TitleList)target).getScbValue();//((Scrollbar)m).getValue();
-
- for ( int j = 0, i = 1; i < nmembers ; i++)
- {
- m = target.getComponent(i);
-
- if ( i < nSbValue * 2 + 1 )
- {
- m.hide();
- continue;
- }
-
- if ( j * (nButonHeight + vgap) > rec.height - nButonHeight )
- {
- m.hide();
- continue;
- }
-
- m.show();
- switch (i % 2)
- {
- case 0://TextField
- m.reshape( PjFinals.nTitleListButtonWidth + hgap, j * (nButonHeight + vgap),
- rec.width - PjFinals.nTitleListButtonWidth - hgap - PjFinals.nScrollbarWidth - 2,
- nButonHeight );
- j++;
- break;
-
- case 1://Button
- m.reshape( 0, j * (nButonHeight + vgap), PjFinals.nTitleListButtonWidth, nButonHeight );
- break;
-
- default:
- break;
- }
- }//for
- }//if
- }
-
- /**
- * Returns the String representation of this TitleListLayout's values.
- */
- public String toString()
- {
- return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]" +
- "[width=" + nWidth + ",height=" + nHeight + "]";
- }
-
- }//TitleListLayout
-
-