1 package net.sourceforge.jpotpourri.gui.table;
2
3 import java.awt.Color;
4 import java.awt.Graphics;
5 import java.awt.Rectangle;
6
7 import javax.swing.table.TableColumn;
8 import javax.swing.table.TableColumnModel;
9
10 import net.sourceforge.jpotpourri.gui.IMacColors;
11 import net.sourceforge.jpotpourri.tools.UserSniffer;
12
13
14
15
16 public final class TableEmptyRowsPainter {
17
18 private final ITableFillEmptyRowsReceiver table;
19
20
21 public TableEmptyRowsPainter(final ITableFillEmptyRowsReceiver table) {
22 if(table == null) {
23 throw new NullPointerException("table");
24 }
25 this.table = table;
26 }
27
28
29
30
31 public void delegatePaint(final Graphics g) {
32
33 final int rowCount = this.table.getRowCount();
34 final Rectangle clip = g.getClipBounds();
35 final int height = clip.y + clip.height;
36
37 if (rowCount * this.table.getRowHeight() < height) {
38
39 for (int i = rowCount; i <= height / this.table.getRowHeight(); ++i) {
40 g.setColor(colorForRow(i));
41 g.fillRect(clip.x, i * this.table.getRowHeight(), clip.width, this.table.getRowHeight());
42 }
43
44
45 if (UserSniffer.isMacOSX() && this.table.getShowVerticalLines()) {
46 g.setColor(IMacColors.MAC_COLOR_UNFOCUSED_UNSELECTED_VERTICAL_LINE);
47 final TableColumnModel model = this.table.getColumnModel();
48 int x = 0;
49
50 for (int i = 0; i < model.getColumnCount(); ++i) {
51 TableColumn column = model.getColumn(i);
52 x += column.getWidth();
53 g.drawLine(x - 1, rowCount * this.table.getRowHeight(), x - 1, height);
54 }
55
56 }
57 }
58 }
59
60 private Color colorForRow(final int row) {
61 return (row % 2 == 1) ? this.table.getColorRowBackgroundOdd() : this.table.getColorRowBackgroundEven();
62 }
63 }