home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 10.3 KB | 312 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.
-
-
- @(#)PjHdlViewLayout.java 0.00 7-Feb-96
-
- A PjListLayout that manages the Label and Column pairlayout in a View(eg. PortView).
-
- Authors:
-
- jlee James Lee
-
- Version Ident:
-
- $Header$
-
- History:
-
- 12-Feb-96 jlee Initial creation.
- 12-Mar-96 jlee Used a custom made TitleList class in place of List class.
- 25-Mar-96 jlee Modified layoutCOntainer so that it dosn't repeat the same layout change.
- 29-Mar-96 jlee Changed the handling of ButtonHeight in TitleList
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
-
- import pj.awt.PjFinals;
- import pj.awt.TitleList;
-
- 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.Rectangle;
-
- /**
- * PjHdlViewLayout is used to layout Headline View.
- * <P>
- * This custom layout places two button( "Business & Finance", "World-Wid" )
- * at the top and two corresponding columns just below. The width of buttons and
- * columns should be the same, but the height can be changed dynamicaly.
- * Below all of these, another column(Personal News) is placed with constraints
- * as its height can not be taller than a certain size.
- * <pre>
- * ____________________________________
- * | Button | Button |
- * |----------------|-----------------|
- * | | |
- * | | |
- * | | |
- * | Column | Column |
- * | | |
- * | | |
- * |________________|_________________|
- * | |
- * | |
- * | Column |
- * | |
- * |__________________________________|
- *
- * </pre>
- *
- * @version 0.00, 2/12/96
- * @author James Lee
- */
- public class PjHdlViewLayout implements LayoutManager
- {
-
- // ---Instance variables
-
- private int hgap;
- private int vgap;
- private Rectangle recLast = new Rectangle(0, 0, 0, 0);
-
-
- // --- Public constructors
- /**
- * Constructs a new Flow Layout with a centered alignment.
- * Default value for hgap and vgap is 0.
- */
- public PjHdlViewLayout()
- {
- this(0, 0);
- }
-
- /**
- * Constructs a new Flow Layout with the specified alignment and gap
- * values.
- * @param hgap the horizontal gap variable
- * @param vgap the vertical gap variable
- */
- public PjHdlViewLayout(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();
-
- for (int i = 0 ; i < nmembers ; i++)
- {
- Component m = target.getComponent(i);
- if (m.isVisible())
- {
- Dimension d = m.preferredSize();
-
- dim.height = Math.max(dim.height, d.height);
- if (i > 0)
- {
- dim.width += hgap;
- }
- dim.width += d.width;
- }
- } // for
-
- Insets insets = target.insets();
- dim.width += insets.left + insets.right;
- dim.height += insets.top + insets.bottom + vgap*2;
-
- return dim;
- } //preferredLayoutSize
-
- /**
- * 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 = Math.max(dim.height, d.height);
- if (i > 0)
- {
- dim.width += hgap;
- }
- dim.width += d.width;
- }
- }//for
- Insets insets = target.insets();
- dim.width += insets.left + insets.right;
- 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 PjAdViewLayout object.
- * @param target the specified component being laid out.
- * @see Container
- */
- public synchronized void layoutContainer(Container target)
- {
- 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;
-
- int maxwidth = rec.width - (insets.left + insets.right + hgap);
- int maxheight = rec.height - (insets.top + insets.bottom + vgap*2);
-
- int nmembers = target.countComponents();
- int upwidth = maxwidth / 2;
- int upheight;
-
- int downwidth = maxwidth;
- int downheight = maxheight * 8 / 30;
-
- int nLabelHeight = ((Container)target.getComponent(2)).getComponent(0).minimumSize().height + 2;
- // Fix this long chain if possible
- int nTitleListItem = (((Container)
- ((Container)
- ((Container)
- target.getComponent(2)).
- getComponent(1)).
- getComponent(0)).
- countComponents() - 1
- ) / 2;
-
- TitleList tlPersonalNews = (TitleList)
- ((Container)
- ((Container)
- target.getComponent(2)).
- getComponent(1)).
- getComponent(0);
- Dimension dimTextFieldMim = null;
-
- if ( tlPersonalNews != null )
- dimTextFieldMim = tlPersonalNews.getTextFieldMinimumSize();
- else
- System.out.println("Error-PjHdlViewLayout-layoutContainer:TitleList is null!");
-
- int nBtnHeight = PjFinals.nTitleListButtonHeight;
-
- if ( dimTextFieldMim.height > PjFinals.nTitleListButtonHeight )
- {
- nBtnHeight = dimTextFieldMim.height;
- tlPersonalNews.setButtonHeight( nBtnHeight );
- }
- else
- tlPersonalNews.setButtonHeight( nBtnHeight );
-
-
- if ( downheight > nTitleListItem * (nBtnHeight + 3) - 3 )
- downheight = (nTitleListItem) * (nBtnHeight + 3) - 3 + nLabelHeight;
- else
- downheight = (downheight / (nBtnHeight + 3) + 1)
- * (nBtnHeight + 3) - 3 + nLabelHeight;
-
- upheight = maxheight - downheight;
-
- int x = insets.left;
- int y = insets.top + vgap;
-
- for (int i = 0 ; i < nmembers ; i++)
- {
- Component m = target.getComponent(i);
-
- if ( m.isVisible() )
- {
- switch ( i )
- {
- case 0://Left Panel
- m.reshape( x, y, upwidth, upheight );
- m.validate();
- break;
- case 1://Right Panel
- x += upwidth + hgap;
- m.reshape( x, y, upwidth, upheight );
- m.validate();
- break;
- case 2://Bottom Panel
- x = insets.left;
- y += upheight + vgap;
- m.reshape( x, y, downwidth, downheight );
- m.validate();
- break;
- default:
- break;
- }//switch
- }//if
- }//for
-
- }//layoutContainer
-
- /**
- * Returns the String representation of this PjListLayout's values.
- */
- public String toString()
- {
- return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]";
- }
- }
-
-
-