home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / GridBagConstraints.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  9.7 KB  |  307 lines

  1. /*
  2.  * @(#)GridBagConstraints.java    1.13 98/03/18
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. /**
  17.  * The <code>GridBagConstraints</code> class specifies constraints 
  18.  * for components that are laid out using the 
  19.  * <code>GridBagLayout</code> class.
  20.  *
  21.  * @version 1.9, 06/16/97
  22.  * @author Doug Stein
  23.  * @see java.awt.GridBagLayout
  24.  * @since JDK1.0
  25.  */
  26. public class GridBagConstraints implements Cloneable, java.io.Serializable {
  27.  
  28.    /**
  29.      * Specify that this component is the next-to-last component in its 
  30.      * column or row (<code>gridwidth</code>, <code>gridheight</code>), 
  31.      * or that this component be placed next to the previously added 
  32.      * component (<code>gridx</code>, <code>gridy</code>). 
  33.      * @see      java.awt.GridBagConstraints#gridwidth
  34.      * @see      java.awt.GridBagConstraints#gridheight
  35.      * @see      java.awt.GridBagConstraints#gridx
  36.      * @see      java.awt.GridBagConstraints#gridy
  37.      */
  38.   public static final int RELATIVE = -1;
  39.  
  40.    /**
  41.      * Specify that this component is the 
  42.      * last component in its column or row. 
  43.      */
  44.   public static final int REMAINDER = 0;
  45.  
  46.    /**
  47.      * Do not resize the component. 
  48.      */
  49.   public static final int NONE = 0;
  50.  
  51.    /**
  52.      * Resize the component both horizontally and vertically. 
  53.      */
  54.   public static final int BOTH = 1;
  55.  
  56.    /**
  57.      * Resize the component horizontally but not vertically. 
  58.      */
  59.   public static final int HORIZONTAL = 2;
  60.  
  61.    /**
  62.      * Resize the component vertically but not horizontally. 
  63.      */
  64.   public static final int VERTICAL = 3;
  65.  
  66.    /**
  67.     * Put the component in the center of its display area.
  68.     */
  69.   public static final int CENTER = 10;
  70.  
  71.    /**
  72.      * Put the component at the top of its display area,
  73.      * centered horizontally. 
  74.      */
  75.   public static final int NORTH = 11;
  76.  
  77.     /**
  78.      * Put the component at the top-right corner of its display area. 
  79.      */
  80.   public static final int NORTHEAST = 12;
  81.  
  82.     /**
  83.      * Put the component on the right side of its display area, 
  84.      * centered vertically.
  85.      */
  86.   public static final int EAST = 13;
  87.  
  88.     /**
  89.      * Put the component at the bottom-right corner of its display area. 
  90.      */
  91.   public static final int SOUTHEAST = 14;
  92.  
  93.     /**
  94.      * Put the component at the bottom of its display area, centered 
  95.      * horizontally. 
  96.      */
  97.   public static final int SOUTH = 15;
  98.  
  99.    /**
  100.      * Put the component at the bottom-left corner of its display area. 
  101.      */
  102.   public static final int SOUTHWEST = 16;
  103.  
  104.     /**
  105.      * Put the component on the left side of its display area, 
  106.      * centered vertically.
  107.      */
  108.   public static final int WEST = 17;
  109.  
  110.    /**
  111.      * Put the component at the top-left corner of its display area. 
  112.      */
  113.   public static final int NORTHWEST = 18;
  114.  
  115.    /**
  116.      * Specifies the cell at the left of the component's display area, 
  117.      * where the leftmost cell has <code>gridx = 0</code>. The value 
  118.      * <code>RELATIVE</code> specifies that the component be placed just 
  119.      * to the right of the component that was added to the container just 
  120.      * before this component was added. 
  121.      * <p>
  122.      * The default value is <code>RELATIVE</code>. 
  123.      * @see      java.awt.GridBagConstraints#gridy
  124.      */
  125.   public int gridx;
  126.  
  127.    /**
  128.      * Specifies the cell at the top of the component's display area, 
  129.      * where the topmost cell has <code>gridy = 0</code>. The value 
  130.      * <code>RELATIVE</code> specifies that the component be placed just 
  131.      * below the component that was added to the container just before 
  132.      * this component was added. 
  133.      * <p>
  134.      * The default value is <code>RELATIVE</code>. 
  135.      * @see      java.awt.GridBagConstraints#gridx
  136.      */
  137.   public int gridy;
  138.  
  139.    /**
  140.      * Specifies the number of cells in a row for the component's 
  141.      * display area. 
  142.      * <p>
  143.      * Use <code>REMAINDER</code> to specify that the component be the 
  144.      * last one in its row. Use <code>RELATIVE</code> to specify that the 
  145.      * component be the next-to-last one in its row. 
  146.      * <p>
  147.      * The default value is 1. 
  148.      * @see      java.awt.GridBagConstraints#gridheight
  149.      */
  150.   public int gridwidth;
  151.  
  152.    /**
  153.      * Specifies the number of cells in a column for the component's 
  154.      * display area. 
  155.      * <p>
  156.      * Use <code>REMAINDER</code> to specify that the component be the 
  157.      * last one in its column. Use <code>RELATIVE</code> to specify that 
  158.      * the component be the next-to-last one in its column. 
  159.      * <p>
  160.      * The default value is 1.
  161.      * @see      java.awt.GridBagConstraints#gridwidth
  162.      */
  163.   public int gridheight;
  164.  
  165.    /**
  166.      * Specifies how to distribute extra horizontal space. 
  167.      * <p>
  168.      * The grid bag layout manager calculates the weight of a column to 
  169.      * be the maximum <code>weighty</code> of all the components in a 
  170.      * row. If the resulting layout is smaller horizontally than the area 
  171.      * it needs to fill, the extra space is distributed to each column in 
  172.      * proportion to its weight. A column that has a weight zero receives no 
  173.      * extra space. 
  174.      * <p>
  175.      * If all the weights are zero, all the extra space appears between 
  176.      * the grids of the cell and the left and right edges. 
  177.      * <p>
  178.      * The default value of this field is <code>0</code>. 
  179.      * @see      java.awt.GridBagConstraints#weighty
  180.      */
  181.   public double weightx;
  182.  
  183.    /**
  184.      * Specifies how to distribute extra vertical space. 
  185.      * <p>
  186.      * The grid bag layout manager calculates the weight of a row to be 
  187.      * the maximum <code>weightx</code> of all the components in a row. 
  188.      * If the resulting layout is smaller vertically than the area it 
  189.      * needs to fill, the extra space is distributed to each row in 
  190.      * proportion to its weight. A row that has a weight of zero receives no 
  191.      * extra space. 
  192.      * <p>
  193.      * If all the weights are zero, all the extra space appears between 
  194.      * the grids of the cell and the top and bottom edges. 
  195.      * <p>
  196.      * The default value of this field is <code>0</code>. 
  197.      * @see      java.awt.GridBagConstraints#weightx
  198.      */
  199.   public double weighty;
  200.  
  201.    /**
  202.      * This field is used when the component is smaller than its display 
  203.      * area. It determines where, within the display area, to place the 
  204.      * component. Possible values are <code>CENTER<code>, 
  205.      * <code>NORTH<code>, <code>NORTHEAST<code>, <code>EAST<code>, 
  206.      * <code>SOUTHEAST<code>, <code>SOUTH<code>, <code>SOUTHWEST<code>, 
  207.      * <code>WEST<code>, and <code>NORTHWEST<code>.
  208.      * The default value is <code>CENTER</code>. 
  209.      */
  210.   public int anchor;
  211.  
  212.    /**
  213.      * This field is used when the component's display area is larger 
  214.      * than the component's requested size. It determines whether to 
  215.      * resize the component, and if so, how. 
  216.      * <p>
  217.      * The following values are valid for <code>fill</code>: 
  218.      * <p>
  219.      * <ul>
  220.      * <li>
  221.      * <code>NONE</code>: Do not resize the component. 
  222.      * <li>
  223.      * <code>HORIZONTAL</code>: Make the component wide enough to fill 
  224.      *         its display area horizontally, but do not change its height. 
  225.      * <li>
  226.      * <code>VERTICAL</code>: Make the component tall enough to fill its 
  227.      *         display area vertically, but do not change its width. 
  228.      * <li>
  229.      * <code>BOTH</code>: Make the component fill its display area 
  230.      *         entirely. 
  231.      * </ul>
  232.      * <p>
  233.      * The default value is <code>NONE</code>. 
  234.      */
  235.   public int fill;
  236.  
  237.    /**
  238.      * This field specifies the external padding of the component, the 
  239.      * minimum amount of space between the component and the edges of its 
  240.      * display area. 
  241.      * <p>
  242.      * The default value is <code>new Insets(0, 0, 0, 0)</code>. 
  243.      */
  244.   public Insets insets;
  245.  
  246.    /**
  247.      * This field specifies the internal padding of the component, how much 
  248.      * space to add to the minimum width of the component. The width of 
  249.      * the component is at least its minimum width plus 
  250.      * <code>(ipadx * 2)</code> pixels. 
  251.      * <p>
  252.      * The default value is <code>0</code>. 
  253.      * @see      java.awt.GridBagConstraints#ipady
  254.      */
  255.   public int ipadx;
  256.  
  257.    /**
  258.      * This field specifies the internal padding, that is, how much 
  259.      * space to add to the minimum height of the component. The height of 
  260.      * the component is at least its minimum height plus 
  261.      * <code>(ipady * 2)</code> pixels. 
  262.      * <p>
  263.      * The default value is 0. 
  264.      * @see      java.awt.GridBagConstraints#ipadx
  265.      */
  266.   public int ipady;
  267.  
  268.   int tempX, tempY;
  269.   int tempWidth, tempHeight;
  270.   int minWidth, minHeight;
  271.  
  272.    /**
  273.      * Creates a <code>GridBagConstraint</code> object with 
  274.      * all of its fields set to their default value. 
  275.      */
  276.   public GridBagConstraints () {
  277.     gridx = RELATIVE;
  278.     gridy = RELATIVE;
  279.     gridwidth = 1;
  280.     gridheight = 1;
  281.  
  282.     weightx = 0;
  283.     weighty = 0;
  284.     anchor = CENTER;
  285.     fill = NONE;
  286.  
  287.     insets = new Insets(0, 0, 0, 0);
  288.     ipadx = 0;
  289.     ipady = 0;
  290.   }
  291.  
  292.    /**
  293.     * Creates a copy of this grid bag constraint.
  294.     * @return     a copy of this grid bag constraint
  295.     */
  296.   public Object clone () {
  297.       try { 
  298.       GridBagConstraints c = (GridBagConstraints)super.clone();
  299.       c.insets = (Insets)insets.clone();
  300.       return c;
  301.       } catch (CloneNotSupportedException e) { 
  302.       // this shouldn't happen, since we are Cloneable
  303.       throw new InternalError();
  304.       }
  305.   }
  306. }
  307.