}
@Override
@SuppressWarnings("unchecked")
public void paint(Graphics2D graphics) {
TableView tableView = (TableView)getComponent();
List<Object> tableData = (List<Object>)tableView.getTableData();
TableView.ColumnSequence columns = tableView.getColumns();
int width = getWidth();
int height = getHeight();
// Paint the background
if (backgroundColor != null) {
graphics.setPaint(backgroundColor);
graphics.fillRect(0, 0, width, height);
}
// Ensure that we only paint items that are visible
int rowStart = 0;
int rowEnd = tableData.getLength() - 1;
Rectangle clipBounds = graphics.getClipBounds();
if (clipBounds != null) {
if (variableRowHeight) {
rowStart = getRowAt(clipBounds.y);
if (rowStart == -1) {
rowStart = tableData.getLength();
}
int lastRowBottomY = rowHeights.get(rowEnd+1) - 1;
rowEnd = getRowAt(Math.min(clipBounds.y + clipBounds.height - 1, lastRowBottomY));
} else {
rowStart = Math.max(rowStart, (int)Math.floor(clipBounds.y
/ (double)(fixedRowHeight + 1)));
rowEnd = Math.min(rowEnd, (int)Math.ceil((clipBounds.y
+ clipBounds.height) / (double)(fixedRowHeight + 1)) - 1);
}
}
// Paint the row backgrounds
if (alternateRowColor != null) {
for (int rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
int rowY = getRowY(rowIndex);
int rowHeight = getRowHeight(rowIndex);
if (rowIndex % 2 > 0) {
graphics.setPaint(alternateRowColor);
graphics.fillRect(0, rowY, width, rowHeight + 1);
}
}
}
// Paint the column backgrounds
int columnX = 0;
if (columnSelectionColor != null) {
graphics.setColor(columnSelectionColor);
columnX = 0;
for (int columnIndex = 0, columnCount = columns.getLength();
columnIndex < columnCount; columnIndex++) {
TableView.Column column = columns.get(columnIndex);
int columnWidth = columnWidths.get(columnIndex);
String columnName = column.getName();
SortDirection sortDirection = tableView.getSort().get(columnName);
if (sortDirection != null) {
graphics.fillRect(columnX, 0, columnWidth, height);
}
columnX += columnWidth + 1;
}
}
// Paint the table contents
for (int rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
Object rowData = tableData.get(rowIndex);
boolean rowHighlighted = (rowIndex == highlightedIndex
&& tableView.getSelectMode() != TableView.SelectMode.NONE);
boolean rowSelected = tableView.isRowSelected(rowIndex);
boolean rowDisabled = tableView.isRowDisabled(rowIndex);
int rowY = getRowY(rowIndex);
int rowHeight = getRowHeight(rowIndex);
// Paint selection state
Color rowBackgroundColor = null;
if (rowSelected) {
rowBackgroundColor = (tableView.isFocused())
? this.selectionBackgroundColor : inactiveSelectionBackgroundColor;
} else {
if (rowHighlighted && showHighlight && !rowDisabled) {
rowBackgroundColor = highlightBackgroundColor;
}
}
if (rowBackgroundColor != null) {
graphics.setPaint(rowBackgroundColor);
graphics.fillRect(0, rowY, width, rowHeight);
}
// Paint the cells
columnX = 0;
for (int columnIndex = 0, columnCount = columns.getLength();
columnIndex < columnCount; columnIndex++) {
TableView.Column column = columns.get(columnIndex);
TableView.CellRenderer cellRenderer = column.getCellRenderer();
int columnWidth = columnWidths.get(columnIndex);
Graphics2D rendererGraphics = (Graphics2D)graphics.create(columnX, rowY,
columnWidth, rowHeight);
cellRenderer.render(rowData, rowIndex, columnIndex, tableView, column.getName(),
rowSelected, rowHighlighted, rowDisabled);
cellRenderer.setSize(columnWidth, rowHeight);
cellRenderer.paint(rendererGraphics);
rendererGraphics.dispose();
columnX += columnWidth + 1;
}
}
// Paint the vertical grid lines
graphics.setPaint(verticalGridColor);
if (showVerticalGridLines) {
columnX = 0;
for (int columnIndex = 0, columnCount = columns.getLength();
columnIndex < columnCount; columnIndex++) {
columnX += columnWidths.get(columnIndex);
if (columnIndex < columnCount - 1
|| includeTrailingVerticalGridLine) {
GraphicsUtilities.drawLine(graphics, columnX, 0, height, Orientation.VERTICAL);
}
columnX++;
}
}
// Paint the horizontal grid lines
graphics.setPaint(horizontalGridColor);
if (showHorizontalGridLines) {
int rowCount = tableData.getLength();
for (int rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
int gridY = getRowY(rowIndex + 1) - 1;
if (rowIndex < rowCount - 1
|| includeTrailingHorizontalGridLine) {
GraphicsUtilities.drawLine(graphics, 0, gridY, width, Orientation.HORIZONTAL);
}
}
if (columnSelectionHorizontalGridColor != null) {
graphics.setColor(columnSelectionHorizontalGridColor);
columnX = 0;
for (int columnIndex = 0, columnCount = columns.getLength();
columnIndex < columnCount; columnIndex++) {
TableView.Column column = columns.get(columnIndex);
int columnWidth = columnWidths.get(columnIndex);
String columnName = column.getName();
SortDirection sortDirection = tableView.getSort().get(columnName);
if (sortDirection != null) {
for (int rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
int gridY = getRowY(rowIndex + 1) - 1;
if (rowIndex < rowCount - 1