1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.guilayer.swing.models;
17
18 import java.beans.PropertyChangeEvent;
19 import java.beans.PropertyChangeListener;
20
21 import javax.swing.JComponent;
22 import javax.swing.table.TableCellEditor;
23 import javax.swing.table.TableCellRenderer;
24 import javax.swing.table.TableColumn;
25
26 import org.xulux.api.gui.IWidget;
27 import org.xulux.gui.XuluxCombo;
28 import org.xulux.guilayer.swing.widgets.Table;
29 import org.xulux.utils.BooleanUtils;
30
31
32
33
34
35
36
37
38 public class NyxTableColumn extends TableColumn {
39
40
41
42
43 private IWidget widget;
44
45
46
47 private NyxTableColumnModel model;
48
49
50
51
52 public NyxTableColumn() {
53 super();
54 }
55
56
57
58
59
60 public NyxTableColumn(IWidget widget) {
61 this.widget = widget;
62 addPropertyChangeListener(new PropertyChangeListener() {
63
64 public void propertyChange(PropertyChangeEvent evt) {
65 String property = evt.getPropertyName();
66 if ("preferredWith".equals(property) || "width".equals(property)) {
67
68 if (isLocked()) {
69 if (getModel() != null && !getModel().isInitializing()) {
70 int chgValue = ((Integer) evt.getNewValue()).intValue() - ((Integer) evt.getOldValue()).intValue();
71 int resultValue = (int) getModel().getLockedColumnWidth().getWidth() + chgValue;
72 getModel().setLockedColumnWidth(resultValue);
73 Table table = (Table) NyxTableColumn.this.widget.getParent();
74 table.getLockedJTable().setPreferredScrollableViewportSize(getModel().getLockedColumnWidth());
75 }
76 }
77 }
78 }
79
80 });
81 String resizable = widget.getProperty("resizable");
82 if ("false".equals(resizable)) {
83 setResizable(false);
84 } else {
85
86 setResizable(true);
87 }
88 setHeaderValue(widget.getProperty("text"));
89 int width = widget.getRectangle().getWidth();
90 if (width == 0) {
91 width = ((JComponent)widget.getNativeWidget()).getPreferredSize().width;
92 }
93 setPreferredWidth(width);
94 setWidth(width);
95 if (widget instanceof XuluxCombo) {
96 setCellEditor(new NyxTableCellEditor(widget));
97 }
98 }
99
100
101
102
103 public NyxTableColumn(int modelIndex) {
104 super(modelIndex);
105 }
106
107
108
109
110
111 public NyxTableColumn(int modelIndex, int width) {
112 super(modelIndex, width);
113 }
114
115
116
117
118
119
120
121 public NyxTableColumn(int modelIndex, int width, TableCellRenderer cellRenderer, TableCellEditor cellEditor) {
122 super(modelIndex, width, cellRenderer, cellEditor);
123 }
124
125
126
127
128 public boolean isLocked() {
129 return BooleanUtils.toBoolean(widget.getProperty("locked"));
130 }
131
132
133
134
135
136 public void setModel(NyxTableColumnModel model) {
137 this.model = model;
138 }
139
140
141
142
143 public NyxTableColumnModel getModel() {
144 return this.model;
145 }
146
147 }