double y = 0.0;
double maxWidth = 0.0;
List itemsInColumn = new ArrayList();
for (int i = 0; i < blocks.size(); i++) {
Block block = (Block) blocks.get(i);
Size2D size = block.arrange(g2, RectangleConstraint.NONE);
if (y + size.height <= height) {
itemsInColumn.add(block);
block.setBounds(
new Rectangle2D.Double(x, y, size.width, size.height)
);
y = y + size.height + this.verticalGap;
maxWidth = Math.max(maxWidth, size.width);
}
else {
if (itemsInColumn.isEmpty()) {
// place in this column (truncated) anyway
block.setBounds(
new Rectangle2D.Double(
x, y, size.width, Math.min(size.height, height - y)
)
);
y = 0.0;
x = x + size.width + this.horizontalGap;
}
else {
// start new column
itemsInColumn.clear();
x = x + maxWidth + this.horizontalGap;
y = 0.0;
maxWidth = size.width;
block.setBounds(
new Rectangle2D.Double(
x, y, size.width, Math.min(size.height, height)
)
);
y = size.height + this.verticalGap;
itemsInColumn.add(block);
}
}
}
return new Size2D(x + maxWidth, constraint.getHeight());
}