home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 7.7 KB | 226 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.
-
-
- @(#)PjAdViewLayout.java 0.00 5-Feb-96
-
- A PjAdViewLayout that manages the AdView layout.
-
- Authors:
-
- jlee James Lee
-
- Version Ident:
-
- $Header$
-
- History:
-
- 5-Feb-96 jlee Initial creation.
- 15-Feb-96 jlee Added and used PjFinals class for all size info.
- 12-Mar-96 jlee Modified so that it can accomadate enclosing 3D box.
- 25-Mar-96 jlee Modified layoutCOntainer so that it dosn't repeat the same layout change.
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.PjFinals;
-
- 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;
-
- /**
- * PjAdViewLayout is used to layout Ad view controls in a panel.
- * <P>
- * This custom layout places the image to the left and the ad
- * text to the right. The url, if present, is below the text.
- * <pre>
- * ____________________________________________
- * | | |
- * | Image | Text |
- * | | |
- * |___________________|_______________________|
- * |________________URL________________________|
- *
- * </pre>
- * @version 0.00, 2/5/96
- * @author James Lee
- */
- public class PjAdViewLayout implements LayoutManager {
-
- // --- Instance variables
- private int hgap;
- private int vgap;
- private int padding = PjFinals.nPjVerticalSpacing;
-
- private final Dimension adImageSize = new Dimension( PjFinals.nPjAdImageWidth, PjFinals.nPjAdImageHeight );
- private final Dimension adTextSize = new Dimension( PjFinals.nPjAdTextBoxWidth, PjFinals.nPjAdTextBoxHeight );
- private final Dimension adMoreSize = new Dimension( PjFinals.nPjMinimumPageViewWidth, PjFinals.nPjButtonHeight );
- 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 PjAdViewLayout()
- {
- 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 PjAdViewLayout(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)
- {
- int upperHeight = adTextSize.height > adImageSize.height ? adTextSize.height: adImageSize.height;
-
- Dimension dim = new Dimension(adMoreSize.width - 2, adMoreSize.height + upperHeight + padding);
- int nmembers = target.countComponents();
-
- 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)
- {
- int upperHeight = adTextSize.height > adImageSize.height ? adTextSize.height: adImageSize.height;
-
- Dimension dim = new Dimension(adMoreSize.width - 2, adMoreSize.height + upperHeight + padding );
-
- 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 PjAdViewLayout object.
- * @param target the specified component being laid out.
- * @see Container
- */
- public 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*2);
- int nmembers = target.countComponents();
- int width = maxwidth - adMoreSize.width;
-
- int x = 0;
- int y = 0;
-
- for (int i = 0 ; i < nmembers ; i++)
- {
- Component m = target.getComponent(i);
-
- //y = (rec.height - adImageSize.height - adMoreSize.height - padding) / 2;
- y = 0;
- if ( m.isVisible() )
- {
- switch ( i )
- {
- case 0://Ad Text
- x = width / 2 + adImageSize.width + padding;
- m.reshape( x, y, adTextSize.width, adTextSize.height );
- break;
- case 1://Ad More button
- x = width / 2;
- y += (adTextSize.height > adImageSize.height ? adTextSize.height: adImageSize.height);// + padding;
- m.reshape( x, y, adMoreSize.width - 2, adMoreSize.height );
- break;
- case 2://Ad GifCanvas
- x = width / 2;
- //y += (PjFinals.nPjAdTextBoxHeight - PjFinals.nPjAdImageHeight) / 2;
- y = 0;
- m.reshape( x, y, adImageSize.width, adImageSize.height );
- break;
-
- default:
- break;
- }//switch
- }//if
- }//for
-
- }
-
- /**
- * Returns the String representation of this PjAdViewLayout's values.
- */
- public String toString()
- {
- return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]" +
- "[width=" + adMoreSize.width + ",height=" + (adMoreSize.height + adImageSize.height) + "]";
- }
- }
-