jdk/src/share/classes/javax/swing/BoxLayout.java
author dmarkov
Wed, 16 Apr 2014 12:51:25 +0400
changeset 24184 4da2f6ec4dab
parent 23010 6dadb192ad81
child 25201 4adc75e0c4e5
permissions -rw-r--r--
8032874: ArrayIndexOutOfBoundsException in JTable while clearing data in JTable Reviewed-by: alexp, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21592
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.ConstructorProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * A layout manager that allows multiple components to be laid out either
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * vertically or horizontally. The components will not wrap so, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * example, a vertical arrangement of components will stay vertically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * arranged when the frame is resized.
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    39
 * <TABLE STYLE="FLOAT:RIGHT" BORDER="0" SUMMARY="layout">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *    <TR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *      <TD ALIGN="CENTER">
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    42
 *         <P STYLE="TEXT-ALIGN:CENTER"><IMG SRC="doc-files/BoxLayout-1.gif"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *          alt="The following text describes this graphic."
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    44
 *          WIDTH="191" HEIGHT="201" STYLE="FLOAT:BOTTOM; BORDER:0">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      </TD>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *    </TR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * </TABLE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Nesting multiple panels with different combinations of horizontal and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * vertical gives an effect similar to GridBagLayout, without the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * complexity. The diagram shows two panels arranged horizontally, each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * of which contains 3 components arranged vertically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p> The BoxLayout manager is constructed with an axis parameter that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * specifies the type of layout that will be done. There are four choices:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <blockquote><b><tt>X_AXIS</tt></b> - Components are laid out horizontally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * from left to right.</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <blockquote><b><tt>Y_AXIS</tt></b> - Components are laid out vertically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * from top to bottom.</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <blockquote><b><tt>LINE_AXIS</tt></b> - Components are laid out the way
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * words are laid out in a line, based on the container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <tt>ComponentOrientation</tt> property. If the container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <tt>ComponentOrientation</tt> is horizontal then components are laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * horizontally, otherwise they are laid out vertically.  For horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * orientations, if the container's <tt>ComponentOrientation</tt> is left to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * right then components are laid out left to right, otherwise they are laid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * out right to left. For vertical orientations components are always laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * from top to bottom.</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <blockquote><b><tt>PAGE_AXIS</tt></b> - Components are laid out the way
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * text lines are laid out on a page, based on the container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <tt>ComponentOrientation</tt> property. If the container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <tt>ComponentOrientation</tt> is horizontal then components are laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * vertically, otherwise they are laid out horizontally.  For horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * orientations, if the container's <tt>ComponentOrientation</tt> is left to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * right then components are laid out left to right, otherwise they are laid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * out right to left.&nbsp; For vertical orientations components are always
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * laid out from top to bottom.</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * For all directions, components are arranged in the same order as they were
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * added to the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * BoxLayout attempts to arrange components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * at their preferred widths (for horizontal layout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * or heights (for vertical layout).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * For a horizontal layout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * if not all the components are the same height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * BoxLayout attempts to make all the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * as high as the highest component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * If that's not possible for a particular component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * then BoxLayout aligns that component vertically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * according to the component's Y alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * By default, a component has a Y alignment of 0.5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * which means that the vertical center of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * should have the same Y coordinate as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * the vertical centers of other components with 0.5 Y alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * Similarly, for a vertical layout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * BoxLayout attempts to make all components in the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * as wide as the widest component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * If that fails, it aligns them horizontally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * according to their X alignments.  For <code>PAGE_AXIS</code> layout,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * horizontal alignment is done based on the leading edge of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * In other words, an X alignment value of 0.0 means the left edge of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * component if the container's <code>ComponentOrientation</code> is left to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * right and it means the right edge of the component otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * Instead of using BoxLayout directly, many programs use the Box class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * The Box class is a lightweight container that uses a BoxLayout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * It also provides handy methods to help you use BoxLayout well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * Adding components to multiple nested boxes is a powerful way to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * the arrangement you want.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * For further information and examples see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 11268
diff changeset
   119
 href="http://docs.oracle.com/javase/tutorial/uiswing/layout/box.html">How to Use BoxLayout</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   127
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * @see Box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * @see java.awt.ComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * @see JComponent#getAlignmentX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * @see JComponent#getAlignmentY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * @author   Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   138
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
public class BoxLayout implements LayoutManager2, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Specifies that components should be laid out left to right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public static final int X_AXIS = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Specifies that components should be laid out top to bottom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public static final int Y_AXIS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Specifies that components should be laid out in the direction of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * a line of text as determined by the target container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * <code>ComponentOrientation</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public static final int LINE_AXIS = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Specifies that components should be laid out in the direction that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * lines flow across a page as determined by the target container's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <code>ComponentOrientation</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public static final int PAGE_AXIS = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Creates a layout manager that will lay out components along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * given axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param target  the container that needs to be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param axis  the axis to lay out components along. Can be one of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *              <code>BoxLayout.X_AXIS</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *              <code>BoxLayout.Y_AXIS</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *              <code>BoxLayout.LINE_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *              <code>BoxLayout.PAGE_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @exception AWTError  if the value of <code>axis</code> is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    @ConstructorProperties({"target", "axis"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public BoxLayout(Container target, int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (axis != X_AXIS && axis != Y_AXIS &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            axis != LINE_AXIS && axis != PAGE_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            throw new AWTError("Invalid axis");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        this.axis = axis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Constructs a BoxLayout that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * produces debugging messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param target  the container that needs to be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param axis  the axis to lay out components along. Can be one of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *              <code>BoxLayout.X_AXIS</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *              <code>BoxLayout.Y_AXIS</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *              <code>BoxLayout.LINE_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *              <code>BoxLayout.PAGE_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param dbg  the stream to which debugging messages should be sent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *   null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    BoxLayout(Container target, int axis, PrintStream dbg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        this(target, axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        this.dbg = dbg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Returns the container that uses this layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @return the container that uses this layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public final Container getTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns the axis that was used to lay out components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Returns one of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <code>BoxLayout.X_AXIS</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <code>BoxLayout.Y_AXIS</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <code>BoxLayout.LINE_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <code>BoxLayout.PAGE_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @return the axis that was used to lay out components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public final int getAxis() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return this.axis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Indicates that a child has changed its layout related information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * and thus any cached calculations should be flushed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * This method is called by AWT when the invalidate method is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * on the Container.  Since the invalidate method may be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * asynchronously to the event thread, this method may be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * asynchronously.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param target  the affected container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @exception AWTError  if the target isn't the container specified to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *                      BoxLayout constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public synchronized void invalidateLayout(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        xChildren = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        yChildren = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        xTotal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        yTotal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Not used by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @param name the name of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param comp the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public void addLayoutComponent(String name, Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        invalidateLayout(comp.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Not used by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param comp the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public void removeLayoutComponent(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        invalidateLayout(comp.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Not used by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param comp the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param constraints constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public void addLayoutComponent(Component comp, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        invalidateLayout(comp.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Returns the preferred dimensions for this layout, given the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * in the specified target container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param target  the container that needs to be laid out
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   290
     * @return the dimensions &gt;= 0 &amp;&amp; &lt;= Integer.MAX_VALUE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @exception AWTError  if the target isn't the container specified to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *                      BoxLayout constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @see Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @see #minimumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @see #maximumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public Dimension preferredLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        Dimension size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            size = new Dimension(xTotal.preferred, yTotal.preferred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        size.width = (int) Math.min((long) size.width + (long) insets.left + (long) insets.right, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        size.height = (int) Math.min((long) size.height + (long) insets.top + (long) insets.bottom, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Returns the minimum dimensions needed to lay out the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * contained in the specified target container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param target  the container that needs to be laid out
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   316
     * @return the dimensions &gt;= 0 &amp;&amp; &lt;= Integer.MAX_VALUE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @exception AWTError  if the target isn't the container specified to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *                      BoxLayout constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @see #preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @see #maximumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public Dimension minimumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        Dimension size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            size = new Dimension(xTotal.minimum, yTotal.minimum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        size.width = (int) Math.min((long) size.width + (long) insets.left + (long) insets.right, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        size.height = (int) Math.min((long) size.height + (long) insets.top + (long) insets.bottom, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Returns the maximum dimensions the target container can use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * to lay out the components it contains.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @param target  the container that needs to be laid out
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   341
     * @return the dimensions &gt;= 0 &amp;&amp; &lt;= Integer.MAX_VALUE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @exception AWTError  if the target isn't the container specified to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *                      BoxLayout constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see #preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @see #minimumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public Dimension maximumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        Dimension size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            size = new Dimension(xTotal.maximum, yTotal.maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        size.width = (int) Math.min((long) size.width + (long) insets.left + (long) insets.right, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        size.height = (int) Math.min((long) size.height + (long) insets.top + (long) insets.bottom, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Returns the alignment along the X axis for the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * If the box is horizontal, the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * alignment will be returned. Otherwise, the alignment needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * to place the children along the X axis will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param target  the container
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   368
     * @return the alignment &gt;= 0.0f &amp;&amp; &lt;= 1.0f
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @exception AWTError  if the target isn't the container specified to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *                      BoxLayout constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public synchronized float getLayoutAlignmentX(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return xTotal.alignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Returns the alignment along the Y axis for the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * If the box is vertical, the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * alignment will be returned. Otherwise, the alignment needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * to place the children along the Y axis will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @param target  the container
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   385
     * @return the alignment &gt;= 0.0f &amp;&amp; &lt;= 1.0f
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @exception AWTError  if the target isn't the container specified to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *                      BoxLayout constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public synchronized float getLayoutAlignmentY(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        return yTotal.alignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * Called by the AWT <!-- XXX CHECK! --> when the specified container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * needs to be laid out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @param target  the container to lay out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @exception AWTError  if the target isn't the container specified to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *                      BoxLayout constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public void layoutContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        int nChildren = target.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        int[] xOffsets = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        int[] xSpans = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        int[] yOffsets = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        int[] ySpans = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        Dimension alloc = target.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        Insets in = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        alloc.width -= in.left + in.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        alloc.height -= in.top + in.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        // Resolve axis to an absolute value (either X_AXIS or Y_AXIS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        ComponentOrientation o = target.getComponentOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        int absoluteAxis = resolveAxis( axis, o );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        boolean ltr = (absoluteAxis != axis) ? o.isLeftToRight() : true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // determine the child placements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            if (absoluteAxis == X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                SizeRequirements.calculateTiledPositions(alloc.width, xTotal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                                         xChildren, xOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                                         xSpans, ltr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                SizeRequirements.calculateAlignedPositions(alloc.height, yTotal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                                           yChildren, yOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                                           ySpans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                SizeRequirements.calculateAlignedPositions(alloc.width, xTotal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                                                           xChildren, xOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                                           xSpans, ltr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                SizeRequirements.calculateTiledPositions(alloc.height, yTotal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                                                         yChildren, yOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                                         ySpans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        // flush changes to the container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        for (int i = 0; i < nChildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            c.setBounds((int) Math.min((long) in.left + (long) xOffsets[i], Integer.MAX_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        (int) Math.min((long) in.top + (long) yOffsets[i], Integer.MAX_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                        xSpans[i], ySpans[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (dbg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            for (int i = 0; i < nChildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                dbg.println(c.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                dbg.println("X: " + xChildren[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                dbg.println("Y: " + yChildren[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    void checkContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (this.target != target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            throw new AWTError("BoxLayout can't be shared");
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
    void checkRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (xChildren == null || yChildren == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            // The requests have been invalidated... recalculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            // the request information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            int n = target.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            xChildren = new SizeRequirements[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            yChildren = new SizeRequirements[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                if (!c.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    xChildren[i] = new SizeRequirements(0,0,0, c.getAlignmentX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    yChildren[i] = new SizeRequirements(0,0,0, c.getAlignmentY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                Dimension min = c.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                Dimension typ = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                Dimension max = c.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                xChildren[i] = new SizeRequirements(min.width, typ.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                                    max.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                                    c.getAlignmentX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                yChildren[i] = new SizeRequirements(min.height, typ.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                                    max.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                                    c.getAlignmentY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            // Resolve axis to an absolute value (either X_AXIS or Y_AXIS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            int absoluteAxis = resolveAxis(axis,target.getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            if (absoluteAxis == X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                xTotal = SizeRequirements.getTiledSizeRequirements(xChildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                yTotal = SizeRequirements.getAlignedSizeRequirements(yChildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                xTotal = SizeRequirements.getAlignedSizeRequirements(xChildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                yTotal = SizeRequirements.getTiledSizeRequirements(yChildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Given one of the 4 axis values, resolve it to an absolute axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * The relative axis values, PAGE_AXIS and LINE_AXIS are converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * to their absolute couterpart given the target's ComponentOrientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * value.  The absolute axes, X_AXIS and Y_AXIS are returned unmodified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @param axis the axis to resolve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @param o the ComponentOrientation to resolve against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @return the resolved axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    private int resolveAxis( int axis, ComponentOrientation o ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        int absoluteAxis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if( axis == LINE_AXIS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            absoluteAxis = o.isHorizontal() ? X_AXIS : Y_AXIS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        } else if( axis == PAGE_AXIS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            absoluteAxis = o.isHorizontal() ? Y_AXIS : X_AXIS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            absoluteAxis = axis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        return absoluteAxis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    private int axis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    private Container target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    private transient SizeRequirements[] xChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    private transient SizeRequirements[] yChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    private transient SizeRequirements xTotal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    private transient SizeRequirements yTotal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    private transient PrintStream dbg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
}