try {
if (layoutPanel == null || !init(layoutPanel)) {
return;
}
final Dimension box = DOM.getClientSize(layoutPanel.getElement());
final int left = paddingLeftMeasure.sizeOf(layoutPanel);
final int top = paddingTopMeasure.sizeOf(layoutPanel);
int width = box.width - (left + paddingRightMeasure.sizeOf(layoutPanel));
int height = box.height
- (top + paddingBottomMeasure.sizeOf(layoutPanel));
final int spacing = layoutPanel.getWidgetSpacing();
// adjust for spacing
width -= ((cols - 1) * spacing);
height -= ((rows - 1) * spacing);
final int colWidth = width / cols;
final int rowHeight = height / rows;
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
Widget widget = widgetMatrix[c][r];
if (widget == null || widget == SPAN) {
continue;
}
if (widget instanceof InternalDecoratorPanel) {
widget = ((InternalDecoratorPanel) widget).getWidget();
}
int cellWidth;
int cellHeight;
final GridLayoutData layoutData = (GridLayoutData) widget.getLayoutData();
final Widget parent = widget.getParent();
if (parent instanceof InternalDecoratorPanel) {
final InternalDecoratorPanel decPanel = (InternalDecoratorPanel) parent;
final int borderSizes[] = decPanel.getBorderSizes();
final Dimension decPanelFrameSize = new Dimension(borderSizes[1]
+ borderSizes[3], borderSizes[0] + borderSizes[0]);
cellWidth = colWidth * layoutData.colspan - decPanelFrameSize.width
+ spacing * (layoutData.colspan - 1);
cellHeight = rowHeight * layoutData.rowspan
- decPanelFrameSize.height + spacing * (layoutData.rowspan - 1);
} else {
cellWidth = colWidth * layoutData.colspan + spacing
* (layoutData.colspan - 1);
cellHeight = rowHeight * layoutData.rowspan + spacing
* (layoutData.rowspan - 1);
}
HorizontalAlignmentConstant hAlignment = layoutData.getHorizontalAlignment();
if (hAlignment == null) {
hAlignment = getHorizontalAlignment();
}
Dimension prefSize = null;
if (hAlignment == null) {
layoutData.targetLeft = left + (spacing + colWidth) * c;
layoutData.targetWidth = cellWidth;
} else {
// (ggeorg) this call to WidgetHelper.getPreferredSize() is
// required even for ALIGN_LEFT
prefSize = new Dimension(preferredWidthMeasure.sizeOf(widget),
preferredHeightMeasure.sizeOf(widget));
if (HasHorizontalAlignment.ALIGN_LEFT == hAlignment) {
layoutData.targetLeft = left + (spacing + colWidth) * c;
} else if (HasHorizontalAlignment.ALIGN_CENTER == hAlignment) {
layoutData.targetLeft = left + (spacing + colWidth) * c
+ (cellWidth / 2) - prefSize.width / 2;
} else {
layoutData.targetLeft = left + (spacing + colWidth) * c
+ cellWidth - prefSize.width;
}
layoutData.targetWidth = prefSize.width;
}
VerticalAlignmentConstant vAlignment = layoutData.getVerticalAlignment();
if (vAlignment == null) {
vAlignment = getVerticalAlignment();
}
if (vAlignment == null) {
layoutData.targetTop = top + (spacing + rowHeight) * r;
layoutData.targetHeight = cellHeight;
} else {
if (prefSize == null) {
// (ggeorg) this call to WidgetHelper.getPreferredSize() is
// required even for ALIGN_TOP
prefSize = new Dimension(preferredWidthMeasure.sizeOf(widget),
preferredHeightMeasure.sizeOf(widget));
}
if (HasVerticalAlignment.ALIGN_TOP == vAlignment) {
layoutData.targetTop = top + (spacing + rowHeight) * r;
} else if (HasVerticalAlignment.ALIGN_MIDDLE == vAlignment) {