SpanModel

Top  Previous  Next

 

SpanDrawer queries a SpanModel in order to discover which cells of the table are spanned so that it can draw them appropriately. SpanModel's method:

 

public CellSpan getCellSpanAt(int row, int column);

 

is used to return a CellSpan object that specifies which cells are spanned.

 

CellSpan's structure is simple. A CellSpan object has four attributes:

 

spannedRow, spannedColumn: in a series of cell spans, these two integers define the top-left cell where the span begins.

rowSpan, columnSpan: these two integers define the number of rows and columns that the cell spans respectively.

 

Note: In a series of spanned cells, the getCellSpanAt method should return the same CellSpan object for all the affected cells.

 

If no SpanModel is specified in SpanDrawer's constructor, a DefaultSpanModel is created. DefaultSpanModel has the ability to dynamically add/remove spanned cells through the methods:

 

public void addCellSpan(CellSpan cellSpan);

public void removeAllCellSpans();

public void removeCellSpan(CellSpan cellSpan);

public void removeCellSpan(int row, int column);

 

You can create your own SpanModel by either implementing the SpanModel interface, or by extending the AbstractSpanModel class.

 

Example: Create a SpanModel that spans cells every three rows:

 

SpanModel spanModel = new AbstractSpanModel() {

       public CellSpan getCellSpanAt(int row, int column) {

               if (row % 3 == 0) {

                       return new CellSpan(row, column, 0, 4);

               }

       }

};

SpanDrawer drawer = table.getSpanDrawer();

drawer.setSpanModel(spanModel);