borderInsets = new Insets(0, 0, 0, 0);
}
Rectangle clipRc = fixRectangle(oldRc, borderInsets);
//calc rectangle
SheetModel model = table.getModel();
CellPosition origin0 = getTopLeft(clipRc);
CellPosition originN = getBottomRight(clipRc);
if(origin0 == null || originN == null) {
//no cells
return;
}
int yBase = borderInsets.top;
for (int iRow = 0; iRow < origin0.row; iRow++) {
yBase += model.getRow(iRow).getHeight();
}
int xBase = borderInsets.left;
for (int iCol = 0; iCol < origin0.col; iCol++) {
xBase += model.getColumn(iCol).getWidth();
}
Spanned spanned[] = new Spanned[originN.col - origin0.col + 1];
for (int iRow = origin0.row; iRow <= originN.row; iRow++) {
int xLocalBase = xBase;
for (int iCol = origin0.col; iCol <= originN.col; ) { /// increment at end
//check if spanned
int index = iCol - origin0.col;
if(spanned[index] != null) {
spanned[index].rows--;
iCol += spanned[index].cols;
xLocalBase += spanned[index].width;
if(spanned[index].rows == 0) {
spanned[index] = null;
}
continue;
}
//define dimensions
CellPosition origin = model.getOrigin(new CellPosition(iRow, iCol));
Dimension size = model.getSize(origin);
Rectangle rc = new Rectangle();
//y offset for spanned cells may be > 0
rc.y = yBase;
for(int i=0; i < iRow-origin.row; i++) {
rc.y -= model.getRow(origin.row + i).getHeight();
}
//x offset for spanned cells may be > 0
rc.x = xLocalBase;
for(int i=0; i < iCol-origin.col; i++) {
rc.x -= model.getColumn(origin.col + i).getWidth();
}
//define cell width
rc.width = 0;
for (int i = 0; i < size.width; i++) {
rc.width += model.getColumn(origin.col + i).getWidth();
}
//define cell height
rc.height = 0;
for (int i = 0; i < size.height; i++) {
rc.height += model.getRow(origin.row + i).getHeight();
}
if(clipRc.intersects(rc)) {
//paint cell
g.setClip(clipRc.createIntersection(rc));
paintCell(g, rc, origin);
//update span info
int yLeft = (origin.row + size.height) - iRow;
if(yLeft > 1) {
int xLeft = (origin.col + size.width) - iCol;
spanned[index] = new Spanned(yLeft-1, xLeft, rc.width);
}
}
//update current position
iCol += size.width;
xLocalBase += rc.width;
}
//update current position
yBase += model.getRow(iRow).getHeight();
}
g.setColor(oldColor);
g.setClip(oldRc);
}