use of com.itextpdf.layout.renderer.CellRenderer in project i7js-highlevel by itext.
the class AlternatingBackgroundTableRenderer method draw.
@Override
public void draw(DrawContext drawContext) {
for (int i = 0; i < rows.size() && null != rows.get(i) && null != rows.get(i)[0]; i++) {
CellRenderer[] renderers = rows.get(i);
Rectangle leftCell = renderers[0].getOccupiedAreaBBox();
Rectangle rightCell = renderers[renderers.length - 1].getOccupiedAreaBBox();
Rectangle rect = new Rectangle(leftCell.getLeft(), leftCell.getBottom(), rightCell.getRight() - leftCell.getLeft(), leftCell.getHeight());
PdfCanvas canvas = drawContext.getCanvas();
canvas.saveState();
if (isOdd) {
canvas.setFillColor(ColorConstants.LIGHT_GRAY);
isOdd = false;
} else {
canvas.setFillColor(ColorConstants.YELLOW);
isOdd = true;
}
canvas.rectangle(rect);
canvas.fill();
canvas.restoreState();
}
super.draw(drawContext);
}
Aggregations