home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / awt / GridBagConstraints.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  13.0 KB  |  421 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)GridBagConstraints.java    1.16 98/09/09
  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.      * gridx should be a non-negative value.
  124.      * @serial
  125.      * @see clone()
  126.      * @see java.awt.GridBagConstraints#gridy
  127.      */
  128.   public int gridx;
  129.  
  130.    /**
  131.      * Specifies the cell at the top of the component's display area, 
  132.      * where the topmost cell has <code>gridy=0</code>. The value 
  133.      * <code>RELATIVE</code> specifies that the component be placed just 
  134.      * below the component that was added to the container just before 
  135.      * this component was added. 
  136.      * <p>
  137.      * The default value is <code>RELATIVE</code>.
  138.      * gridy should be a non-negative value.
  139.      * @serial
  140.      * @see clone() 
  141.      * @see java.awt.GridBagConstraints#gridx
  142.      */
  143.   public int gridy;
  144.  
  145.    /**
  146.      * Specifies the number of cells in a row for the component's 
  147.      * display area. 
  148.      * <p>
  149.      * Use <code>REMAINDER</code> to specify that the component be the 
  150.      * last one in its row. Use <code>RELATIVE</code> to specify that the 
  151.      * component be the next-to-last one in its row. 
  152.      * <p>
  153.      * gridwidth should be non-negative and the default value is 1.
  154.      * @serial
  155.      * @see clone() 
  156.      * @see java.awt.GridBagConstraints#gridheight
  157.      */
  158.   public int gridwidth;
  159.  
  160.    /**
  161.      * Specifies the number of cells in a column for the component's 
  162.      * display area. 
  163.      * <p>
  164.      * Use <code>REMAINDER</code> to specify that the component be the 
  165.      * last one in its column. Use <code>RELATIVE</code> to specify that 
  166.      * the component be the next-to-last one in its column. 
  167.      * <p>
  168.      * gridheight should be a non-negative value and the default value is 1.
  169.      * @serial
  170.      * @see clone()
  171.      * @see java.awt.GridBagConstraints#gridwidth
  172.      */
  173.   public int gridheight;
  174.  
  175.    /**
  176.      * Specifies how to distribute extra horizontal space. 
  177.      * <p>
  178.      * The grid bag layout manager calculates the weight of a column to 
  179.      * be the maximum <code>weighty</code> of all the components in a 
  180.      * row. If the resulting layout is smaller horizontally than the area 
  181.      * it needs to fill, the extra space is distributed to each column in 
  182.      * proportion to its weight. A column that has a weight zero receives no 
  183.      * extra space. 
  184.      * <p>
  185.      * If all the weights are zero, all the extra space appears between 
  186.      * the grids of the cell and the left and right edges. 
  187.      * <p>
  188.      * The default value of this field is <code>0</code>.
  189.      * weightx should be a non-negative value.
  190.      * @serial
  191.      * @see clone() 
  192.      * @see java.awt.GridBagConstraints#weighty
  193.      */
  194.   public double weightx;
  195.  
  196.    /**
  197.      * Specifies how to distribute extra vertical space. 
  198.      * <p>
  199.      * The grid bag layout manager calculates the weight of a row to be 
  200.      * the maximum <code>weightx</code> of all the components in a row. 
  201.      * If the resulting layout is smaller vertically than the area it 
  202.      * needs to fill, the extra space is distributed to each row in 
  203.      * proportion to its weight. A row that has a weight of zero receives no 
  204.      * extra space. 
  205.      * <p>
  206.      * If all the weights are zero, all the extra space appears between 
  207.      * the grids of the cell and the top and bottom edges. 
  208.      * <p>
  209.      * The default value of this field is <code>0</code>. 
  210.      * weighty should be a non-negative value.
  211.      * @serial
  212.      * @see clone()
  213.      * @see java.awt.GridBagConstraints#weightx
  214.      */
  215.   public double weighty;
  216.  
  217.    /**
  218.      * This field is used when the component is smaller than its display 
  219.      * area. It determines where, within the display area, to place the 
  220.      * component. Possible values are <code>CENTER<code>, 
  221.      * <code>NORTH<code>, <code>NORTHEAST<code>, <code>EAST<code>, 
  222.      * <code>SOUTHEAST<code>, <code>SOUTH<code>, <code>SOUTHWEST<code>, 
  223.      * <code>WEST<code>, and <code>NORTHWEST<code>.
  224.      * The default value is <code>CENTER</code>. 
  225.      * @serial
  226.      * @see clone()
  227.      */
  228.   public int anchor;
  229.  
  230.    /**
  231.      * This field is used when the component's display area is larger 
  232.      * than the component's requested size. It determines whether to 
  233.      * resize the component, and if so, how. 
  234.      * <p>
  235.      * The following values are valid for <code>fill</code>: 
  236.      * <p>
  237.      * <ul>
  238.      * <li>
  239.      * <code>NONE</code>: Do not resize the component. 
  240.      * <li>
  241.      * <code>HORIZONTAL</code>: Make the component wide enough to fill 
  242.      *         its display area horizontally, but do not change its height. 
  243.      * <li>
  244.      * <code>VERTICAL</code>: Make the component tall enough to fill its 
  245.      *         display area vertically, but do not change its width. 
  246.      * <li>
  247.      * <code>BOTH</code>: Make the component fill its display area 
  248.      *         entirely. 
  249.      * </ul>
  250.      * <p>
  251.      * The default value is <code>NONE</code>. 
  252.      * @serial
  253.      * @see clone()
  254.      */
  255.   public int fill;
  256.  
  257.    /**
  258.      * This field specifies the external padding of the component, the 
  259.      * minimum amount of space between the component and the edges of its 
  260.      * display area. 
  261.      * <p>
  262.      * The default value is <code>new Insets(0, 0, 0, 0)</code>. 
  263.      * @serial
  264.      * @see clone()
  265.      */
  266.   public Insets insets;
  267.  
  268.    /**
  269.      * This field specifies the internal padding of the component, how much 
  270.      * space to add to the minimum width of the component. The width of 
  271.      * the component is at least its minimum width plus 
  272.      * <code>(ipadx * 2)</code> pixels. 
  273.      * <p>
  274.      * The default value is <code>0</code>. 
  275.      * @serial
  276.      * @see clone()
  277.      * @see java.awt.GridBagConstraints#ipady
  278.      */
  279.   public int ipadx;
  280.  
  281.    /**
  282.      * This field specifies the internal padding, that is, how much 
  283.      * space to add to the minimum height of the component. The height of 
  284.      * the component is at least its minimum height plus 
  285.      * <code>(ipady * 2)</code> pixels. 
  286.      * <p>
  287.      * The default value is 0. 
  288.      * @serial
  289.      * @see clone()
  290.      * @see java.awt.GridBagConstraints#ipadx
  291.      */
  292.   public int ipady;
  293.  
  294.    /**
  295.      * Temporary place holder for the x coordinate.
  296.      * @serial
  297.      */
  298.   int tempX;
  299.    /**
  300.      * Temporary place holder for the y coordinate.
  301.      * @serial
  302.      */
  303.   int tempY;
  304.    /**
  305.      * Temporary place holder for the Width of the component.
  306.      * @serial
  307.      */
  308.   int tempWidth;
  309.    /**
  310.      * Temporary place holder for the Height of the component.
  311.      * @serial
  312.      */
  313.   int tempHeight;
  314.    /**
  315.      * The minimum width of the component.  It is used to calculate
  316.      * <code>ipady<code>, where the default will be 0.
  317.      * @serial
  318.      * @see ipady
  319.      */
  320.   int minWidth;
  321.    /**
  322.      * The minimum height of the component. It is used to calculate
  323.      * <code>ipadx<code>, where the default will be 0.
  324.      * @serial
  325.      * @see ipadx
  326.      */
  327.   int minHeight;
  328.  
  329.   /*
  330.    * JDK 1.1 serialVersionUID 
  331.    */
  332.   private static final long serialVersionUID = -1000070633030801713L;
  333.  
  334.    /**
  335.      * Creates a <code>GridBagConstraint</code> object with 
  336.      * all of its fields set to their default value. 
  337.      */
  338.   public GridBagConstraints () {
  339.     gridx = RELATIVE;
  340.     gridy = RELATIVE;
  341.     gridwidth = 1;
  342.     gridheight = 1;
  343.  
  344.     weightx = 0;
  345.     weighty = 0;
  346.     anchor = CENTER;
  347.     fill = NONE;
  348.  
  349.     insets = new Insets(0, 0, 0, 0);
  350.     ipadx = 0;
  351.     ipady = 0;
  352.   }
  353.  
  354.   /**
  355.     * Creates a <code>GridBagConstraints</code> object with
  356.     * all of its fields set to the passed-in arguments.
  357.     * 
  358.     * Note: Because the use of this constructor hinders readability
  359.     * of source code, this constructor should only be used by
  360.     * automatic source code generation tools.
  361.     * 
  362.     * @param gridx    The initial gridx value.
  363.     * @param gridy    The initial gridy value.
  364.     * @param gridwidth    The initial gridwidth value.
  365.     * @param gridheight    The initial gridheight value.
  366.     * @param weightx    The initial weightx value.
  367.     * @param weighty    The initial weighty value.
  368.     * @param anchor    The initial anchor value.
  369.     * @param fill    The initial fill value.
  370.     * @param insets    The initial insets value.
  371.     * @param ipadx    The initial ipadx value.
  372.     * @param ipady    The initial ipady value.
  373.     * 
  374.     * @see java.awt.GridBagConstraints#gridx
  375.     * @see java.awt.GridBagConstraints#gridy
  376.     * @see java.awt.GridBagConstraints#gridwidth
  377.     * @see java.awt.GridBagConstraints#gridheight
  378.     * @see java.awt.GridBagConstraints#weightx
  379.     * @see java.awt.GridBagConstraints#weighty
  380.     * @see java.awt.GridBagConstraints#anchor
  381.     * @see java.awt.GridBagConstraints#fill
  382.     * @see java.awt.GridBagConstraints#insets
  383.     * @see java.awt.GridBagConstraints#ipadx
  384.     * @see java.awt.GridBagConstraints#ipady
  385.     * 
  386.     * @since JDK1.2
  387.     */
  388.   public GridBagConstraints(int gridx, int gridy,
  389.                             int gridwidth, int gridheight,
  390.                             double weightx, double weighty,
  391.                             int anchor, int fill,
  392.                             Insets insets, int ipadx, int ipady) {
  393.     this.gridx = gridx;
  394.     this.gridy = gridy;
  395.     this.gridwidth = gridwidth;
  396.     this.gridheight = gridheight;
  397.     this.fill = fill;
  398.     this.ipadx = ipadx;
  399.     this.ipady = ipady;
  400.     this.insets = insets;
  401.     this.anchor  = anchor;
  402.     this.weightx = weightx;
  403.     this.weighty = weighty;
  404.   }
  405.  
  406.    /**
  407.     * Creates a copy of this grid bag constraint.
  408.     * @return     a copy of this grid bag constraint
  409.     */
  410.   public Object clone () {
  411.       try { 
  412.       GridBagConstraints c = (GridBagConstraints)super.clone();
  413.       c.insets = (Insets)insets.clone();
  414.       return c;
  415.       } catch (CloneNotSupportedException e) { 
  416.       // this shouldn't happen, since we are Cloneable
  417.       throw new InternalError();
  418.       }
  419.   }
  420. }
  421.