// determine the child placements
synchronized(this) {
checkRequests();
if (absoluteAxis == X_AXIS) {
SizeRequirements.calculateTiledPositions(alloc.width, xTotal,
xChildren, xOffsets,
xSpans, ltr);
SizeRequirements.calculateAlignedPositions(alloc.height, yTotal,
yChildren, yOffsets,
ySpans);
} else {
SizeRequirements.calculateAlignedPositions(alloc.width, xTotal,
xChildren, xOffsets,
xSpans, ltr);
SizeRequirements.calculateTiledPositions(alloc.height, yTotal,
yChildren, yOffsets,
ySpans);
}
}
// flush changes to the container
for (int i = 0; i < nChildren; i++) {
Component c = target.getComponent(i);
c.setBounds((int) Math.min((long) in.left + (long) xOffsets[i], Integer.MAX_VALUE),
(int) Math.min((long) in.top + (long) yOffsets[i], Integer.MAX_VALUE),
xSpans[i], ySpans[i]);
}
if (dbg != null) {
for (int i = 0; i < nChildren; i++) {
Component c = target.getComponent(i);
dbg.println(c.toString());
dbg.println("X: " + xChildren[i]);
dbg.println("Y: " + yChildren[i]);
}
}
}
void checkContainer(Container target) {
if (this.target != target) {
throw new AWTError("BoxLayout can't be shared");
}
}
void checkRequests() {
if (xChildren == null || yChildren == null) {
// The requests have been invalidated... recalculate
// the request information.
int n = target.getComponentCount();
xChildren = new SizeRequirements[n];
yChildren = new SizeRequirements[n];
for (int i = 0; i < n; i++) {
Component c = target.getComponent(i);
if (!c.isVisible()) {
xChildren[i] = new SizeRequirements(0,0,0, c.getAlignmentX());
yChildren[i] = new SizeRequirements(0,0,0, c.getAlignmentY());
continue;
}
Dimension min = c.getMinimumSize();
Dimension typ = c.getPreferredSize();
Dimension max = c.getMaximumSize();
xChildren[i] = new SizeRequirements(min.width, typ.width,
max.width,
c.getAlignmentX());
yChildren[i] = new SizeRequirements(min.height, typ.height,
max.height,
c.getAlignmentY());
}
// Resolve axis to an absolute value (either X_AXIS or Y_AXIS)
int absoluteAxis = resolveAxis(axis,target.getComponentOrientation());
if (absoluteAxis == X_AXIS) {
xTotal = SizeRequirements.getTiledSizeRequirements(xChildren);
yTotal = SizeRequirements.getAlignedSizeRequirements(yChildren);
} else {
xTotal = SizeRequirements.getAlignedSizeRequirements(xChildren);
yTotal = SizeRequirements.getTiledSizeRequirements(yChildren);
}
}
}
/**
* Given one of the 4 axis values, resolve it to an absolute axis.
* The relative axis values, PAGE_AXIS and LINE_AXIS are converted
* to their absolute couterpart given the target's ComponentOrientation
* value. The absolute axes, X_AXIS and Y_AXIS are returned unmodified.
*
* @param axis the axis to resolve
* @param o the ComponentOrientation to resolve against
* @return the resolved axis
*/
private int resolveAxis( int axis, ComponentOrientation o ) {
int absoluteAxis;
if( axis == LINE_AXIS ) {
absoluteAxis = o.isHorizontal() ? X_AXIS : Y_AXIS;
=5= |