01: package snow.sortabletable;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05: import javax.swing.*;
06: import javax.swing.event.*;
07: import javax.swing.table.*;
08:
09: import java.util.*;
10:
11: /** wraps around a table model to extract first column of rest
12: */
13: public class RowHeaderExtractorWrapperTableModel extends
14: FineGrainTableModel {
15: boolean first;
16: FineGrainTableModel baseModel;
17: int numberOfColumnHeaders;
18:
19: public RowHeaderExtractorWrapperTableModel(boolean first,
20: FineGrainTableModel baseModel, int numberOfColumnHeaders) {
21: this .first = first;
22: this .baseModel = baseModel;
23: this .numberOfColumnHeaders = numberOfColumnHeaders;
24:
25: // give the events of the bassModel to this
26: baseModel.addTableModelListener(new TableModelListener() {
27: public void tableChanged(TableModelEvent e) {
28: fireTableDataChanged();
29: }
30: });
31: }
32:
33: private int getColumn(int col) {
34: if (first)
35: return col;
36: return col + numberOfColumnHeaders;
37: }
38:
39: // AbstractTableModel impl
40: //
41:
42: public int getRowCount() {
43: return baseModel.getRowCount();
44: }
45:
46: public int getColumnCount() {
47: return (first ? numberOfColumnHeaders : baseModel
48: .getColumnCount()
49: - numberOfColumnHeaders);
50: }
51:
52: @Override
53: public Object getValueAt(int row, int column) {
54: return baseModel.getValueAt(row, getColumn(column));
55: }
56:
57: /*
58: public boolean hitForTextSearch(int row, String str)
59: {
60: return baseModel.hitForTextSearch(row, str, null);
61: }*/
62: @Override
63: public boolean isCellEditable(int row, int col) {
64: return baseModel.isCellEditable(row, getColumn(col));
65: }
66:
67: @Override
68: public void setValueAt(Object val, int row, int col) {
69: super .setValueAt(val, row, getColumn(col));
70: }
71:
72: @Override
73: public String getColumnName(int column) {
74: return baseModel.getColumnName(getColumn(column));
75: }
76:
77: @Override
78: public Class getColumnClass(int col) {
79: return baseModel.getColumnClass(getColumn(col));
80: }
81:
82: @Override
83: public int compareForColumnSort(int pos1, int pos2, int col) {
84: return baseModel.compareForColumnSort(pos1, pos2,
85: getColumn(col));
86: }
87:
88: @Override
89: public int getPreferredColumnWidth(int col) {
90: return baseModel.getPreferredColumnWidth(getColumn(col));
91: }
92:
93: }
|