long position = currentTable.getPosition();
// Second step: Apply the row heights to all cells.
// + Align all cells.
final TableRow[] rows = rowModel.getRows();
RenderNode rowNode = section.getFirstChild();
boolean firstRow = true;
while (rowNode != null)
{
if (rowNode instanceof TableRowRenderBox == false)
{
rowNode = rowNode.getNext();
continue;
}
if (rowNode.isDirty() == false)
{
throw new IllegalStateException("The row is not dirty?");
}
final TableRowRenderBox rowBox = (TableRowRenderBox) rowNode;
final int rowNumber = rowBox.getRowInfoStructure().getRowNumber();
final TableRow row = rows[rowNumber];
final long validatedRowHeight = row.getValidateSize();
if (firstRow)
{
firstRow = false;
}
else
{
position += rowModel.getRowSpacing();
}
final long oldPosition = rowBox.getY();
final long shift = position - oldPosition;
if (shift < 0)
{
throw new IllegalStateException("Shift-back is not allowed.");
}
shift(rowBox, shift);
shiftDistance += shift;
RenderNode cellNode = rowBox.getFirstChild();
while (cellNode != null)
{
if (cellNode instanceof TableCellRenderBox == false)
{
cellNode = cellNode.getNext();
continue;
}
final TableCellRenderBox cellBox = (TableCellRenderBox) cellNode;
final long cellShift = position - cellBox.getY();
if (cellShift != 0)
{
shift(cellBox, cellShift);
// this is an inner shift and therefore it has no influence on the
// global shiftdistance
}
cellBox.setHeight(validatedRowHeight);
// Todo: now align all the childs of the cellbox.
cellNode = cellNode.getNext();
}
rowBox.setHeight(validatedRowHeight);
rowBox.setDirty(false);
position += validatedRowHeight;
rowNode = rowNode.getNext();
}
// finally shift down all the content that comes afterwards.
// We have to update our parent's height as well as we extended the height
// of the table ..
final long newHeight = position - section.getY();
final long extendedHeight = newHeight - section.getHeight();
section.setHeight(newHeight);
if (extendedHeight != 0)
{
RenderNode parent = section.getParent();
while (parent != null)
{
parent.setHeight(parent.getHeight() + extendedHeight);
parent = parent.getParent();
}
shiftDistance += extendedHeight;
}