01: package com.salmonllc.swing.table;
02:
03: import com.salmonllc.swing.STable;
04: import com.salmonllc.personalization.Nameable;
05:
06: import javax.swing.table.TableColumn;
07:
08: /**
09: * SOFIA implementation of a table column.
10: */
11:
12: public class STableColumn extends TableColumn implements Nameable {
13: STable _tab;
14:
15: public STableColumn(String name, STable tab) {
16: _tab = tab;
17: setIdentifier(name);
18: }
19:
20: /** \
21: * get the identifier for the column in the table
22: * @return
23: */
24: public String getName() {
25: Object o = getIdentifier();
26: if (o instanceof String)
27: return (String) o;
28: return null;
29: }
30:
31: /**
32: * Returns the STable that the column is associated with
33: */
34: public STable getTable() {
35: return _tab;
36: }
37:
38: /**
39: * Returns true if the column is editable
40: */
41: public boolean isEditable() {
42: DataStoreTableModel tabMod = (DataStoreTableModel) _tab
43: .getModel();
44: return tabMod.isColumnEditable(getModelIndex());
45: }
46:
47: /**
48: * Sets whether or not the column is editable
49: */
50: public void setEditable(boolean editable) {
51: if (getModelIndex() != -1) {
52: DataStoreTableModel tabMod = (DataStoreTableModel) _tab
53: .getModel();
54: tabMod.setColumnEditable(getModelIndex(), editable);
55: }
56: }
57:
58: /**
59: * Sets whether or not the column is visible
60: */
61: public void setVisible(boolean visible) {
62: if (visible)
63: _tab.showColumn(getName());
64: else
65: _tab.hideColumn(getName());
66: }
67:
68: /**
69: * Sets the width of the column
70: */
71: public void setWidth(int width) {
72: super .setWidth(width);
73: setPreferredWidth(width);
74: }
75:
76: /**
77: * Sets the position of the column in the grid
78: */
79: public void setPosition(int newPos) {
80: _tab.moveColumn(getName(), newPos);
81: }
82: }
|