01: package org.swingml.tablebrowser.rowheader;
02:
03: import java.awt.*;
04:
05: import javax.swing.*;
06:
07: import org.swingml.tablebrowser.ext.*;
08:
09: /**
10: * @author CrossLogic
11: */
12: public class RowHeaderTable extends JTable {
13:
14: private boolean painting = false;
15: private TableBrowserComponent table = null;
16:
17: public RowHeaderTable(TableBrowserComponent table,
18: RowHeaderTableModel model) {
19: super (model);
20: setTable(table);
21: }
22:
23: public TableBrowserComponent getTable() {
24: return table;
25: }
26:
27: public boolean isPainting() {
28: return painting;
29: }
30:
31: public void paint(Graphics g) {
32: while (isPainting()) {
33: // wait
34: }
35: try {
36: setPainting(true);
37: super .paint(g);
38: } catch (Exception e) {
39:
40: } finally {
41: setPainting(false);
42: }
43:
44: }
45:
46: public void refresh() {
47: while (isPainting()) {
48: // wait
49: }
50: RowHeaderTableModel rowHeaderData = new RowHeaderTableModel(0,
51: 1);
52:
53: for (int x = 1; x <= getTable().getRowCount(); x++) {
54: // create row labels
55: rowHeaderData.addRow(new Object[] { x + "" });
56: }
57: setModel(rowHeaderData);
58: setEmptyHeaderCell();
59: }
60:
61: private void setEmptyHeaderCell() {
62: // empty out the first cell (0,0 location)
63: getTableHeader().getColumnModel().getColumn(0).setHeaderValue(
64: "");
65: }
66:
67: public void setPainting(boolean painting) {
68: this .painting = painting;
69: }
70:
71: public void setTable(TableBrowserComponent aTable) {
72: if (aTable != null) {
73: setEmptyHeaderCell();
74: }
75: this.table = aTable;
76: }
77:
78: }
|