jdk/src/share/classes/javax/swing/OverlayLayout.java
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE Summary: Add the Transient annotation and support it (JSR-273) Reviewed-by: peterz, loneid
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 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
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.ConstructorProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A layout manager to arrange components over the top
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * of each other.  The requested size of the container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * will be the largest requested size of the children,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * taking alignment needs into consideration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The alignment is based upon what is needed to properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * fit the children in the allocation area.  The children
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * will be placed such that their alignment points are all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * on top of each other.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author   Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class OverlayLayout implements LayoutManager2,Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Constructs a layout manager that performs overlay
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * arrangement of the children.  The layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * created is dedicated to the given container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param target  the container to do layout against
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    @ConstructorProperties({"target"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public OverlayLayout(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Returns the container that uses this layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @return the container that uses this layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public final Container getTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Indicates a child has changed its layout related information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * which causes any cached calculations to be flushed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param target the container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public void invalidateLayout(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        xChildren = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        yChildren = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        xTotal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        yTotal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Adds the specified component to the layout. Used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * this class to know when to invalidate layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param name the name of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param comp the the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void addLayoutComponent(String name, Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        invalidateLayout(comp.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Removes the specified component from the layout. Used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * this class to know when to invalidate layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param comp the component to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public void removeLayoutComponent(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        invalidateLayout(comp.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Adds the specified component to the layout, using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * constraint object. Used by this class to know when to invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param comp the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param constraints  where/how the component is added to the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void addLayoutComponent(Component comp, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        invalidateLayout(comp.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Returns the preferred dimensions for this layout given the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * in the specified target container.  Recomputes the layout if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * has been invalidated.  Factors in the current inset setting returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * by getInsets().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param target the component which needs to be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return a Dimension object containing the preferred dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @see #minimumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public Dimension preferredLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        Dimension size = new Dimension(xTotal.preferred, yTotal.preferred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        size.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        size.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Returns the minimum dimensions needed to lay out the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * contained in the specified target container.  Recomputes the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * if it has been invalidated, and factors in the current inset setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param target the component which needs to be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return a Dimension object containing the minimum dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @see #preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public Dimension minimumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        Dimension size = new Dimension(xTotal.minimum, yTotal.minimum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        size.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        size.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Returns the maximum dimensions needed to lay out the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * contained in the specified target container.  Recomputes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * layout if it has been invalidated, and factors in the inset setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * returned by <code>getInset</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param target the component that needs to be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @return a <code>Dimension</code> object containing the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *         dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @see #preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public Dimension maximumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        Dimension size = new Dimension(xTotal.maximum, yTotal.maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        size.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        size.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Returns the alignment along the x axis for the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param target the container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @return the alignment >= 0.0f && <= 1.0f
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public float getLayoutAlignmentX(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return xTotal.alignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns the alignment along the y axis for the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param target the container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @return the alignment >= 0.0f && <= 1.0f
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public float getLayoutAlignmentY(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return yTotal.alignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Called by the AWT when the specified container needs to be laid out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param target  the container to lay out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @exception AWTError  if the target isn't the container specified to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *                      constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public void layoutContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        int nChildren = target.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        int[] xOffsets = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        int[] xSpans = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        int[] yOffsets = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        int[] ySpans = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        // determine the child placements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Dimension alloc = target.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        Insets in = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        alloc.width -= in.left + in.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        alloc.height -= in.top + in.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        SizeRequirements.calculateAlignedPositions(alloc.width, xTotal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                                   xChildren, xOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                                   xSpans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        SizeRequirements.calculateAlignedPositions(alloc.height, yTotal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                                   yChildren, yOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                                   ySpans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        // flush changes to the container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        for (int i = 0; i < nChildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            c.setBounds(in.left + xOffsets[i], in.top + yOffsets[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        xSpans[i], ySpans[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    void checkContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (this.target != target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            throw new AWTError("OverlayLayout can't be shared");
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
    void checkRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (xChildren == null || yChildren == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            // The requests have been invalidated... recalculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            // the request information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            int n = target.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            xChildren = new SizeRequirements[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            yChildren = new SizeRequirements[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                Dimension min = c.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                Dimension typ = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                Dimension max = c.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                xChildren[i] = new SizeRequirements(min.width, typ.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                                    max.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                                    c.getAlignmentX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                yChildren[i] = new SizeRequirements(min.height, typ.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                                    max.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                                    c.getAlignmentY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            xTotal = SizeRequirements.getAlignedSizeRequirements(xChildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            yTotal = SizeRequirements.getAlignedSizeRequirements(yChildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private Container target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private SizeRequirements[] xChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private SizeRequirements[] yChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private SizeRequirements xTotal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private SizeRequirements yTotal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
}