Java Reference
In-Depth Information
/** The height of each row, as found by computLayoutSize(). */
int
int
[]
heights
;
/** Compute the size of the whole mess. Serves as the guts of
* preferredLayoutSize() and minimumLayoutSize().
* @param parent The container in which to do the layout.
* @param hp The horizontal padding (may be zero)
* @param vp The Vertical Padding (may be zero).
*/
protected
protected
Dimension
computeLayoutSize
(
Container parent
,
int
int
hp
,
int
int
vp
) {
iif
(!
validWidths
)
return
null
;
Component
[]
components
=
parent
.
getComponents
();
int
return null
int
preferredWidth
=
0
,
preferredHeight
=
0
;
widths
=
new
new
int
int
[
COLUMNS
];
heights
=
new
int
[
components
.
length
/
COLUMNS
];
// System.out.println("Grid: " + widths.length + ", " + heights.length);
new
int
int
int
i
;
// Pass One: Compute largest widths and heights.
for
for
(
i
=
0
;
i
<
components
.
length
;
i
++) {
int
int
row
=
i
/
widthPercentages
.
length
;
int
int
col
=
i
%
widthPercentages
.
length
;
Component c
=
components
[
i
];
Dimension d
=
c
.
getPreferredSize
();
widths
[
col
] =
Math
.
max
(
widths
[
col
],
d
.
width
);
heights
[
row
] =
Math
.
max
(
heights
[
row
],
d
.
height
);
}
// Pass two: agregate them.
for
for
(
i
=
0
;
i
<
widths
.
length
;
i
++)
preferredWidth
+=
widths
[
i
] +
hp
;
for
for
(
i
=
0
;
i
<
heights
.
length
;
i
++)
preferredHeight
+=
heights
[
i
] +
vp
;
// Finally, pass the sums back as the actual size.
return
return new
new
Dimension
(
preferredWidth
,
preferredHeight
);
}
/** Lays out the container in the specified panel. This is a row-column
* type layout; find x, y, width and height of each Component.
* @param parent The Container whose children we are laying out.
*/
public
public
void
void
layoutContainer
(
Container parent
) {
Debug
.
println
(
"layout"
,
"layoutContainer:"
);
iif
(!
validWidths
)