1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
package prefs.editors;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.text.*;
import prefs.*;
public class VSEditorTable extends JTable {
private static final int MIN_ROWS = 20;
private VSPrefs prefs;
private ArrayList<VSNode> nodes;
private VSEditorTableModel model;
private class VSNode {
private String key;
private Component comp;
public VSNode(String key) {
this.key = key;
}
public VSNode(String key, Component comp) {
this.key = key;
this.comp = comp;
}
public String getKey() {
return key;
}
public Component getComponent() {
return comp;
}
public Component getRendererComponent() {
return comp;
}
public boolean isSeparator() {
return comp == null;
}
}
private class VSEditorTableModel extends AbstractTableModel implements TableCellRenderer {
public VSEditorTableModel() {
}
public String getColumnName(int col) {
return "";
}
public int getRowCount() {
return nodes.size();
}
public int getColumnCount() {
return 2;
}
public Object getValueAt(int row, int col) {
VSNode node = nodes.get(row);
if (node.isSeparator()) {
if (col == 1)
return "";
return node.getKey();
}
if (col == 0)
return node.getKey();
return node.getComponent();
}
public boolean isCellEditable(int row, int col) {
if (col == 0)
return false;
if (nodes.get(row).isSeparator())
return false;
return true;
}
public void setValueAt(Object value, int row, int col) {
}
public Component getTableCellRendererComponent(JTable table,
Object object, boolean isSelected, boolean hasFocus, int
row, int col) {
VSNode node = nodes.get(row);
if (node.isSeparator()) {
JTextPane pane = new JTextPane();
if (col == 0) {
pane.setText(node.getKey());
Style style = pane.addStyle("Bold", null);
StyleConstants.setBold(style, true);
}
pane.setBackground(new Color(0xCF, 0xCF, 0XCF));
return pane;
}
if (col == 0) {
JTextField field = new JTextField(" "+node.getKey()+":");
field.setBorder(null);
field.setEditable(false);
field.setBackground(Color.WHITE);
return field;
}
return node.getRendererComponent();
}
}
private class VSTableCellEditor extends AbstractCellEditor implements TableCellEditor {
public Component getTableCellEditorComponent(JTable table, Object object,
boolean isSelected, int row, int col) {
return nodes.get(row).getComponent();
}
public Object getCellEditorValue() {
return new String("");
}
}
public VSEditorTable(VSPrefs prefs) {
this.prefs = prefs;
this.nodes = new ArrayList<VSNode>();
this.model = new VSEditorTableModel();
setModel(model);
setDefaultRenderer(Object.class, model);
setDefaultEditor(Object.class, new VSTableCellEditor());
setIntercellSpacing(new Dimension(5, 5));
setRowHeight(25);
setBackground(Color.WHITE);
getTableHeader().setVisible(false);
TableColumn col = getColumnModel().getColumn(1);
col.setMinWidth(100);
col.setMaxWidth(100);
col.setResizable(false);
col = getColumnModel().getColumn(0);
col.sizeWidthToFit();
}
public void addVariable(String key, Component comp) {
nodes.add(new VSNode(key, comp));
}
public void addSeparator(String text) {
nodes.add(new VSNode(text));
}
public void fireTableDataChanged() {
model.fireTableDataChanged();
}
}
|