diff options
| author | Paul Buetow <paul@buetow.org> | 2008-05-21 15:21:58 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-05-21 15:21:58 +0000 |
| commit | 004458bb854fe4376fe35ec55d7f08853e08895b (patch) | |
| tree | 3d1bb023e7a5560bb968d4d532de5bf0a2303a44 /sources/prefs/editors/VSEditorTable.java | |
| parent | 47f50635ca3fa3665f2b0bfb3cc29b2e9b88e88e (diff) | |
JTable editor better now.
Diffstat (limited to 'sources/prefs/editors/VSEditorTable.java')
| -rw-r--r-- | sources/prefs/editors/VSEditorTable.java | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/sources/prefs/editors/VSEditorTable.java b/sources/prefs/editors/VSEditorTable.java index 874abaa..ef4488f 100644 --- a/sources/prefs/editors/VSEditorTable.java +++ b/sources/prefs/editors/VSEditorTable.java @@ -10,6 +10,7 @@ import javax.swing.table.*; import prefs.*; public class VSEditorTable extends JTable { + private static final int MIN_ROWS = 20; private VSPrefs prefs; private ArrayList<VSNode> nodes; private VSEditorTableModel model; @@ -30,17 +31,18 @@ public class VSEditorTable extends JTable { public Component getComponent() { return comp; } + + public Component getRendererComponent() { + return comp; + } } - private class VSEditorTableModel extends AbstractTableModel { + private class VSEditorTableModel extends AbstractTableModel implements TableCellRenderer { public VSEditorTableModel() { } public String getColumnName(int col) { - if (col == 0) - return prefs.getString("lang.variable"); - - return prefs.getString("lang.value"); + return ""; } public int getRowCount() { @@ -69,13 +71,54 @@ public class VSEditorTable extends JTable { 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 (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.setMaxWidth(90); + col.setResizable(false); + + col = getColumnModel().getColumn(0); + col.sizeWidthToFit(); } public void addVariable(String key, Component comp) { |
