diff options
| author | Paul Buetow <paul@buetow.org> | 2008-05-21 11:25:06 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-05-21 11:25:06 +0000 |
| commit | 47f50635ca3fa3665f2b0bfb3cc29b2e9b88e88e (patch) | |
| tree | 8539c14942ff620b0ee11d861b90e8026445577b /sources | |
| parent | 986ba9e27e6a3f6bced32d675246c85448b83f4f (diff) | |
Initial JTable editor.
Diffstat (limited to 'sources')
| -rw-r--r-- | sources/prefs/VSDefaultPrefs.java | 2 | ||||
| -rw-r--r-- | sources/prefs/editors/VSEditor.java | 174 | ||||
| -rw-r--r-- | sources/prefs/editors/VSEditorTable.java | 85 | ||||
| -rw-r--r-- | sources/prefs/editors/VSProcessEditor.java | 66 | ||||
| -rw-r--r-- | sources/simulator/VSSimulation.java | 4 |
5 files changed, 115 insertions, 216 deletions
diff --git a/sources/prefs/VSDefaultPrefs.java b/sources/prefs/VSDefaultPrefs.java index c89d8ad..6511b0f 100644 --- a/sources/prefs/VSDefaultPrefs.java +++ b/sources/prefs/VSDefaultPrefs.java @@ -75,6 +75,8 @@ public class VSDefaultPrefs extends VSPrefs { initString("lang.open", "Öffnen"); initString("lang.pause", "Pausieren"); initString("lang.variables", "Variablen"); + initString("lang.variable", "Variable"); + initString("lang.value", "Wert"); initString("lang.variables.global", "Globale Variablen"); initString("lang.prefs", "Einstellungen"); initString("lang.prefs.ext", "Erweiterte Einstellungen"); diff --git a/sources/prefs/editors/VSEditor.java b/sources/prefs/editors/VSEditor.java index faea37f..40c02ba 100644 --- a/sources/prefs/editors/VSEditor.java +++ b/sources/prefs/editors/VSEditor.java @@ -34,12 +34,8 @@ public abstract class VSEditor implements ActionListener { protected VSPrefs prefsToEdit; public static final int ALL_PREFERENCES = 0; public static final int SIMULATION_PREFERENCES = 1; - protected GridBagConstraints editPanelConstraints; - protected int editPanelRow; - //protected Insets insetsTopSpaceing = new Insets(15, 0, 0, 0); - protected Insets insetsTopSpaceing = new Insets(0, 0, 0, 0); - protected Insets insets = new Insets(0, 0, 0, 0); private VSFrame frame; + protected VSEditorTable editTable; public VSEditor(VSPrefs prefs, VSPrefs prefsToEdit) { init(prefs, prefsToEdit, SIMULATION_PREFERENCES); @@ -167,49 +163,30 @@ public abstract class VSEditor implements ActionListener { } private JPanel createEditPanel() { - JPanel editPanel = new JPanel(new GridBagLayout()); + JPanel editPanel = new JPanel(); + editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.Y_AXIS)); editPanel.setBackground(Color.WHITE); - editPanelConstraints = new GridBagConstraints(); - editPanelConstraints.fill = GridBagConstraints.HORIZONTAL; - editPanelConstraints.ipady = 10;//15; - editPanelConstraints.ipadx = 10;//15; - editPanelRow = 0; + editTable = new VSEditorTable(prefs); + editPanel.add(editTable); addToEditPanelFront(editPanel); for (String key : integerKeys) { String fullKey = VSPrefs.INTEGER_PREFIX + key; String descr = prefsToEdit.getDescription(fullKey); - - JTextField keyLabel = new JTextField(LABEL_FIELD_COLS);; - keyLabel.setEditable(false); - keyLabel.setBackground(Color.WHITE); - - if (descr == null) - keyLabel.setText(fullKey); - else - keyLabel.setText(descr); - - editPanelConstraints.insets = insetsTopSpaceing; - editPanelConstraints.gridy = editPanelRow++; - editPanel.add(keyLabel, editPanelConstraints); - editPanelConstraints.insets = insets; - + String label = descr == null ? fullKey : descr; Integer integer = prefsToEdit.getInteger(key); Integer initialSelection[] = { integer }; JComboBox valComboBox = new JComboBox(initialSelection); VSPrefs.SettingRestriction settingRestriction = prefsToEdit.getRestriction(fullKey); int minValue, maxValue; - if (settingRestriction != null) { VSPrefs.IntegerSettingRestriction integerSettingRestriction = (VSPrefs.IntegerSettingRestriction) settingRestriction; - minValue = integerSettingRestriction.getMinValue(); maxValue = integerSettingRestriction.getMaxValue(); - } else { minValue = 0; maxValue = 100; @@ -218,68 +195,26 @@ public abstract class VSEditor implements ActionListener { for (int i = minValue; i <= maxValue; ++i) valComboBox.addItem(new Integer(i)); - valComboBox.repaint(); - - //JPanel pane = new JPanel(new BorderLayout()); - //pane.setBackground(Color.WHITE); - //pane.add(createUnitPanel(valComboBox, fullKey), BorderLayout.WEST); - - editPanelConstraints.insets = insets; - editPanelConstraints.gridx = 1; - editPanel.add(createUnitPanel(valComboBox, fullKey), editPanelConstraints); + //valComboBox.repaint(); integerFields.put(key, valComboBox); - editPanelConstraints.gridy = editPanelRow++; - editPanelConstraints.gridx = 0; + editTable.addVariable(label, createUnitPanel(valComboBox, fullKey)); } final String activated = prefs.getString("lang.activated"); for (String key : booleanKeys) { String fullKey = VSPrefs.BOOLEAN_PREFIX + key; String descr = prefsToEdit.getDescription(fullKey); - - JTextField keyLabel = new JTextField(LABEL_FIELD_COLS); - keyLabel.setEditable(false); - keyLabel.setBackground(Color.WHITE); - if (descr == null) - keyLabel.setText(fullKey); - else - keyLabel.setText(descr); - - editPanelConstraints.insets = insetsTopSpaceing; - editPanelConstraints.gridy = editPanelRow++; - editPanel.add(keyLabel, editPanelConstraints); - + String label = descr == null ? fullKey : descr; JCheckBox valField = new JCheckBox(activated, prefsToEdit.getBoolean(key)); valField.setBackground(Color.WHITE); - - JPanel pane = new JPanel(new BorderLayout()); - pane.setBackground(Color.WHITE); - pane.add(createUnitPanel(valField, fullKey), BorderLayout.WEST); - - editPanelConstraints.insets = insets; - editPanelConstraints.gridx = 1; - editPanel.add(pane, editPanelConstraints); - editPanelConstraints.gridx = 0; - editPanelConstraints.gridy = editPanelRow++; booleanFields.put(key, valField); + editTable.addVariable(label, createUnitPanel(valField, fullKey)); } for (String key : longKeys) { String fullKey = VSPrefs.LONG_PREFIX + key; String descr = prefsToEdit.getDescription(fullKey); - - JTextField keyLabel = new JTextField(LABEL_FIELD_COLS); - keyLabel.setEditable(false); - keyLabel.setBackground(Color.WHITE); - if (descr == null) - keyLabel.setText(fullKey); - else - keyLabel.setText(descr); - - editPanelConstraints.insets = insetsTopSpaceing; - editPanelConstraints.gridy = editPanelRow++; - editPanel.add(keyLabel, editPanelConstraints); - + String label = descr == null ? fullKey : descr; JTextField valField = new JTextField(VALUE_FIELD_COLS); valField.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent e) { @@ -289,36 +224,15 @@ public abstract class VSEditor implements ActionListener { } }); valField.setText(""+prefsToEdit.getLong(key)); - - JPanel pane = new JPanel(new BorderLayout()); - pane.setBackground(Color.WHITE); - pane.add(createUnitPanel(valField, fullKey), BorderLayout.WEST); - - editPanelConstraints.insets = insets; - editPanelConstraints.gridx = 1; - editPanel.add(pane, editPanelConstraints); - editPanelConstraints.gridx = 0; - editPanelConstraints.gridy = editPanelRow++; longFields.put(key, valField); + editTable.addVariable(label, createUnitPanel(valField, fullKey)); } for (String key : floatKeys) { String fullKey = VSPrefs.FLOAT_PREFIX + key; String descr = prefsToEdit.getDescription(fullKey); - - JTextField keyLabel = new JTextField(LABEL_FIELD_COLS); - keyLabel.setEditable(false); - keyLabel.setBackground(Color.WHITE); - if (descr == null) - keyLabel.setText(fullKey); - else - keyLabel.setText(descr); - - editPanelConstraints.insets = insetsTopSpaceing; - editPanelConstraints.gridy = editPanelRow++; - editPanel.add(keyLabel, editPanelConstraints); - + String label = descr == null ? fullKey : descr; JTextField valField = new JTextField(VALUE_FIELD_COLS); valField.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent e) { @@ -328,36 +242,15 @@ public abstract class VSEditor implements ActionListener { } }); valField.setText(""+prefsToEdit.getFloat(key)); - - JPanel pane = new JPanel(new BorderLayout()); - pane.setBackground(Color.WHITE); - pane.add(createUnitPanel(valField, fullKey), BorderLayout.WEST); - - editPanelConstraints.insets = insets; - editPanelConstraints.gridx = 1; - editPanel.add(pane, editPanelConstraints); - editPanelConstraints.gridx = 0; - editPanelConstraints.gridy = editPanelRow++; floatFields.put(key, valField); + editTable.addVariable(label, createUnitPanel(valField, fullKey)); } for (String key : colorKeys) { String fullKey = VSPrefs.COLOR_PREFIX + key; String descr = prefsToEdit.getDescription(fullKey); - - JTextField keyLabel = new JTextField(LABEL_FIELD_COLS); - keyLabel.setEditable(false); - keyLabel.setBackground(Color.WHITE); - if (descr == null) - keyLabel.setText(fullKey); - else - keyLabel.setText(descr); - - editPanelConstraints.insets = insetsTopSpaceing; - editPanelConstraints.gridy = editPanelRow++; - editPanel.add(keyLabel, editPanelConstraints); - + String label = descr == null ? fullKey : descr; final JTextField valField = new JTextField(VALUE_FIELD_COLS); Color color = prefsToEdit.getColor(key); valField.setBackground(color); @@ -383,31 +276,14 @@ public abstract class VSEditor implements ActionListener { frame.setVisible(true); } }); - - editPanelConstraints.insets = insets; - editPanelConstraints.gridx = 1; - editPanel.add(valField, editPanelConstraints); - editPanelConstraints.gridx = 0; - editPanelConstraints.gridy = editPanelRow++; colorFields.put(key, valField); + editTable.addVariable(label, valField); } for (String key : stringKeys) { String fullKey = VSPrefs.STRING_PREFIX + key; String descr = prefsToEdit.getDescription(fullKey); - - JTextField keyLabel = new JTextField(LABEL_FIELD_COLS); - keyLabel.setEditable(false); - keyLabel.setBackground(Color.WHITE); - if (descr == null) - keyLabel.setText(fullKey); - else - keyLabel.setText(descr); - - editPanelConstraints.insets = insetsTopSpaceing; - editPanelConstraints.gridy = editPanelRow++; - editPanel.add(keyLabel, editPanelConstraints); - + String label = descr == null ? fullKey : descr; JTextField valField = new JTextField(VALUE_FIELD_COLS); valField.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent e) { @@ -417,17 +293,11 @@ public abstract class VSEditor implements ActionListener { } }); valField.setText(prefsToEdit.getString(key)); - - editPanelConstraints.insets = insets; - editPanelConstraints.gridx = 1; - editPanel.add(createUnitPanel(valField, fullKey), editPanelConstraints); - editPanelConstraints.gridx = 0; - editPanelConstraints.gridy = editPanelRow++; stringFields.put(key, valField); + editTable.addVariable(label, createUnitPanel(valField, fullKey)); } addToEditPanelLast(editPanel); - return editPanel; } @@ -464,16 +334,21 @@ public abstract class VSEditor implements ActionListener { } protected void savePrefs() { + int i = 0; + System.out.println("FOO" + ++i); for (String key : integerKeys) { JComboBox valComboBox = integerFields.get(key); + System.out.println(valComboBox == null); prefsToEdit.setInteger(key, (Integer) valComboBox.getSelectedItem()); } + System.out.println("FOO" + ++i); for (String key : booleanKeys) { JCheckBox valField = booleanFields.get(key); prefsToEdit.setBoolean(key, valField.isSelected()); } + System.out.println("FOO" + ++i); for (String key : floatKeys) { JTextField valField = floatFields.get(key); @@ -486,6 +361,7 @@ public abstract class VSEditor implements ActionListener { } } + System.out.println("FOO" + ++i); for (String key : longKeys) { JTextField valField = longFields.get(key); @@ -498,11 +374,13 @@ public abstract class VSEditor implements ActionListener { } } + System.out.println("FOO" + ++i); for (String key : colorKeys) { JTextField valField = colorFields.get(key); prefsToEdit.setColor(key, valField.getBackground()); } + System.out.println("FOO" + ++i); for (String key : stringKeys) { JTextField valField = stringFields.get(key); prefsToEdit.setString(key, valField.getText()); diff --git a/sources/prefs/editors/VSEditorTable.java b/sources/prefs/editors/VSEditorTable.java new file mode 100644 index 0000000..874abaa --- /dev/null +++ b/sources/prefs/editors/VSEditorTable.java @@ -0,0 +1,85 @@ +package prefs.editors; + +import java.util.*; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.table.*; + +import prefs.*; + +public class VSEditorTable extends JTable { + private VSPrefs prefs; + private ArrayList<VSNode> nodes; + private VSEditorTableModel model; + + private class VSNode { + private String key; + private Component comp; + + public VSNode(String key, Component comp) { + this.key = key; + this.comp = comp; + } + + public String getKey() { + return key; + } + + public Component getComponent() { + return comp; + } + } + + private class VSEditorTableModel extends AbstractTableModel { + public VSEditorTableModel() { + } + + public String getColumnName(int col) { + if (col == 0) + return prefs.getString("lang.variable"); + + return prefs.getString("lang.value"); + } + + public int getRowCount() { + return nodes.size(); + } + + public int getColumnCount() { + return 2; + } + + public Object getValueAt(int row, int col) { + VSNode node = nodes.get(row); + + if (col == 0) + return node.getKey(); + else + return node.getComponent(); + } + + public boolean isCellEditable(int row, int col) { + if (col == 0) + return false; + + return true; + } + + public void setValueAt(Object value, int row, int col) { + } + } + + public VSEditorTable(VSPrefs prefs) { + this.prefs = prefs; + this.nodes = new ArrayList<VSNode>(); + this.model = new VSEditorTableModel(); + setModel(model); + } + + public void addVariable(String key, Component comp) { + nodes.add(new VSNode(key, comp)); + model.fireTableDataChanged(); + } +} diff --git a/sources/prefs/editors/VSProcessEditor.java b/sources/prefs/editors/VSProcessEditor.java index 0d55e86..1632ff1 100644 --- a/sources/prefs/editors/VSProcessEditor.java +++ b/sources/prefs/editors/VSProcessEditor.java @@ -52,72 +52,6 @@ public class VSProcessEditor extends VSBetterEditor { if (prefsCategory != SIMULATION_PREFERENCES) return; - editPanelConstraints.gridy = editPanelRow++; - editPanel.add(new JLabel(prefs.getString("lang.protocol.editor")), editPanelConstraints); - - editPanelConstraints.insets = insets; - editPanelConstraints.gridy = editPanelRow++; - JPanel protocolSelectorPanel = createProtocolSelector(); - editPanel.add(protocolSelectorPanel, editPanelConstraints); - - editPanelConstraints.insets = insetsTopSpaceing; - editPanelConstraints.gridy = editPanelRow++; - } - - private JPanel createProtocolSelector() { - JPanel panel = new JPanel(new GridBagLayout()); - panel.setBorder(BorderFactory.createLineBorder(Color.black)); - - Vector<String> registeredProtocolsNames = VSRegisteredEvents.getProtocolNames(); - Vector<String> registeredProtocolsShortnames = new Vector<String>(); - final HashMap<String,String> eventNames = new HashMap<String,String>(); - - for (String protocolName : registeredProtocolsNames) { - String protocolClassname = VSRegisteredEvents.getClassname(protocolName); - String protocolShortname = VSRegisteredEvents.getShortname(protocolClassname); - registeredProtocolsShortnames.add(protocolShortname); - eventNames.put(protocolShortname, protocolName); - } - - GridBagConstraints constraints = new GridBagConstraints(); - constraints.fill = GridBagConstraints.HORIZONTAL; - constraints.gridx = 0; - constraints.gridy = 0; - constraints.insets = new Insets(5, 0, 5, 0); - constraints.ipadx = 10; - constraints.ipady = 10; - - final JComboBox comboBox = new JComboBox(registeredProtocolsShortnames); - comboBox.setBackground(Color.WHITE); - panel.add(comboBox, constraints); - constraints.gridy = 1; - JButton button = new JButton(prefs.getString("lang.edit")); - button.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent ae) { - if (ae.getActionCommand().equals(prefs.getString("lang.edit"))) { - String eventShortname = (String) comboBox.getSelectedItem(); - String eventName = eventNames.get(eventShortname); - String eventClassname = VSRegisteredEvents.getClassname(eventName); - VSProtocol protocol = null; - if (process.objectExists(eventClassname)) { - Object object = process.getObject(eventClassname); - if (object instanceof VSProtocol) - protocol = (VSProtocol) process.getObject(eventClassname); - else - return; - } else { - protocol = (VSProtocol) VSRegisteredEvents.createEventInstanceByName(eventName, process); - process.setObject(eventClassname, protocol); - } - - //new VSProtocolEditor(prefs, frame, protocol); - } - } - }); - - panel.add(button, constraints); - - return panel; } protected void resetEditPanel() { diff --git a/sources/simulator/VSSimulation.java b/sources/simulator/VSSimulation.java index 0216550..31bc536 100644 --- a/sources/simulator/VSSimulation.java +++ b/sources/simulator/VSSimulation.java @@ -287,7 +287,7 @@ public class VSSimulation extends JPanel { localPIDComboBox.addItem(prefs.getString("lang.all")); globalPIDComboBox.addItem(prefs.getString("lang.all")); - tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); + tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT); tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { JTabbedPane pane = (JTabbedPane) ce.getSource(); @@ -350,7 +350,7 @@ public class VSSimulation extends JPanel { tabbedPane.add(prefs.getString("lang.variables"), variablesPanel); tabbedPane.add(prefs.getString("lang.variables.global"), globalVariablesPanel); - VSSimulationEditor editor = new VSSimulationEditor(prefs, simulatorFrame); + VSSimulationEditor editor = new VSSimulationEditor(prefs, simulatorFrame); globalVariablesPanel.add(new JScrollPane(editor.getContentPane())); editPanel.add(processesComboBox); |
