jdk/src/java.desktop/share/classes/javax/swing/OverlayLayout.java
author aghaisas
Mon, 10 Jul 2017 14:55:29 +0530
changeset 47151 362dcbee0613
parent 28059 e576535359cc
permissions -rw-r--r--
6919529: NPE from MultiUIDefaults.getUIError Reviewed-by: aghaisas, psadhukhan, serb Contributed-by: shashidhara.veerabhadraiah@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package 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
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20157
diff changeset
    48
 * of all JavaBeans&trade;
2
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
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22574
diff changeset
    53
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    55
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class OverlayLayout implements LayoutManager2,Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Constructs a layout manager that performs overlay
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * arrangement of the children.  The layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * created is dedicated to the given container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @param target  the container to do layout against
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    @ConstructorProperties({"target"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public OverlayLayout(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Returns the container that uses this layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @return the container that uses this layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public final Container getTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Indicates a child has changed its layout related information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * which causes any cached calculations to be flushed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param target the container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public void invalidateLayout(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        xChildren = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        yChildren = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        xTotal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        yTotal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Adds the specified component to the layout. Used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * this class to know when to invalidate layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param name the name of the component
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   100
     * @param comp the component to be added
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public void addLayoutComponent(String name, Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        invalidateLayout(comp.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Removes the specified component from the layout. Used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * this class to know when to invalidate layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param comp the component to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public void removeLayoutComponent(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        invalidateLayout(comp.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Adds the specified component to the layout, using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * constraint object. Used by this class to know when to invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param comp the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param constraints  where/how the component is added to the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public void addLayoutComponent(Component comp, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        invalidateLayout(comp.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Returns the preferred dimensions for this layout given the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * in the specified target container.  Recomputes the layout if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * has been invalidated.  Factors in the current inset setting returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * by getInsets().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param target the component which needs to be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @return a Dimension object containing the preferred dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see #minimumLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public Dimension preferredLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        Dimension size = new Dimension(xTotal.preferred, yTotal.preferred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        size.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        size.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Returns the minimum dimensions needed to lay out the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * contained in the specified target container.  Recomputes the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * if it has been invalidated, and factors in the current inset setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param target the component which needs to be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @return a Dimension object containing the minimum dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @see #preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public Dimension minimumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        Dimension size = new Dimension(xTotal.minimum, yTotal.minimum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        size.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        size.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Returns the maximum dimensions needed to lay out the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * contained in the specified target container.  Recomputes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * layout if it has been invalidated, and factors in the inset setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * returned by <code>getInset</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param target the component that needs to be laid out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @return a <code>Dimension</code> object containing the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *         dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @see #preferredLayoutSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public Dimension maximumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        Dimension size = new Dimension(xTotal.maximum, yTotal.maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        Insets insets = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        size.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        size.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Returns the alignment along the x axis for the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param target the container
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   195
     * @return the alignment &gt;= 0.0f &amp;&amp; &lt;= 1.0f
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public float getLayoutAlignmentX(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return xTotal.alignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Returns the alignment along the y axis for the container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param target the container
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 5506
diff changeset
   207
     * @return the alignment &gt;= 0.0f &amp;&amp; &lt;= 1.0f
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public float getLayoutAlignmentY(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return yTotal.alignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Called by the AWT when the specified container needs to be laid out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param target  the container to lay out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @exception AWTError  if the target isn't the container specified to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *                      constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public void layoutContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        checkContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        checkRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        int nChildren = target.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        int[] xOffsets = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        int[] xSpans = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        int[] yOffsets = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        int[] ySpans = new int[nChildren];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        // determine the child placements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        Dimension alloc = target.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        Insets in = target.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        alloc.width -= in.left + in.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        alloc.height -= in.top + in.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        SizeRequirements.calculateAlignedPositions(alloc.width, xTotal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                                   xChildren, xOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                                   xSpans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        SizeRequirements.calculateAlignedPositions(alloc.height, yTotal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                                   yChildren, yOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                                   ySpans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        // flush changes to the container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        for (int i = 0; i < nChildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            c.setBounds(in.left + xOffsets[i], in.top + yOffsets[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        xSpans[i], ySpans[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    void checkContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (this.target != target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            throw new AWTError("OverlayLayout can't be shared");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    void checkRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (xChildren == null || yChildren == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            // The requests have been invalidated... recalculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            // the request information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            int n = target.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            xChildren = new SizeRequirements[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            yChildren = new SizeRequirements[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                Dimension min = c.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                Dimension typ = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                Dimension max = c.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                xChildren[i] = new SizeRequirements(min.width, typ.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                                    max.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                                    c.getAlignmentX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                yChildren[i] = new SizeRequirements(min.height, typ.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                                    max.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                                    c.getAlignmentY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            xTotal = SizeRequirements.getAlignedSizeRequirements(xChildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            yTotal = SizeRequirements.getAlignedSizeRequirements(yChildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private Container target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private SizeRequirements[] xChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private SizeRequirements[] yChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    private SizeRequirements xTotal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private SizeRequirements yTotal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
}