home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 10.5 KB | 367 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.
-
-
- Panel3D.java
-
- a 3 dimesional panel.
-
-
- Authors:
-
- jlee James Lee
-
-
- Version Ident:
-
- $Header$
-
-
- History:
-
- 4-Mar-96 jlee Initial Creation
- 12-Mar-96 jlee Modified Panel3D so that it can display without border.
- 25-Mar-96 jlee Modified layoutCOntainer so that it dosn't repeat the same layout change.
- And used line drawing to make 3d effect instead panel drawing.
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import collections.Assertable;
- import collections.ImplementationCheckable;
- 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.Event;
- import java.awt.Graphics;
- import java.awt.GridLayout;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Panel;
- import java.awt.Rectangle;
- import java.lang.String;
-
- /**
- * A 3 dimensional panel implemented using Panel3DLayout.
- *
- * @version 0.00 4-Mar-96
- * @author James lee
- */
- public class Panel3D extends Panel
- {
- // --- Instance variables
- private int nBorderWidth;
-
- // --- Public constructors
-
- /**
- * Construct a 3 dimensional panel, the width of border is 2.
- */
- public Panel3D()
- {
- initBorderWidth();
- setLayout( new Panel3DLayout() );
- } // Panel3D
-
- /**
- * Construct a 3 dimensional panel, with specified border width.
- * @param nBW Border width
- */
- public Panel3D( int nBW )
- {
- nBorderWidth = (nBW <= 0) ? 1: nBW;//Fix: somehow, zero Border Width prevents text drawing, so this hack.
- setLayout( new Panel3DLayout() );
- } // Panel3D
-
- /**
- * Construct a 3 dimensional panel, with specified component.
- * @param cpnt A component that's going to be contained int this Panel3D.
- */
- public Panel3D( Component cpnt )
- {
- initBorderWidth();
- setLayout( new Panel3DLayout() );
- add( cpnt );
- } // Panel3D
-
- /**
- * Construct a 3 dimensional panel, with specified component & border width.
- * @param cpnt A component that's going to be contained int this Panel3D.
- * @param nBW Border Width
- */
- public Panel3D( Component cpnt, int nBW )
- {
- nBorderWidth = (nBW <= 0) ? 1: nBW;//Fix: somehow, zero Border Width prevents text drawing, so this hack.
- setLayout( new Panel3DLayout() );
- add( cpnt );
- } // Panel3D
-
- // --- Public operations
-
- public int getBorderWidth()
- {
- return nBorderWidth;
- }
-
- public void paint( Graphics g )
- {
- for ( int j = 0; j < 4; j++ )
- {
- for ( int i = 0; i < nBorderWidth; i++ )
- {
- switch ( j )
- {
- case 0://east
- g.setColor( Color.white );
- g.drawLine( size().width - i, 0, size().width - i, size().height );
- break;
-
- case 2://north
- g.setColor( Color.gray );
- g.drawLine( 0, i, size().width, i );
- break;
-
- case 3://south
- g.setColor( Color.white );
- g.drawLine( 0, size().height - i, size().width, size().height - i );
- break;
-
- case 1://west
- g.setColor( Color.gray );
- g.drawLine( i, 0, i, size().height );
- break;
- }//switch
- }//for i
- }//for j
- }
-
- // --- Private operations
-
- private protected void initBorderWidth()
- {
- nBorderWidth = 2;
- }
-
-
- } // TabBar
-
- /*---------------------------------------------------------------------------
-
- 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.
-
-
- @(#)Panel3DLayout.java 0.00 4-Mar-96
-
- A Panel3DLayout that implements 3D panel.
-
- Authors:
-
- jlee James Lee
-
- Version Ident:
-
- $Header$
-
- History:
-
- 4-Mar-96 jlee Initial creation.
-
- ---------------------------------------------------------------------------*/
-
- /**
- * Panel3DLayout is used to layout Tabs panel and 3D lines in a panel.
- * @version 0.00, 4-Mar-96
- * @author James Lee
- */
- class Panel3DLayout implements LayoutManager {
-
- // --- Instance variables
- private int hgap;
- private int vgap;
-
- private int nWidth;
- private int nHeight;
-
- private Rectangle recLast = new Rectangle(0, 0, 0, 0);
-
-
- // --- Public constructors
- /**
- * Constructs a new Panel3DLayout
- * Default value for hgap and vgap is 0.
- */
- public Panel3DLayout()
- {
- this(0, 0);
- }
-
- /**
- * Constructs a new Panel3DLayout with the specified gap values.
- * @param hgap the horizontal gap variable
- * @param vgap the vertical gap variable
- */
- public Panel3DLayout(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(0, 0);
- int nmembers = target.countComponents();
-
- Component m;
-
- if ( nmembers > 0 )
- {
- m = target.getComponent(nmembers - 1);
-
- if (m.isVisible())
- {
- Dimension d = m.preferredSize();
- dim.height += d.height;
- dim.width += d.width;
-
- dim.width += ((Panel3D)target).getBorderWidth();
- dim.height += ((Panel3D)target).getBorderWidth();
- }
- }
-
- 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();
-
- Component m;
-
- if ( nmembers > 0 )
- {
- m = target.getComponent(nmembers - 1);
-
- if (m.isVisible())
- {
- Dimension d = m.minimumSize();
- dim.height += d.height;
- dim.width += d.width;
-
- dim.width += ((Panel3D)target).getBorderWidth();
- dim.height += ((Panel3D)target).getBorderWidth();
- }
- }
-
- 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 Panel3DLayout object.
- * @param target the specified component being laid out.
- * @see Container
- */
- public void layoutContainer(Container target)
- {
- int nBorderWidth = ((Panel3D)target).getBorderWidth();
- int nmembers = target.countComponents();
-
- 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;
-
- for (int i = 0 ; i < nmembers ; i++)
- {
- Component m = target.getComponent(i);
-
- if ( m.isVisible() )
- {
- if ( i == 0 ) //Center
- m.reshape( nBorderWidth, nBorderWidth, rec.width - 2 * nBorderWidth, rec.height - 2 * nBorderWidth );
- }//if
- }//for
- }
-
- /**
- * Returns the String representation of this Panel3DLayout's values.
- */
- public String toString()
- {
- return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]" +
- "[width=" + nWidth + ",height=" + nHeight + "]";
- }
- } //Panel3DLayout
-