jdk/src/share/classes/sun/awt/OrientableFlowLayout.java
author art
Thu, 14 Oct 2010 14:07:50 +0400
changeset 6825 795e9fe949d3
parent 5506 202f599c92aa
permissions -rw-r--r--
6989721: awt native code compiler warnings Reviewed-by: yan, uta
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1996, 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 sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * Extends the FlowLayout class to support both vertical and horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * layout of components.  Orientation can be changed dynamically after
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * creation by calling either of the methods @method orientHorizontally or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @method orientVertically.  Separate values for alignment, vertical gap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * and horizontal gap can be specified for horizontal and vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author Terry Cline
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class OrientableFlowLayout extends FlowLayout {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * The horizontal orientation constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public static final int HORIZONTAL = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * The vertical orientation constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final int VERTICAL   = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * The top vertical alignment constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final int TOP        = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * The bottom vertical alignment constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static final int BOTTOM     = 2; // CENTER == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    int vAlign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    int vHGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    int vVGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Constructs a new flow layout with a horizontal orientation and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * centered alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public OrientableFlowLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this(HORIZONTAL, CENTER, CENTER, 5, 5, 5, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Constructs a new flow layout with the specified orientation and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * a centered alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param orientation the orientation, one of HORIZONTAL or VERTICAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public OrientableFlowLayout(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this(orientation, CENTER, CENTER, 5, 5, 5, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Constructs a new flow layout with the specified orientation and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param orientation the orientation, one of HORIZONTAL or VERTICAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param hAlign the horizontal alignment, one of LEFT, CENTER, or RIGHT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param vAlign the vertical alignment, one of TOP, CENTER, or BOTTOM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public OrientableFlowLayout(int orientation, int hAlign, int vAlign) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        this(orientation, hAlign, vAlign, 5, 5, 5, 5);
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
     * Constructs a new flow layout with the specified orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * alignment, and gap values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param orientation the orientation, one of HORIZONTAL or VERTICAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param hAlign the horizontal alignment, one of LEFT, CENTER, or RIGHT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param vAlign the vertical alignment, one of TOP, CENTER, or BOTTOM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param hHGap the horizontal gap between components in HORIZONTAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param hVGap the vertical gap between components in HORIZONTAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param vHGap the horizontal gap between components in VERTICAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param vVGap the vertical gap between components in VERTICAL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public OrientableFlowLayout(int orientation, int hAlign, int vAlign, int hHGap, int hVGap, int vHGap, int vVGap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        super(hAlign, hHGap, hVGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.vAlign      = vAlign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.vHGap       = vHGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.vVGap       = vVGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Set the layout's current orientation to horizontal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public synchronized void orientHorizontally() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        orientation = HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Set the layout's current orientation to vertical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public synchronized void orientVertically() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        orientation = VERTICAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Returns the preferred dimensions for this layout given the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * components in the specified target container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param target the component which needs to be laid out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @see Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @see FlowLayout
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
        if (orientation == HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            return super.preferredLayoutSize(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            Dimension dim = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            int n = target.countComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                if (c.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    Dimension cDim = c.preferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    dim.width = Math.max(dim.width, cDim.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                        dim.height += vVGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    dim.height += cDim.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            Insets insets = target.insets();;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            dim.width  += insets.left + insets.right  + vHGap*2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            dim.height += insets.top  + insets.bottom + vVGap*2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Returns the minimum dimensions needed to layout the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * contained in the specified target container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param target the component which needs to be laid out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @see #preferredLayoutSize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public Dimension minimumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (orientation == HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            return super.minimumLayoutSize(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            Dimension dim = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            int n = target.countComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                if (c.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    Dimension cDim = c.minimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    dim.width = Math.max(dim.width, cDim.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        dim.height += vVGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    dim.height += cDim.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            Insets insets = target.insets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            dim.width  += insets.left + insets.right  + vHGap*2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            dim.height += insets.top  + insets.bottom + vVGap*2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
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
     * Lays out the container.  This method will reshape the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * components in the target to satisfy the constraints of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param target the specified component being laid out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @see Container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public void layoutContainer(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (orientation == HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            super.layoutContainer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            Insets insets = target.insets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            Dimension targetDim = target.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            int maxHeight = targetDim.height - (insets.top + insets.bottom + vVGap*2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            int x = insets.left + vHGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            int y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            int colWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            int start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            int n = target.countComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                if (c.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    Dimension cDim = c.preferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    c.resize(cDim.width, cDim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    if ((y == 0) || ((y + cDim.height) <= maxHeight)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                        if (y > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                            y += vVGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        y += cDim.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                        colWidth = Math.max(colWidth, cDim.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                        moveComponents(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                       x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                       insets.top + vVGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                       colWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                       maxHeight - y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                       start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                       i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        x += vHGap + colWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        y = cDim.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        colWidth = cDim.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        start = 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            moveComponents(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                           x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                           insets.top + vVGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                           colWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                           maxHeight - y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                           start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                           n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Aligns the components vertically if there is any slack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param target the container whose components need to be moved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param x the x coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param y the y coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param width the width available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param height the height available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param colStart the beginning of the column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @param colEnd the end of the column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private void moveComponents(Container target, int x, int y, int width, int height, int colStart, int colEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        switch (vAlign) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        case TOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        case CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            y += height/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        case BOTTOM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            y += height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        for (int i = colStart; i < colEnd; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            Component c = target.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            Dimension cDim = c.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            if (c.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                c.move(x + (width - cDim.width)/2, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                y += vVGap + cDim.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Returns the String representation of this layout's values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        String str = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        switch (orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        case HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            str = "orientation=horizontal, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        case VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            str = "orientation=vertical, ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return getClass().getName() + "[" + str + super.toString() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
}