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