2362N/A * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * The <code>GridBagLayout</code> class is a flexible layout 0N/A * manager that aligns components vertically, horizontally or along their 0N/A * baseline without requiring that the components be of the same size. 0N/A * Each <code>GridBagLayout</code> object maintains a dynamic, 0N/A * rectangular grid of cells, with each component occupying 0N/A * one or more cells, called its <em>display area</em>. 0N/A * Each component managed by a <code>GridBagLayout</code> is associated with 0N/A * an instance of {@link GridBagConstraints}. The constraints object 0N/A * specifies where a component's display area should be located on the grid 0N/A * and how the component should be positioned within its display area. In 0N/A * addition to its constraints object, the <code>GridBagLayout</code> also 0N/A * considers each component's minimum and preferred sizes in order to 0N/A * determine a component's size. 0N/A * The overall orientation of the grid depends on the container's 0N/A * {@link ComponentOrientation} property. For horizontal left-to-right 0N/A * orientations, grid coordinate (0,0) is in the upper left corner of the 0N/A * container with x increasing to the right and y increasing downward. For 0N/A * horizontal right-to-left orientations, grid coordinate (0,0) is in the upper 0N/A * right corner of the container with x increasing to the left and y 0N/A * increasing downward. 0N/A * To use a grid bag layout effectively, you must customize one or more 0N/A * of the <code>GridBagConstraints</code> objects that are associated 0N/A * with its components. You customize a <code>GridBagConstraints</code> 0N/A * object by setting one or more of its instance variables: 0N/A * <dt>{@link GridBagConstraints#gridx}, 0N/A * {@link GridBagConstraints#gridy} 0N/A * <dd>Specifies the cell containing the leading corner of the component's 0N/A * display area, where the cell at the origin of the grid has address 0N/A * <code>gridx = 0</code>, 0N/A * <code>gridy = 0</code>. For horizontal left-to-right layout, 0N/A * a component's leading corner is its upper left. For horizontal 0N/A * right-to-left layout, a component's leading corner is its upper right. 0N/A * Use <code>GridBagConstraints.RELATIVE</code> (the default value) 0N/A * to specify that the component be placed immediately following 0N/A * (along the x axis for <code>gridx</code> or the y axis for 0N/A * <code>gridy</code>) the component that was added to the container 0N/A * just before this component was added. 0N/A * <dt>{@link GridBagConstraints#gridwidth}, 0N/A * {@link GridBagConstraints#gridheight} 0N/A * <dd>Specifies the number of cells in a row (for <code>gridwidth</code>) 0N/A * or column (for <code>gridheight</code>) 0N/A * in the component's display area. 0N/A * The default value is 1. 0N/A * Use <code>GridBagConstraints.REMAINDER</code> to specify 0N/A * that the component's display area will be from <code>gridx</code> 0N/A * to the last cell in the row (for <code>gridwidth</code>) 0N/A * or from <code>gridy</code> to the last cell in the column 0N/A * (for <code>gridheight</code>). 0N/A * Use <code>GridBagConstraints.RELATIVE</code> to specify 0N/A * that the component's display area will be from <code>gridx</code> 0N/A * to the next to the last cell in its row (for <code>gridwidth</code> 0N/A * or from <code>gridy</code> to the next to the last cell in its 0N/A * column (for <code>gridheight</code>). 0N/A * <dt>{@link GridBagConstraints#fill} 0N/A * <dd>Used when the component's display area 0N/A * is larger than the component's requested size 0N/A * to determine whether (and how) to resize the component. 0N/A * Possible values are 0N/A * <code>GridBagConstraints.NONE</code> (the default), 0N/A * <code>GridBagConstraints.HORIZONTAL</code> 0N/A * (make the component wide enough to fill its display area 0N/A * horizontally, but don't change its height), 0N/A * <code>GridBagConstraints.VERTICAL</code> 0N/A * (make the component tall enough to fill its display area 0N/A * vertically, but don't change its width), and 0N/A * <code>GridBagConstraints.BOTH</code> 0N/A * (make the component fill its display area entirely). 0N/A * <dt>{@link GridBagConstraints#ipadx}, 0N/A * {@link GridBagConstraints#ipady} 0N/A * <dd>Specifies the component's internal padding within the layout, 0N/A * how much to add to the minimum size of the component. 0N/A * The width of the component will be at least its minimum width 0N/A * plus <code>ipadx</code> pixels. Similarly, the height of 0N/A * the component will be at least the minimum height plus 0N/A * <code>ipady</code> pixels. 0N/A * <dt>{@link GridBagConstraints#insets} 0N/A * <dd>Specifies the component's external padding, the minimum 0N/A * amount of space between the component and the edges of its display area. 0N/A * <dt>{@link GridBagConstraints#anchor} 0N/A * <dd>Specifies where the component should be positioned in its display area. 0N/A * There are three kinds of possible values: absolute, orientation-relative, 0N/A * and baseline-relative 0N/A * Orientation relative values are interpreted relative to the container's 0N/A * <code>ComponentOrientation</code> property while absolute values 0N/A * are not. Baseline relative values are calculated relative to the 0N/A * baseline. Valid values are:</dd> 0N/A * <center><table BORDER=0 COLS=3 WIDTH=800 0N/A * SUMMARY="absolute, relative and baseline values as described above"> 0N/A * <th><P ALIGN="LEFT">Absolute Values</th> 0N/A * <th><P ALIGN="LEFT">Orientation Relative Values</th> 0N/A * <th><P ALIGN="LEFT">Baseline Relative Values</th> 0N/A * <li><code>GridBagConstraints.NORTH</code></li> 0N/A * <li><code>GridBagConstraints.SOUTH</code></li> 0N/A * <li><code>GridBagConstraints.WEST</code></li> 0N/A * <li><code>GridBagConstraints.EAST</code></li> 0N/A * <li><code>GridBagConstraints.NORTHWEST</code></li> 0N/A * <li><code>GridBagConstraints.NORTHEAST</code></li> 0N/A * <li><code>GridBagConstraints.SOUTHWEST</code></li> 0N/A * <li><code>GridBagConstraints.SOUTHEAST</code></li> 0N/A * <li><code>GridBagConstraints.CENTER</code> (the default)</li> 0N/A * <li><code>GridBagConstraints.PAGE_START</code></li> 0N/A * <li><code>GridBagConstraints.PAGE_END</code></li> 0N/A * <li><code>GridBagConstraints.LINE_START</code></li> 0N/A * <li><code>GridBagConstraints.LINE_END</code></li> 0N/A * <li><code>GridBagConstraints.FIRST_LINE_START</code></li> 0N/A * <li><code>GridBagConstraints.FIRST_LINE_END</code></li> 0N/A * <li><code>GridBagConstraints.LAST_LINE_START</code></li> 0N/A * <li><code>GridBagConstraints.LAST_LINE_END</code></li> 0N/A * <li><code>GridBagConstraints.BASELINE</code></li> 0N/A * <li><code>GridBagConstraints.BASELINE_LEADING</code></li> 0N/A * <li><code>GridBagConstraints.BASELINE_TRAILING</code></li> 0N/A * <li><code>GridBagConstraints.ABOVE_BASELINE</code></li> 0N/A * <li><code>GridBagConstraints.ABOVE_BASELINE_LEADING</code></li> 0N/A * <li><code>GridBagConstraints.ABOVE_BASELINE_TRAILING</code></li> 0N/A * <li><code>GridBagConstraints.BELOW_BASELINE</code></li> 0N/A * <li><code>GridBagConstraints.BELOW_BASELINE_LEADING</code></li> 0N/A * <li><code>GridBagConstraints.BELOW_BASELINE_TRAILING</code></li> 0N/A * </table></center><p> 0N/A * <dt>{@link GridBagConstraints#weightx}, 0N/A * {@link GridBagConstraints#weighty} 0N/A * <dd>Used to determine how to distribute space, which is 0N/A * important for specifying resizing behavior. 0N/A * Unless you specify a weight for at least one component 0N/A * in a row (<code>weightx</code>) and column (<code>weighty</code>), 0N/A * all the components clump together in the center of their container. 0N/A * This is because when the weight is zero (the default), 0N/A * the <code>GridBagLayout</code> object puts any extra space 0N/A * between its grid of cells and the edges of the container. 0N/A * Each row may have a baseline; the baseline is determined by the 0N/A * components in that row that have a valid baseline and are aligned 0N/A * along the baseline (the component's anchor value is one of {@code 0N/A * BASELINE}, {@code BASELINE_LEADING} or {@code BASELINE_TRAILING}). 0N/A * If none of the components in the row has a valid baseline, the row 0N/A * does not have a baseline. 0N/A * If a component spans rows it is aligned either to the baseline of 0N/A * the start row (if the baseline-resize behavior is {@code 0N/A * CONSTANT_ASCENT}) or the end row (if the baseline-resize behavior 0N/A * is {@code CONSTANT_DESCENT}). The row that the component is 0N/A * aligned to is called the <em>prevailing row</em>. 0N/A * The following figure shows a baseline layout and includes a 0N/A * component that spans rows: 0N/A * <center><table summary="Baseline Layout"> 0N/A * alt="The following text describes this graphic (Figure 1)." ALIGN=center> 0N/A * This layout consists of three components: 0N/A * <ul><li>A panel that starts in row 0 and ends in row 1. The panel 0N/A * has a baseline-resize behavior of <code>CONSTANT_DESCENT</code> and has 0N/A * an anchor of <code>BASELINE</code>. As the baseline-resize behavior 0N/A * is <code>CONSTANT_DESCENT</code> the prevailing row for the panel is 0N/A * <li>Two buttons, each with a baseline-resize behavior of 0N/A * <code>CENTER_OFFSET</code> and an anchor of <code>BASELINE</code>. 0N/A * Because the second button and the panel share the same prevailing row, 0N/A * they are both aligned along their baseline. 0N/A * Components positioned using one of the baseline-relative values resize 0N/A * differently than when positioned using an absolute or orientation-relative 0N/A * value. How components change is dictated by how the baseline of the 0N/A * prevailing row changes. The baseline is anchored to the 0N/A * bottom of the display area if any components with the same prevailing row 0N/A * have a baseline-resize behavior of <code>CONSTANT_DESCENT</code>, 0N/A * otherwise the baseline is anchored to the top of the display area. 0N/A * The following rules dictate the resize behavior: 0N/A * <li>Resizable components positioned above the baseline can only 0N/A * grow as tall as the baseline. For example, if the baseline is at 100 0N/A * and anchored at the top, a resizable component positioned above the 0N/A * baseline can never grow more than 100 units. 0N/A * <li>Similarly, resizable components positioned below the baseline can 0N/A * only grow as high as the difference between the display height and the 0N/A * <li>Resizable components positioned on the baseline with a 0N/A * baseline-resize behavior of <code>OTHER</code> are only resized if 0N/A * the baseline at the resized size fits within the display area. If 0N/A * the baseline is such that it does not fit within the display area 0N/A * the component is not resized. 0N/A * <li>Components positioned on the baseline that do not have a 0N/A * baseline-resize behavior of <code>OTHER</code> 0N/A * can only grow as tall as {@code display height - baseline + baseline of component}. 0N/A * If you position a component along the baseline, but the 0N/A * component does not have a valid baseline, it will be vertically centered 0N/A * in its space. Similarly if you have positioned a component relative 0N/A * to the baseline and none of the components in the row have a valid 0N/A * baseline the component is vertically centered. 0N/A * The following figures show ten components (all buttons) 0N/A * managed by a grid bag layout. Figure 2 shows the layout for a horizontal, 0N/A * left-to-right container and Figure 3 shows the layout for a horizontal, 0N/A * right-to-left container. 0N/A * <center><table COLS=2 WIDTH=600 summary="layout"> 0N/A * <td>Figure 2: Horizontal, Left-to-Right</td> 0N/A * <td>Figure 3: Horizontal, Right-to-Left</td> 0N/A * Each of the ten components has the <code>fill</code> field 0N/A * of its associated <code>GridBagConstraints</code> object 0N/A * set to <code>GridBagConstraints.BOTH</code>. 0N/A * In addition, the components have the following non-default constraints: 0N/A * <li>Button1, Button2, Button3: <code>weightx = 1.0</code> 0N/A * <li>Button4: <code>weightx = 1.0</code>, 0N/A * <code>gridwidth = GridBagConstraints.REMAINDER</code> 0N/A * <li>Button5: <code>gridwidth = GridBagConstraints.REMAINDER</code> 0N/A * <li>Button6: <code>gridwidth = GridBagConstraints.RELATIVE</code> 0N/A * <li>Button7: <code>gridwidth = GridBagConstraints.REMAINDER</code> 0N/A * <li>Button8: <code>gridheight = 2</code>, 0N/A * <code>weighty = 1.0</code> 0N/A * <li>Button9, Button 10: 0N/A * <code>gridwidth = GridBagConstraints.REMAINDER</code> 0N/A * Here is the code that implements the example shown above: 0N/A * <hr><blockquote><pre> 0N/A * import java.awt.*; 0N/A * import java.util.*; 0N/A * import java.applet.Applet; 0N/A * public class GridBagEx1 extends Applet { 0N/A * protected void makebutton(String name, 0N/A * GridBagLayout gridbag, 0N/A * GridBagConstraints c) { 0N/A * Button button = new Button(name); 0N/A * gridbag.setConstraints(button, c); 0N/A * public void init() { 0N/A * GridBagLayout gridbag = new GridBagLayout(); 0N/A * GridBagConstraints c = new GridBagConstraints(); 0N/A * setFont(new Font("SansSerif", Font.PLAIN, 14)); 0N/A * setLayout(gridbag); 0N/A * c.fill = GridBagConstraints.BOTH; 0N/A * makebutton("Button1", gridbag, c); 0N/A * makebutton("Button2", gridbag, c); 0N/A * makebutton("Button3", gridbag, c); 0N/A * c.gridwidth = GridBagConstraints.REMAINDER; //end row 0N/A * makebutton("Button4", gridbag, c); 0N/A * c.weightx = 0.0; //reset to the default 0N/A * makebutton("Button5", gridbag, c); //another row 0N/A * c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row 0N/A * makebutton("Button6", gridbag, c); 0N/A * c.gridwidth = GridBagConstraints.REMAINDER; //end row 0N/A * makebutton("Button7", gridbag, c); 0N/A * c.gridwidth = 1; //reset to the default 0N/A * makebutton("Button8", gridbag, c); 0N/A * c.weighty = 0.0; //reset to the default 0N/A * c.gridwidth = GridBagConstraints.REMAINDER; //end row 0N/A * c.gridheight = 1; //reset to the default 0N/A * makebutton("Button9", gridbag, c); 0N/A * makebutton("Button10", gridbag, c); 0N/A * setSize(300, 100); 0N/A * public static void main(String args[]) { 0N/A * Frame f = new Frame("GridBag Layout Example"); 0N/A * GridBagEx1 ex1 = new GridBagEx1(); 0N/A * f.add("Center", ex1); 0N/A * f.setSize(f.getPreferredSize()); 0N/A * </pre></blockquote><hr> 0N/A * @author Doug Stein 0N/A * @author Bill Spitzak (orignial NeWS & OLIT implementation) 0N/A * @see java.awt.GridBagConstraints 0N/A * @see java.awt.GridBagLayoutInfo 0N/A * @see java.awt.ComponentOrientation 0N/A * This field is no longer used to reserve arrays and keeped for backward 0N/A * compatibility. Previously, this was 0N/A * the maximum number of grid positions (both horizontal and 0N/A * vertical) that could be laid out by the grid bag layout. 0N/A * Current implementation doesn't impose any limits 0N/A * on the size of a grid. 0N/A * The smallest grid that can be laid out by the grid bag layout. 0N/A * The preferred grid size that can be laid out by the grid bag layout. 0N/A * This hashtable maintains the association between 0N/A * a component and its gridbag constraints. 0N/A * The Keys in <code>comptable</code> are the components and the 0N/A * values are the instances of <code>GridBagConstraints</code>. 0N/A * @see java.awt.GridBagConstraints 0N/A * This field holds a gridbag constraints instance 0N/A * containing the default values, so if a component 0N/A * does not have gridbag constraints associated with 0N/A * it, then the component will be assigned a 0N/A * copy of the <code>defaultConstraints</code>. 0N/A * @see #getConstraints(Component) 0N/A * @see #setConstraints(Component, GridBagConstraints) 0N/A * @see #lookupConstraints(Component) 0N/A * This field holds the layout information 0N/A * for the gridbag. The information in this field 0N/A * is based on the most recent validation of the 0N/A * If <code>layoutInfo</code> is <code>null</code> 0N/A * this indicates that there are no components in 0N/A * the gridbag or if there are components, they have 0N/A * not yet been validated. 0N/A * @see #getLayoutInfo(Container, int) 0N/A * This field holds the overrides to the column minimum 0N/A * width. If this field is non-<code>null</code> the values are 0N/A * applied to the gridbag after all of the minimum columns 0N/A * widths have been calculated. 0N/A * If columnWidths has more elements than the number of 0N/A * columns, columns are added to the gridbag to match 0N/A * the number of elements in columnWidth. 0N/A * @see #getLayoutDimensions() 0N/A * This field holds the overrides to the row minimum 0N/A * heights. If this field is non-<code>null</code> the values are 0N/A * applied to the gridbag after all of the minimum row 0N/A * heights have been calculated. 0N/A * If <code>rowHeights</code> has more elements than the number of 0N/A * rows, rowa are added to the gridbag to match 0N/A * the number of elements in <code>rowHeights</code>. 0N/A * @see #getLayoutDimensions() 0N/A * This field holds the overrides to the column weights. 0N/A * If this field is non-<code>null</code> the values are 0N/A * applied to the gridbag after all of the columns 0N/A * weights have been calculated. 0N/A * If <code>columnWeights[i]</code> > weight for column i, then 0N/A * column i is assigned the weight in <code>columnWeights[i]</code>. 0N/A * If <code>columnWeights</code> has more elements than the number 0N/A * of columns, the excess elements are ignored - they do 0N/A * not cause more columns to be created. 0N/A * This field holds the overrides to the row weights. 0N/A * If this field is non-<code>null</code> the values are 0N/A * applied to the gridbag after all of the rows 0N/A * weights have been calculated. 0N/A * If <code>rowWeights[i]</code> > weight for row i, then 0N/A * row i is assigned the weight in <code>rowWeights[i]</code>. 0N/A * If <code>rowWeights</code> has more elements than the number 0N/A * of rows, the excess elements are ignored - they do 0N/A * not cause more rows to be created. 0N/A * The component being positioned. This is set before calling into 0N/A * <code>adjustForGravity</code>. 0N/A * Creates a grid bag layout manager. 0N/A * Sets the constraints for the specified component in this layout. 0N/A * @param comp the component to be modified 0N/A * @param constraints the constraints to be applied 0N/A * Gets the constraints for the specified component. A copy of 0N/A * the actual <code>GridBagConstraints</code> object is returned. 0N/A * @param comp the component to be queried 0N/A * @return the constraint for the specified component in this 0N/A * grid bag layout; a copy of the actual constraint 0N/A * object is returned 0N/A * Retrieves the constraints for the specified component. 0N/A * The return value is not a copy, but is the actual 0N/A * <code>GridBagConstraints</code> object used by the layout mechanism. 0N/A * If <code>comp</code> is not in the <code>GridBagLayout</code>, 0N/A * a set of default <code>GridBagConstraints</code> are returned. 0N/A * A <code>comp</code> value of <code>null</code> is invalid 0N/A * and returns <code>null</code>. 0N/A * @param comp the component to be queried 0N/A * @return the contraints for the specified component 0N/A * Removes the constraints for the specified component in this layout 0N/A * @param comp the component to be modified 0N/A * Determines the origin of the layout area, in the graphics coordinate 0N/A * space of the target container. This value represents the pixel 0N/A * coordinates of the top-left corner of the layout area regardless of 0N/A * the <code>ComponentOrientation</code> value of the container. This 0N/A * is distinct from the grid origin given by the cell coordinates (0,0). 0N/A * Most applications do not call this method directly. 0N/A * @return the graphics origin of the cell in the top-left 0N/A * corner of the layout grid 0N/A * @see java.awt.ComponentOrientation 0N/A * Determines column widths and row heights for the layout grid. 0N/A * Most applications do not call this method directly. 0N/A * @return an array of two arrays, containing the widths 0N/A * of the layout columns and 0N/A * the heights of the layout rows 0N/A return new int[
2][
0];
0N/A * Determines the weights of the layout grid's columns and rows. 0N/A * Weights are used to calculate how much a given column or row 0N/A * stretches beyond its preferred size, if the layout has extra 0N/A * Most applications do not call this method directly. 0N/A * @return an array of two arrays, representing the 0N/A * horizontal weights of the layout columns 0N/A * and the vertical weights of the layout rows 0N/A return new double[
2][
0];
0N/A * Determines which cell in the layout grid contains the point 0N/A * specified by <code>(x, y)</code>. Each cell is identified 0N/A * by its column index (ranging from 0 to the number of columns 0N/A * minus 1) and its row index (ranging from 0 to the number of 0N/A * If the <code>(x, y)</code> point lies 0N/A * outside the grid, the following rules are used. 0N/A * The column index is returned as zero if <code>x</code> lies to the 0N/A * left of the layout for a left-to-right container or to the right of 0N/A * the layout for a right-to-left container. The column index is returned 0N/A * as the number of columns if <code>x</code> lies 0N/A * to the right of the layout in a left-to-right container or to the left 0N/A * in a right-to-left container. 0N/A * The row index is returned as zero if <code>y</code> lies above the 0N/A * layout, and as the number of rows if <code>y</code> lies 0N/A * below the layout. The orientation of a container is determined by its 0N/A * <code>ComponentOrientation</code> property. 0N/A * @param x the <i>x</i> coordinate of a point 0N/A * @param y the <i>y</i> coordinate of a point 0N/A * @return an ordered pair of indexes that indicate which cell 0N/A * in the layout grid contains the point 0N/A * (<i>x</i>, <i>y</i>). 0N/A * @see java.awt.ComponentOrientation 0N/A * Has no effect, since this layout manager does not use a per-component string. 0N/A * Adds the specified component to the layout, using the specified 0N/A * <code>constraints</code> object. Note that constraints 0N/A * are mutable and are, therefore, cloned when cached. 0N/A * @param comp the component to be added 0N/A * @param constraints an object that determines how 0N/A * the component is added to the layout 0N/A * @exception IllegalArgumentException if <code>constraints</code> 0N/A * is not a <code>GridBagConstraint</code> 0N/A * Removes the specified component from this layout. 0N/A * Most applications do not call this method directly. 0N/A * @param comp the component to be removed. 0N/A * @see java.awt.Container#remove(java.awt.Component) 0N/A * @see java.awt.Container#removeAll() 0N/A * Determines the preferred size of the <code>parent</code> 0N/A * container using this grid bag layout. 0N/A * Most applications do not call this method directly. 0N/A * @param parent the container in which to do the layout 0N/A * @see java.awt.Container#getPreferredSize 0N/A * @return the preferred size of the <code>parent</code> 0N/A * Determines the minimum size of the <code>parent</code> container 0N/A * using this grid bag layout. 0N/A * Most applications do not call this method directly. 0N/A * @param parent the container in which to do the layout 0N/A * @see java.awt.Container#doLayout 0N/A * @return the minimum size of the <code>parent</code> container 0N/A * Returns the maximum dimensions for this layout given the components 0N/A * in the specified target container. 0N/A * @param target the container which needs to be laid out 0N/A * @see #minimumLayoutSize(Container) 0N/A * @see #preferredLayoutSize(Container) 0N/A * @return the maximum dimensions for this layout 0N/A * Returns the alignment along the x axis. This specifies how 0N/A * the component would like to be aligned relative to other 0N/A * components. The value should be a number between 0 and 1 0N/A * where 0 represents alignment along the origin, 1 is aligned 0N/A * the furthest away from the origin, 0.5 is centered, etc. 0N/A * @return the value <code>0.5f</code> to indicate centered 0N/A * Returns the alignment along the y axis. This specifies how 0N/A * the component would like to be aligned relative to other 0N/A * components. The value should be a number between 0 and 1 0N/A * where 0 represents alignment along the origin, 1 is aligned 0N/A * the furthest away from the origin, 0.5 is centered, etc. 0N/A * @return the value <code>0.5f</code> to indicate centered 0N/A * Invalidates the layout, indicating that if the layout manager 0N/A * has cached information it should be discarded. 0N/A * Lays out the specified container using this grid bag layout. 0N/A * This method reshapes components in the specified container in 0N/A * order to satisfy the contraints of this <code>GridBagLayout</code> 0N/A * Most applications do not call this method directly. 0N/A * @param parent the container in which to do the layout 0N/A * @see java.awt.Container 0N/A * @see java.awt.Container#doLayout 0N/A * Returns a string representation of this grid bag layout's values. 0N/A * @return a string representation of this grid bag layout. 0N/A * Print the layout information. Useful for debugging. 0N/A * protected void dumpLayoutInfo(GridBagLayoutInfo s) { 0N/A * System.out.println("Col\tWidth\tWeight"); 0N/A * for (x=0; x<s.width; x++) { 0N/A * System.out.println(x + "\t" + 0N/A * s.minWidth[x] + "\t" + 0N/A * System.out.println("Row\tHeight\tWeight"); 0N/A * for (x=0; x<s.height; x++) { 0N/A * System.out.println(x + "\t" + 0N/A * s.minHeight[x] + "\t" + 0N/A * Print the layout constraints. Useful for debugging. 0N/A * protected void dumpConstraints(GridBagConstraints constraints) { 0N/A * System.out.println( 0N/A * constraints.weightx + 0N/A * constraints.weighty + 0N/A * constraints.gridx + 0N/A * constraints.gridy + 0N/A * constraints.gridwidth + 0N/A * constraints.gridheight + 0N/A * constraints.minWidth + 0N/A * constraints.minHeight + 0N/A * constraints.insets.bottom + 0N/A * constraints.insets.left + 0N/A * constraints.insets.right + 0N/A * constraints.insets.top + 0N/A * constraints.ipadx + 0N/A * constraints.ipady); 0N/A * Fills in an instance of <code>GridBagLayoutInfo</code> for the 0N/A * current set of managed children. This requires three passes through the 0N/A * <li>Figure out the dimensions of the layout grid. 0N/A * <li>Determine which cells the components occupy. 0N/A * This also caches the minsizes for all the children when they are 0N/A * first encountered (so subsequent loops don't need to ask again). 0N/A * This method should only be used internally by 0N/A * <code>GridBagLayout</code>. 0N/A * @param parent the layout container 0N/A * @param sizeflag either <code>PREFERREDSIZE</code> or 0N/A * <code>MINSIZE</code> 0N/A * @return the <code>GridBagLayoutInfo</code> for the set of children 0N/A * Calculate maximum array sizes to allocate arrays without ensureCapacity 0N/A * we may use preCalculated sizes in whole class because of upper estimation of 0N/A * maximumArrayXIndex and maximumArrayYIndex. 0N/A // -1==RELATIVE, means that column|row equals to previously added component, 0N/A // since each next Component with gridx|gridy == RELATIVE starts from 0N/A // previous position, so we should start from previous component which 0N/A // already used in maximumArray[X|Y]Index calculation. We could just increase 0N/A // maximum by 1 to handle situation when component with gridx=-1 was added. 0N/A // gridwidth|gridheight may be equal to RELATIVE (-1) or REMAINDER (0) 0N/A // in any case using 1 instead of 0 or -1 should be sufficient to for 0N/A // correct maximumArraySizes calculation 0N/A }
//for (components) loop 0N/A // Must specify index++ to allocate well-working arrays. 0N/A * now return long array instead of Point 0N/A }
//PreInitMaximumSizes 0N/A * This method is obsolete and supplied for backwards 0N/A * compatability only; new code should call {@link 0N/A * #getLayoutInfo(java.awt.Container, int) getLayoutInfo} instead. 0N/A * This method is the same as <code>getLayoutInfo</code>; 0N/A * refer to <code>getLayoutInfo</code> for details on parameters 0N/A // Code below will address index curX+curWidth in the case of yMaxArray, weightY 0N/A // ( respectively curY+curHeight for xMaxArray, weightX ) where 0N/A // curX in 0 to preInitMaximumArraySizes.y 0N/A // Thus, the maximum index that could 0N/A // be calculated in the following code is curX+curX. 0N/A // EmpericMultier equals 2 because of this. 0N/A * Figure out the dimensions of the layout grid (use a value of 1 for 0N/A * zero or negative widths and heights). 0N/A * If user try to create a very big grid we can 0N/A * get NegativeArraySizeException because of integer value 0N/A * overflow (EMPIRICMULTIPLIER*gridSize might be more then Integer.MAX_VALUE). 0N/A * We need to detect this situation and try to create a 0N/A * grid with Integer.MAX_VALUE size instead. 0N/A /* If x or y is negative, then use relative positioning: */ 0N/A /* Adjust the grid width and height 0N/A * fix for 5005945: unneccessary loops removed 0N/A /* Adjust xMaxArray and yMaxArray */ 0N/A /* Cache the current slave's size. */ 0N/A /* Zero width and height must mean that this is the last item (or 0N/A * else something is wrong). */ 0N/A /* Zero width starts a new row */ 0N/A /* Zero height starts a new column */ 0N/A }
//for (components) loop 0N/A * Negative values for gridX are filled in with the current x value. 0N/A * Negative values for gridY are filled in with the current y value. 0N/A * Negative or zero values for gridWidth and gridHeight end the current 0N/A * row or column, respectively. 0N/A /* If x or y is negative, then use relative positioning: */ 0N/A /* Assign the new values to the gridbag slave */ 0N/A // Component positioned above the baseline. 0N/A // To make the bottom edge of the component aligned 0N/A // with the baseline the bottom inset is 0N/A // added to the descent, the rest to the ascent. 0N/A // Component positioned below the baseline. 0N/A // To make the top edge of the component aligned 0N/A // with the baseline the top inset is 0N/A // added to the ascent, the rest to the descent. 0N/A * Distribute the minimun widths and weights: 0N/A * Figure out if we should use this slave\'s weight. If the weight 0N/A * is less than the total weight spanned by the width of the cell, 0N/A * then discard the weight. Otherwise split the difference 0N/A * according to the existing weights. 0N/A /* Assign the remainder to the rightmost cell */ 0N/A * Calculate the minWidth array values. 0N/A * First, figure out how wide the current slave needs to be. 0N/A * Then, see if it will fit within the current minWidth values. 0N/A * If it will not fit, add the difference according to the 0N/A /* Any leftovers go into the rightmost cell */ 0N/A * Figure out if we should use this slave's weight. If the weight 0N/A * is less than the total weight spanned by the height of the cell, 0N/A * then discard the weight. Otherwise split it the difference 0N/A * according to the existing weights. 0N/A /* Assign the remainder to the bottom cell */ 0N/A * Calculate the minHeight array values. 0N/A * First, figure out how tall the current slave needs to be. 0N/A * Then, see if it will fit within the current minHeight values. 0N/A * If it will not fit, add the difference according to the 0N/A /* Any leftovers go into the bottom cell */ 0N/A * Calculate the baseline for the specified component. 0N/A * If {@code c} is positioned along it's baseline, the baseline is 0N/A * obtained and the {@code constraints} ascent, descent and 0N/A * baseline resize behavior are set from the component; and true is 0N/A * returned. Otherwise false is returned. 0N/A // Apply the padding to the component, then ask for the baseline. 0N/A // Component has a baseline 0N/A // Adjust the ascent and descent to include the insets. 0N/A // Component has a baseline resize behavior of 0N/A // CENTER_OFFSET, calculate centerPadding and 0N/A // centerOffset (see the description of 0N/A // CENTER_OFFSET in the enum for detais on this 0N/A * Adjusts the x, y, width, and height fields to the correct 0N/A * values depending on the constraint geometry and pads. 0N/A * This method should only be used internally by 0N/A * <code>GridBagLayout</code>. 0N/A * @param constraints the constraints to be applied 0N/A * @param r the <code>Rectangle</code> to be adjusted 0N/A * This method is obsolete and supplied for backwards 0N/A * compatability only; new code should call {@link 0N/A * #adjustForGravity(java.awt.GridBagConstraints, java.awt.Rectangle) 0N/A * adjustForGravity} instead. 0N/A * This method is the same as <code>adjustForGravity</code>; 0N/A * refer to <code>adjustForGravity</code> for details 0N/A * Positions on the baseline. 0N/A * @param cellY the location of the row, does not include insets 0N/A * @param cellHeight the height of the row, does not take into account 0N/A * @param r available bounds for the component, is padded by insets and 0N/A // Anchor to the bottom. 0N/A // Baseline is at (cellY + cellHeight - maxDescent). 0N/A // Bottom of component (maxY) is at baseline + descent 0N/A // of component. We need to subtract the bottom inset here 0N/A // as the descent in the constraints object includes the 0N/A // Component not resizable, calculate y location 0N/A // from maxY - height. 0N/A // Component is resizable. As brb is constant descent, 0N/A // can expand component to fill region above baseline. 0N/A // Subtract out the top inset so that components insets 0N/A // BRB is not constant_descent 0N/A int baseline;
// baseline for the row, relative to cellY 0N/A // Component baseline, includes insets.top 0N/A // BRB is other, which means we can only determine 0N/A // the baseline by asking for it again giving the 0N/A // size we plan on using for the component. 0N/A // Component has a baseline, pad with top inset 0N/A // (this follows from calculateBaseline which 0N/A // Components baseline fits within rows baseline. 0N/A // Make sure the descent fits within the space as well. 0N/A // It fits, we're good. 0N/A // Doesn't fit, but it's resizable. Try 0N/A // again assuming we'll get ascent again. 0N/A // Doesn't fit, use min size and original ascent 0N/A // Reset the components y location based on 0N/A // components ascent and baseline for row. Because ascent 0N/A // includes the baseline 0N/A * Positions the specified component above the baseline. That is 0N/A * the bottom edge of the component will be aligned along the baseline. 0N/A * If the row does not have a baseline, this centers the component. 0N/A // Component is resizable. Top edge is offset by top 0N/A // inset, bottom edge on baseline. 0N/A * Positions below the baseline. 0N/A * Figures out the minimum size of the 0N/A * master based on the information from <code>getLayoutInfo</code>. 0N/A * This method should only be used internally by 0N/A * <code>GridBagLayout</code>. 0N/A * @param parent the layout container 0N/A * @param info the layout info for this parent 0N/A * @return a <code>Dimension</code> object containing the 0N/A * This method is obsolete and supplied for backwards 0N/A * compatability only; new code should call {@link 0N/A * #getMinSize(java.awt.Container, GridBagLayoutInfo) getMinSize} instead. 0N/A * This method is the same as <code>getMinSize</code>; 0N/A * refer to <code>getMinSize</code> for details on parameters 0N/A * Lays out the grid. 0N/A * This method should only be used internally by 0N/A * <code>GridBagLayout</code>. 0N/A * @param parent the layout container 0N/A * This method is obsolete and supplied for backwards 0N/A * compatability only; new code should call {@link 0N/A * #arrangeGrid(Container) arrangeGrid} instead. 0N/A * This method is the same as <code>arrangeGrid</code>; 0N/A * refer to <code>arrangeGrid</code> for details on the 0N/A * If the parent has no slaves anymore, then don't do anything 0N/A * at all: just leave the parent's size as-is. 0N/A * Pass #1: scan all the slaves to figure out the total amount 0N/A * DumpLayoutInfo(info); 0N/A * for (compindex = 0 ; compindex < components.length ; compindex++) { 0N/A * comp = components[compindex]; 0N/A * if (!comp.isVisible()) 0N/A * constraints = lookupConstraints(comp); 0N/A * DumpConstraints(constraints); 0N/A * System.out.println("minSize " + r.width + " " + r.height); 0N/A * If the current dimensions of the window don't match the desired 0N/A * dimensions, then adjust the minWidth and minHeight arrays 0N/A * according to the weights. 0N/A * System.out.println("Re-adjusted:"); 0N/A * DumpLayoutInfo(info); 0N/A * Now do the actual layout of the slaves using the layout information 0N/A * that has been collected. 0N/A /* fix for 4408108 - components were being created outside of the container */ 0N/A /* fix for 4969409 "-" replaced by "+" */ 0N/A * If the window is too small to be interesting then 0N/A * unmap it. Otherwise configure it and then make sure 0N/A // Added for serial backwards compatability (4348425)