home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / GridBagConstraints.java < prev    next >
Text File  |  1997-10-01  |  11KB  |  343 lines

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