jdk/src/share/classes/java/awt/BorderLayout.java
author mchung
Tue, 08 Dec 2009 09:02:09 -0800
changeset 4374 f672d9cf521e
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset Summary: Reapply fix for 6879044 in java.awt.KeyboardFocusManager Reviewed-by: dcherepanov, asaha
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
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * A border layout lays out a container, arranging and resizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * its components to fit in five regions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * north, south, east, west, and center.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Each region may contain no more than one component, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * is identified by a corresponding constant:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <code>NORTH</code>, <code>SOUTH</code>, <code>EAST</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <code>WEST</code>, and <code>CENTER</code>.  When adding a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * component to a container with a border layout, use one of these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * five constants, for example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *    Panel p = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *    p.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *    p.add(new Button("Okay"), BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * As a convenience, <code>BorderLayout</code> interprets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * absence of a string specification the same as the constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <code>CENTER</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *    Panel p2 = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *    p2.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *    p2.add(new TextArea());  // Same as p.add(new TextArea(), BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * In addition, <code>BorderLayout</code> supports the relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * positioning constants, <code>PAGE_START</code>, <code>PAGE_END</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <code>LINE_START</code>, and <code>LINE_END</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * In a container whose <code>ComponentOrientation</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <code>ComponentOrientation.LEFT_TO_RIGHT</code>, these constants map to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <code>NORTH</code>, <code>SOUTH</code>, <code>WEST</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <code>EAST</code>, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * For compatibility with previous releases, <code>BorderLayout</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * also includes the relative positioning constants <code>BEFORE_FIRST_LINE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <code>AFTER_LAST_LINE</code>, <code>BEFORE_LINE_BEGINS</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <code>AFTER_LINE_ENDS</code>.  These are equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <code>PAGE_START</code>, <code>PAGE_END</code>, <code>LINE_START</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * and <code>LINE_END</code> respectively.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * consistency with the relative positioning constants used by other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * components, the latter constants are preferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Mixing both absolute and relative positioning constants can lead to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * unpredicable results.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * you use both types, the relative constants will take precedence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * For example, if you add components using both the <code>NORTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * and <code>PAGE_START</code> constants in a container whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * orientation is <code>LEFT_TO_RIGHT</code>, only the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <code>PAGE_START</code> will be layed out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * NOTE: Currently (in the Java 2 platform v1.2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <code>BorderLayout</code> does not support vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * orientations.  The <code>isVertical</code> setting on the container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <code>ComponentOrientation</code> is not respected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * The components are laid out according to their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * preferred sizes and the constraints of the container's size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * The <code>NORTH</code> and <code>SOUTH</code> components may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * be stretched horizontally; the <code>EAST</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <code>WEST</code> components may be stretched vertically;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * the <code>CENTER</code> component may stretch both horizontally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * and vertically to fill any space left over.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * Here is an example of five buttons in an applet laid out using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * the <code>BorderLayout</code> layout manager:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <img src="doc-files/BorderLayout-1.gif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * alt="Diagram of an applet demonstrating BorderLayout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *      Each section of the BorderLayout contains a Button corresponding to its position in the layout, one of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *      North, West, Center, East, or South."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * ALIGN=center HSPACE=10 VSPACE=7>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * The code for this applet is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <hr><blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * public class buttonDir extends Applet {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *   public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *     setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *     add(new Button("North"), BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *     add(new Button("South"), BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *     add(new Button("East"), BorderLayout.EAST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *     add(new Button("West"), BorderLayout.WEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *     add(new Button("Center"), BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * </pre></blockquote><hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * @see         java.awt.Container#add(String, Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * @see         java.awt.ComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
public class BorderLayout implements LayoutManager2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                     java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Constructs a border layout with the horizontal gaps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * between components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * The horizontal gap is specified by <code>hgap</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see #getHgap()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @see #setHgap(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        int hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Constructs a border layout with the vertical gaps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * between components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * The vertical gap is specified by <code>vgap</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @see #getVgap()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @see #setVgap(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        int vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Constant to specify components location to be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *      north portion of the border layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see #getChild(String, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @see #addLayoutComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @see #getLayoutAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @see #getLayoutAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see #removeLayoutComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        Component north;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Constant to specify components location to be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *      west portion of the border layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see #getChild(String, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see #addLayoutComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @see #getLayoutAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @see #getLayoutAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @see #removeLayoutComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        Component west;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Constant to specify components location to be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *      east portion of the border layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @see #getChild(String, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @see #addLayoutComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @see #getLayoutAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @see #getLayoutAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see #removeLayoutComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        Component east;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Constant to specify components location to be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *      south portion of the border layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @see #getChild(String, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see #addLayoutComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @see #getLayoutAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see #getLayoutAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see #removeLayoutComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    Component south;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Constant to specify components location to be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *      center portion of the border layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @see #getChild(String, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @see #addLayoutComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see #getLayoutAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @see #getLayoutAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see #removeLayoutComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        Component center;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * A relative positioning constant, that can be used instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * north, south, east, west or center.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * mixing the two types of constants can lead to unpredicable results.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * you use both types, the relative constants will take precedence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * For example, if you add components using both the <code>NORTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * and <code>BEFORE_FIRST_LINE</code> constants in a container whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * orientation is <code>LEFT_TO_RIGHT</code>, only the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * <code>BEFORE_FIRST_LINE</code> will be layed out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * This will be the same for lastLine, firstItem, lastItem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    Component firstLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * A relative positioning constant, that can be used instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * north, south, east, west or center.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Please read Description for firstLine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        Component lastLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * A relative positioning constant, that can be used instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * north, south, east, west or center.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Please read Description for firstLine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Component firstItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * A relative positioning constant, that can be used instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * north, south, east, west or center.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Please read Description for firstLine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        Component lastItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * The north layout constraint (top of container).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public static final String NORTH  = "North";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * The south layout constraint (bottom of container).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public static final String SOUTH  = "South";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * The east layout constraint (right side of container).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public static final String EAST   = "East";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * The west layout constraint (left side of container).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public static final String WEST   = "West";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * The center layout constraint (middle of container).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public static final String CENTER = "Center";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Synonym for PAGE_START.  Exists for compatibility with previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * versions.  PAGE_START is preferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see #PAGE_START
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public static final String BEFORE_FIRST_LINE = "First";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Synonym for PAGE_END.  Exists for compatibility with previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * versions.  PAGE_END is preferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @see #PAGE_END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public static final String AFTER_LAST_LINE = "Last";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Synonym for LINE_START.  Exists for compatibility with previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * versions.  LINE_START is preferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @see #LINE_START
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public static final String BEFORE_LINE_BEGINS = "Before";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Synonym for LINE_END.  Exists for compatibility with previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * versions.  LINE_END is preferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @see #LINE_END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public static final String AFTER_LINE_ENDS = "After";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * The component comes before the first line of the layout's content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * For Western, left-to-right and top-to-bottom orientations, this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * equivalent to NORTH.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @see java.awt.Component#getComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public static final String PAGE_START = BEFORE_FIRST_LINE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * The component comes after the last line of the layout's content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * For Western, left-to-right and top-to-bottom orientations, this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * equivalent to SOUTH.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @see java.awt.Component#getComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public static final String PAGE_END = AFTER_LAST_LINE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * The component goes at the beginning of the line direction for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * layout. For Western, left-to-right and top-to-bottom orientations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * this is equivalent to WEST.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @see java.awt.Component#getComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public static final String LINE_START = BEFORE_LINE_BEGINS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * The component goes at the end of the line direction for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * layout. For Western, left-to-right and top-to-bottom orientations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * this is equivalent to EAST.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @see java.awt.Component#getComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public static final String LINE_END = AFTER_LINE_ENDS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     private static final long serialVersionUID = -8658291919501921765L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Constructs a new border layout with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * no gaps between components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public BorderLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        this(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Constructs a border layout with the specified gaps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * between components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * The horizontal gap is specified by <code>hgap</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * and the vertical gap is specified by <code>vgap</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @param   hgap   the horizontal gap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @param   vgap   the vertical gap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public BorderLayout(int hgap, int vgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        this.hgap = hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        this.vgap = vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Returns the horizontal gap between components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public int getHgap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        return hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Sets the horizontal gap between components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @param hgap the horizontal gap between components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public void setHgap(int hgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        this.hgap = hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Returns the vertical gap between components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public int getVgap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        return vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * Sets the vertical gap between components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @param vgap the vertical gap between components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public void setVgap(int vgap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        this.vgap = 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
     * Adds the specified component to the layout, using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * constraint object.  For border layouts, the constraint must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * one of the following constants:  <code>NORTH</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * <code>SOUTH</code>, <code>EAST</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <code>WEST</code>, or <code>CENTER</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Most applications do not call this method directly. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * is called when a component is added to a container using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * <code>Container.add</code> method with the same argument types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @param   comp         the component to be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @param   constraints  an object that specifies how and where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *                       the component is added to the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @see     java.awt.Container#add(java.awt.Component, java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @exception   IllegalArgumentException  if the constraint object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *                 a string, or if it not one of the five specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
         *              constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public void addLayoutComponent(Component comp, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
      synchronized (comp.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if ((constraints == null) || (constraints instanceof String)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            addLayoutComponent((String)constraints, comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            throw new IllegalArgumentException("cannot add to layout: constraint must be a string (or null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @deprecated  replaced by <code>addLayoutComponent(Component, Object)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public void addLayoutComponent(String name, Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
      synchronized (comp.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        /* Special case:  treat null the same as "Center". */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            name = "Center";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        /* Assign the component to one of the known regions of the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if ("Center".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            center = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        } else if ("North".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            north = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        } else if ("South".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            south = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        } else if ("East".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            east = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        } else if ("West".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            west = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        } else if (BEFORE_FIRST_LINE.equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            firstLine = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        } else if (AFTER_LAST_LINE.equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            lastLine = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        } else if (BEFORE_LINE_BEGINS.equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            firstItem = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        } else if (AFTER_LINE_ENDS.equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            lastItem = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            throw new IllegalArgumentException("cannot add to layout: unknown constraint: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
      }
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
     * Removes the specified component from this border layout. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * method is called when a container calls its <code>remove</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * <code>removeAll</code> methods. Most applications do not call this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * method directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @param   comp   the component to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @see     java.awt.Container#remove(java.awt.Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @see     java.awt.Container#removeAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public void removeLayoutComponent(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
      synchronized (comp.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (comp == center) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            center = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        } else if (comp == north) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            north = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        } else if (comp == south) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            south = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        } else if (comp == east) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            east = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        } else if (comp == west) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            west = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (comp == firstLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            firstLine = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        } else if (comp == lastLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            lastLine = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        } else if (comp == firstItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            firstItem = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        } else if (comp == lastItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            lastItem = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Gets the component that was added using the given constraint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @param   constraints  the desired constraint, one of <code>CENTER</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *                       <code>NORTH</code>, <code>SOUTH</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *                       <code>WEST</code>, <code>EAST</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *                       <code>PAGE_START</code>, <code>PAGE_END</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *                       <code>LINE_START</code>, <code>LINE_END</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @return  the component at the given location, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *          the location is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @exception   IllegalArgumentException  if the constraint object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *              not one of the nine specified constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @see     #addLayoutComponent(java.awt.Component, java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    public Component getLayoutComponent(Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if (CENTER.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            return center;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        } else if (NORTH.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            return north;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        } else if (SOUTH.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            return south;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        } else if (WEST.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            return west;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        } else if (EAST.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            return east;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        } else if (PAGE_START.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            return firstLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        } else if (PAGE_END.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            return lastLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        } else if (LINE_START.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            return firstItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        } else if (LINE_END.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            return lastItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            throw new IllegalArgumentException("cannot get component: unknown constraint: " + constraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * Returns the component that corresponds to the given constraint location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * based on the target <code>Container</code>'s component orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * Components added with the relative constraints <code>PAGE_START</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * <code>PAGE_END</code>, <code>LINE_START</code>, and <code>LINE_END</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * take precedence over components added with the explicit constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * <code>NORTH</code>, <code>SOUTH</code>, <code>WEST</code>, and <code>EAST</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * The <code>Container</code>'s component orientation is used to determine the location of components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * added with <code>LINE_START</code> and <code>LINE_END</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @param   constraints     the desired absolute position, one of <code>CENTER</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *                          <code>NORTH</code>, <code>SOUTH</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *                          <code>EAST</code>, <code>WEST</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @param   target     the {@code Container} used to obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *                     the constraint location based on the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *                     {@code Container}'s component orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @return  the component at the given location, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *          the location is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @exception   IllegalArgumentException  if the constraint object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *              not one of the five specified constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @exception   NullPointerException  if the target parameter is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @see     #addLayoutComponent(java.awt.Component, java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    public Component getLayoutComponent(Container target, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        boolean ltr = target.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        Component result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        if (NORTH.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            result = (firstLine != null) ? firstLine : north;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        } else if (SOUTH.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            result = (lastLine != null) ? lastLine : south;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        } else if (WEST.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            result = ltr ? firstItem : lastItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                result = west;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        } else if (EAST.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            result = ltr ? lastItem : firstItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                result = east;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        } else if (CENTER.equals(constraints)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            result = center;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            throw new IllegalArgumentException("cannot get component: invalid constraint: " + constraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Gets the constraints for the specified component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @param   comp the component to be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @return  the constraint for the specified component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *          or null if component is null or is not present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *          in this layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @see #addLayoutComponent(java.awt.Component, java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    public Object getConstraints(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        //fix for 6242148 : API method java.awt.BorderLayout.getConstraints(null) should return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (comp == null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (comp == center) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            return CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        } else if (comp == north) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            return NORTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        } else if (comp == south) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            return SOUTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        } else if (comp == west) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            return WEST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        } else if (comp == east) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            return EAST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        } else if (comp == firstLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            return PAGE_START;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        } else if (comp == lastLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            return PAGE_END;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        } else if (comp == firstItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            return LINE_START;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        } else if (comp == lastItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            return LINE_END;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Determines the minimum size of the <code>target</code> container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * using this layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * This method is called when a container calls its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * <code>getMinimumSize</code> method. Most applications do not call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * this method directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @param   target   the container in which to do the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @return  the minimum dimensions needed to lay out the subcomponents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *          of the specified container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @see     java.awt.Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @see     java.awt.BorderLayout#preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @see     java.awt.Container#getMinimumSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    public Dimension minimumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
      synchronized (target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        Dimension dim = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        boolean ltr = target.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        Component c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if ((c=getChild(EAST,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            Dimension d = c.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            dim.width += d.width + hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            dim.height = Math.max(d.height, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        if ((c=getChild(WEST,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            Dimension d = c.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            dim.width += d.width + hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            dim.height = Math.max(d.height, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        if ((c=getChild(CENTER,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            Dimension d = c.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            dim.width += d.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            dim.height = Math.max(d.height, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        if ((c=getChild(NORTH,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            Dimension d = c.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            dim.width = Math.max(d.width, dim.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            dim.height += d.height + vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        if ((c=getChild(SOUTH,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            Dimension d = c.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            dim.width = Math.max(d.width, dim.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            dim.height += d.height + vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        dim.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        dim.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * Determines the preferred size of the <code>target</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * container using this layout manager, based on the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * in the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * Most applications do not call this method directly. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * is called when a container calls its <code>getPreferredSize</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * @param   target   the container in which to do the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @return  the preferred dimensions to lay out the subcomponents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     *          of the specified container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @see     java.awt.Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @see     java.awt.BorderLayout#minimumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @see     java.awt.Container#getPreferredSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    public Dimension preferredLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
      synchronized (target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        Dimension dim = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        boolean ltr = target.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        Component c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        if ((c=getChild(EAST,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            Dimension d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            dim.width += d.width + hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            dim.height = Math.max(d.height, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        if ((c=getChild(WEST,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            Dimension d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            dim.width += d.width + hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            dim.height = Math.max(d.height, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        if ((c=getChild(CENTER,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            Dimension d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            dim.width += d.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            dim.height = Math.max(d.height, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        if ((c=getChild(NORTH,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            Dimension d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            dim.width = Math.max(d.width, dim.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            dim.height += d.height + vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        if ((c=getChild(SOUTH,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            Dimension d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            dim.width = Math.max(d.width, dim.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            dim.height += d.height + vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        dim.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        dim.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * Returns the maximum dimensions for this layout given the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * in the specified target container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @param target the component which needs to be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @see Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @see #minimumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * @see #preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    public Dimension maximumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
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 alignment along the x axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * the furthest away from the origin, 0.5 is centered, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    public float getLayoutAlignmentX(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        return 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * Returns the alignment along the y axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * the furthest away from the origin, 0.5 is centered, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    public float getLayoutAlignmentY(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        return 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * Invalidates the layout, indicating that if the layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * has cached information it should be discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    public void invalidateLayout(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * Lays out the container argument using this border layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * This method actually reshapes the components in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * container in order to satisfy the constraints of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * <code>BorderLayout</code> object. The <code>NORTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * and <code>SOUTH</code> components, if any, are placed at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * the top and bottom of the container, respectively. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * <code>WEST</code> and <code>EAST</code> components are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * then placed on the left and right, respectively. Finally,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * the <code>CENTER</code> object is placed in any remaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * space in the middle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * Most applications do not call this method directly. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * is called when a container calls its <code>doLayout</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @param   target   the container in which to do the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @see     java.awt.Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @see     java.awt.Container#doLayout()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    public void layoutContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
      synchronized (target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        int top = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        int bottom = target.height - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        int left = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        int right = target.width - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        boolean ltr = target.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        Component c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        if ((c=getChild(NORTH,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            c.setSize(right - left, c.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            Dimension d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            c.setBounds(left, top, right - left, d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            top += d.height + vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        if ((c=getChild(SOUTH,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            c.setSize(right - left, c.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            Dimension d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            c.setBounds(left, bottom - d.height, right - left, d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            bottom -= d.height + vgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if ((c=getChild(EAST,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            c.setSize(c.width, bottom - top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            Dimension d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            c.setBounds(right - d.width, top, d.width, bottom - top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            right -= d.width + hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        if ((c=getChild(WEST,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            c.setSize(c.width, bottom - top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            Dimension d = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            c.setBounds(left, top, d.width, bottom - top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            left += d.width + hgap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        if ((c=getChild(CENTER,ltr)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            c.setBounds(left, top, right - left, bottom - top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Get the component that corresponds to the given constraint location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * @param   key     The desired absolute position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     *                  either NORTH, SOUTH, EAST, or WEST.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @param   ltr     Is the component line direction left-to-right?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    private Component getChild(String key, boolean ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        Component result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        if (key == NORTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            result = (firstLine != null) ? firstLine : north;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        else if (key == SOUTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            result = (lastLine != null) ? lastLine : south;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        else if (key == WEST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            result = ltr ? firstItem : lastItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                result = west;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        else if (key == EAST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            result = ltr ? lastItem : firstItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                result = east;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        else if (key == CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            result = center;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        if (result != null && !result.visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * Returns a string representation of the state of this border layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @return    a string representation of this border layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
}