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 | |
| parent | 47f50635ca3fa3665f2b0bfb3cc29b2e9b88e88e (diff) | |
JTable editor better now.
Diffstat (limited to 'sources/prefs/editors')
| -rw-r--r-- | sources/prefs/editors/VSBetterEditor.java | 9 | ||||
| -rw-r--r-- | sources/prefs/editors/VSEditor.java | 21 | ||||
| -rw-r--r-- | sources/prefs/editors/VSEditorTable.java | 53 |
3 files changed, 70 insertions, 13 deletions
diff --git a/sources/prefs/editors/VSBetterEditor.java b/sources/prefs/editors/VSBetterEditor.java index b280edc..217b13b 100644 --- a/sources/prefs/editors/VSBetterEditor.java +++ b/sources/prefs/editors/VSBetterEditor.java @@ -34,6 +34,7 @@ public abstract class VSBetterEditor extends VSEditor { } public Container getContentPane() { + contentPane.setBackground(Color.WHITE); return contentPane; } @@ -45,10 +46,10 @@ public abstract class VSBetterEditor extends VSEditor { JPanel editPanel = super.editPanel; JPanel buttonPanel = createButtonPanel(); - JScrollPane scrollPane = new JScrollPane(editPanel); - panel.add(infoArea, BorderLayout.NORTH); - panel.add(scrollPane, BorderLayout.CENTER); - panel.add(buttonPanel, BorderLayout.SOUTH); + //JScrollPane scrollPane = new JScrollPane(editPanel); + panel.add(infoArea); + panel.add(editPanel); + panel.add(buttonPanel); return panel; } diff --git a/sources/prefs/editors/VSEditor.java b/sources/prefs/editors/VSEditor.java index 40c02ba..6e554b2 100644 --- a/sources/prefs/editors/VSEditor.java +++ b/sources/prefs/editors/VSEditor.java @@ -15,6 +15,7 @@ import prefs.VSPrefs; public abstract class VSEditor implements ActionListener { protected static final int LABEL_FIELD_COLS = 18; protected static final int VALUE_FIELD_COLS = 7; + protected static final int MIN_UNIT_LENGTH = 5; protected int prefsCategory; private HashMap<String,JComboBox> integerFields; private HashMap<String,JTextField> colorFields; @@ -148,12 +149,16 @@ public abstract class VSEditor implements ActionListener { private JPanel createUnitPanel(Component comp, String key) { JPanel unitPanel = new JPanel(new GridBagLayout()); unitPanel.setBackground(Color.WHITE); + unitPanel.setBorder(null); String unitText = prefs.getUnit(key); if (unitText == null) unitText = ""; - JLabel unitLabel = new JLabel(" " + unitText); + unitText = " " + unitText; + while (unitText.length() < MIN_UNIT_LENGTH) + unitText = unitText + " "; + JLabel unitLabel = new JLabel(unitText); unitPanel.setLayout(new BoxLayout(unitPanel, BoxLayout.X_AXIS)); unitPanel.add(comp); @@ -166,11 +171,12 @@ public abstract class VSEditor implements ActionListener { JPanel editPanel = new JPanel(); editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.Y_AXIS)); editPanel.setBackground(Color.WHITE); + addToEditPanelFront(editPanel); editTable = new VSEditorTable(prefs); - editPanel.add(editTable); - - addToEditPanelFront(editPanel); + JScrollPane scrollPane = new JScrollPane(editTable); + //scrollPane.setBackground(Color.WHITE); + editPanel.add(scrollPane); for (String key : integerKeys) { String fullKey = VSPrefs.INTEGER_PREFIX + key; @@ -197,6 +203,7 @@ public abstract class VSEditor implements ActionListener { //valComboBox.repaint(); integerFields.put(key, valComboBox); + valComboBox.setBorder(null); editTable.addVariable(label, createUnitPanel(valComboBox, fullKey)); } @@ -208,6 +215,7 @@ public abstract class VSEditor implements ActionListener { JCheckBox valField = new JCheckBox(activated, prefsToEdit.getBoolean(key)); valField.setBackground(Color.WHITE); booleanFields.put(key, valField); + valField.setBorder(null); editTable.addVariable(label, createUnitPanel(valField, fullKey)); } @@ -225,6 +233,7 @@ public abstract class VSEditor implements ActionListener { }); valField.setText(""+prefsToEdit.getLong(key)); longFields.put(key, valField); + valField.setBorder(null); editTable.addVariable(label, createUnitPanel(valField, fullKey)); } @@ -243,6 +252,7 @@ public abstract class VSEditor implements ActionListener { }); valField.setText(""+prefsToEdit.getFloat(key)); floatFields.put(key, valField); + valField.setBorder(null); editTable.addVariable(label, createUnitPanel(valField, fullKey)); } @@ -277,6 +287,7 @@ public abstract class VSEditor implements ActionListener { } }); colorFields.put(key, valField); + valField.setBorder(null); editTable.addVariable(label, valField); } @@ -294,10 +305,12 @@ public abstract class VSEditor implements ActionListener { }); valField.setText(prefsToEdit.getString(key)); stringFields.put(key, valField); + valField.setBorder(null); editTable.addVariable(label, createUnitPanel(valField, fullKey)); } addToEditPanelLast(editPanel); + return editPanel; } 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) { |
