int cellsInRow = (Integer) invokeMethod(object, "getCellCount(int)", row);
rowCellCount.add(cellsInRow);
for (int cell = 0; cell < cellsInRow; cell++) {
int rowSpan = (Integer) invokeMethod(flex, "getRowSpan(int,int)", row, cell);
int colSpan = (Integer) invokeMethod(flex, "getColSpan(int,int)", row, cell);
cellToSpan.put(new Point(cell, row), new Dimension(colSpan, rowSpan));
}
}
}
// prepare m_columnCount as maximum count of columns in each row
for (int row = 0; row < m_rowCount; row++) {
int columnsInRow = 0;
int cellsInRow = rowCellCount.get(row);
for (int cell = 0; cell < cellsInRow; cell++) {
int colSpan = cellToSpan.get(new Point(cell, row)).width;
columnsInRow += colSpan;
}
m_columnCount = Math.max(m_columnCount, columnsInRow);
}
// last step: fill final m_rowCellCount and m_cellToSpan
for (int row = 0; row < m_rowCount; row++) {
// iterate over existing cells
int column = 0;
int cell = 0;
{
int cellsInRow = rowCellCount.get(row);
for (; cell < cellsInRow; cell++) {
Point key = new Point(cell, row);
// remember existing span
Dimension span = cellToSpan.get(key);
m_cellToSpan.put(key, span);
// move column index
column += span.width;
}
}
// if cells are over, but we still did not reach required number of columns...
while (column < m_columnCount) {
Point key = new Point(cell, row);
// remember default span
Dimension span = new Dimension(1, 1);
m_cellToSpan.put(key, span);
// next column/cell
column++;