jdk/src/share/classes/java/awt/GridBagLayout.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 21244 7c2ac5ca05a2
child 21957 97758de70fbd
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * The <code>GridBagLayout</code> class is a flexible layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * manager that aligns components vertically, horizontally or along their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * baseline without requiring that the components be of the same size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Each <code>GridBagLayout</code> object maintains a dynamic,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * rectangular grid of cells, with each component occupying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * one or more cells, called its <em>display area</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Each component managed by a <code>GridBagLayout</code> is associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * an instance of {@link GridBagConstraints}.  The constraints object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * specifies where a component's display area should be located on the grid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * and how the component should be positioned within its display area.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * addition to its constraints object, the <code>GridBagLayout</code> also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * considers each component's minimum and preferred sizes in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * determine a component's size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The overall orientation of the grid depends on the container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * {@link ComponentOrientation} property.  For horizontal left-to-right
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * orientations, grid coordinate (0,0) is in the upper left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * container with x increasing to the right and y increasing downward.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * horizontal right-to-left orientations, grid coordinate (0,0) is in the upper
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * right corner of the container with x increasing to the left and y
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * increasing downward.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * To use a grid bag layout effectively, you must customize one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * of the <code>GridBagConstraints</code> objects that are associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * with its components. You customize a <code>GridBagConstraints</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * object by setting one or more of its instance variables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <dt>{@link GridBagConstraints#gridx},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * {@link GridBagConstraints#gridy}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <dd>Specifies the cell containing the leading corner of the component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * display area, where the cell at the origin of the grid has address
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <code>gridx&nbsp;=&nbsp;0</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <code>gridy&nbsp;=&nbsp;0</code>.  For horizontal left-to-right layout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * a component's leading corner is its upper left.  For horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * right-to-left layout, a component's leading corner is its upper right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Use <code>GridBagConstraints.RELATIVE</code> (the default value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * to specify that the component be placed immediately following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * (along the x axis for <code>gridx</code> or the y axis for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <code>gridy</code>) the component that was added to the container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * just before this component was added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <dt>{@link GridBagConstraints#gridwidth},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * {@link GridBagConstraints#gridheight}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <dd>Specifies the number of cells in a row (for <code>gridwidth</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * or column (for <code>gridheight</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * in the component's display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * The default value is 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Use <code>GridBagConstraints.REMAINDER</code> to specify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * that the component's display area will be from <code>gridx</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * to the last cell in the row (for <code>gridwidth</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * or from <code>gridy</code> to the last cell in the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * (for <code>gridheight</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Use <code>GridBagConstraints.RELATIVE</code> to specify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * that the component's display area will be from <code>gridx</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * to the next to the last cell in its row (for <code>gridwidth</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * or from <code>gridy</code> to the next to the last cell in its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * column (for <code>gridheight</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <dt>{@link GridBagConstraints#fill}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <dd>Used when the component's display area
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * is larger than the component's requested size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * to determine whether (and how) to resize the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * Possible values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <code>GridBagConstraints.NONE</code> (the default),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <code>GridBagConstraints.HORIZONTAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * (make the component wide enough to fill its display area
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * horizontally, but don't change its height),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <code>GridBagConstraints.VERTICAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * (make the component tall enough to fill its display area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * vertically, but don't change its width), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <code>GridBagConstraints.BOTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * (make the component fill its display area entirely).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <dt>{@link GridBagConstraints#ipadx},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * {@link GridBagConstraints#ipady}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <dd>Specifies the component's internal padding within the layout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * how much to add to the minimum size of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * The width of the component will be at least its minimum width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * plus <code>ipadx</code> pixels. Similarly, the height of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * the component will be at least the minimum height plus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <code>ipady</code> pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * <dt>{@link GridBagConstraints#insets}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <dd>Specifies the component's external padding, the minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * amount of space between the component and the edges of its display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <dt>{@link GridBagConstraints#anchor}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <dd>Specifies where the component should be positioned in its display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * There are three kinds of possible values: absolute, orientation-relative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * and baseline-relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * Orientation relative values are interpreted relative to the container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <code>ComponentOrientation</code> property while absolute values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * are not.  Baseline relative values are calculated relative to the
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   123
 * baseline.  Valid values are:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <p>
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   125
 * <center><table BORDER=0 WIDTH=800
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *        SUMMARY="absolute, relative and baseline values as described above">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * <tr>
21244
7c2ac5ca05a2 8026021: more fix of javadoc errors and warnings reported by doclint, see the description
cl
parents: 20451
diff changeset
   128
 * <th><P style="text-align:left">Absolute Values</th>
7c2ac5ca05a2 8026021: more fix of javadoc errors and warnings reported by doclint, see the description
cl
parents: 20451
diff changeset
   129
 * <th><P style="text-align:left">Orientation Relative Values</th>
7c2ac5ca05a2 8026021: more fix of javadoc errors and warnings reported by doclint, see the description
cl
parents: 20451
diff changeset
   130
 * <th><P style="text-align:left">Baseline Relative Values</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * <td>
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   134
 * <ul style="list-style-type:none">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <li><code>GridBagConstraints.NORTH</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <li><code>GridBagConstraints.SOUTH</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * <li><code>GridBagConstraints.WEST</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * <li><code>GridBagConstraints.EAST</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * <li><code>GridBagConstraints.NORTHWEST</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <li><code>GridBagConstraints.NORTHEAST</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <li><code>GridBagConstraints.SOUTHWEST</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * <li><code>GridBagConstraints.SOUTHEAST</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <li><code>GridBagConstraints.CENTER</code> (the default)</li>
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   144
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <td>
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   147
 * <ul style="list-style-type:none">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <li><code>GridBagConstraints.PAGE_START</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * <li><code>GridBagConstraints.PAGE_END</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <li><code>GridBagConstraints.LINE_START</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * <li><code>GridBagConstraints.LINE_END</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <li><code>GridBagConstraints.FIRST_LINE_START</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * <li><code>GridBagConstraints.FIRST_LINE_END</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * <li><code>GridBagConstraints.LAST_LINE_START</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * <li><code>GridBagConstraints.LAST_LINE_END</code></li>
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   156
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * <td>
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   159
 * <ul style="list-style-type:none">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * <li><code>GridBagConstraints.BASELINE</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * <li><code>GridBagConstraints.BASELINE_LEADING</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * <li><code>GridBagConstraints.BASELINE_TRAILING</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * <li><code>GridBagConstraints.ABOVE_BASELINE</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * <li><code>GridBagConstraints.ABOVE_BASELINE_LEADING</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * <li><code>GridBagConstraints.ABOVE_BASELINE_TRAILING</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * <li><code>GridBagConstraints.BELOW_BASELINE</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * <li><code>GridBagConstraints.BELOW_BASELINE_LEADING</code></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * <li><code>GridBagConstraints.BELOW_BASELINE_TRAILING</code></li>
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   169
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * </tr>
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   172
 * </table></center>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * <dt>{@link GridBagConstraints#weightx},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * {@link GridBagConstraints#weighty}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * <dd>Used to determine how to distribute space, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * important for specifying resizing behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * Unless you specify a weight for at least one component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * in a row (<code>weightx</code>) and column (<code>weighty</code>),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * all the components clump together in the center of their container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * This is because when the weight is zero (the default),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * the <code>GridBagLayout</code> object puts any extra space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * between its grid of cells and the edges of the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * Each row may have a baseline; the baseline is determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * components in that row that have a valid baseline and are aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * along the baseline (the component's anchor value is one of {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * BASELINE}, {@code BASELINE_LEADING} or {@code BASELINE_TRAILING}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * If none of the components in the row has a valid baseline, the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * does not have a baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * If a component spans rows it is aligned either to the baseline of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * the start row (if the baseline-resize behavior is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * CONSTANT_ASCENT}) or the end row (if the baseline-resize behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * is {@code CONSTANT_DESCENT}).  The row that the component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * aligned to is called the <em>prevailing row</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * The following figure shows a baseline layout and includes a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * component that spans rows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * <center><table summary="Baseline Layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * <tr ALIGN=CENTER>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * <td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * <img src="doc-files/GridBagLayout-baseline.png"
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20172
diff changeset
   204
 *  alt="The following text describes this graphic (Figure 1)." style="float:center">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * </table></center>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * This layout consists of three components:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * <ul><li>A panel that starts in row 0 and ends in row 1.  The panel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 *   has a baseline-resize behavior of <code>CONSTANT_DESCENT</code> and has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 *   an anchor of <code>BASELINE</code>.  As the baseline-resize behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *   is <code>CONSTANT_DESCENT</code> the prevailing row for the panel is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 *   row 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * <li>Two buttons, each with a baseline-resize behavior of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 *   <code>CENTER_OFFSET</code> and an anchor of <code>BASELINE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * Because the second button and the panel share the same prevailing row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * they are both aligned along their baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * Components positioned using one of the baseline-relative values resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * differently than when positioned using an absolute or orientation-relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * value.  How components change is dictated by how the baseline of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * prevailing row changes.  The baseline is anchored to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * bottom of the display area if any components with the same prevailing row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * have a baseline-resize behavior of <code>CONSTANT_DESCENT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * otherwise the baseline is anchored to the top of the display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * The following rules dictate the resize behavior:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * <li>Resizable components positioned above the baseline can only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * grow as tall as the baseline.  For example, if the baseline is at 100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * and anchored at the top, a resizable component positioned above the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 * baseline can never grow more than 100 units.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * <li>Similarly, resizable components positioned below the baseline can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * only grow as high as the difference between the display height and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * <li>Resizable components positioned on the baseline with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 * baseline-resize behavior of <code>OTHER</code> are only resized if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * the baseline at the resized size fits within the display area.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * the baseline is such that it does not fit within the display area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * the component is not resized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 * <li>Components positioned on the baseline that do not have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * baseline-resize behavior of <code>OTHER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * can only grow as tall as {@code display height - baseline + baseline of component}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * If you position a component along the baseline, but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * component does not have a valid baseline, it will be vertically centered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * in its space.  Similarly if you have positioned a component relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 * to the baseline and none of the components in the row have a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * baseline the component is vertically centered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * The following figures show ten components (all buttons)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * managed by a grid bag layout.  Figure 2 shows the layout for a horizontal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * left-to-right container and Figure 3 shows the layout for a horizontal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * right-to-left container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 * <p>
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   255
 * <center><table WIDTH=600 summary="layout">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * <tr ALIGN=CENTER>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * <td>
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   258
 * <img src="doc-files/GridBagLayout-1.gif" alt="The preceding text describes this graphic (Figure 1)." style="float:center; margin: 7px 10px;">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * <td>
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   261
 * <img src="doc-files/GridBagLayout-2.gif" alt="The preceding text describes this graphic (Figure 2)." style="float:center; margin: 7px 10px;">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * <tr ALIGN=CENTER>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * <td>Figure 2: Horizontal, Left-to-Right</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * <td>Figure 3: Horizontal, Right-to-Left</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * </table></center>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * Each of the ten components has the <code>fill</code> field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * of its associated <code>GridBagConstraints</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * set to <code>GridBagConstraints.BOTH</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * In addition, the components have the following non-default constraints:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * <li>Button1, Button2, Button3: <code>weightx&nbsp;=&nbsp;1.0</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * <li>Button4: <code>weightx&nbsp;=&nbsp;1.0</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * <code>gridwidth&nbsp;=&nbsp;GridBagConstraints.REMAINDER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * <li>Button5: <code>gridwidth&nbsp;=&nbsp;GridBagConstraints.REMAINDER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * <li>Button6: <code>gridwidth&nbsp;=&nbsp;GridBagConstraints.RELATIVE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * <li>Button7: <code>gridwidth&nbsp;=&nbsp;GridBagConstraints.REMAINDER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * <li>Button8: <code>gridheight&nbsp;=&nbsp;2</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * <code>weighty&nbsp;=&nbsp;1.0</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 * <li>Button9, Button 10:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * <code>gridwidth&nbsp;=&nbsp;GridBagConstraints.REMAINDER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * Here is the code that implements the example shown above:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 * <hr><blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * public class GridBagEx1 extends Applet {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 *     protected void makebutton(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 *                               GridBagLayout gridbag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 *                               GridBagConstraints c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 *         Button button = new Button(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 *         gridbag.setConstraints(button, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 *         add(button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 *     public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 *         GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 *         GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 *         setFont(new Font("SansSerif", Font.PLAIN, 14));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 *         setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
 *         c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 *         c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 *         makebutton("Button1", gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
 *         makebutton("Button2", gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 *         makebutton("Button3", gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
 *         c.gridwidth = GridBagConstraints.REMAINDER; //end row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
 *         makebutton("Button4", gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 *         c.weightx = 0.0;                //reset to the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
 *         makebutton("Button5", gridbag, c); //another row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
 *         c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 *         makebutton("Button6", gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 *         c.gridwidth = GridBagConstraints.REMAINDER; //end row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 *         makebutton("Button7", gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 *         c.gridwidth = 1;                //reset to the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 *         c.gridheight = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 *         c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 *         makebutton("Button8", gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
 *         c.weighty = 0.0;                //reset to the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
 *         c.gridwidth = GridBagConstraints.REMAINDER; //end row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
 *         c.gridheight = 1;               //reset to the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
 *         makebutton("Button9", gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
 *         makebutton("Button10", gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
 *         setSize(300, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
 *     public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
 *         Frame f = new Frame("GridBag Layout Example");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
 *         GridBagEx1 ex1 = new GridBagEx1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
 *         ex1.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
 *         f.add("Center", ex1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
 *         f.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
 *         f.setSize(f.getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
 *         f.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
 * </pre></blockquote><hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
 * @author Doug Stein
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 5506
diff changeset
   358
 * @author Bill Spitzak (orignial NeWS &amp; OLIT implementation)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
 * @see       java.awt.GridBagConstraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
 * @see       java.awt.GridBagLayoutInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
 * @see       java.awt.ComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
public class GridBagLayout implements LayoutManager2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    static final int EMPIRICMULTIPLIER = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   369
     * This field is no longer used to reserve arrays and kept for backward
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * compatibility. Previously, this was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * the maximum number of grid positions (both horizontal and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * vertical) that could be laid out by the grid bag layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Current implementation doesn't impose any limits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * on the size of a grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    protected static final int MAXGRIDSIZE = 512;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * The smallest grid that can be laid out by the grid bag layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    protected static final int MINSIZE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * The preferred grid size that can be laid out by the grid bag layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    protected static final int PREFERREDSIZE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * This hashtable maintains the association between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * a component and its gridbag constraints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * The Keys in <code>comptable</code> are the components and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * values are the instances of <code>GridBagConstraints</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see java.awt.GridBagConstraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    protected Hashtable<Component,GridBagConstraints> comptable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * This field holds a gridbag constraints instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * containing the default values, so if a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * does not have gridbag constraints associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * it, then the component will be assigned a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * copy of the <code>defaultConstraints</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @see #getConstraints(Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @see #setConstraints(Component, GridBagConstraints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @see #lookupConstraints(Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    protected GridBagConstraints defaultConstraints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * This field holds the layout information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * for the gridbag.  The information in this field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * is based on the most recent validation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * gridbag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * If <code>layoutInfo</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * this indicates that there are no components in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * the gridbag or if there are components, they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * not yet been validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @see #getLayoutInfo(Container, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    protected GridBagLayoutInfo layoutInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * This field holds the overrides to the column minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * width.  If this field is non-<code>null</code> the values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * applied to the gridbag after all of the minimum columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * widths have been calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * If columnWidths has more elements than the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * columns, columns are added to the gridbag to match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * the number of elements in columnWidth.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see #getLayoutDimensions()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public int columnWidths[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * This field holds the overrides to the row minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * heights.  If this field is non-<code>null</code> the values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * applied to the gridbag after all of the minimum row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * heights have been calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * If <code>rowHeights</code> has more elements than the number of
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   447
     * rows, rows are added to the gridbag to match
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * the number of elements in <code>rowHeights</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @see #getLayoutDimensions()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public int rowHeights[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * This field holds the overrides to the column weights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * If this field is non-<code>null</code> the values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * applied to the gridbag after all of the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * weights have been calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * If <code>columnWeights[i]</code> &gt; weight for column i, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * column i is assigned the weight in <code>columnWeights[i]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * If <code>columnWeights</code> has more elements than the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * of columns, the excess elements are ignored - they do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * not cause more columns to be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public double columnWeights[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * This field holds the overrides to the row weights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * If this field is non-<code>null</code> the values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * applied to the gridbag after all of the rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * weights have been calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * If <code>rowWeights[i]</code> &gt; weight for row i, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * row i is assigned the weight in <code>rowWeights[i]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * If <code>rowWeights</code> has more elements than the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * of rows, the excess elements are ignored - they do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * not cause more rows to be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public double rowWeights[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * The component being positioned.  This is set before calling into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * <code>adjustForGravity</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    private Component componentAdjusting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * Creates a grid bag layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public GridBagLayout () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        comptable = new Hashtable<Component,GridBagConstraints>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        defaultConstraints = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Sets the constraints for the specified component in this layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @param       comp the component to be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @param       constraints the constraints to be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public void setConstraints(Component comp, GridBagConstraints constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        comptable.put(comp, (GridBagConstraints)constraints.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * Gets the constraints for the specified component.  A copy of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * the actual <code>GridBagConstraints</code> object is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @param       comp the component to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @return      the constraint for the specified component in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *                  grid bag layout; a copy of the actual constraint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *                  object is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public GridBagConstraints getConstraints(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        GridBagConstraints constraints = comptable.get(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if (constraints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            setConstraints(comp, defaultConstraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            constraints = comptable.get(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        return (GridBagConstraints)constraints.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Retrieves the constraints for the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * The return value is not a copy, but is the actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * <code>GridBagConstraints</code> object used by the layout mechanism.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * If <code>comp</code> is not in the <code>GridBagLayout</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * a set of default <code>GridBagConstraints</code> are returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * A <code>comp</code> value of <code>null</code> is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * and returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @param       comp the component to be queried
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   536
     * @return      the constraints for the specified component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    protected GridBagConstraints lookupConstraints(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        GridBagConstraints constraints = comptable.get(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        if (constraints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            setConstraints(comp, defaultConstraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            constraints = comptable.get(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        return constraints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * Removes the constraints for the specified component in this layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @param       comp the component to be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    private void removeConstraints(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        comptable.remove(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * Determines the origin of the layout area, in the graphics coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * space of the target container.  This value represents the pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * coordinates of the top-left corner of the layout area regardless of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * the <code>ComponentOrientation</code> value of the container.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * is distinct from the grid origin given by the cell coordinates (0,0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * Most applications do not call this method directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @return     the graphics origin of the cell in the top-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *             corner of the layout grid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @see        java.awt.ComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public Point getLayoutOrigin () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        Point origin = new Point(0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        if (layoutInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            origin.x = layoutInfo.startx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            origin.y = layoutInfo.starty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        return origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * Determines column widths and row heights for the layout grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * Most applications do not call this method directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @return     an array of two arrays, containing the widths
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *                       of the layout columns and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *                       the heights of the layout rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    public int [][] getLayoutDimensions () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        if (layoutInfo == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            return new int[2][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        int dim[][] = new int [2][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        dim[0] = new int[layoutInfo.width];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        dim[1] = new int[layoutInfo.height];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        System.arraycopy(layoutInfo.minWidth, 0, dim[0], 0, layoutInfo.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        System.arraycopy(layoutInfo.minHeight, 0, dim[1], 0, layoutInfo.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * Determines the weights of the layout grid's columns and rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Weights are used to calculate how much a given column or row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * stretches beyond its preferred size, if the layout has extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * room to fill.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * Most applications do not call this method directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @return      an array of two arrays, representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *                    horizontal weights of the layout columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     *                    and the vertical weights of the layout rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    public double [][] getLayoutWeights () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        if (layoutInfo == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            return new double[2][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        double weights[][] = new double [2][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        weights[0] = new double[layoutInfo.width];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        weights[1] = new double[layoutInfo.height];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        System.arraycopy(layoutInfo.weightX, 0, weights[0], 0, layoutInfo.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        System.arraycopy(layoutInfo.weightY, 0, weights[1], 0, layoutInfo.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        return weights;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * Determines which cell in the layout grid contains the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * specified by <code>(x,&nbsp;y)</code>. Each cell is identified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * by its column index (ranging from 0 to the number of columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * minus 1) and its row index (ranging from 0 to the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * rows minus 1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * If the <code>(x,&nbsp;y)</code> point lies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * outside the grid, the following rules are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * The column index is returned as zero if <code>x</code> lies to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * left of the layout for a left-to-right container or to the right of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * the layout for a right-to-left container.  The column index is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * as the number of columns if <code>x</code> lies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * to the right of the layout in a left-to-right container or to the left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * in a right-to-left container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * The row index is returned as zero if <code>y</code> lies above the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * layout, and as the number of rows if <code>y</code> lies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * below the layout.  The orientation of a container is determined by its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * <code>ComponentOrientation</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @param      x    the <i>x</i> coordinate of a point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @param      y    the <i>y</i> coordinate of a point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @return     an ordered pair of indexes that indicate which cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *             in the layout grid contains the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *             (<i>x</i>,&nbsp;<i>y</i>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @see        java.awt.ComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    public Point location(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        Point loc = new Point(0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        int i, d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        if (layoutInfo == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            return loc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        d = layoutInfo.startx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        if (!rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            for (i=0; i<layoutInfo.width; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                d += layoutInfo.minWidth[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                if (d > x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            for (i=layoutInfo.width-1; i>=0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                if (d > x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                d += layoutInfo.minWidth[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        loc.x = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        d = layoutInfo.starty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        for (i=0; i<layoutInfo.height; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            d += layoutInfo.minHeight[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (d > y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        loc.y = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        return loc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * Has no effect, since this layout manager does not use a per-component string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    public void addLayoutComponent(String name, Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * Adds the specified component to the layout, using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * <code>constraints</code> object.  Note that constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * are mutable and are, therefore, cloned when cached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @param      comp         the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @param      constraints  an object that determines how
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *                          the component is added to the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @exception IllegalArgumentException if <code>constraints</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *            is not a <code>GridBagConstraint</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    public void addLayoutComponent(Component comp, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        if (constraints instanceof GridBagConstraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            setConstraints(comp, (GridBagConstraints)constraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        } else if (constraints != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            throw new IllegalArgumentException("cannot add to layout: constraints must be a GridBagConstraint");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * Removes the specified component from this layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * Most applications do not call this method directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @param    comp   the component to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @see      java.awt.Container#remove(java.awt.Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @see      java.awt.Container#removeAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    public void removeLayoutComponent(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        removeConstraints(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * Determines the preferred size of the <code>parent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * container using this grid bag layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Most applications do not call this method directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * @param     parent   the container in which to do the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @see       java.awt.Container#getPreferredSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @return the preferred size of the <code>parent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *  container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    public Dimension preferredLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        GridBagLayoutInfo info = getLayoutInfo(parent, PREFERREDSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        return getMinSize(parent, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * Determines the minimum size of the <code>parent</code> container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * using this grid bag layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * Most applications do not call this method directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @param     parent   the container in which to do the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @see       java.awt.Container#doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @return the minimum size of the <code>parent</code> container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public Dimension minimumLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        GridBagLayoutInfo info = getLayoutInfo(parent, MINSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        return getMinSize(parent, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * Returns the maximum dimensions for this layout given the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * in the specified target container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @param target the container which needs to be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * @see Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * @see #minimumLayoutSize(Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @see #preferredLayoutSize(Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @return the maximum dimensions for this layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    public Dimension maximumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * Returns the alignment along the x axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * the furthest away from the origin, 0.5 is centered, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * @return the value <code>0.5f</code> to indicate centered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    public float getLayoutAlignmentX(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        return 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * Returns the alignment along the y axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * the furthest away from the origin, 0.5 is centered, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * @return the value <code>0.5f</code> to indicate centered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    public float getLayoutAlignmentY(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        return 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * Invalidates the layout, indicating that if the layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * has cached information it should be discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    public void invalidateLayout(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * Lays out the specified container using this grid bag layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * This method reshapes components in the specified container in
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   803
     * order to satisfy the constraints of this <code>GridBagLayout</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * Most applications do not call this method directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * @param parent the container in which to do the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @see java.awt.Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @see java.awt.Container#doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    public void layoutContainer(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        arrangeGrid(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * Returns a string representation of this grid bag layout's values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @return     a string representation of this grid bag layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        return getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * Print the layout information.  Useful for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    /* DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     *  protected void dumpLayoutInfo(GridBagLayoutInfo s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *    int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     *    System.out.println("Col\tWidth\tWeight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     *    for (x=0; x<s.width; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *      System.out.println(x + "\t" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     *                   s.minWidth[x] + "\t" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     *                   s.weightX[x]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     *    System.out.println("Row\tHeight\tWeight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     *    for (x=0; x<s.height; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     *      System.out.println(x + "\t" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     *                   s.minHeight[x] + "\t" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     *                   s.weightY[x]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * Print the layout constraints.  Useful for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    /* DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     *  protected void dumpConstraints(GridBagConstraints constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *    System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *                 "wt " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *                 constraints.weightx +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     *                 " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *                 constraints.weighty +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *                 ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     *                 "box " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *                 constraints.gridx +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     *                 " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *                 constraints.gridy +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     *                 " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     *                 constraints.gridwidth +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     *                 " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     *                 constraints.gridheight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     *                 ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     *                 "min " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     *                 constraints.minWidth +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     *                 " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     *                 constraints.minHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     *                 ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     *                 "pad " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     *                 constraints.insets.bottom +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     *                 " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *                 constraints.insets.left +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *                 " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *                 constraints.insets.right +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     *                 " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *                 constraints.insets.top +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *                 " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     *                 constraints.ipadx +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     *                 " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     *                 constraints.ipady);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     *  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * Fills in an instance of <code>GridBagLayoutInfo</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * current set of managed children. This requires three passes through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * set of children:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * <li>Figure out the dimensions of the layout grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * <li>Determine which cells the components occupy.
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   900
     * <li>Distribute the weights and min sizes among the rows/columns.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * This also caches the minsizes for all the children when they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * first encountered (so subsequent loops don't need to ask again).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * This method should only be used internally by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * <code>GridBagLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * @param parent  the layout container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * @param sizeflag either <code>PREFERREDSIZE</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     *   <code>MINSIZE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @return the <code>GridBagLayoutInfo</code> for the set of children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    protected GridBagLayoutInfo getLayoutInfo(Container parent, int sizeflag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        return GetLayoutInfo(parent, sizeflag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * Calculate maximum array sizes to allocate arrays without ensureCapacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * we may use preCalculated sizes in whole class because of upper estimation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * maximumArrayXIndex and maximumArrayYIndex.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    private long[]  preInitMaximumArraySizes(Container parent){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        Component components[] = parent.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        GridBagConstraints constraints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        int curX, curY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        int curWidth, curHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        int preMaximumArrayXIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        int preMaximumArrayYIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        long [] returnArray = new long[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        for (int compId = 0 ; compId < components.length ; compId++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            comp = components[compId];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            if (!comp.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            constraints = lookupConstraints(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            curX = constraints.gridx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            curY = constraints.gridy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            curWidth = constraints.gridwidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            curHeight = constraints.gridheight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            // -1==RELATIVE, means that column|row equals to previously added component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            // since each next Component with gridx|gridy == RELATIVE starts from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            // previous position, so we should start from previous component which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            // already used in maximumArray[X|Y]Index calculation. We could just increase
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            // maximum by 1 to handle situation when component with gridx=-1 was added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            if (curX < 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                curX = ++preMaximumArrayYIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            if (curY < 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                curY = ++preMaximumArrayXIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            // gridwidth|gridheight may be equal to RELATIVE (-1) or REMAINDER (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            // in any case using 1 instead of 0 or -1 should be sufficient to for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            // correct maximumArraySizes calculation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            if (curWidth <= 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                curWidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            if (curHeight <= 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                curHeight = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            preMaximumArrayXIndex = Math.max(curY + curHeight, preMaximumArrayXIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            preMaximumArrayYIndex = Math.max(curX + curWidth, preMaximumArrayYIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        } //for (components) loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        // Must specify index++ to allocate well-working arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        /* fix for 4623196.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
         * now return long array instead of Point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        returnArray[0] = preMaximumArrayXIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        returnArray[1] = preMaximumArrayYIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        return returnArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    } //PreInitMaximumSizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * This method is obsolete and supplied for backwards
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
   982
     * compatibility only; new code should call {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * #getLayoutInfo(java.awt.Container, int) getLayoutInfo} instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * This method is the same as <code>getLayoutInfo</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * refer to <code>getLayoutInfo</code> for details on parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * and return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    protected GridBagLayoutInfo GetLayoutInfo(Container parent, int sizeflag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        synchronized (parent.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            GridBagLayoutInfo r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            GridBagConstraints constraints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            Dimension d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            Component components[] = parent.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            // Code below will address index curX+curWidth in the case of yMaxArray, weightY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            // ( respectively curY+curHeight for xMaxArray, weightX ) where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            //  curX in 0 to preInitMaximumArraySizes.y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            // Thus, the maximum index that could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            // be calculated in the following code is curX+curX.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            // EmpericMultier equals 2 because of this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            int layoutWidth, layoutHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            int []xMaxArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            int []yMaxArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            int compindex, i, k, px, py, pixels_diff, nextSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            int curX = 0; // constraints.gridx
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            int curY = 0; // constraints.gridy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            int curWidth = 1;  // constraints.gridwidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            int curHeight = 1;  // constraints.gridheight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            int curRow, curCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            double weight_diff, weight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            int maximumArrayXIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            int maximumArrayYIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            int anchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
             * Pass #1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
             * Figure out the dimensions of the layout grid (use a value of 1 for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
             * zero or negative widths and heights).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            layoutWidth = layoutHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            curRow = curCol = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            long [] arraySizes = preInitMaximumArraySizes(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            /* fix for 4623196.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
             * If user try to create a very big grid we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
             * get NegativeArraySizeException because of integer value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
             * overflow (EMPIRICMULTIPLIER*gridSize might be more then Integer.MAX_VALUE).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
             * We need to detect this situation and try to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
             * grid with Integer.MAX_VALUE size instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            maximumArrayXIndex = (EMPIRICMULTIPLIER * arraySizes[0] > Integer.MAX_VALUE )? Integer.MAX_VALUE : EMPIRICMULTIPLIER*(int)arraySizes[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            maximumArrayYIndex = (EMPIRICMULTIPLIER * arraySizes[1] > Integer.MAX_VALUE )? Integer.MAX_VALUE : EMPIRICMULTIPLIER*(int)arraySizes[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            if (rowHeights != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                maximumArrayXIndex = Math.max(maximumArrayXIndex, rowHeights.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            if (columnWidths != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                maximumArrayYIndex = Math.max(maximumArrayYIndex, columnWidths.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            xMaxArray = new int[maximumArrayXIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            yMaxArray = new int[maximumArrayYIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            boolean hasBaseline = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            for (compindex = 0 ; compindex < components.length ; compindex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                comp = components[compindex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                if (!comp.isVisible())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                constraints = lookupConstraints(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                curX = constraints.gridx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                curY = constraints.gridy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                curWidth = constraints.gridwidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                if (curWidth <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                    curWidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                curHeight = constraints.gridheight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                if (curHeight <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                    curHeight = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                /* If x or y is negative, then use relative positioning: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                if (curX < 0 && curY < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                    if (curRow >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                        curY = curRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                    else if (curCol >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                        curX = curCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                        curY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                if (curX < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                    px = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                    for (i = curY; i < (curY + curHeight); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                        px = Math.max(px, xMaxArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                    curX = px - curX - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    if(curX < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                        curX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                else if (curY < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                    py = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                    for (i = curX; i < (curX + curWidth); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                        py = Math.max(py, yMaxArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                    curY = py - curY - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                    if(curY < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                        curY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                /* Adjust the grid width and height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                 *  fix for 5005945: unneccessary loops removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                px = curX + curWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                if (layoutWidth < px) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                    layoutWidth = px;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                py = curY + curHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                if (layoutHeight < py) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                    layoutHeight = py;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                /* Adjust xMaxArray and yMaxArray */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                for (i = curX; i < (curX + curWidth); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                    yMaxArray[i] =py;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                for (i = curY; i < (curY + curHeight); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                    xMaxArray[i] = px;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                /* Cache the current slave's size. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                if (sizeflag == PREFERREDSIZE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                    d = comp.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                    d = comp.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                constraints.minWidth = d.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                constraints.minHeight = d.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                if (calculateBaseline(comp, constraints, d)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                    hasBaseline = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                /* Zero width and height must mean that this is the last item (or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                 * else something is wrong). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                if (constraints.gridheight == 0 && constraints.gridwidth == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                    curRow = curCol = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                /* Zero width starts a new row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                if (constraints.gridheight == 0 && curRow < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                    curCol = curX + curWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                /* Zero height starts a new column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                else if (constraints.gridwidth == 0 && curCol < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                    curRow = curY + curHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            } //for (components) loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
             * Apply minimum row/column dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            if (columnWidths != null && layoutWidth < columnWidths.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                layoutWidth = columnWidths.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            if (rowHeights != null && layoutHeight < rowHeights.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                layoutHeight = rowHeights.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            r = new GridBagLayoutInfo(layoutWidth, layoutHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
             * Pass #2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
             * Negative values for gridX are filled in with the current x value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
             * Negative values for gridY are filled in with the current y value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
             * Negative or zero values for gridWidth and gridHeight end the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
             *  row or column, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            curRow = curCol = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            Arrays.fill(xMaxArray, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            Arrays.fill(yMaxArray, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            int[] maxAscent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            int[] maxDescent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            short[] baselineType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            if (hasBaseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                r.maxAscent = maxAscent = new int[layoutHeight];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                r.maxDescent = maxDescent = new int[layoutHeight];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                r.baselineType = baselineType = new short[layoutHeight];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                r.hasBaseline = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            for (compindex = 0 ; compindex < components.length ; compindex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                comp = components[compindex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                if (!comp.isVisible())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                constraints = lookupConstraints(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                curX = constraints.gridx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                curY = constraints.gridy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                curWidth = constraints.gridwidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                curHeight = constraints.gridheight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                /* If x or y is negative, then use relative positioning: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                if (curX < 0 && curY < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                    if(curRow >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                        curY = curRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                    else if(curCol >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                        curX = curCol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                        curY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                if (curX < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                    if (curHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                        curHeight += r.height - curY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                        if (curHeight < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                            curHeight = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                    px = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                    for (i = curY; i < (curY + curHeight); i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                        px = Math.max(px, xMaxArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                    curX = px - curX - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                    if(curX < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                        curX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                else if (curY < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                    if (curWidth <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                        curWidth += r.width - curX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                        if (curWidth < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                            curWidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                    py = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                    for (i = curX; i < (curX + curWidth); i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                        py = Math.max(py, yMaxArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                    curY = py - curY - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                    if(curY < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                        curY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                if (curWidth <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                    curWidth += r.width - curX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                    if (curWidth < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                        curWidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                if (curHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                    curHeight += r.height - curY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                    if (curHeight < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                        curHeight = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                px = curX + curWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                py = curY + curHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                for (i = curX; i < (curX + curWidth); i++) { yMaxArray[i] = py; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                for (i = curY; i < (curY + curHeight); i++) { xMaxArray[i] = px; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                /* Make negative sizes start a new row/column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                if (constraints.gridheight == 0 && constraints.gridwidth == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                    curRow = curCol = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                if (constraints.gridheight == 0 && curRow < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                    curCol = curX + curWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                else if (constraints.gridwidth == 0 && curCol < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                    curRow = curY + curHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                /* Assign the new values to the gridbag slave */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                constraints.tempX = curX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                constraints.tempY = curY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                constraints.tempWidth = curWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                constraints.tempHeight = curHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                anchor = constraints.anchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                if (hasBaseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    switch(anchor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                    case GridBagConstraints.BASELINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                    case GridBagConstraints.BASELINE_LEADING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                    case GridBagConstraints.BASELINE_TRAILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                        if (constraints.ascent >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                            if (curHeight == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                                maxAscent[curY] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                                        Math.max(maxAscent[curY],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                                                 constraints.ascent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                                maxDescent[curY] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                                        Math.max(maxDescent[curY],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                                                 constraints.descent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                                if (constraints.baselineResizeBehavior ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                                        Component.BaselineResizeBehavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                                        CONSTANT_DESCENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                                    maxDescent[curY + curHeight - 1] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                                        Math.max(maxDescent[curY + curHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                                                            - 1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                                                 constraints.descent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                                    maxAscent[curY] = Math.max(maxAscent[curY],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                                                           constraints.ascent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                            if (constraints.baselineResizeBehavior ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                                    Component.BaselineResizeBehavior.CONSTANT_DESCENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                                baselineType[curY + curHeight - 1] |=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                                        (1 << constraints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                                         baselineResizeBehavior.ordinal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                                baselineType[curY] |= (1 << constraints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                                             baselineResizeBehavior.ordinal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    case GridBagConstraints.ABOVE_BASELINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                    case GridBagConstraints.ABOVE_BASELINE_LEADING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                    case GridBagConstraints.ABOVE_BASELINE_TRAILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                        // Component positioned above the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                        // To make the bottom edge of the component aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                        // with the baseline the bottom inset is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                        // added to the descent, the rest to the ascent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                        pixels_diff = constraints.minHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                                constraints.insets.top +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                                constraints.ipady;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                        maxAscent[curY] = Math.max(maxAscent[curY],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                                                   pixels_diff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                        maxDescent[curY] = Math.max(maxDescent[curY],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                                                    constraints.insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                    case GridBagConstraints.BELOW_BASELINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                    case GridBagConstraints.BELOW_BASELINE_LEADING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                    case GridBagConstraints.BELOW_BASELINE_TRAILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                        // Component positioned below the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                        // To make the top edge of the component aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                        // with the baseline the top inset is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                        // added to the ascent, the rest to the descent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                        pixels_diff = constraints.minHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                                constraints.insets.bottom + constraints.ipady;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                        maxDescent[curY] = Math.max(maxDescent[curY],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                                                    pixels_diff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                        maxAscent[curY] = Math.max(maxAscent[curY],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                                                   constraints.insets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            r.weightX = new double[maximumArrayYIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            r.weightY = new double[maximumArrayXIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            r.minWidth = new int[maximumArrayYIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            r.minHeight = new int[maximumArrayXIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
             * Apply minimum row/column dimensions and weights
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            if (columnWidths != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                System.arraycopy(columnWidths, 0, r.minWidth, 0, columnWidths.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            if (rowHeights != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                System.arraycopy(rowHeights, 0, r.minHeight, 0, rowHeights.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            if (columnWeights != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                System.arraycopy(columnWeights, 0, r.weightX, 0,  Math.min(r.weightX.length, columnWeights.length));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            if (rowWeights != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                System.arraycopy(rowWeights, 0, r.weightY, 0,  Math.min(r.weightY.length, rowWeights.length));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
             * Pass #3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
             * Distribute the minimun widths and weights:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            nextSize = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            for (i = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                 i != Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                 i = nextSize, nextSize = Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                for (compindex = 0 ; compindex < components.length ; compindex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                    comp = components[compindex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                    if (!comp.isVisible())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                    constraints = lookupConstraints(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                    if (constraints.tempWidth == i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                        px = constraints.tempX + constraints.tempWidth; /* right column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                         * Figure out if we should use this slave\'s weight.  If the weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                         * is less than the total weight spanned by the width of the cell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                         * then discard the weight.  Otherwise split the difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                         * according to the existing weights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                        weight_diff = constraints.weightx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                        for (k = constraints.tempX; k < px; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                            weight_diff -= r.weightX[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                        if (weight_diff > 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                            weight = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                            for (k = constraints.tempX; k < px; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                                weight += r.weightX[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                            for (k = constraints.tempX; weight > 0.0 && k < px; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                                double wt = r.weightX[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                                double dx = (wt * weight_diff) / weight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                                r.weightX[k] += dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                                weight_diff -= dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                                weight -= wt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                            /* Assign the remainder to the rightmost cell */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                            r.weightX[px-1] += weight_diff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                         * Calculate the minWidth array values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                         * First, figure out how wide the current slave needs to be.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                         * Then, see if it will fit within the current minWidth values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                         * If it will not fit, add the difference according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                         * weightX array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                        pixels_diff =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                            constraints.minWidth + constraints.ipadx +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                            constraints.insets.left + constraints.insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                        for (k = constraints.tempX; k < px; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                            pixels_diff -= r.minWidth[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                        if (pixels_diff > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                            weight = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                            for (k = constraints.tempX; k < px; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                                weight += r.weightX[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                            for (k = constraints.tempX; weight > 0.0 && k < px; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                                double wt = r.weightX[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                                int dx = (int)((wt * ((double)pixels_diff)) / weight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                                r.minWidth[k] += dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                                pixels_diff -= dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                                weight -= wt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                            /* Any leftovers go into the rightmost cell */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                            r.minWidth[px-1] += pixels_diff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                    else if (constraints.tempWidth > i && constraints.tempWidth < nextSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                        nextSize = constraints.tempWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                    if (constraints.tempHeight == i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                        py = constraints.tempY + constraints.tempHeight; /* bottom row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                         * Figure out if we should use this slave's weight.  If the weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                         * is less than the total weight spanned by the height of the cell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                         * then discard the weight.  Otherwise split it the difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                         * according to the existing weights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                        weight_diff = constraints.weighty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                        for (k = constraints.tempY; k < py; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                            weight_diff -= r.weightY[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                        if (weight_diff > 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                            weight = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                            for (k = constraints.tempY; k < py; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                                weight += r.weightY[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                            for (k = constraints.tempY; weight > 0.0 && k < py; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                                double wt = r.weightY[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                                double dy = (wt * weight_diff) / weight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                                r.weightY[k] += dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                                weight_diff -= dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                                weight -= wt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                            /* Assign the remainder to the bottom cell */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                            r.weightY[py-1] += weight_diff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                         * Calculate the minHeight array values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                         * First, figure out how tall the current slave needs to be.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                         * Then, see if it will fit within the current minHeight values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                         * If it will not fit, add the difference according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                         * weightY array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                        pixels_diff = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                        if (hasBaseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                            switch(constraints.anchor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                            case GridBagConstraints.BASELINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                            case GridBagConstraints.BASELINE_LEADING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                            case GridBagConstraints.BASELINE_TRAILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                                if (constraints.ascent >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                                    if (constraints.tempHeight == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                                        pixels_diff =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                                            maxAscent[constraints.tempY] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                                            maxDescent[constraints.tempY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                                    else if (constraints.baselineResizeBehavior !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                                             Component.BaselineResizeBehavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                                             CONSTANT_DESCENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                                        pixels_diff =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                                                maxAscent[constraints.tempY] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                                                constraints.descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                                        pixels_diff = constraints.ascent +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                                                maxDescent[constraints.tempY +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                                                   constraints.tempHeight - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                            case GridBagConstraints.ABOVE_BASELINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                            case GridBagConstraints.ABOVE_BASELINE_LEADING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                            case GridBagConstraints.ABOVE_BASELINE_TRAILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                                pixels_diff = constraints.insets.top +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                                        constraints.minHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                                        constraints.ipady +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                                        maxDescent[constraints.tempY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                            case GridBagConstraints.BELOW_BASELINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                            case GridBagConstraints.BELOW_BASELINE_LEADING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                            case GridBagConstraints.BELOW_BASELINE_TRAILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                                pixels_diff = maxAscent[constraints.tempY] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                                        constraints.minHeight +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                                        constraints.insets.bottom +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                                        constraints.ipady;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                        if (pixels_diff == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                            pixels_diff =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                                constraints.minHeight + constraints.ipady +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                                constraints.insets.top +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                                constraints.insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                        for (k = constraints.tempY; k < py; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                            pixels_diff -= r.minHeight[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                        if (pixels_diff > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                            weight = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                            for (k = constraints.tempY; k < py; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                                weight += r.weightY[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                            for (k = constraints.tempY; weight > 0.0 && k < py; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                                double wt = r.weightY[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                                int dy = (int)((wt * ((double)pixels_diff)) / weight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                                r.minHeight[k] += dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                                pixels_diff -= dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                                weight -= wt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                            /* Any leftovers go into the bottom cell */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                            r.minHeight[py-1] += pixels_diff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                    else if (constraints.tempHeight > i &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                             constraints.tempHeight < nextSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                        nextSize = constraints.tempHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
    } //getLayoutInfo()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     * Calculate the baseline for the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     * If {@code c} is positioned along it's baseline, the baseline is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     * obtained and the {@code constraints} ascent, descent and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     * baseline resize behavior are set from the component; and true is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     * returned. Otherwise false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    private boolean calculateBaseline(Component c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                                      GridBagConstraints constraints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                                      Dimension size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        int anchor = constraints.anchor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        if (anchor == GridBagConstraints.BASELINE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                anchor == GridBagConstraints.BASELINE_LEADING ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                anchor == GridBagConstraints.BASELINE_TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
            // Apply the padding to the component, then ask for the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            int w = size.width + constraints.ipadx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
            int h = size.height + constraints.ipady;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            constraints.ascent = c.getBaseline(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            if (constraints.ascent >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                // Component has a baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                int baseline = constraints.ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                // Adjust the ascent and descent to include the insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                constraints.descent = h - constraints.ascent +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                            constraints.insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                constraints.ascent += constraints.insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                constraints.baselineResizeBehavior =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                        c.getBaselineResizeBehavior();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                constraints.centerPadding = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                if (constraints.baselineResizeBehavior == Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                        BaselineResizeBehavior.CENTER_OFFSET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                    // Component has a baseline resize behavior of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                    // CENTER_OFFSET, calculate centerPadding and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                    // centerOffset (see the description of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                    // CENTER_OFFSET in the enum for detais on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                    // algorithm).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                    int nextBaseline = c.getBaseline(w, h + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                    constraints.centerOffset = baseline - h / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                    if (h % 2 == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                        if (baseline != nextBaseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                            constraints.centerPadding = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                    else if (baseline == nextBaseline){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                        constraints.centerOffset--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                        constraints.centerPadding = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            constraints.ascent = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     * Adjusts the x, y, width, and height fields to the correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * values depending on the constraint geometry and pads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * This method should only be used internally by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     * <code>GridBagLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     * @param constraints the constraints to be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * @param r the <code>Rectangle</code> to be adjusted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    protected void adjustForGravity(GridBagConstraints constraints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                                    Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        AdjustForGravity(constraints, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     * This method is obsolete and supplied for backwards
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
  1615
     * compatibility only; new code should call {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     * #adjustForGravity(java.awt.GridBagConstraints, java.awt.Rectangle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * adjustForGravity} instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     * This method is the same as <code>adjustForGravity</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     * refer to <code>adjustForGravity</code> for details
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     * on parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    protected void AdjustForGravity(GridBagConstraints constraints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                                    Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        int diffx, diffy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        int cellY = r.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        int cellHeight = r.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        if (!rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
            r.x += constraints.insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            r.x -= r.width - constraints.insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        r.width -= (constraints.insets.left + constraints.insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        r.y += constraints.insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        r.height -= (constraints.insets.top + constraints.insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        diffx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        if ((constraints.fill != GridBagConstraints.HORIZONTAL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
             constraints.fill != GridBagConstraints.BOTH)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            && (r.width > (constraints.minWidth + constraints.ipadx))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            diffx = r.width - (constraints.minWidth + constraints.ipadx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            r.width = constraints.minWidth + constraints.ipadx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        diffy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        if ((constraints.fill != GridBagConstraints.VERTICAL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
             constraints.fill != GridBagConstraints.BOTH)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            && (r.height > (constraints.minHeight + constraints.ipady))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
            diffy = r.height - (constraints.minHeight + constraints.ipady);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
            r.height = constraints.minHeight + constraints.ipady;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
        switch (constraints.anchor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
          case GridBagConstraints.BASELINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
              r.x += diffx/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
              alignOnBaseline(constraints, r, cellY, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
          case GridBagConstraints.BASELINE_LEADING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
              if (rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
              alignOnBaseline(constraints, r, cellY, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
          case GridBagConstraints.BASELINE_TRAILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
              if (!rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
              alignOnBaseline(constraints, r, cellY, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
          case GridBagConstraints.ABOVE_BASELINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
              r.x += diffx/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
              alignAboveBaseline(constraints, r, cellY, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
          case GridBagConstraints.ABOVE_BASELINE_LEADING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
              if (rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
              alignAboveBaseline(constraints, r, cellY, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
          case GridBagConstraints.ABOVE_BASELINE_TRAILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
              if (!rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
              alignAboveBaseline(constraints, r, cellY, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
          case GridBagConstraints.BELOW_BASELINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
              r.x += diffx/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
              alignBelowBaseline(constraints, r, cellY, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
          case GridBagConstraints.BELOW_BASELINE_LEADING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
              if (rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
              alignBelowBaseline(constraints, r, cellY, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
          case GridBagConstraints.BELOW_BASELINE_TRAILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
              if (!rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
              alignBelowBaseline(constraints, r, cellY, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
          case GridBagConstraints.CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
              r.x += diffx/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
              r.y += diffy/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
          case GridBagConstraints.PAGE_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
          case GridBagConstraints.NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
              r.x += diffx/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
          case GridBagConstraints.NORTHEAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
              r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
          case GridBagConstraints.EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
              r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
              r.y += diffy/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
          case GridBagConstraints.SOUTHEAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
              r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
              r.y += diffy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
          case GridBagConstraints.PAGE_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
          case GridBagConstraints.SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
              r.x += diffx/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
              r.y += diffy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
          case GridBagConstraints.SOUTHWEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
              r.y += diffy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
          case GridBagConstraints.WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
              r.y += diffy/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
          case GridBagConstraints.NORTHWEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
          case GridBagConstraints.LINE_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
              if (rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
              r.y += diffy/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
          case GridBagConstraints.LINE_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
              if (!rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
              r.y += diffy/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
          case GridBagConstraints.FIRST_LINE_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
              if (rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
          case GridBagConstraints.FIRST_LINE_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
              if (!rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
          case GridBagConstraints.LAST_LINE_START:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
              if (rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
              r.y += diffy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
          case GridBagConstraints.LAST_LINE_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
              if (!rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                  r.x += diffx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
              r.y += diffy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
              throw new IllegalArgumentException("illegal anchor value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     * Positions on the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * @param cellY the location of the row, does not include insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * @param cellHeight the height of the row, does not take into account
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     *        insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * @param r available bounds for the component, is padded by insets and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     *        ipady
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
    private void alignOnBaseline(GridBagConstraints cons, Rectangle r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                                 int cellY, int cellHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        if (cons.ascent >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            if (cons.baselineResizeBehavior == Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                    BaselineResizeBehavior.CONSTANT_DESCENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                // Anchor to the bottom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                // Baseline is at (cellY + cellHeight - maxDescent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                // Bottom of component (maxY) is at baseline + descent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                // of component. We need to subtract the bottom inset here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                // as the descent in the constraints object includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                // bottom inset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                int maxY = cellY + cellHeight -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                      layoutInfo.maxDescent[cons.tempY + cons.tempHeight - 1] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                      cons.descent - cons.insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                if (!cons.isVerticallyResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                    // Component not resizable, calculate y location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                    // from maxY - height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                    r.y = maxY - cons.minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                    r.height = cons.minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                    // Component is resizable. As brb is constant descent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                    // can expand component to fill region above baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                    // Subtract out the top inset so that components insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                    // are honored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
                    r.height = maxY - cellY - cons.insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
                // BRB is not constant_descent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                int baseline; // baseline for the row, relative to cellY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                // Component baseline, includes insets.top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                int ascent = cons.ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
                if (layoutInfo.hasConstantDescent(cons.tempY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                    // Mixed ascent/descent in same row, calculate position
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                    // off maxDescent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                    baseline = cellHeight - layoutInfo.maxDescent[cons.tempY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                    // Only ascents/unknown in this row, anchor to top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                    baseline = layoutInfo.maxAscent[cons.tempY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                if (cons.baselineResizeBehavior == Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                        BaselineResizeBehavior.OTHER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                    // BRB is other, which means we can only determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                    // the baseline by asking for it again giving the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                    // size we plan on using for the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                    boolean fits = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                    ascent = componentAdjusting.getBaseline(r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                    if (ascent >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                        // Component has a baseline, pad with top inset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                        // (this follows from calculateBaseline which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                        // does the same).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                        ascent += cons.insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                    if (ascent >= 0 && ascent <= baseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                        // Components baseline fits within rows baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                        // Make sure the descent fits within the space as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                        if (baseline + (r.height - ascent - cons.insets.top) <=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                                cellHeight - cons.insets.bottom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                            // It fits, we're good.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                            fits = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                        else if (cons.isVerticallyResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                            // Doesn't fit, but it's resizable.  Try
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                            // again assuming we'll get ascent again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                            int ascent2 = componentAdjusting.getBaseline(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                                    r.width, cellHeight - cons.insets.bottom -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
                                    baseline + ascent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
                            if (ascent2 >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
                                ascent2 += cons.insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                            if (ascent2 >= 0 && ascent2 <= ascent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                                // It'll fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                                r.height = cellHeight - cons.insets.bottom -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                                        baseline + ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                                ascent = ascent2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                                fits = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                    if (!fits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                        // Doesn't fit, use min size and original ascent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                        ascent = cons.ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                        r.width = cons.minWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                        r.height = cons.minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                // Reset the components y location based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                // components ascent and baseline for row. Because ascent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                // includes the baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                r.y = cellY + baseline - ascent + cons.insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                if (cons.isVerticallyResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                    switch(cons.baselineResizeBehavior) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                    case CONSTANT_ASCENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                        r.height = Math.max(cons.minHeight,cellY + cellHeight -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                                            r.y - cons.insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                    case CENTER_OFFSET:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                            int upper = r.y - cellY - cons.insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                            int lower = cellY + cellHeight - r.y -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                                cons.minHeight - cons.insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                            int delta = Math.min(upper, lower);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                            delta += delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                            if (delta > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                                (cons.minHeight + cons.centerPadding +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                                 delta) / 2 + cons.centerOffset != baseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                                // Off by 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                                delta--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                            r.height = cons.minHeight + delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                            r.y = cellY + baseline -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                                (r.height + cons.centerPadding) / 2 -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                                cons.centerOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                    case OTHER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                        // Handled above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
            centerVertically(cons, r, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     * Positions the specified component above the baseline. That is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     * the bottom edge of the component will be aligned along the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     * If the row does not have a baseline, this centers the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
    private void alignAboveBaseline(GridBagConstraints cons, Rectangle r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                                    int cellY, int cellHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
        if (layoutInfo.hasBaseline(cons.tempY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            int maxY; // Baseline for the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            if (layoutInfo.hasConstantDescent(cons.tempY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                // Prefer descent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
                maxY = cellY + cellHeight - layoutInfo.maxDescent[cons.tempY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                // Prefer ascent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                maxY = cellY + layoutInfo.maxAscent[cons.tempY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
            if (cons.isVerticallyResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                // Component is resizable. Top edge is offset by top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
                // inset, bottom edge on baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                r.y = cellY + cons.insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
                r.height = maxY - r.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                // Not resizable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
                r.height = cons.minHeight + cons.ipady;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                r.y = maxY - r.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
            centerVertically(cons, r, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * Positions below the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
    private void alignBelowBaseline(GridBagConstraints cons, Rectangle r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                                    int cellY, int cellHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
        if (layoutInfo.hasBaseline(cons.tempY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
            if (layoutInfo.hasConstantDescent(cons.tempY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                // Prefer descent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                r.y = cellY + cellHeight - layoutInfo.maxDescent[cons.tempY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                // Prefer ascent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                r.y = cellY + layoutInfo.maxAscent[cons.tempY];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
            if (cons.isVerticallyResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                r.height = cellY + cellHeight - r.y - cons.insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
            centerVertically(cons, r, cellHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    private void centerVertically(GridBagConstraints cons, Rectangle r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
                                  int cellHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        if (!cons.isVerticallyResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
            r.y += Math.max(0, (cellHeight - cons.insets.top -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                                cons.insets.bottom - cons.minHeight -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                                cons.ipady) / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
     * Figures out the minimum size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     * master based on the information from <code>getLayoutInfo</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
     * This method should only be used internally by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
     * <code>GridBagLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     * @param parent the layout container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     * @param info the layout info for this parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     * @return a <code>Dimension</code> object containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
     *   minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
    protected Dimension getMinSize(Container parent, GridBagLayoutInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        return GetMinSize(parent, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     * This method is obsolete and supplied for backwards
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
  1996
     * compatibility only; new code should call {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * #getMinSize(java.awt.Container, GridBagLayoutInfo) getMinSize} instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     * This method is the same as <code>getMinSize</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     * refer to <code>getMinSize</code> for details on parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     * and return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
    protected Dimension GetMinSize(Container parent, GridBagLayoutInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        Dimension d = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        int i, t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
        Insets insets = parent.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
        t = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        for(i = 0; i < info.width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
            t += info.minWidth[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
        d.width = t + insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
        t = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        for(i = 0; i < info.height; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            t += info.minHeight[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        d.height = t + insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
    transient boolean rightToLeft = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
     * Lays out the grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
     * This method should only be used internally by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
     * <code>GridBagLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
     * @param parent the layout container
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
    protected void arrangeGrid(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
        ArrangeGrid(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
     * This method is obsolete and supplied for backwards
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
  2036
     * compatibility only; new code should call {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     * #arrangeGrid(Container) arrangeGrid} instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * This method is the same as <code>arrangeGrid</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * refer to <code>arrangeGrid</code> for details on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
    protected void ArrangeGrid(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
        Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
        int compindex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
        GridBagConstraints constraints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
        Insets insets = parent.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
        Component components[] = parent.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
        Dimension d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
        Rectangle r = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        int i, diffw, diffh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        double weight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
        GridBagLayoutInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
        rightToLeft = !parent.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
         * If the parent has no slaves anymore, then don't do anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
         * at all:  just leave the parent's size as-is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
        if (components.length == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
            (columnWidths == null || columnWidths.length == 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
            (rowHeights == null || rowHeights.length == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
         * Pass #1: scan all the slaves to figure out the total amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
         * of space needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
        info = getLayoutInfo(parent, PREFERREDSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
        d = getMinSize(parent, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
        if (parent.width < d.width || parent.height < d.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
            info = getLayoutInfo(parent, MINSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
            d = getMinSize(parent, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
        layoutInfo = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
        r.width = d.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
        r.height = d.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
         * DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
         * DumpLayoutInfo(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
         * for (compindex = 0 ; compindex < components.length ; compindex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
         * comp = components[compindex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
         * if (!comp.isVisible())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
         *      continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
         * constraints = lookupConstraints(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
         * DumpConstraints(constraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
         * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
         * System.out.println("minSize " + r.width + " " + r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
         * If the current dimensions of the window don't match the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
         * dimensions, then adjust the minWidth and minHeight arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
         * according to the weights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        diffw = parent.width - r.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
        if (diffw != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            weight = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
            for (i = 0; i < info.width; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                weight += info.weightX[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
            if (weight > 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                for (i = 0; i < info.width; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                    int dx = (int)(( ((double)diffw) * info.weightX[i]) / weight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
                    info.minWidth[i] += dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
                    r.width += dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
                    if (info.minWidth[i] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                        r.width -= info.minWidth[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
                        info.minWidth[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
            diffw = parent.width - r.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
            diffw = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        diffh = parent.height - r.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
        if (diffh != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
            weight = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            for (i = 0; i < info.height; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                weight += info.weightY[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
            if (weight > 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                for (i = 0; i < info.height; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                    int dy = (int)(( ((double)diffh) * info.weightY[i]) / weight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                    info.minHeight[i] += dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
                    r.height += dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                    if (info.minHeight[i] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                        r.height -= info.minHeight[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                        info.minHeight[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
            diffh = parent.height - r.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
            diffh = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
         * DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
         * System.out.println("Re-adjusted:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
         * DumpLayoutInfo(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
         * Now do the actual layout of the slaves using the layout information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
         * that has been collected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
        info.startx = diffw/2 + insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
        info.starty = diffh/2 + insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
        for (compindex = 0 ; compindex < components.length ; compindex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            comp = components[compindex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
            if (!comp.isVisible()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            constraints = lookupConstraints(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
            if (!rightToLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
                r.x = info.startx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                for(i = 0; i < constraints.tempX; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                    r.x += info.minWidth[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                r.x = parent.width - (diffw/2 + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
                for(i = 0; i < constraints.tempX; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
                    r.x -= info.minWidth[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
            r.y = info.starty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
            for(i = 0; i < constraints.tempY; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                r.y += info.minHeight[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            r.width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
            for(i = constraints.tempX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
                i < (constraints.tempX + constraints.tempWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
                i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                r.width += info.minWidth[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
            r.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
            for(i = constraints.tempY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
                i < (constraints.tempY + constraints.tempHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
                r.height += info.minHeight[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
            componentAdjusting = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
            adjustForGravity(constraints, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
            /* fix for 4408108 - components were being created outside of the container */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
            /* fix for 4969409 "-" replaced by "+"  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
            if (r.x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                r.width += r.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
                r.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
            if (r.y < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                r.height += r.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
                r.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
             * If the window is too small to be interesting then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
             * unmap it.  Otherwise configure it and then make sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
             * it's mapped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
            if ((r.width <= 0) || (r.height <= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
                comp.setBounds(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
                if (comp.x != r.x || comp.y != r.y ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
                    comp.width != r.width || comp.height != r.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
                    comp.setBounds(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21244
diff changeset
  2232
    // Added for serial backwards compatibility (4348425)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
    static final long serialVersionUID = 8838754796412211005L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
}