jdk/src/share/classes/java/awt/GridLayout.java
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE Summary: Add the Transient annotation and support it (JSR-273) Reviewed-by: peterz, loneid
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1995-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The <code>GridLayout</code> class is a layout manager that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * lays out a container's components in a rectangular grid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * The container is divided into equal-sized rectangles,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * and one component is placed in each rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * For example, the following is an applet that lays out six buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * into three rows and two columns:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <hr><blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * public class ButtonGrid extends Applet {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *     public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *         setLayout(new GridLayout(3,2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *         add(new Button("1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *         add(new Button("2"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *         add(new Button("3"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *         add(new Button("4"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *         add(new Button("5"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *         add(new Button("6"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * </pre></blockquote><hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * If the container's <code>ComponentOrientation</code> property is horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * and left-to-right, the above example produces the output shown in Figure 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * If the container's <code>ComponentOrientation</code> property is horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * and right-to-left, the example produces the output shown in Figure 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <center><table COLS=2 WIDTH=600 summary="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <tr ALIGN=CENTER>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <td><img SRC="doc-files/GridLayout-1.gif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *      alt="Shows 6 buttons in rows of 2. Row 1 shows buttons 1 then 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Row 2 shows buttons 3 then 4. Row 3 shows buttons 5 then 6.">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <td ALIGN=CENTER><img SRC="doc-files/GridLayout-2.gif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *                   alt="Shows 6 buttons in rows of 2. Row 1 shows buttons 2 then 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Row 2 shows buttons 4 then 3. Row 3 shows buttons 6 then 5.">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <tr ALIGN=CENTER>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <td>Figure 1: Horizontal, Left-to-Right</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <td>Figure 2: Horizontal, Right-to-Left</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * </table></center>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * When both the number of rows and the number of columns have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * been set to non-zero values, either by a constructor or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * by the <tt>setRows</tt> and <tt>setColumns</tt> methods, the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * columns specified is ignored.  Instead, the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * columns is determined from the specified number of rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * and the total number of components in the layout. So, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * example, if three rows and two columns have been specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * and nine components are added to the layout, they will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * be displayed as three rows of three columns.  Specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * the number of columns affects the layout only when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * number of rows is set to zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @author  Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * @since   JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
public class GridLayout implements LayoutManager, java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final long serialVersionUID = -7411804673224730901L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * This is the horizontal gap (in pixels) which specifies the space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * between columns.  They can be changed at any time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * This should be a non-negative integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @see #getHgap()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #setHgap(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    int hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * This is the vertical gap (in pixels) which specifies the space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * between rows.  They can be changed at any time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * This should be a non negative integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @see #getVgap()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @see #setVgap(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    int vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * This is the number of rows specified for the grid.  The number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * of rows can be changed at any time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * This should be a non negative integer, where '0' means
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * 'any number' meaning that the number of Rows in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * dimension depends on the other dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @see #getRows()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @see #setRows(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    int rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * This is the number of columns specified for the grid.  The number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * of columns can be changed at any time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * This should be a non negative integer, where '0' means
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * 'any number' meaning that the number of Columns in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * dimension depends on the other dimension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @see #getColumns()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @see #setColumns(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    int cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Creates a grid layout with a default of one column per component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * in a single row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public GridLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        this(1, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Creates a grid layout with the specified number of rows and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * columns. All components in the layout are given equal size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * One, but not both, of <code>rows</code> and <code>cols</code> can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * be zero, which means that any number of objects can be placed in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * row or in a column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param     rows   the rows, with the value zero meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *                   any number of rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param     cols   the columns, with the value zero meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *                   any number of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public GridLayout(int rows, int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        this(rows, cols, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Creates a grid layout with the specified number of rows and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * columns. All components in the layout are given equal size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * In addition, the horizontal and vertical gaps are set to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * specified values. Horizontal gaps are placed between each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * of the columns. Vertical gaps are placed between each of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * the rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * One, but not both, of <code>rows</code> and <code>cols</code> can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * be zero, which means that any number of objects can be placed in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * row or in a column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * All <code>GridLayout</code> constructors defer to this one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param     rows   the rows, with the value zero meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *                   any number of rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param     cols   the columns, with the value zero meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *                   any number of columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param     hgap   the horizontal gap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param     vgap   the vertical gap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @exception   IllegalArgumentException  if the value of both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *                  <code>rows</code> and <code>cols</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *                  set to zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public GridLayout(int rows, int cols, int hgap, int vgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if ((rows == 0) && (cols == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            throw new IllegalArgumentException("rows and cols cannot both be zero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        this.rows = rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        this.cols = cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        this.hgap = hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        this.vgap = vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Gets the number of rows in this layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @return    the number of rows in this layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public int getRows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Sets the number of rows in this layout to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param        rows   the number of rows in this layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @exception    IllegalArgumentException  if the value of both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *               <code>rows</code> and <code>cols</code> is set to zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public void setRows(int rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if ((rows == 0) && (this.cols == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            throw new IllegalArgumentException("rows and cols cannot both be zero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        this.rows = rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Gets the number of columns in this layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @return     the number of columns in this layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public int getColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Sets the number of columns in this layout to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Setting the number of columns has no affect on the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * if the number of rows specified by a constructor or by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * the <tt>setRows</tt> method is non-zero. In that case, the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * of columns displayed in the layout is determined by the total
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * number of components and the number of rows specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param        cols   the number of columns in this layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @exception    IllegalArgumentException  if the value of both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *               <code>rows</code> and <code>cols</code> is set to zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public void setColumns(int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if ((cols == 0) && (this.rows == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            throw new IllegalArgumentException("rows and cols cannot both be zero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        this.cols = cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Gets the horizontal gap between components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return       the horizontal gap between components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public int getHgap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Sets the horizontal gap between components to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param        hgap   the horizontal gap between components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public void setHgap(int hgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        this.hgap = hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Gets the vertical gap between components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return       the vertical gap between components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public int getVgap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Sets the vertical gap between components to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param         vgap  the vertical gap between components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public void setVgap(int vgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        this.vgap = vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Adds the specified component with the specified name to the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param name the name of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @param comp the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public void addLayoutComponent(String name, Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Removes the specified component from the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param comp the component to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void removeLayoutComponent(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Determines the preferred size of the container argument using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * this grid layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * The preferred width of a grid layout is the largest preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * width of all of the components in the container times the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * columns, plus the horizontal padding times the number of columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * minus one, plus the left and right insets of the target container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * The preferred height of a grid layout is the largest preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * height of all of the components in the container times the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * rows, plus the vertical padding times the number of rows minus one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * plus the top and bottom insets of the target container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @param     parent   the container in which to do the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @return    the preferred dimensions to lay out the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *                      subcomponents of the specified container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @see       java.awt.GridLayout#minimumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see       java.awt.Container#getPreferredSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public Dimension preferredLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
      synchronized (parent.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        Insets insets = parent.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        int ncomponents = parent.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        int nrows = rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        int ncols = cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (nrows > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            ncols = (ncomponents + nrows - 1) / nrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            nrows = (ncomponents + ncols - 1) / ncols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        int w = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        int h = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        for (int i = 0 ; i < ncomponents ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            Component comp = parent.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            Dimension d = comp.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            if (w < d.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                w = d.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            if (h < d.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                h = d.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return new Dimension(insets.left + insets.right + ncols*w + (ncols-1)*hgap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                             insets.top + insets.bottom + nrows*h + (nrows-1)*vgap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Determines the minimum size of the container argument using this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * grid layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * The minimum width of a grid layout is the largest minimum width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * of all of the components in the container times the number of columns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * plus the horizontal padding times the number of columns minus one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * plus the left and right insets of the target container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * The minimum height of a grid layout is the largest minimum height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * of all of the components in the container times the number of rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * plus the vertical padding times the number of rows minus one, plus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * the top and bottom insets of the target container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @param       parent   the container in which to do the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @return      the minimum dimensions needed to lay out the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *                      subcomponents of the specified container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see         java.awt.GridLayout#preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see         java.awt.Container#doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public Dimension minimumLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
      synchronized (parent.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        Insets insets = parent.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        int ncomponents = parent.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        int nrows = rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        int ncols = cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (nrows > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            ncols = (ncomponents + nrows - 1) / nrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            nrows = (ncomponents + ncols - 1) / ncols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        int w = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        int h = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        for (int i = 0 ; i < ncomponents ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            Component comp = parent.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            Dimension d = comp.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            if (w < d.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                w = d.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (h < d.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                h = d.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return new Dimension(insets.left + insets.right + ncols*w + (ncols-1)*hgap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                             insets.top + insets.bottom + nrows*h + (nrows-1)*vgap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Lays out the specified container using this layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * This method reshapes the components in the specified target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * container in order to satisfy the constraints of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * <code>GridLayout</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * The grid layout manager determines the size of individual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * components by dividing the free space in the container into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * equal-sized portions according to the number of rows and columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * in the layout. The container's free space equals the container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * size minus any insets and any specified horizontal or vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * gap. All components in a grid layout are given the same size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @param      parent   the container in which to do the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @see        java.awt.Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @see        java.awt.Container#doLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public void layoutContainer(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
      synchronized (parent.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        Insets insets = parent.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        int ncomponents = parent.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        int nrows = rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        int ncols = cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        boolean ltr = parent.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        if (ncomponents == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (nrows > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            ncols = (ncomponents + nrows - 1) / nrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            nrows = (ncomponents + ncols - 1) / ncols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        // 4370316. To position components in the center we should:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        // 1. get an amount of extra space within Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        // 2. incorporate half of that value to the left/top position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        // Note that we use trancating division for widthOnComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        // The reminder goes to extraWidthAvailable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        int totalGapsWidth = (ncols - 1) * hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        int widthWOInsets = parent.width - (insets.left + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        int widthOnComponent = (widthWOInsets - totalGapsWidth) / ncols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        int extraWidthAvailable = (widthWOInsets - (widthOnComponent * ncols + totalGapsWidth)) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        int totalGapsHeight = (nrows - 1) * vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        int heightWOInsets = parent.height - (insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        int heightOnComponent = (heightWOInsets - totalGapsHeight) / nrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        int extraHeightAvailable = (heightWOInsets - (heightOnComponent * nrows + totalGapsHeight)) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            for (int c = 0, x = insets.left + extraWidthAvailable; c < ncols ; c++, x += widthOnComponent + hgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                for (int r = 0, y = insets.top + extraHeightAvailable; r < nrows ; r++, y += heightOnComponent + vgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    int i = r * ncols + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    if (i < ncomponents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                        parent.getComponent(i).setBounds(x, y, widthOnComponent, heightOnComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            for (int c = 0, x = (parent.width - insets.right - widthOnComponent) - extraWidthAvailable; c < ncols ; c++, x -= widthOnComponent + hgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                for (int r = 0, y = insets.top + extraHeightAvailable; r < nrows ; r++, y += heightOnComponent + vgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    int i = r * ncols + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    if (i < ncomponents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                        parent.getComponent(i).setBounds(x, y, widthOnComponent, heightOnComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Returns the string representation of this grid layout's values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @return     a string representation of this grid layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                                       ",rows=" + rows + ",cols=" + cols + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
}