jdk/src/share/classes/java/awt/GridBagLayoutInfo.java
author rkennke
Wed, 03 Feb 2010 10:02:33 +0100
changeset 4825 2398a67f1f58
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6896335: GraphicsEnvironment.getDefaultScreenDevice() throws UnsatisfiedLinkError in headless mode Summary: Use local ge variable instead of localEnv field in GE. Reviewed-by: igor, prr
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 2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The {@code GridBagLayoutInfo} is an utility class for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * {@code GridBagLayout} layout manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * It stores align, size and baseline parameters for every component within a container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @see       java.awt.GridBagLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @see       java.awt.GridBagConstraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class GridBagLayoutInfo implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final long serialVersionUID = -4899416460737170217L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    int width, height;          /* number of  cells: horizontal and vertical */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    int startx, starty;         /* starting point for layout */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    int minWidth[];             /* largest minWidth in each column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    int minHeight[];            /* largest minHeight in each row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    double weightX[];           /* largest weight in each column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    double weightY[];           /* largest weight in each row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    boolean hasBaseline;        /* Whether or not baseline layout has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                                 * requested and one of the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                                 * has a valid baseline. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // These are only valid if hasBaseline is true and are indexed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    short baselineType[];       /* The type of baseline for a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                                 * row.  A mix of the BaselineResizeBehavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                                 * constants (1 << ordinal()) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    int maxAscent[];            /* Max ascent (baseline). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    int maxDescent[];           /* Max descent (height - baseline) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Creates an instance of GridBagLayoutInfo representing {@code GridBagLayout}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * grid cells with it's own parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @param width the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @param height the rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @since 6.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    GridBagLayoutInfo(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        this.width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Returns true if the specified row has any component aligned on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * baseline with a baseline resize behavior of CONSTANT_DESCENT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    boolean hasConstantDescent(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        return ((baselineType[row] & (1 << Component.BaselineResizeBehavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                      CONSTANT_DESCENT.ordinal())) != 0);
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
     * Returns true if there is a baseline for the specified row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    boolean hasBaseline(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return (hasBaseline && baselineType[row] != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
}