home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / awt / VerticalBagLayout.java < prev   
Encoding:
Java Source  |  1997-01-27  |  4.5 KB  |  154 lines

  1. /*
  2.  * @(#)VerticalBagLayout.java    1.1 95/10/06 Herb Jellinek
  3.  *
  4.  * Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.awt;
  21.  
  22. import java.awt.*;
  23.  
  24.  
  25. /**
  26.  * A vertical 'bag' of Components.  Allocates space for each Component from
  27.  * top to bottom.
  28.  *
  29.  * @version     1.1 10/06/95
  30.  * @author     Herb Jellinek
  31.  */
  32. public class VerticalBagLayout implements LayoutManager {
  33.  
  34.     int vgap;
  35.  
  36.     /**
  37.      * Constructs a new VerticalBagLayout.
  38.      */
  39.     public VerticalBagLayout() {
  40.     this(0);
  41.     }
  42.  
  43.     /**
  44.      * Constructs a VerticalBagLayout with the specified gaps.
  45.      * @param vgap the vertical gap
  46.      */
  47.     public VerticalBagLayout(int vgap) {
  48.     this.vgap = vgap;
  49.     }
  50.  
  51.     /**
  52.      * Adds the specified named component to the layout.
  53.      * @param name the String name
  54.      * @param comp the component to be added
  55.      */
  56.     public void addLayoutComponent(String name, Component comp) {
  57.     }
  58.  
  59.     /**
  60.      * Removes the specified component from the layout.
  61.      * @param comp the component to be removed
  62.      */
  63.     public void removeLayoutComponent(Component comp) {
  64.     }
  65.  
  66.     /**
  67.      * Returns the minimum dimensions needed to lay out the components
  68.      * contained in the specified target container. 
  69.      * @param target the Container on which to do the layout
  70.      * @see Container
  71.      * @see #preferredLayoutSize
  72.      */
  73.     public Dimension minimumLayoutSize(Container target) {
  74.     Dimension dim = new Dimension();
  75.     int nmembers = target.countComponents();
  76.  
  77.     for (int i = 0; i < nmembers; i++) {
  78.         Component comp = target.getComponent(i);
  79.         if (comp.isVisible()) {
  80.         Dimension d = comp.minimumSize();
  81.         dim.width = Math.max(d.width, dim.width);
  82.         dim.height += d.height + vgap;
  83.         }
  84.     }
  85.  
  86.     Insets insets = target.insets();
  87.     dim.width += insets.left + insets.right;
  88.     dim.height += insets.top + insets.bottom;
  89.  
  90.     return dim;
  91.     }
  92.     
  93.     /**
  94.      * Returns the preferred dimensions for this layout given the components
  95.      * in the specified target container.
  96.      * @param target the component which needs to be laid out
  97.      * @see Container
  98.      * @see #minimumLayoutSize
  99.      */
  100.     public Dimension preferredLayoutSize(Container target) {
  101.     Dimension dim = new Dimension();
  102.     int nmembers = target.countComponents();
  103.  
  104.     for (int i = 0; i < nmembers; i++) {
  105.         Component comp = target.getComponent(i);
  106.         if (true || comp.isVisible()) {
  107.         Dimension d = comp.preferredSize();
  108.         dim.width = Math.max(d.width, dim.width);
  109.         dim.height += d.height + vgap;
  110.         }
  111.     }
  112.  
  113.     Insets insets = target.insets();
  114.     dim.width += insets.left + insets.right;
  115.     dim.height += insets.top + insets.bottom;
  116.  
  117.     return dim;
  118.     }
  119.  
  120.     /**
  121.      * Lays out the specified container. This method will actually reshape the
  122.      * components in the specified target container in order to satisfy the 
  123.      * constraints of the VerticalBagLayout object. 
  124.      * @param target the component being laid out
  125.      * @see Container
  126.      */
  127.     public void layoutContainer(Container target) {
  128.     Insets insets = target.insets();
  129.     int top = insets.top;
  130.     int bottom = target.size().height - insets.bottom;
  131.     int left = insets.left;
  132.     int right = target.size().width - insets.right;
  133.     int nmembers = target.countComponents();
  134.     
  135.     for (int i = 0; i < nmembers; i++) {
  136.         Component comp = target.getComponent(i);
  137.         if (comp.isVisible()) {
  138.         int compHeight = comp.size().height;
  139.         comp.resize(right - left, compHeight);
  140.         Dimension d = comp.preferredSize();
  141.         comp.reshape(left, top, right - left, d.height);
  142.         top += d.height + vgap;
  143.         }
  144.     }
  145.     }
  146.     
  147.     /**
  148.      * Returns the String representation of this VerticalBagLayout's values.
  149.      */
  150.     public String toString() {
  151.     return getClass().getName() + "[vgap=" + vgap + "]";
  152.     }
  153. }
  154.