From 9f0d5c8015f4504bc8400cbb4247f38d9df62768 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 24 May 2008 16:47:25 +0000 Subject: new protocol editor works. --- sources/core/VSProcess.java | 2 +- sources/events/VSRegisteredEvents.java | 18 + sources/prefs/VSPrefs.java | 22 ++ sources/prefs/editors/VSBetterEditor.java | 1 + sources/prefs/editors/VSEditor.java | 456 +++++++++++++++++--------- sources/prefs/editors/VSProcessEditor.java | 14 +- sources/prefs/editors/VSSimulationEditor.java | 2 - sources/protocols/VSProtocol.java | 9 + sources/utils/VSPair.java | 19 -- sources/utils/VSTupel.java | 25 ++ 10 files changed, 386 insertions(+), 182 deletions(-) delete mode 100644 sources/utils/VSPair.java create mode 100644 sources/utils/VSTupel.java (limited to 'sources') diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java index ad3af56..faa7a09 100644 --- a/sources/core/VSProcess.java +++ b/sources/core/VSProcess.java @@ -11,7 +11,7 @@ import protocols.*; import simulator.*; import utils.*; -public final class VSProcess extends VSPrefs { +public class VSProcess extends VSPrefs { private ArrayList protocolsToReset; private ArrayList crashHistory; private ArrayList lamportTimeHistory; diff --git a/sources/events/VSRegisteredEvents.java b/sources/events/VSRegisteredEvents.java index 79fd31c..2643d6f 100644 --- a/sources/events/VSRegisteredEvents.java +++ b/sources/events/VSRegisteredEvents.java @@ -10,6 +10,7 @@ public final class VSRegisteredEvents { private static HashMap eventClassnames; private static HashMap eventShortnames; private static HashMap eventNames; + private static ArrayList editableProtocolsClassnames; private static VSPrefs prefs; public static void init(VSPrefs prefs_) { @@ -17,6 +18,7 @@ public final class VSRegisteredEvents { eventNames = new HashMap(); eventShortnames = new HashMap(); eventClassnames = new HashMap(); + editableProtocolsClassnames = new ArrayList(); registerEvent("events.implementations.ProcessCrashEvent", "Prozessabsturz", null); registerEvent("events.implementations.ProcessRecoverEvent", "Prozesswiederbelebung", null); @@ -26,6 +28,22 @@ public final class VSRegisteredEvents { registerEvent("protocols.implementations.ExternalTimeSyncProtocol", "Christians Methode zur externen Sync.", "Christians"); registerEvent("protocols.implementations.InternalTimeSyncProtocol", "Interne Synchronisation", "Interne Sync."); registerEvent("protocols.implementations.PingPongProtocol", "Ping Pong", null); + + /* Make dummy objects of each protocol, to see if they contain VSPrefs values to edit */ + Vector protocolClassnames = getProtocolClassnames(); + VSClassLoader classLoader = new VSClassLoader(); + for (String protocolClassname : protocolClassnames) { + Object object = classLoader.newInstance(protocolClassname); + if (object instanceof protocols.VSProtocol) { + protocols.VSProtocol protocol = (protocols.VSProtocol) object; + if (!protocol.isEmpty()) + editableProtocolsClassnames.add(protocolClassname); + } + } + } + + public static ArrayList getEditableProtocolsClassnames() { + return editableProtocolsClassnames; } public static Vector getProtocolNames() { diff --git a/sources/prefs/VSPrefs.java b/sources/prefs/VSPrefs.java index 6af0156..5b2cc9c 100644 --- a/sources/prefs/VSPrefs.java +++ b/sources/prefs/VSPrefs.java @@ -561,4 +561,26 @@ public abstract class VSPrefs implements Serializable { public long getID() { return id; } + + public boolean isEmpty() { + if (!colorPrefs.isEmpty()) + return false; + + if (!floatPrefs.isEmpty()) + return false; + + if (!integerPrefs.isEmpty()) + return false; + + if (!longPrefs.isEmpty()) + return false; + + if (!stringPrefs.isEmpty()) + return false; + + if (!booleanPrefs.isEmpty()) + return false; + + return true; + } } diff --git a/sources/prefs/editors/VSBetterEditor.java b/sources/prefs/editors/VSBetterEditor.java index 2ecf099..16aa4e2 100644 --- a/sources/prefs/editors/VSBetterEditor.java +++ b/sources/prefs/editors/VSBetterEditor.java @@ -50,6 +50,7 @@ public abstract class VSBetterEditor extends VSEditor { protected void addToButtonPanelFront(JPanel buttonPanel) { } protected void addToButtonPanelLast(JPanel buttonPanel) { } + protected void addToEditTableLast() { } public void actionPerformed(ActionEvent e) { //String actionCommand = e.getActionCommand(); diff --git a/sources/prefs/editors/VSEditor.java b/sources/prefs/editors/VSEditor.java index d8e3222..1ff488e 100644 --- a/sources/prefs/editors/VSEditor.java +++ b/sources/prefs/editors/VSEditor.java @@ -13,34 +13,39 @@ import utils.*; import prefs.VSPrefs; public abstract class VSEditor implements ActionListener { - protected static final int VALUE_FIELD_COLS = 9; - protected static final int MIN_UNIT_LENGTH = 5; - private HashMap integerFields; - private HashMap colorFields; - private HashMap floatFields; - private HashMap longFields; - private HashMap booleanFields; - private HashMap stringFields; + private ArrayList booleanKeys; private ArrayList colorKeys; private ArrayList floatKeys; private ArrayList integerKeys; private ArrayList longKeys; - private ArrayList booleanKeys; private ArrayList stringKeys; + private HashMap booleanFields; + private HashMap integerFields; + private HashMap colorFields; + private HashMap floatFields; + private HashMap longFields; + private HashMap stringFields; + private HashMap prefsToEditMap; private JPanel buttonPanel; private JPanel editPanel; + private VSEditorTable editTable; + private VSFrame frame; + private boolean expertModeChanged; protected VSPrefs prefs; protected VSPrefs prefsToEdit; + protected static final int MIN_UNIT_LENGTH = 5; + protected static final int VALUE_FIELD_COLS = 9; public static final int ALL_PREFERENCES = 0; public static final int SIMULATION_PREFERENCES = 1; - private VSFrame frame; - protected VSEditorTable editTable; - private boolean expertModeChanged; public VSEditor(VSPrefs prefs, VSPrefs prefsToEdit) { init(prefs, prefsToEdit); } + abstract protected void addToButtonPanelFront(JPanel buttonPanel); + abstract protected void addToButtonPanelLast(JPanel buttonPanel); + abstract protected void addToEditTableLast(); + public void setPrefs(VSPrefs prefs) { this.prefs = prefs; } @@ -74,12 +79,8 @@ public abstract class VSEditor implements ActionListener { editPanel = createEditPanel(); buttonPanel = createButtonPanel(); - colorKeys = filterKeys(prefsToEdit.getColorKeySet()); - floatKeys = filterKeys(prefsToEdit.getFloatKeySet()); - integerKeys = filterKeys(prefsToEdit.getIntegerKeySet()); - longKeys = filterKeys(prefsToEdit.getLongKeySet()); - booleanKeys = filterKeys(prefsToEdit.getBooleanKeySet()); - stringKeys = filterKeys(prefsToEdit.getStringKeySet()); + prefsToEditMap = new HashMap(); + colorFields = new HashMap(); floatFields = new HashMap(); integerFields = new HashMap(); @@ -87,7 +88,14 @@ public abstract class VSEditor implements ActionListener { booleanFields = new HashMap(); stringFields = new HashMap(); - fillEditPanel(editPanel, editTable); + colorKeys = filterKeys(prefsToEdit.getColorKeySet()); + floatKeys = filterKeys(prefsToEdit.getFloatKeySet()); + integerKeys = filterKeys(prefsToEdit.getIntegerKeySet()); + longKeys = filterKeys(prefsToEdit.getLongKeySet()); + booleanKeys = filterKeys(prefsToEdit.getBooleanKeySet()); + stringKeys = filterKeys(prefsToEdit.getStringKeySet()); + + fillEditPanel(prefsToEdit); } private ArrayList filterKeys(Set set) { @@ -106,9 +114,6 @@ public abstract class VSEditor implements ActionListener { return filtered; } - abstract protected void addToButtonPanelFront(JPanel buttonPanel); - abstract protected void addToButtonPanelLast(JPanel buttonPanel); - private JPanel createButtonPanel() { JPanel buttonPanel = new JPanel(); buttonPanel.setBackground(Color.WHITE); @@ -158,147 +163,175 @@ public abstract class VSEditor implements ActionListener { return editPanel; } - private void fillEditPanel(JPanel editPanel, VSEditorTable editTable) { - HashMap components = new HashMap(); - HashMap labels = new HashMap(); + protected VSTupel createIntegerComponent(String fullKey, String key, VSPrefs prefsToEdit) { + String descr = prefsToEdit.getDescription(fullKey); + 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; + } - for (String key : integerKeys) { - String fullKey = VSPrefs.INTEGER_PREFIX + key; - String descr = prefsToEdit.getDescription(fullKey); - 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; + for (int i = minValue; i <= maxValue; ++i) + valComboBox.addItem(new Integer(i)); + valComboBox.setBorder(null); + + return new VSTupel(label, createUnitPanel(valComboBox, fullKey), valComboBox); + } + + protected VSTupel createBooleanComponent(String fullKey, String key, VSPrefs prefsToEdit) { + final String activated = prefs.getString("lang.activated"); + String descr = prefsToEdit.getDescription(fullKey); + String label = descr == null ? fullKey : descr; + JCheckBox valField = new JCheckBox(activated, prefsToEdit.getBoolean(key)); + valField.setBackground(Color.WHITE); + valField.setBorder(null); + return new VSTupel(label, createUnitPanel(valField, fullKey), valField); + } + + protected VSTupel createLongComponent(String fullKey, String key, VSPrefs prefsToEdit) { + String descr = prefsToEdit.getDescription(fullKey); + 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) { + JTextField valField = (JTextField)e.getSource(); + if (valField.getText().length() >= valField.getColumns() + 10) + e.consume(); + } + }); + valField.setText(""+prefsToEdit.getLong(key)); + valField.setBorder(null); + return new VSTupel(label, createUnitPanel(valField, fullKey), valField); + } + + protected VSTupel createFloatComponent(String fullKey, String key, VSPrefs prefsToEdit) { + String descr = prefsToEdit.getDescription(fullKey); + 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) { + JTextField valField = (JTextField)e.getSource(); + if (valField.getText().length() >= valField.getColumns() + 10) + e.consume(); + } + }); + valField.setText(""+prefsToEdit.getFloat(key)); + valField.setBorder(null); + return new VSTupel(label, createUnitPanel(valField, fullKey), valField); + } + + protected VSTupel createColorComponent(String fullKey, String key, final VSPrefs prefsToEdit) { + String descr = prefsToEdit.getDescription(fullKey); + String label = descr == null ? fullKey : descr; + final JTextField valField = new JTextField(VALUE_FIELD_COLS); + Color color = prefsToEdit.getColor(key); + valField.setBackground(color); + valField.setEditable(false); + valField.addMouseListener(new MouseListener() { + public void mouseExited(MouseEvent e) { } + public void mouseReleased(MouseEvent e) { } + public void mouseEntered(MouseEvent e) { } + public void mousePressed(MouseEvent e) { } + public void mouseClicked(MouseEvent e) { + JFrame parentFrame = getFrame(); + JFrame frame = new VSFrame( + prefs.getString("lang.name") + " - " + + prefs.getString( + "lang.colorchooser"),parentFrame); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + JComponent colorChooserPane = new VSColorChooser(prefs, valField); + colorChooserPane.setOpaque(true); + + frame.setContentPane(colorChooserPane); + frame.pack(); + frame.setVisible(true); } + }); + valField.setBorder(null); + return new VSTupel(label, createUnitPanel(valField, fullKey), valField); + } - for (int i = minValue; i <= maxValue; ++i) - valComboBox.addItem(new Integer(i)); + protected VSTupel createStringComponent(String fullKey, String key, VSPrefs prefsToEdit) { + String descr = prefsToEdit.getDescription(fullKey); + 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) { + JTextField valField = (JTextField)e.getSource(); + if (valField.getText().length() >= valField.getColumns() + 10) + e.consume(); + } + }); + valField.setText(prefsToEdit.getString(key)); + valField.setBorder(null); + return new VSTupel(label, createUnitPanel(valField, fullKey), valField); + } - integerFields.put(key, valComboBox); - valComboBox.setBorder(null); + private void fillEditPanel(VSPrefs prefsToEdit) { + HashMap components = new HashMap(); + HashMap labels = new HashMap(); - labels.put(fullKey, label); - components.put(fullKey, createUnitPanel(valComboBox, fullKey)); + for (String key : integerKeys) { + String fullKey = VSPrefs.INTEGER_PREFIX + key; + VSTupel tupel = createIntegerComponent(fullKey, key, prefsToEdit); + labels.put(fullKey, tupel.getA()); + components.put(fullKey, tupel.getB()); + integerFields.put(key, tupel.getC()); } - final String activated = prefs.getString("lang.activated"); for (String key : booleanKeys) { String fullKey = VSPrefs.BOOLEAN_PREFIX + key; - String descr = prefsToEdit.getDescription(fullKey); - String label = descr == null ? fullKey : descr; - JCheckBox valField = new JCheckBox(activated, prefsToEdit.getBoolean(key)); - valField.setBackground(Color.WHITE); - booleanFields.put(key, valField); - valField.setBorder(null); - - labels.put(fullKey, label); - components.put(fullKey, createUnitPanel(valField, fullKey)); + VSTupel tupel = createBooleanComponent(fullKey, key, prefsToEdit); + labels.put(fullKey, tupel.getA()); + components.put(fullKey, tupel.getB()); + booleanFields.put(key, tupel.getC()); } for (String key : longKeys) { String fullKey = VSPrefs.LONG_PREFIX + key; - String descr = prefsToEdit.getDescription(fullKey); - 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) { - JTextField valField = (JTextField)e.getSource(); - if (valField.getText().length() >= valField.getColumns() + 10) - e.consume(); - } - }); - valField.setText(""+prefsToEdit.getLong(key)); - longFields.put(key, valField); - valField.setBorder(null); - - labels.put(fullKey, label); - components.put(fullKey, createUnitPanel(valField, fullKey)); + VSTupel tupel = createLongComponent(fullKey, key, prefsToEdit); + labels.put(fullKey, tupel.getA()); + components.put(fullKey, tupel.getB()); + longFields.put(key, tupel.getC()); } for (String key : floatKeys) { String fullKey = VSPrefs.FLOAT_PREFIX + key; - String descr = prefsToEdit.getDescription(fullKey); - 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) { - JTextField valField = (JTextField)e.getSource(); - if (valField.getText().length() >= valField.getColumns() + 10) - e.consume(); - } - }); - valField.setText(""+prefsToEdit.getFloat(key)); - floatFields.put(key, valField); - valField.setBorder(null); - labels.put(fullKey, label); - components.put(fullKey, createUnitPanel(valField, fullKey)); + VSTupel tupel = createFloatComponent(fullKey, key, prefsToEdit); + labels.put(fullKey, tupel.getA()); + components.put(fullKey, tupel.getB()); + floatFields.put(key, tupel.getC()); } for (String key : colorKeys) { String fullKey = VSPrefs.COLOR_PREFIX + key; - String descr = prefsToEdit.getDescription(fullKey); - String label = descr == null ? fullKey : descr; - final JTextField valField = new JTextField(VALUE_FIELD_COLS); - Color color = prefsToEdit.getColor(key); - valField.setBackground(color); - valField.setEditable(false); - valField.addMouseListener(new MouseListener() { - public void mouseExited(MouseEvent e) { } - public void mouseReleased(MouseEvent e) { } - public void mouseEntered(MouseEvent e) { } - public void mousePressed(MouseEvent e) { } - public void mouseClicked(MouseEvent e) { - JFrame parentFrame = getFrame(); - JFrame frame = new VSFrame( - prefs.getString("lang.name") + " - " + - prefs.getString( - "lang.colorchooser"),parentFrame); - frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - JComponent colorChooserPane = new VSColorChooser(prefs, valField); - colorChooserPane.setOpaque(true); - - frame.setContentPane(colorChooserPane); - frame.pack(); - frame.setVisible(true); - } - }); - colorFields.put(key, valField); - valField.setBorder(null); - labels.put(fullKey, label); - components.put(fullKey, valField); + VSTupel tupel = createColorComponent(fullKey, key, prefsToEdit); + labels.put(fullKey, tupel.getA()); + components.put(fullKey, tupel.getB()); + colorFields.put(key, tupel.getC()); } for (String key : stringKeys) { String fullKey = VSPrefs.STRING_PREFIX + key; - String descr = prefsToEdit.getDescription(fullKey); - 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) { - JTextField valField = (JTextField)e.getSource(); - if (valField.getText().length() >= valField.getColumns() + 10) - e.consume(); - } - }); - valField.setText(prefsToEdit.getString(key)); - stringFields.put(key, valField); - valField.setBorder(null); - labels.put(fullKey, label); - components.put(fullKey, createUnitPanel(valField, fullKey)); + VSTupel tupel = createStringComponent(fullKey, key, prefsToEdit); + labels.put(fullKey, tupel.getA()); + components.put(fullKey, tupel.getB()); + stringFields.put(key, tupel.getC()); } ArrayList fullKeys = new ArrayList(); @@ -311,9 +344,9 @@ public abstract class VSEditor implements ActionListener { if (key.startsWith("sim.")) { if (!flag) { flag = true; - editTable.addSeparator(prefs.getString("lang.prefs.simulation")); + addSeparator(prefs.getString("lang.prefs.simulation")); } - editTable.addVariable(labels.get(fullKey), components.get(fullKey)); + addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); } } @@ -323,9 +356,9 @@ public abstract class VSEditor implements ActionListener { if (key.startsWith("process.")) { if (!flag) { flag = true; - editTable.addSeparator(prefs.getString("lang.prefs.process")); + addSeparator(prefs.getString("lang.prefs.process")); } - editTable.addVariable(labels.get(fullKey), components.get(fullKey)); + addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); } } @@ -335,9 +368,9 @@ public abstract class VSEditor implements ActionListener { if (key.startsWith("message.")) { if (!flag) { flag = true; - editTable.addSeparator(prefs.getString("lang.prefs.message")); + addSeparator(prefs.getString("lang.prefs.message")); } - editTable.addVariable(labels.get(fullKey), components.get(fullKey)); + addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); } } @@ -347,9 +380,9 @@ public abstract class VSEditor implements ActionListener { if (key.startsWith("col.")) { if (!flag) { flag = true; - editTable.addSeparator(prefs.getString("lang.prefs.color")); + addSeparator(prefs.getString("lang.prefs.color")); } - editTable.addVariable(labels.get(fullKey), components.get(fullKey)); + addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); } } @@ -359,15 +392,90 @@ public abstract class VSEditor implements ActionListener { if (key.startsWith("div.")) { if (!flag) { flag = true; - editTable.addSeparator(prefs.getString("lang.prefs.diverse")); + addSeparator(prefs.getString("lang.prefs.diverse")); } - editTable.addVariable(labels.get(fullKey), components.get(fullKey)); + addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); } } + addToEditTableLast(); editTable.fireTableDataChanged(); } + protected void addToEditor(String label, String prefsKey, VSPrefs prefsToAdd) { + addSeparator(label); + prefsKey = "(" + prefsKey + ")"; + + ArrayList fullKeys = new ArrayList(); + + Set integerKeys = prefsToAdd.getIntegerKeySet(); + Set floatKeys = prefsToAdd.getFloatKeySet(); + Set longKeys = prefsToAdd.getLongKeySet(); + Set booleanKeys = prefsToAdd.getBooleanKeySet(); + Set stringKeys = prefsToAdd.getStringKeySet(); + + for (String key : integerKeys) fullKeys.add(VSPrefs.INTEGER_PREFIX + key); + for (String key : floatKeys) fullKeys.add(VSPrefs.FLOAT_PREFIX + key); + for (String key : longKeys) fullKeys.add(VSPrefs.LONG_PREFIX + key); + for (String key : booleanKeys) fullKeys.add(VSPrefs.BOOLEAN_PREFIX + key); + for (String key : stringKeys) fullKeys.add(VSPrefs.STRING_PREFIX + key); + + Collections.sort(fullKeys); + + for (String fullKey : fullKeys) { + String key = fullKey.substring(fullKey.indexOf(": ") + 2); + if (fullKey.startsWith(VSPrefs.INTEGER_PREFIX)) { + VSTupel tupel = + createIntegerComponent(fullKey, key, prefsToAdd); + this.integerKeys.add(prefsKey+key); + this.integerFields.put(prefsKey+key, tupel.getC()); + addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd); + + } else if (fullKey.startsWith(VSPrefs.BOOLEAN_PREFIX)) { + VSTupel tupel = + createBooleanComponent(fullKey, key, prefsToAdd); + this.booleanKeys.add(prefsKey + key); + this.booleanFields.put(prefsKey+key, tupel.getC()); + addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd); + + } else if (fullKey.startsWith(VSPrefs.LONG_PREFIX)) { + VSTupel tupel = + createLongComponent(fullKey, key, prefsToAdd); + this.longKeys.add(prefsKey+key); + this.longFields.put(prefsKey+key, tupel.getC()); + addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd); + + } else if (fullKey.startsWith(VSPrefs.FLOAT_PREFIX)) { + VSTupel tupel = + createFloatComponent(fullKey, key, prefsToAdd); + this.floatKeys.add(prefsKey + key); + this.floatFields.put(prefsKey+key, tupel.getC()); + addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd); + + } else if (fullKey.startsWith(VSPrefs.STRING_PREFIX)) { + VSTupel tupel = + createStringComponent(fullKey, key, prefsToAdd); + this.stringKeys.add(prefsKey + key); + this.stringFields.put(prefsKey+key, tupel.getC()); + addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd); + } + + } + } + + private void addSeparator(String label) { + editTable.addSeparator(label); + } + + private void addVariable(String label, Component component, VSPrefs prefs) { + addVariable("", label, component, prefs); + } + + private void addVariable(String prefsKey, String label, Component component, VSPrefs prefs) { + prefsToEditMap.put(prefsKey, prefs); + editTable.addVariable(label, component); + } + protected void resetEditPanel() { for (String key : integerKeys) { JComboBox valComboBox = integerFields.get(key); @@ -375,51 +483,75 @@ public abstract class VSEditor implements ActionListener { } for (String key : booleanKeys) { + String keys[] = getKeys(key); JCheckBox valField = booleanFields.get(key); - valField.setSelected(prefsToEdit.getBoolean(key)); + valField.setSelected(prefsToEditMap.get(keys[1]).getBoolean(keys[0])); } for (String key : floatKeys) { + String keys[] = getKeys(key); JTextField valField = floatFields.get(key); - valField.setText(""+prefsToEdit.getFloat(key)); + valField.setText(""+prefsToEditMap.get(keys[1]).getFloat(keys[0])); } for (String key : longKeys) { + String keys[] = getKeys(key); JTextField valField = longFields.get(key); - valField.setText(""+prefsToEdit.getLong(key)); + valField.setText(""+prefsToEditMap.get(keys[1]).getLong(keys[0])); } for (String key : colorKeys) { + String keys[] = getKeys(key); JTextField valField = colorFields.get(key); - valField.setBackground(prefsToEdit.getColor(key)); + valField.setBackground(prefsToEditMap.get(keys[1]).getColor(keys[0])); } for (String key : stringKeys) { - JTextField valField = stringFields.get(key); - valField.setText(prefsToEdit.getString(key)); + String keys[] = getKeys(key); + JTextField valField = stringFields.get(keys); + valField.setText(prefsToEditMap.get(keys[1]).getString(keys[0])); + } + } + + /** + * @return [0] := key, [1] := prefsKey + */ + private String[] getKeys(String key) { + String keys[] = { key, "" }; + + if (key.startsWith("(")) { + keys[1] = key.substring(0, key.indexOf(")") + 1); + keys[0] = key.substring(key.indexOf(")")+1); } + + return keys; } protected void savePrefs() { boolean expertMode = prefs.getBoolean("sim.mode.expert"); - int i = 0; for (String key : integerKeys) { + String keys[] = getKeys(key); + //String fullKey = VSPrefs.INTEGER_PREFIX + keys[0]; JComboBox valComboBox = integerFields.get(key); - prefsToEdit.setInteger(key, (Integer) valComboBox.getSelectedItem()); + prefsToEditMap.get(keys[1]).setInteger(keys[0], (Integer) valComboBox.getSelectedItem()); } for (String key : booleanKeys) { + String keys[] = getKeys(key); + //String fullKey = VSPrefs.BOOLEAN_PREFIX + keys[0]; JCheckBox valField = booleanFields.get(key); - prefsToEdit.setBoolean(key, valField.isSelected()); + prefsToEditMap.get(keys[1]).setBoolean(keys[0], valField.isSelected()); } for (String key : floatKeys) { + String keys[] = getKeys(key); JTextField valField = floatFields.get(key); try { + //String fullKey = VSPrefs.FLOAT_PREFIX + keys[0]; Float val = Float.valueOf(valField.getText()); - prefsToEdit.setFloat(key, val); + prefsToEditMap.get(keys[1]).setFloat(keys[0], val); } catch (NumberFormatException e) { valField.setText("0.0"); @@ -427,11 +559,13 @@ public abstract class VSEditor implements ActionListener { } for (String key : longKeys) { + String keys[] = getKeys(key); JTextField valField = longFields.get(key); try { + //String fullKey = VSPrefs.LONG_PREFIX + keys[0]; Long val = Long.valueOf(valField.getText()); - prefsToEdit.setLong(key, val); + prefsToEditMap.get(keys[1]).setLong(keys[0], val); } catch (NumberFormatException e) { valField.setText("0"); @@ -439,13 +573,17 @@ public abstract class VSEditor implements ActionListener { } for (String key : colorKeys) { + String keys[] = getKeys(key); + //String fullKey = VSPrefs.COLOR_PREFIX + keys[0]; JTextField valField = colorFields.get(key); - prefsToEdit.setColor(key, valField.getBackground()); + prefsToEditMap.get(keys[1]).setColor(keys[0], valField.getBackground()); } for (String key : stringKeys) { + String keys[] = getKeys(key); + //String fullKey = VSPrefs.STRING_PREFIX + keys[0]; JTextField valField = stringFields.get(key); - prefsToEdit.setString(key, valField.getText()); + prefsToEditMap.get(keys[1]).setString(keys[0], valField.getText()); } expertModeChanged = expertMode != prefs.getBoolean("sim.mode.expert"); diff --git a/sources/prefs/editors/VSProcessEditor.java b/sources/prefs/editors/VSProcessEditor.java index 891b597..51e4319 100644 --- a/sources/prefs/editors/VSProcessEditor.java +++ b/sources/prefs/editors/VSProcessEditor.java @@ -23,7 +23,7 @@ public class VSProcessEditor extends VSBetterEditor { super(prefs, process, prefs.getString("lang.name") + " - " + prefs.getString("lang.prefs.process"));; this.process = process; disposeFrameWithParentIfExists(); - getInfoArea().setText(prefs.getString("lang.prefs.process.info!")); + makeProtocolVariablesEditable(); } protected void addToButtonPanelFront(JPanel buttonPanel) { @@ -34,6 +34,18 @@ public class VSProcessEditor extends VSBetterEditor { buttonPanel.add(takeoverButton); } + protected void makeProtocolVariablesEditable() { + ArrayList editableProtocolsClassnames = + VSRegisteredEvents.getEditableProtocolsClassnames(); + + String protocolString = " " + prefs.getString("lang.protocol"); + for (String protocolClassname : editableProtocolsClassnames) { + String protocolShortname = VSRegisteredEvents.getShortname(protocolClassname); + VSProtocol protocol = process.getProtocolObject(protocolClassname); + addToEditor(protocolShortname + protocolString, protocolShortname, protocol); + } + } + public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); diff --git a/sources/prefs/editors/VSSimulationEditor.java b/sources/prefs/editors/VSSimulationEditor.java index 538ba70..4637ec9 100644 --- a/sources/prefs/editors/VSSimulationEditor.java +++ b/sources/prefs/editors/VSSimulationEditor.java @@ -24,14 +24,12 @@ public class VSSimulationEditor extends VSBetterEditor { this.dontStartNewSimulation = true;//simulation != null; this.simulatorFrame = simulatorFrame; this.simulation = simulation; - getInfoArea().setText(prefs.getString("lang.prefs.info!")); } public VSSimulationEditor(VSPrefs prefs, VSSimulatorFrame simulatorFrame) { super(prefs, prefs, prefs.getString("lang.name") + " - " + prefs.getString("lang.prefs")); this.simulatorFrame = simulatorFrame; - getInfoArea().setText(prefs.getString("lang.prefs.info!")); } protected void addToButtonPanelFront(JPanel buttonPanel) { diff --git a/sources/protocols/VSProtocol.java b/sources/protocols/VSProtocol.java index 291b778..e13fe2e 100644 --- a/sources/protocols/VSProtocol.java +++ b/sources/protocols/VSProtocol.java @@ -10,6 +10,9 @@ abstract public class VSProtocol extends VSEvent { private boolean currentContextIsServer; protected void sendMessage(VSMessage message) { + if (process == null) + return; + process.increaseLamportTime(); process.increaseVectorTime(); message.init(process); @@ -72,10 +75,16 @@ abstract public class VSProtocol extends VSEvent { abstract protected void onServerRecv(VSMessage message); protected int getNumProcesses() { + if (process == null) + return 0; + return process.getSimulationCanvas().getNumProcesses(); } public String toString() { + if (process == null) + return ""; + StringBuffer buffer = new StringBuffer(); buffer.append(prefs.getString("lang.protocol")); diff --git a/sources/utils/VSPair.java b/sources/utils/VSPair.java deleted file mode 100644 index d642a18..0000000 --- a/sources/utils/VSPair.java +++ /dev/null @@ -1,19 +0,0 @@ -package utils; - -public final class VSPair { - private A a; - private B b; - - public VSPair(A a, B b) { - this.a = a; - this.b = b; - } - - public A getA() { - return a; - } - - public B getB() { - return b; - } -} diff --git a/sources/utils/VSTupel.java b/sources/utils/VSTupel.java new file mode 100644 index 0000000..f2c6f87 --- /dev/null +++ b/sources/utils/VSTupel.java @@ -0,0 +1,25 @@ +package utils; + +public final class VSTupel { + private A a; + private B b; + private C c; + + public VSTupel(A a, B b, C c) { + this.a = a; + this.b = b; + this.c = c; + } + + public A getA() { + return a; + } + + public B getB() { + return b; + } + + public C getC() { + return c; + } +} -- cgit v1.2.3