From a2cd723c26d9999b752ca5474f7a24de952b5fdb Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 26 May 2008 19:12:29 +0000 Subject: All abstract classes now have an Abstract in it's name --- sources/core/VSProcess.java | 16 +- sources/core/VSTask.java | 14 +- sources/events/VSAbstractEvent.java | 129 +++ sources/events/VSEvent.java | 129 --- sources/events/VSRegisteredEvents.java | 12 +- .../events/implementations/ProcessCrashEvent.java | 8 +- .../implementations/ProcessRecoverEvent.java | 8 +- sources/events/internal/MessageReceiveEvent.java | 12 +- sources/events/internal/ProtocolEvent.java | 10 +- sources/prefs/VSPrefs.java | 2 +- sources/prefs/editors/VSAbstractBetterEditor.java | 116 +++ sources/prefs/editors/VSAbstractEditor.java | 938 +++++++++++++++++++++ sources/prefs/editors/VSBetterEditor.java | 116 --- sources/prefs/editors/VSEditor.java | 938 --------------------- sources/prefs/editors/VSEditorFrame.java | 4 +- sources/prefs/editors/VSProcessEditor.java | 8 +- sources/prefs/editors/VSSimulatorEditor.java | 6 +- sources/protocols/VSAbstractProtocol.java | 178 ++++ sources/protocols/VSProtocol.java | 179 ---- .../implementations/BerkelyTimeProtocol.java | 20 +- .../implementations/BroadcastSturmProtocol.java | 18 +- .../protocols/implementations/DummyProtocol.java | 18 +- .../implementations/ExternalTimeSyncProtocol.java | 18 +- .../implementations/InternalTimeSyncProtocol.java | 20 +- .../implementations/OnePhaseCommitProtocol.java | 20 +- .../implementations/PingPongProtocol.java | 18 +- .../implementations/TwoPhaseCommitProtocol.java | 18 +- sources/simulator/VSSimulator.java | 2 +- sources/simulator/VSSimulatorCanvas.java | 6 +- 29 files changed, 1490 insertions(+), 1491 deletions(-) create mode 100644 sources/events/VSAbstractEvent.java delete mode 100644 sources/events/VSEvent.java create mode 100644 sources/prefs/editors/VSAbstractBetterEditor.java create mode 100644 sources/prefs/editors/VSAbstractEditor.java delete mode 100644 sources/prefs/editors/VSBetterEditor.java delete mode 100644 sources/prefs/editors/VSEditor.java create mode 100644 sources/protocols/VSAbstractProtocol.java delete mode 100644 sources/protocols/VSProtocol.java diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java index ffb17e4..caa081f 100644 --- a/sources/core/VSProcess.java +++ b/sources/core/VSProcess.java @@ -22,7 +22,7 @@ public class VSProcess extends VSPrefs { private static final long serialVersionUID = 1L; /** The protocols to reset if the simulation is over or the reset button has been pressed. */ - private ArrayList protocolsToReset; + private ArrayList protocolsToReset; /** The crash history. represents all crashes of the process using the global simulation time. */ private ArrayList crashHistory; @@ -161,7 +161,7 @@ public class VSProcess extends VSPrefs { * @param logging the logging object */ public VSProcess(VSPrefs prefs, int processNum, VSSimulatorCanvas simulationCanvas, VSLogging logging) { - this.protocolsToReset = new ArrayList(); + this.protocolsToReset = new ArrayList(); this.processNum = processNum; this.prefs = prefs; this.simulationCanvas = simulationCanvas; @@ -305,7 +305,7 @@ public class VSProcess extends VSPrefs { globalTime = 0; clockOffset = 0; - for (VSProtocol protocol : protocolsToReset) + for (VSAbstractProtocol protocol : protocolsToReset) protocol.reset(); setCurrentColor(getColor("col.process.default")); @@ -328,7 +328,7 @@ public class VSProcess extends VSPrefs { if (crashTime >= getGlobalTime()) { - VSEvent event = new ProcessCrashEvent(); + VSAbstractEvent event = new ProcessCrashEvent(); //event.init(this); randomCrashTask = new VSTask(crashTime, this, event, VSTask.GLOBAL); taskManager.addTask(randomCrashTask); @@ -885,17 +885,17 @@ public class VSProcess extends VSPrefs { * * @return the protocol object */ - public VSProtocol getProtocolObject(String protocolClassname) { - VSProtocol protocol = null; + public VSAbstractProtocol getProtocolObject(String protocolClassname) { + VSAbstractProtocol protocol = null; if (!objectExists(protocolClassname)) { - protocol = (VSProtocol) + protocol = (VSAbstractProtocol) VSRegisteredEvents.createEventInstanceByClassname(protocolClassname, this); setObject(protocolClassname, protocol); protocolsToReset.add(protocol); } else { - protocol = (VSProtocol) getObject(protocolClassname); + protocol = (VSAbstractProtocol) getObject(protocolClassname); } return protocol; diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java index 2c6500f..dc55fcc 100644 --- a/sources/core/VSTask.java +++ b/sources/core/VSTask.java @@ -8,7 +8,7 @@ import events.*; import events.implementations.*; import events.internal.*; import prefs.VSPrefs; -import protocols.VSProtocol; +import protocols.VSAbstractProtocol; /** * The Class VSTask. An object of this class represents a task to do or done. @@ -29,7 +29,7 @@ public class VSTask implements Comparable { private long taskTime; /** The event. */ - private VSEvent event; + private VSAbstractEvent event; /** The process. */ private VSProcess process; @@ -57,7 +57,7 @@ public class VSTask implements Comparable { * @param event the event * @param isLocal the taks is local timed */ - public VSTask(long taskTime, VSProcess process, VSEvent event, boolean isLocal) { + public VSTask(long taskTime, VSProcess process, VSAbstractEvent event, boolean isLocal) { this.process = process; this.taskTime = taskTime > 0 ? taskTime : 0; this.event = event; @@ -118,9 +118,9 @@ public class VSTask implements Comparable { * * @return true, if it's a task using the protocol object. */ - public boolean isProtocol(VSProtocol protocol) { - if (event instanceof VSProtocol) - return ((VSProtocol) event).equals(protocol); + public boolean isProtocol(VSAbstractProtocol protocol) { + if (event instanceof VSAbstractProtocol) + return ((VSAbstractProtocol) event).equals(protocol); return false; } @@ -200,7 +200,7 @@ public class VSTask implements Comparable { * * @return the event */ - public VSEvent getEvent() { + public VSAbstractEvent getEvent() { return event; } diff --git a/sources/events/VSAbstractEvent.java b/sources/events/VSAbstractEvent.java new file mode 100644 index 0000000..9562233 --- /dev/null +++ b/sources/events/VSAbstractEvent.java @@ -0,0 +1,129 @@ +/* + * VS is (c) 2008 by Paul C. Buetow + * vs@dev.buetow.org + */ +package events; + +import core.VSProcess; +import prefs.VSPrefs; + +/** + * The Class VSAbstractEvent. + */ +abstract public class VSAbstractEvent extends VSPrefs { + private static final long serialVersionUID = 1L; + + /** The prefs. */ + protected VSPrefs prefs; + + /** The process. */ + protected VSProcess process; + + /** The event shortname. */ + private String eventShortname; + + /** The event classname. */ + private String eventClassname; + + /** + * Inits the. + * + * @param process the process + */ + public void init(VSProcess process) { + this.process = process; + this.prefs = process.getPrefs(); + + onInit(); + } + + /** + * Sets the classname. + * + * @param eventClassname the new classname + */ + protected final void setClassname(String eventClassname) { + if (eventClassname.startsWith("class ")) + eventClassname = eventClassname.substring(6); + + this.eventClassname = eventClassname; + } + + /** + * Gets the classname. + * + * @return the classname + */ + public String getClassname() { + return eventClassname; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return VSRegisteredEvents.getName(eventClassname); + } + + /** + * Sets the shortname. + * + * @param eventShortname the new shortname + */ + public void setShortname(String eventShortname) { + this.eventShortname = eventShortname; + } + + /** + * Gets the shortname. + * + * @return the shortname + */ + public String getShortname() { + if (eventShortname == null) + return VSRegisteredEvents.getShortname(eventClassname); + + return eventShortname; + } + + /** + * Gets the process. + * + * @return the process + */ + public VSProcess getProcess() { + return process; + } + + /** + * Logg. + * + * @param message the message + */ + public void logg(String message) { + process.logg(/*toString() + "; " + */message); + } + + /** + * Equals. + * + * @param event the event + * + * @return true, if successful + */ + public boolean equals(VSAbstractEvent event) { + return super.getID() == event.getID(); + } + + /** + * On init. + */ + abstract protected void onInit(); + + /** + * On start. + */ + abstract public void onStart(); +} diff --git a/sources/events/VSEvent.java b/sources/events/VSEvent.java deleted file mode 100644 index 28abf8c..0000000 --- a/sources/events/VSEvent.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * VS is (c) 2008 by Paul C. Buetow - * vs@dev.buetow.org - */ -package events; - -import core.VSProcess; -import prefs.VSPrefs; - -/** - * The Class VSEvent. - */ -abstract public class VSEvent extends VSPrefs { - private static final long serialVersionUID = 1L; - - /** The prefs. */ - protected VSPrefs prefs; - - /** The process. */ - protected VSProcess process; - - /** The event shortname. */ - private String eventShortname; - - /** The event classname. */ - private String eventClassname; - - /** - * Inits the. - * - * @param process the process - */ - public void init(VSProcess process) { - this.process = process; - this.prefs = process.getPrefs(); - - onInit(); - } - - /** - * Sets the classname. - * - * @param eventClassname the new classname - */ - protected final void setClassname(String eventClassname) { - if (eventClassname.startsWith("class ")) - eventClassname = eventClassname.substring(6); - - this.eventClassname = eventClassname; - } - - /** - * Gets the classname. - * - * @return the classname - */ - public String getClassname() { - return eventClassname; - } - - /** - * Gets the name. - * - * @return the name - */ - public String getName() { - return VSRegisteredEvents.getName(eventClassname); - } - - /** - * Sets the shortname. - * - * @param eventShortname the new shortname - */ - public void setShortname(String eventShortname) { - this.eventShortname = eventShortname; - } - - /** - * Gets the shortname. - * - * @return the shortname - */ - public String getShortname() { - if (eventShortname == null) - return VSRegisteredEvents.getShortname(eventClassname); - - return eventShortname; - } - - /** - * Gets the process. - * - * @return the process - */ - public VSProcess getProcess() { - return process; - } - - /** - * Logg. - * - * @param message the message - */ - public void logg(String message) { - process.logg(/*toString() + "; " + */message); - } - - /** - * Equals. - * - * @param event the event - * - * @return true, if successful - */ - public boolean equals(VSEvent event) { - return super.getID() == event.getID(); - } - - /** - * On init. - */ - abstract protected void onInit(); - - /** - * On start. - */ - abstract public void onStart(); -} diff --git a/sources/events/VSRegisteredEvents.java b/sources/events/VSRegisteredEvents.java index ca0b224..81b68dc 100644 --- a/sources/events/VSRegisteredEvents.java +++ b/sources/events/VSRegisteredEvents.java @@ -59,8 +59,8 @@ public final class VSRegisteredEvents { 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 (object instanceof protocols.VSAbstractProtocol) { + protocols.VSAbstractProtocol protocol = (protocols.VSAbstractProtocol) object; if (!protocol.isEmpty()) editableProtocolsClassnames.add(protocolClassname); } @@ -191,11 +191,11 @@ public final class VSRegisteredEvents { * * @return the lang.process.removeevent */ - public static VSEvent createEventInstanceByClassname(String eventClassname, VSProcess process) { + public static VSAbstractEvent createEventInstanceByClassname(String eventClassname, VSProcess process) { final Object protocolObj = new VSClassLoader().newInstance(eventClassname); - if (protocolObj instanceof VSEvent) { - VSEvent event = (VSEvent) protocolObj; + if (protocolObj instanceof VSAbstractEvent) { + VSAbstractEvent event = (VSAbstractEvent) protocolObj; event.init(process); return event; } @@ -211,7 +211,7 @@ public final class VSRegisteredEvents { * * @return the lang.process.removeevent */ - public static VSEvent createEventInstanceByName(String eventName, VSProcess process) { + public static VSAbstractEvent createEventInstanceByName(String eventName, VSProcess process) { return createEventInstanceByClassname(eventClassnames.get(eventName), process); } diff --git a/sources/events/implementations/ProcessCrashEvent.java b/sources/events/implementations/ProcessCrashEvent.java index 2064371..873debc 100644 --- a/sources/events/implementations/ProcessCrashEvent.java +++ b/sources/events/implementations/ProcessCrashEvent.java @@ -4,22 +4,22 @@ */ package events.implementations; -import events.VSEvent; +import events.VSAbstractEvent; /** * The Class ProcessCrashEvent. */ -public class ProcessCrashEvent extends VSEvent { +public class ProcessCrashEvent extends VSAbstractEvent { /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { setClassname(getClass().toString()); } /* (non-Javadoc) - * @see events.VSEvent#onStart() + * @see events.VSAbstractEvent#onStart() */ public void onStart() { if (!process.isCrashed()) { diff --git a/sources/events/implementations/ProcessRecoverEvent.java b/sources/events/implementations/ProcessRecoverEvent.java index 35f964a..9d85f13 100644 --- a/sources/events/implementations/ProcessRecoverEvent.java +++ b/sources/events/implementations/ProcessRecoverEvent.java @@ -4,23 +4,23 @@ */ package events.implementations; -import events.VSEvent; +import events.VSAbstractEvent; /** * The Class ProcessRecoverEvent. */ -public class ProcessRecoverEvent extends VSEvent { +public class ProcessRecoverEvent extends VSAbstractEvent { private static final long serialVersionUID = 1L; /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { setClassname(getClass().toString()); } /* (non-Javadoc) - * @see events.VSEvent#onStart() + * @see events.VSAbstractEvent#onStart() */ public void onStart() { if (process.isCrashed()) { diff --git a/sources/events/internal/MessageReceiveEvent.java b/sources/events/internal/MessageReceiveEvent.java index ba7f1b7..300c4b3 100644 --- a/sources/events/internal/MessageReceiveEvent.java +++ b/sources/events/internal/MessageReceiveEvent.java @@ -5,13 +5,13 @@ package events.internal; import core.VSMessage; -import events.VSEvent; -import protocols.VSProtocol; +import events.VSAbstractEvent; +import protocols.VSAbstractProtocol; /** * The Class MessageReceiveEvent. */ -public class MessageReceiveEvent extends VSEvent { +public class MessageReceiveEvent extends VSAbstractEvent { private static final long serialVersionUID = 1L; /** The message. */ @@ -27,14 +27,14 @@ public class MessageReceiveEvent extends VSEvent { } /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { setClassname(getClass().toString()); } /* (non-Javadoc) - * @see events.VSEvent#onStart() + * @see events.VSAbstractEvent#onStart() */ public void onStart() { String eventName = message.getName(); @@ -57,7 +57,7 @@ public class MessageReceiveEvent extends VSEvent { logg(buffer.toString()); } else { - final VSProtocol protocol = (VSProtocol) protocolObj; + final VSAbstractProtocol protocol = (VSAbstractProtocol) protocolObj; logg(buffer.toString()); protocol.onMessageRecv(message); } diff --git a/sources/events/internal/ProtocolEvent.java b/sources/events/internal/ProtocolEvent.java index eb20dc7..e5260db 100644 --- a/sources/events/internal/ProtocolEvent.java +++ b/sources/events/internal/ProtocolEvent.java @@ -5,12 +5,12 @@ package events.internal; import events.*; -import protocols.VSProtocol; +import protocols.VSAbstractProtocol; /** * The Class ProtocolEvent. */ -public class ProtocolEvent extends VSEvent { +public class ProtocolEvent extends VSAbstractEvent { private static final long serialVersionUID = 1L; /** The protocol classname. */ @@ -23,7 +23,7 @@ public class ProtocolEvent extends VSEvent { private boolean isProtocolActivation; /* true = activate, false = deactivate */ /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { setClassname(getClass().toString()); @@ -75,10 +75,10 @@ public class ProtocolEvent extends VSEvent { } /* (non-Javadoc) - * @see events.VSEvent#onStart() + * @see events.VSAbstractEvent#onStart() */ public void onStart() { - VSProtocol protocol = process.getProtocolObject(protocolClassname); + VSAbstractProtocol protocol = process.getProtocolObject(protocolClassname); if (isClientProtocol) protocol.isClient(isProtocolActivation); diff --git a/sources/prefs/VSPrefs.java b/sources/prefs/VSPrefs.java index 915d8e3..f8beb66 100644 --- a/sources/prefs/VSPrefs.java +++ b/sources/prefs/VSPrefs.java @@ -11,7 +11,7 @@ import java.util.*; /** * The Class VSPrefs. */ -public abstract class VSPrefs implements Serializable { +public class VSPrefs implements Serializable { /** The Constant BOOLEAN_PREFIX. */ public static final String BOOLEAN_PREFIX = "Boolean: "; diff --git a/sources/prefs/editors/VSAbstractBetterEditor.java b/sources/prefs/editors/VSAbstractBetterEditor.java new file mode 100644 index 0000000..1f448f7 --- /dev/null +++ b/sources/prefs/editors/VSAbstractBetterEditor.java @@ -0,0 +1,116 @@ +/* + * VS is (c) 2008 by Paul C. Buetow + * vs@dev.buetow.org + */ +package prefs.editors; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import prefs.*; +import utils.*; + +// TODO: Auto-generated Javadoc +/** + * The Class VSAbstractBetterEditor. + */ +public abstract class VSAbstractBetterEditor extends VSAbstractEditor { + private static final long serialVersionUID = 1L; + + /** The content pane. */ + private Container contentPane; + + /** The info area. */ + private VSInfoArea infoArea; + + /** The title. */ + private String title; + + /** + * Instantiates a new lang.process.removebetter editor. + * + * @param prefs the prefs + * @param prefsToEdit the prefs to edit + * @param title the title + */ + public VSAbstractBetterEditor(VSPrefs prefs, VSPrefs prefsToEdit, String title) { + super(prefs, prefsToEdit); + this.title = title; + this.contentPane = createContentPane(); + } + + /** + * Gets the title. + * + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * Gets the content pane. + * + * @return the content pane + */ + public Container getContentPane() { + contentPane.setBackground(Color.WHITE); + return contentPane; + } + + /** + * Creates the content pane. + * + * @return the j panel + */ + private JPanel createContentPane() { + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); + + infoArea = new VSInfoArea(); + JPanel editPanel = getEditPanel(); + JPanel buttonPanel = getButtonPanel(); + + JScrollPane scrollPane = new JScrollPane(editPanel); + panel.add(editPanel); + //panel.add(infoArea); + panel.add(buttonPanel); + + return panel; + } + + /* (non-Javadoc) + * @see prefs.editors.VSAbstractEditor#addToButtonPanelFront(javax.swing.JPanel) + */ + protected void addToButtonPanelFront(JPanel buttonPanel) { } + + /* (non-Javadoc) + * @see prefs.editors.VSAbstractEditor#addToButtonPanelLast(javax.swing.JPanel) + */ + protected void addToButtonPanelLast(JPanel buttonPanel) { } + + /* (non-Javadoc) + * @see prefs.editors.VSAbstractEditor#addToEditTableLast() + */ + protected void addToEditTableLast() { } + + /* (non-Javadoc) + * @see prefs.editors.VSAbstractEditor#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) { + //String actionCommand = e.getActionCommand(); + + /* More action in the super class!!! */ + super.actionPerformed(e); + } + + /** + * Gets the info area. + * + * @return the info area + */ + protected VSInfoArea getInfoArea() { + return infoArea; + } +} diff --git a/sources/prefs/editors/VSAbstractEditor.java b/sources/prefs/editors/VSAbstractEditor.java new file mode 100644 index 0000000..9ae98be --- /dev/null +++ b/sources/prefs/editors/VSAbstractEditor.java @@ -0,0 +1,938 @@ +/* + * VS is (c) 2008 by Paul C. Buetow + * vs@dev.buetow.org + */ +package prefs.editors; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; + +import utils.*; +import prefs.VSPrefs; + +// TODO: Auto-generated Javadoc +/** + * The Class VSAbstractEditor. + */ +public abstract class VSAbstractEditor implements ActionListener { + private static final long serialVersionUID = 1L; + + /** The boolean keys. */ + private ArrayList booleanKeys; + + /** The color keys. */ + private ArrayList colorKeys; + + /** The float keys. */ + private ArrayList floatKeys; + + /** The integer keys. */ + private ArrayList integerKeys; + + /** The vector keys. */ + private ArrayList vectorKeys; + + /** The long keys. */ + private ArrayList longKeys; + + /** The string keys. */ + private ArrayList stringKeys; + + /** The boolean fields. */ + private HashMap booleanFields; + + /** The integer fields. */ + private HashMap integerFields; + + /** The vector fields. */ + private HashMap vectorFields; + + /** The color fields. */ + private HashMap colorFields; + + /** The float fields. */ + private HashMap floatFields; + + /** The long fields. */ + private HashMap longFields; + + /** The string fields. */ + private HashMap stringFields; + + /** The prefs to edit map. */ + private HashMap prefsToEditMap; + + /** The button panel. */ + private JPanel buttonPanel; + + /** The edit panel. */ + private JPanel editPanel; + + /** The edit table. */ + private VSEditorTable editTable; + + /** The frame. */ + private VSFrame frame; + + /** The expert mode changed. */ + private boolean expertModeChanged; + + /** The prefs. */ + protected VSPrefs prefs; + + /** The prefs to edit. */ + protected VSPrefs prefsToEdit; + + /** The Constant MIN_UNIT_LENGTH. */ + protected static final int MIN_UNIT_LENGTH = 5; + + /** The Constant VALUE_FIELD_COLS. */ + protected static final int VALUE_FIELD_COLS = 9; + + /** The Constant ALL_PREFERENCES. */ + public static final int ALL_PREFERENCES = 0; + + /** The Constant SIMULATION_PREFERENCES. */ + public static final int SIMULATION_PREFERENCES = 1; + + /** + * Instantiates a new lang.process.removeeditor. + * + * @param prefs the prefs + * @param prefsToEdit the prefs to edit + */ + public VSAbstractEditor(VSPrefs prefs, VSPrefs prefsToEdit) { + init(prefs, prefsToEdit); + } + + /** + * Adds the to button panel front. + * + * @param buttonPanel the button panel + */ + abstract protected void addToButtonPanelFront(JPanel buttonPanel); + + /** + * Adds the to button panel last. + * + * @param buttonPanel the button panel + */ + abstract protected void addToButtonPanelLast(JPanel buttonPanel); + + /** + * Adds the to edit table last. + */ + abstract protected void addToEditTableLast(); + + /** + * Sets the prefs. + * + * @param prefs the new prefs + */ + public void setPrefs(VSPrefs prefs) { + this.prefs = prefs; + } + + /** + * Sets the prefs to edit. + * + * @param prefsToEdit the new prefs to edit + */ + public void setPrefsToEdit(VSPrefs prefsToEdit) { + this.prefsToEdit = prefsToEdit; + } + + /** + * Sets the frame. + * + * @param frame the new frame + */ + public void setFrame(VSFrame frame) { + this.frame = frame; + } + + /** + * Gets the frame. + * + * @return the frame + */ + public VSFrame getFrame() { + return frame; + } + + /** + * Dispose frame if exists. + */ + protected void disposeFrameIfExists() { + if (frame != null) + frame.dispose(); + } + + /** + * Dispose frame with parent if exists. + */ + protected void disposeFrameWithParentIfExists() { + if (frame != null) + frame.disposeWithParent(); + } + + /** + * Inits the. + * + * @param prefs the prefs + * @param prefsToEdit the prefs to edit + */ + private void init(VSPrefs prefs, VSPrefs prefsToEdit) { + this.prefs = prefs; + this.prefsToEdit = prefsToEdit; + + editPanel = createEditPanel(); + buttonPanel = createButtonPanel(); + + prefsToEditMap = new HashMap(); + + colorFields = new HashMap(); + floatFields = new HashMap(); + integerFields = new HashMap(); + vectorFields = new HashMap(); + longFields = new HashMap(); + booleanFields = new HashMap(); + stringFields = new HashMap(); + + colorKeys = filterKeys(prefsToEdit.getColorKeySet()); + floatKeys = filterKeys(prefsToEdit.getFloatKeySet()); + integerKeys = filterKeys(prefsToEdit.getIntegerKeySet()); + vectorKeys = filterKeys(prefsToEdit.getVectorKeySet()); + longKeys = filterKeys(prefsToEdit.getLongKeySet()); + booleanKeys = filterKeys(prefsToEdit.getBooleanKeySet()); + stringKeys = filterKeys(prefsToEdit.getStringKeySet()); + + fillEditPanel(prefsToEdit); + } + + /** + * Filter keys. + * + * @param set the set + * + * @return the array list< string> + */ + private ArrayList filterKeys(Set set) { + ArrayList filtered = new ArrayList(); + boolean expertMode = prefs.getBoolean("sim.mode.expert"); + + for (String elem : set) { + if (!elem.startsWith("lang.") && !elem.startsWith("keyevent")) { + if (expertMode) + filtered.add(elem); + else if (!elem.startsWith("col.") && (!elem.startsWith("div."))) + filtered.add(elem); + } + } + + return filtered; + } + + /** + * Creates the button panel. + * + * @return the j panel + */ + private JPanel createButtonPanel() { + JPanel buttonPanel = new JPanel(); + buttonPanel.setBackground(Color.WHITE); + addToButtonPanelFront(buttonPanel); + + JButton resetButton = new JButton( + prefs.getString("lang.reset")); + resetButton.setMnemonic(prefs.getInteger("keyevent.reset")); + resetButton.addActionListener(this); + buttonPanel.add(resetButton); + + addToButtonPanelLast(buttonPanel); + + return buttonPanel; + } + + /** + * Creates the unit panel. + * + * @param comp the comp + * @param key the key + * + * @return the j panel + */ + private JPanel createUnitPanel(VSPrefs prefsToEdit, Component comp, String fullKey) { + JPanel unitPanel = new JPanel(new GridBagLayout()); + unitPanel.setBackground(Color.WHITE); + unitPanel.setBorder(null); + + String unitText = prefsToEdit.getUnit(fullKey); + if (unitText == null) + 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); + unitPanel.add(unitLabel); + + return unitPanel; + } + + /** + * Creates the edit panel. + * + * @return the j panel + */ + private JPanel createEditPanel() { + JPanel editPanel = new JPanel(); + editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.Y_AXIS)); + editPanel.setBackground(Color.WHITE); + + editTable = new VSEditorTable(prefs); + JScrollPane scrollPane = new JScrollPane(editTable); + editPanel.add(scrollPane); + + return editPanel; + } + + /** + * Creates the integer component. + * + * @param fullKey the full key + * @param key the key + * @param prefsToEdit the prefs to edit + * + * @return the lang.process.removetupel< string, component, j combo box> + */ + 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.VSPrefRestriction settingRestriction = prefsToEdit.getRestriction(fullKey); + + int minValue, maxValue; + if (settingRestriction != null) { + VSPrefs.VSIntegerPrefRestriction integerVSPrefRestriction = + (VSPrefs.VSIntegerPrefRestriction) settingRestriction; + minValue = integerVSPrefRestriction.getMinValue(); + maxValue = integerVSPrefRestriction.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(prefsToEdit, valComboBox, fullKey), valComboBox); + } + + /** + * Creates the vector component. + * + * @param fullKey the full key + * @param key the key + * @param prefsToEdit the prefs to edit + */ + protected VSTupel createVectorComponent(String fullKey, String key, VSPrefs prefsToEdit) { + String descr = prefsToEdit.getDescription(fullKey); + String label = descr == null ? fullKey : descr; + + Vector vec = prefsToEdit.getVector(key); + JTextField valField = new JTextField(); + valField.setBorder(null); + valField.setText(vec.toString()); + + return new VSTupel(label, + createUnitPanel(prefsToEdit, valField, fullKey), valField); + } + + /** + * Creates the boolean component. + * + * @param fullKey the full key + * @param key the key + * @param prefsToEdit the prefs to edit + */ + 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(prefsToEdit, valField, fullKey), valField); + } + + /** + * Creates the long component. + * + * @param fullKey the full key + * @param key the key + * @param prefsToEdit the prefs to edit + * + * @return the lang.process.removetupel< string, component, j text field> + */ + 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(prefsToEdit, valField, fullKey), valField); + } + + /** + * Creates the float component. + * + * @param fullKey the full key + * @param key the key + * @param prefsToEdit the prefs to edit + * + * @return the lang.process.removetupel< string, component, j text field> + */ + 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(prefsToEdit, valField, fullKey), valField); + } + + /** + * Creates the color component. + * + * @param fullKey the full key + * @param key the key + * @param prefsToEdit the prefs to edit + * + * @return the lang.process.removetupel< string, component, j text field> + */ + 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(prefsToEdit, valField, fullKey), valField); + } + + /** + * Creates the string component. + * + * @param fullKey the full key + * @param key the key + * @param prefsToEdit the prefs to edit + * + * @return the lang.process.removetupel< string, component, j text field> + */ + 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(prefsToEdit, valField, fullKey), valField); + } + + /** + * Fill edit panel. + * + * @param prefsToEdit the prefs to edit + */ + private void fillEditPanel(VSPrefs prefsToEdit) { + HashMap components = new HashMap(); + HashMap labels = new HashMap(); + + 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()); + } + + for (String key : vectorKeys) { + String fullKey = VSPrefs.VECTOR_PREFIX + key; + VSTupel tupel = + createVectorComponent(fullKey, key, prefsToEdit); + labels.put(fullKey, tupel.getA()); + components.put(fullKey, tupel.getB()); + vectorFields.put(key, tupel.getC()); + } + + for (String key : booleanKeys) { + String fullKey = VSPrefs.BOOLEAN_PREFIX + key; + 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; + 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; + 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; + 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; + 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(); + fullKeys.addAll(components.keySet()); + Collections.sort(fullKeys); + + boolean flag = false; + for (String fullKey : fullKeys) { + String key = fullKey.substring(fullKey.indexOf(' ')+1); + if (key.startsWith("sim.")) { + if (!flag) { + flag = true; + addSeparator(prefs.getString("lang.prefs.simulation")); + } + addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); + } + } + + flag = false; + for (String fullKey : fullKeys) { + String key = fullKey.substring(fullKey.indexOf(' ')+1); + if (key.startsWith("process.")) { + if (!flag) { + flag = true; + addSeparator(prefs.getString("lang.prefs.process")); + } + addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); + } + } + + flag = false; + for (String fullKey : fullKeys) { + String key = fullKey.substring(fullKey.indexOf(' ')+1); + if (key.startsWith("message.")) { + if (!flag) { + flag = true; + addSeparator(prefs.getString("lang.prefs.message")); + } + addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); + } + } + + flag = false; + for (String fullKey : fullKeys) { + String key = fullKey.substring(fullKey.indexOf(' ')+1); + if (key.startsWith("col.")) { + if (!flag) { + flag = true; + addSeparator(prefs.getString("lang.prefs.color")); + } + addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); + } + } + + flag = false; + for (String fullKey : fullKeys) { + String key = fullKey.substring(fullKey.indexOf(' ')+1); + if (key.startsWith("div.")) { + if (!flag) { + flag = true; + addSeparator(prefs.getString("lang.prefs.diverse")); + } + addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); + } + } + + addToEditTableLast(); + editTable.fireTableDataChanged(); + } + + /** + * Adds the to editor. + * + * @param label the label + * @param prefsKey the prefs key + * @param prefsToAdd the prefs to add + */ + protected void addToEditor(String label, String prefsKey, VSPrefs prefsToAdd) { + addSeparator(label); + prefsKey = "(" + prefsKey + ")"; + + ArrayList fullKeys = new ArrayList(); + + Set integerKeys = prefsToAdd.getIntegerKeySet(); + Set vectorKeys = prefsToAdd.getVectorKeySet(); + 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 : vectorKeys) fullKeys.add(VSPrefs.VECTOR_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.VECTOR_PREFIX)) { + VSTupel tupel = + createVectorComponent(fullKey, key, prefsToAdd); + this.vectorKeys.add(prefsKey+key); + this.vectorFields.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); + } + + } + } + + /** + * Adds the separator. + * + * @param label the label + */ + private void addSeparator(String label) { + editTable.addSeparator(label); + } + + /** + * Adds the variable. + * + * @param label the label + * @param component the component + * @param prefs the prefs + */ + private void addVariable(String label, Component component, VSPrefs prefs) { + addVariable("", label, component, prefs); + } + + /** + * Adds the variable. + * + * @param prefsKey the prefs key + * @param label the label + * @param component the component + * @param prefs the prefs + */ + private void addVariable(String prefsKey, String label, Component component, VSPrefs prefs) { + prefsToEditMap.put(prefsKey, prefs); + editTable.addVariable(label, component); + } + + /** + * Reset edit panel. + */ + protected void resetPrefs() { + for (String key : integerKeys) { + JComboBox valComboBox = integerFields.get(key); + valComboBox.setSelectedIndex(0); + } + + for (String key : booleanKeys) { + String keys[] = getKeys(key); + JCheckBox valField = booleanFields.get(key); + valField.setSelected(prefsToEditMap.get(keys[1]).getBoolean(keys[0])); + } + + for (String key : vectorKeys) { + String keys[] = getKeys(key); + JTextField valField = vectorFields.get(key); + valField.setText(""+prefsToEditMap.get(keys[1]).getVector(keys[0])); + } + + for (String key : floatKeys) { + String keys[] = getKeys(key); + JTextField valField = floatFields.get(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(""+prefsToEditMap.get(keys[1]).getLong(keys[0])); + } + + for (String key : colorKeys) { + String keys[] = getKeys(key); + JTextField valField = colorFields.get(key); + valField.setBackground(prefsToEditMap.get(keys[1]).getColor(keys[0])); + } + + for (String key : stringKeys) { + String keys[] = getKeys(key); + JTextField valField = stringFields.get(keys); + valField.setText(prefsToEditMap.get(keys[1]).getString(keys[0])); + } + } + + /** + * Gets the keys. + * + * @param key the key + * + * @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; + } + + /** + * Save prefs. + */ + protected void savePrefs() { + boolean expertMode = prefs.getBoolean("sim.mode.expert"); + + for (String key : integerKeys) { + String keys[] = getKeys(key); + JComboBox valComboBox = integerFields.get(key); + prefsToEditMap.get(keys[1]).setInteger(keys[0], (Integer) valComboBox.getSelectedItem()); + } + + for (String key : vectorKeys) { + String keys[] = getKeys(key); + JTextField valField = vectorFields.get(key); + + try { + String val = valField.getText(); + Vector vec = utils.VSTools.parseIntegerVector(val); + prefsToEditMap.get(keys[1]).setVector(keys[0], vec); + } catch (exceptions.ParseIntegerVectorException e) { + } + + valField.setText(""+prefsToEditMap.get(keys[1]).getVector(keys[0])); + } + + for (String key : booleanKeys) { + String keys[] = getKeys(key); + JCheckBox valField = booleanFields.get(key); + prefsToEditMap.get(keys[1]).setBoolean(keys[0], valField.isSelected()); + } + + for (String key : floatKeys) { + String keys[] = getKeys(key); + JTextField valField = floatFields.get(key); + + try { + Float val = Float.valueOf(valField.getText()); + prefsToEditMap.get(keys[1]).setFloat(keys[0], val); + + } catch (NumberFormatException e) { + valField.setText(""+prefsToEditMap.get(keys[1]).getFloat(keys[0])); + } + } + + for (String key : longKeys) { + String keys[] = getKeys(key); + JTextField valField = longFields.get(key); + + try { + Long val = Long.valueOf(valField.getText()); + prefsToEditMap.get(keys[1]).setLong(keys[0], val); + + } catch (NumberFormatException e) { + valField.setText(""+prefsToEditMap.get(keys[1]).getLong(keys[0])); + } + } + + for (String key : colorKeys) { + String keys[] = getKeys(key); + JTextField valField = colorFields.get(key); + prefsToEditMap.get(keys[1]).setColor(keys[0], valField.getBackground()); + } + + for (String key : stringKeys) { + String keys[] = getKeys(key); + JTextField valField = stringFields.get(key); + prefsToEditMap.get(keys[1]).setString(keys[0], valField.getText()); + } + + expertModeChanged = expertMode != prefs.getBoolean("sim.mode.expert"); + } + + /** + * Expert mode changed. + * + * @return true, if successful + */ + public boolean expertModeChanged() { + boolean ret = expertModeChanged; + + if (expertModeChanged) + expertModeChanged = false; + + return ret; + } + + /* (non-Javadoc) + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) { + String actionCommand = e.getActionCommand(); + + if (actionCommand.equals(prefs.getString("lang.takeover"))) { + savePrefs(); + + } else if (actionCommand.equals(prefs.getString("lang.reset"))) { + resetPrefs(); + } + } + + /** + * Gets the edits the panel. + * + * @return the edits the panel + */ + public JPanel getEditPanel() { + return editPanel; + } + + /** + * Gets the edits the table. + * + * @return the edits the table + */ + public VSEditorTable getEditTable() { + return editTable; + } + + /** + * Gets the button panel. + * + * @return the button panel + */ + public JPanel getButtonPanel() { + return buttonPanel; + } +} diff --git a/sources/prefs/editors/VSBetterEditor.java b/sources/prefs/editors/VSBetterEditor.java deleted file mode 100644 index ba15672..0000000 --- a/sources/prefs/editors/VSBetterEditor.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * VS is (c) 2008 by Paul C. Buetow - * vs@dev.buetow.org - */ -package prefs.editors; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; - -import prefs.*; -import utils.*; - -// TODO: Auto-generated Javadoc -/** - * The Class VSBetterEditor. - */ -public abstract class VSBetterEditor extends VSEditor { - private static final long serialVersionUID = 1L; - - /** The content pane. */ - private Container contentPane; - - /** The info area. */ - private VSInfoArea infoArea; - - /** The title. */ - private String title; - - /** - * Instantiates a new lang.process.removebetter editor. - * - * @param prefs the prefs - * @param prefsToEdit the prefs to edit - * @param title the title - */ - public VSBetterEditor(VSPrefs prefs, VSPrefs prefsToEdit, String title) { - super(prefs, prefsToEdit); - this.title = title; - this.contentPane = createContentPane(); - } - - /** - * Gets the title. - * - * @return the title - */ - public String getTitle() { - return title; - } - - /** - * Gets the content pane. - * - * @return the content pane - */ - public Container getContentPane() { - contentPane.setBackground(Color.WHITE); - return contentPane; - } - - /** - * Creates the content pane. - * - * @return the j panel - */ - private JPanel createContentPane() { - JPanel panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - - infoArea = new VSInfoArea(); - JPanel editPanel = getEditPanel(); - JPanel buttonPanel = getButtonPanel(); - - JScrollPane scrollPane = new JScrollPane(editPanel); - panel.add(editPanel); - //panel.add(infoArea); - panel.add(buttonPanel); - - return panel; - } - - /* (non-Javadoc) - * @see prefs.editors.VSEditor#addToButtonPanelFront(javax.swing.JPanel) - */ - protected void addToButtonPanelFront(JPanel buttonPanel) { } - - /* (non-Javadoc) - * @see prefs.editors.VSEditor#addToButtonPanelLast(javax.swing.JPanel) - */ - protected void addToButtonPanelLast(JPanel buttonPanel) { } - - /* (non-Javadoc) - * @see prefs.editors.VSEditor#addToEditTableLast() - */ - protected void addToEditTableLast() { } - - /* (non-Javadoc) - * @see prefs.editors.VSEditor#actionPerformed(java.awt.event.ActionEvent) - */ - public void actionPerformed(ActionEvent e) { - //String actionCommand = e.getActionCommand(); - - /* More action in the super class!!! */ - super.actionPerformed(e); - } - - /** - * Gets the info area. - * - * @return the info area - */ - protected VSInfoArea getInfoArea() { - return infoArea; - } -} diff --git a/sources/prefs/editors/VSEditor.java b/sources/prefs/editors/VSEditor.java deleted file mode 100644 index c98434e..0000000 --- a/sources/prefs/editors/VSEditor.java +++ /dev/null @@ -1,938 +0,0 @@ -/* - * VS is (c) 2008 by Paul C. Buetow - * vs@dev.buetow.org - */ -package prefs.editors; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.util.*; - -import utils.*; -import prefs.VSPrefs; - -// TODO: Auto-generated Javadoc -/** - * The Class VSEditor. - */ -public abstract class VSEditor implements ActionListener { - private static final long serialVersionUID = 1L; - - /** The boolean keys. */ - private ArrayList booleanKeys; - - /** The color keys. */ - private ArrayList colorKeys; - - /** The float keys. */ - private ArrayList floatKeys; - - /** The integer keys. */ - private ArrayList integerKeys; - - /** The vector keys. */ - private ArrayList vectorKeys; - - /** The long keys. */ - private ArrayList longKeys; - - /** The string keys. */ - private ArrayList stringKeys; - - /** The boolean fields. */ - private HashMap booleanFields; - - /** The integer fields. */ - private HashMap integerFields; - - /** The vector fields. */ - private HashMap vectorFields; - - /** The color fields. */ - private HashMap colorFields; - - /** The float fields. */ - private HashMap floatFields; - - /** The long fields. */ - private HashMap longFields; - - /** The string fields. */ - private HashMap stringFields; - - /** The prefs to edit map. */ - private HashMap prefsToEditMap; - - /** The button panel. */ - private JPanel buttonPanel; - - /** The edit panel. */ - private JPanel editPanel; - - /** The edit table. */ - private VSEditorTable editTable; - - /** The frame. */ - private VSFrame frame; - - /** The expert mode changed. */ - private boolean expertModeChanged; - - /** The prefs. */ - protected VSPrefs prefs; - - /** The prefs to edit. */ - protected VSPrefs prefsToEdit; - - /** The Constant MIN_UNIT_LENGTH. */ - protected static final int MIN_UNIT_LENGTH = 5; - - /** The Constant VALUE_FIELD_COLS. */ - protected static final int VALUE_FIELD_COLS = 9; - - /** The Constant ALL_PREFERENCES. */ - public static final int ALL_PREFERENCES = 0; - - /** The Constant SIMULATION_PREFERENCES. */ - public static final int SIMULATION_PREFERENCES = 1; - - /** - * Instantiates a new lang.process.removeeditor. - * - * @param prefs the prefs - * @param prefsToEdit the prefs to edit - */ - public VSEditor(VSPrefs prefs, VSPrefs prefsToEdit) { - init(prefs, prefsToEdit); - } - - /** - * Adds the to button panel front. - * - * @param buttonPanel the button panel - */ - abstract protected void addToButtonPanelFront(JPanel buttonPanel); - - /** - * Adds the to button panel last. - * - * @param buttonPanel the button panel - */ - abstract protected void addToButtonPanelLast(JPanel buttonPanel); - - /** - * Adds the to edit table last. - */ - abstract protected void addToEditTableLast(); - - /** - * Sets the prefs. - * - * @param prefs the new prefs - */ - public void setPrefs(VSPrefs prefs) { - this.prefs = prefs; - } - - /** - * Sets the prefs to edit. - * - * @param prefsToEdit the new prefs to edit - */ - public void setPrefsToEdit(VSPrefs prefsToEdit) { - this.prefsToEdit = prefsToEdit; - } - - /** - * Sets the frame. - * - * @param frame the new frame - */ - public void setFrame(VSFrame frame) { - this.frame = frame; - } - - /** - * Gets the frame. - * - * @return the frame - */ - public VSFrame getFrame() { - return frame; - } - - /** - * Dispose frame if exists. - */ - protected void disposeFrameIfExists() { - if (frame != null) - frame.dispose(); - } - - /** - * Dispose frame with parent if exists. - */ - protected void disposeFrameWithParentIfExists() { - if (frame != null) - frame.disposeWithParent(); - } - - /** - * Inits the. - * - * @param prefs the prefs - * @param prefsToEdit the prefs to edit - */ - private void init(VSPrefs prefs, VSPrefs prefsToEdit) { - this.prefs = prefs; - this.prefsToEdit = prefsToEdit; - - editPanel = createEditPanel(); - buttonPanel = createButtonPanel(); - - prefsToEditMap = new HashMap(); - - colorFields = new HashMap(); - floatFields = new HashMap(); - integerFields = new HashMap(); - vectorFields = new HashMap(); - longFields = new HashMap(); - booleanFields = new HashMap(); - stringFields = new HashMap(); - - colorKeys = filterKeys(prefsToEdit.getColorKeySet()); - floatKeys = filterKeys(prefsToEdit.getFloatKeySet()); - integerKeys = filterKeys(prefsToEdit.getIntegerKeySet()); - vectorKeys = filterKeys(prefsToEdit.getVectorKeySet()); - longKeys = filterKeys(prefsToEdit.getLongKeySet()); - booleanKeys = filterKeys(prefsToEdit.getBooleanKeySet()); - stringKeys = filterKeys(prefsToEdit.getStringKeySet()); - - fillEditPanel(prefsToEdit); - } - - /** - * Filter keys. - * - * @param set the set - * - * @return the array list< string> - */ - private ArrayList filterKeys(Set set) { - ArrayList filtered = new ArrayList(); - boolean expertMode = prefs.getBoolean("sim.mode.expert"); - - for (String elem : set) { - if (!elem.startsWith("lang.") && !elem.startsWith("keyevent")) { - if (expertMode) - filtered.add(elem); - else if (!elem.startsWith("col.") && (!elem.startsWith("div."))) - filtered.add(elem); - } - } - - return filtered; - } - - /** - * Creates the button panel. - * - * @return the j panel - */ - private JPanel createButtonPanel() { - JPanel buttonPanel = new JPanel(); - buttonPanel.setBackground(Color.WHITE); - addToButtonPanelFront(buttonPanel); - - JButton resetButton = new JButton( - prefs.getString("lang.reset")); - resetButton.setMnemonic(prefs.getInteger("keyevent.reset")); - resetButton.addActionListener(this); - buttonPanel.add(resetButton); - - addToButtonPanelLast(buttonPanel); - - return buttonPanel; - } - - /** - * Creates the unit panel. - * - * @param comp the comp - * @param key the key - * - * @return the j panel - */ - private JPanel createUnitPanel(VSPrefs prefsToEdit, Component comp, String fullKey) { - JPanel unitPanel = new JPanel(new GridBagLayout()); - unitPanel.setBackground(Color.WHITE); - unitPanel.setBorder(null); - - String unitText = prefsToEdit.getUnit(fullKey); - if (unitText == null) - 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); - unitPanel.add(unitLabel); - - return unitPanel; - } - - /** - * Creates the edit panel. - * - * @return the j panel - */ - private JPanel createEditPanel() { - JPanel editPanel = new JPanel(); - editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.Y_AXIS)); - editPanel.setBackground(Color.WHITE); - - editTable = new VSEditorTable(prefs); - JScrollPane scrollPane = new JScrollPane(editTable); - editPanel.add(scrollPane); - - return editPanel; - } - - /** - * Creates the integer component. - * - * @param fullKey the full key - * @param key the key - * @param prefsToEdit the prefs to edit - * - * @return the lang.process.removetupel< string, component, j combo box> - */ - 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.VSPrefRestriction settingRestriction = prefsToEdit.getRestriction(fullKey); - - int minValue, maxValue; - if (settingRestriction != null) { - VSPrefs.VSIntegerPrefRestriction integerVSPrefRestriction = - (VSPrefs.VSIntegerPrefRestriction) settingRestriction; - minValue = integerVSPrefRestriction.getMinValue(); - maxValue = integerVSPrefRestriction.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(prefsToEdit, valComboBox, fullKey), valComboBox); - } - - /** - * Creates the vector component. - * - * @param fullKey the full key - * @param key the key - * @param prefsToEdit the prefs to edit - */ - protected VSTupel createVectorComponent(String fullKey, String key, VSPrefs prefsToEdit) { - String descr = prefsToEdit.getDescription(fullKey); - String label = descr == null ? fullKey : descr; - - Vector vec = prefsToEdit.getVector(key); - JTextField valField = new JTextField(); - valField.setBorder(null); - valField.setText(vec.toString()); - - return new VSTupel(label, - createUnitPanel(prefsToEdit, valField, fullKey), valField); - } - - /** - * Creates the boolean component. - * - * @param fullKey the full key - * @param key the key - * @param prefsToEdit the prefs to edit - */ - 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(prefsToEdit, valField, fullKey), valField); - } - - /** - * Creates the long component. - * - * @param fullKey the full key - * @param key the key - * @param prefsToEdit the prefs to edit - * - * @return the lang.process.removetupel< string, component, j text field> - */ - 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(prefsToEdit, valField, fullKey), valField); - } - - /** - * Creates the float component. - * - * @param fullKey the full key - * @param key the key - * @param prefsToEdit the prefs to edit - * - * @return the lang.process.removetupel< string, component, j text field> - */ - 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(prefsToEdit, valField, fullKey), valField); - } - - /** - * Creates the color component. - * - * @param fullKey the full key - * @param key the key - * @param prefsToEdit the prefs to edit - * - * @return the lang.process.removetupel< string, component, j text field> - */ - 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(prefsToEdit, valField, fullKey), valField); - } - - /** - * Creates the string component. - * - * @param fullKey the full key - * @param key the key - * @param prefsToEdit the prefs to edit - * - * @return the lang.process.removetupel< string, component, j text field> - */ - 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(prefsToEdit, valField, fullKey), valField); - } - - /** - * Fill edit panel. - * - * @param prefsToEdit the prefs to edit - */ - private void fillEditPanel(VSPrefs prefsToEdit) { - HashMap components = new HashMap(); - HashMap labels = new HashMap(); - - 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()); - } - - for (String key : vectorKeys) { - String fullKey = VSPrefs.VECTOR_PREFIX + key; - VSTupel tupel = - createVectorComponent(fullKey, key, prefsToEdit); - labels.put(fullKey, tupel.getA()); - components.put(fullKey, tupel.getB()); - vectorFields.put(key, tupel.getC()); - } - - for (String key : booleanKeys) { - String fullKey = VSPrefs.BOOLEAN_PREFIX + key; - 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; - 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; - 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; - 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; - 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(); - fullKeys.addAll(components.keySet()); - Collections.sort(fullKeys); - - boolean flag = false; - for (String fullKey : fullKeys) { - String key = fullKey.substring(fullKey.indexOf(' ')+1); - if (key.startsWith("sim.")) { - if (!flag) { - flag = true; - addSeparator(prefs.getString("lang.prefs.simulation")); - } - addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); - } - } - - flag = false; - for (String fullKey : fullKeys) { - String key = fullKey.substring(fullKey.indexOf(' ')+1); - if (key.startsWith("process.")) { - if (!flag) { - flag = true; - addSeparator(prefs.getString("lang.prefs.process")); - } - addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); - } - } - - flag = false; - for (String fullKey : fullKeys) { - String key = fullKey.substring(fullKey.indexOf(' ')+1); - if (key.startsWith("message.")) { - if (!flag) { - flag = true; - addSeparator(prefs.getString("lang.prefs.message")); - } - addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); - } - } - - flag = false; - for (String fullKey : fullKeys) { - String key = fullKey.substring(fullKey.indexOf(' ')+1); - if (key.startsWith("col.")) { - if (!flag) { - flag = true; - addSeparator(prefs.getString("lang.prefs.color")); - } - addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); - } - } - - flag = false; - for (String fullKey : fullKeys) { - String key = fullKey.substring(fullKey.indexOf(' ')+1); - if (key.startsWith("div.")) { - if (!flag) { - flag = true; - addSeparator(prefs.getString("lang.prefs.diverse")); - } - addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); - } - } - - addToEditTableLast(); - editTable.fireTableDataChanged(); - } - - /** - * Adds the to editor. - * - * @param label the label - * @param prefsKey the prefs key - * @param prefsToAdd the prefs to add - */ - protected void addToEditor(String label, String prefsKey, VSPrefs prefsToAdd) { - addSeparator(label); - prefsKey = "(" + prefsKey + ")"; - - ArrayList fullKeys = new ArrayList(); - - Set integerKeys = prefsToAdd.getIntegerKeySet(); - Set vectorKeys = prefsToAdd.getVectorKeySet(); - 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 : vectorKeys) fullKeys.add(VSPrefs.VECTOR_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.VECTOR_PREFIX)) { - VSTupel tupel = - createVectorComponent(fullKey, key, prefsToAdd); - this.vectorKeys.add(prefsKey+key); - this.vectorFields.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); - } - - } - } - - /** - * Adds the separator. - * - * @param label the label - */ - private void addSeparator(String label) { - editTable.addSeparator(label); - } - - /** - * Adds the variable. - * - * @param label the label - * @param component the component - * @param prefs the prefs - */ - private void addVariable(String label, Component component, VSPrefs prefs) { - addVariable("", label, component, prefs); - } - - /** - * Adds the variable. - * - * @param prefsKey the prefs key - * @param label the label - * @param component the component - * @param prefs the prefs - */ - private void addVariable(String prefsKey, String label, Component component, VSPrefs prefs) { - prefsToEditMap.put(prefsKey, prefs); - editTable.addVariable(label, component); - } - - /** - * Reset edit panel. - */ - protected void resetPrefs() { - for (String key : integerKeys) { - JComboBox valComboBox = integerFields.get(key); - valComboBox.setSelectedIndex(0); - } - - for (String key : booleanKeys) { - String keys[] = getKeys(key); - JCheckBox valField = booleanFields.get(key); - valField.setSelected(prefsToEditMap.get(keys[1]).getBoolean(keys[0])); - } - - for (String key : vectorKeys) { - String keys[] = getKeys(key); - JTextField valField = vectorFields.get(key); - valField.setText(""+prefsToEditMap.get(keys[1]).getVector(keys[0])); - } - - for (String key : floatKeys) { - String keys[] = getKeys(key); - JTextField valField = floatFields.get(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(""+prefsToEditMap.get(keys[1]).getLong(keys[0])); - } - - for (String key : colorKeys) { - String keys[] = getKeys(key); - JTextField valField = colorFields.get(key); - valField.setBackground(prefsToEditMap.get(keys[1]).getColor(keys[0])); - } - - for (String key : stringKeys) { - String keys[] = getKeys(key); - JTextField valField = stringFields.get(keys); - valField.setText(prefsToEditMap.get(keys[1]).getString(keys[0])); - } - } - - /** - * Gets the keys. - * - * @param key the key - * - * @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; - } - - /** - * Save prefs. - */ - protected void savePrefs() { - boolean expertMode = prefs.getBoolean("sim.mode.expert"); - - for (String key : integerKeys) { - String keys[] = getKeys(key); - JComboBox valComboBox = integerFields.get(key); - prefsToEditMap.get(keys[1]).setInteger(keys[0], (Integer) valComboBox.getSelectedItem()); - } - - for (String key : vectorKeys) { - String keys[] = getKeys(key); - JTextField valField = vectorFields.get(key); - - try { - String val = valField.getText(); - Vector vec = utils.VSTools.parseIntegerVector(val); - prefsToEditMap.get(keys[1]).setVector(keys[0], vec); - } catch (exceptions.ParseIntegerVectorException e) { - } - - valField.setText(""+prefsToEditMap.get(keys[1]).getVector(keys[0])); - } - - for (String key : booleanKeys) { - String keys[] = getKeys(key); - JCheckBox valField = booleanFields.get(key); - prefsToEditMap.get(keys[1]).setBoolean(keys[0], valField.isSelected()); - } - - for (String key : floatKeys) { - String keys[] = getKeys(key); - JTextField valField = floatFields.get(key); - - try { - Float val = Float.valueOf(valField.getText()); - prefsToEditMap.get(keys[1]).setFloat(keys[0], val); - - } catch (NumberFormatException e) { - valField.setText(""+prefsToEditMap.get(keys[1]).getFloat(keys[0])); - } - } - - for (String key : longKeys) { - String keys[] = getKeys(key); - JTextField valField = longFields.get(key); - - try { - Long val = Long.valueOf(valField.getText()); - prefsToEditMap.get(keys[1]).setLong(keys[0], val); - - } catch (NumberFormatException e) { - valField.setText(""+prefsToEditMap.get(keys[1]).getLong(keys[0])); - } - } - - for (String key : colorKeys) { - String keys[] = getKeys(key); - JTextField valField = colorFields.get(key); - prefsToEditMap.get(keys[1]).setColor(keys[0], valField.getBackground()); - } - - for (String key : stringKeys) { - String keys[] = getKeys(key); - JTextField valField = stringFields.get(key); - prefsToEditMap.get(keys[1]).setString(keys[0], valField.getText()); - } - - expertModeChanged = expertMode != prefs.getBoolean("sim.mode.expert"); - } - - /** - * Expert mode changed. - * - * @return true, if successful - */ - public boolean expertModeChanged() { - boolean ret = expertModeChanged; - - if (expertModeChanged) - expertModeChanged = false; - - return ret; - } - - /* (non-Javadoc) - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - */ - public void actionPerformed(ActionEvent e) { - String actionCommand = e.getActionCommand(); - - if (actionCommand.equals(prefs.getString("lang.takeover"))) { - savePrefs(); - - } else if (actionCommand.equals(prefs.getString("lang.reset"))) { - resetPrefs(); - } - } - - /** - * Gets the edits the panel. - * - * @return the edits the panel - */ - public JPanel getEditPanel() { - return editPanel; - } - - /** - * Gets the edits the table. - * - * @return the edits the table - */ - public VSEditorTable getEditTable() { - return editTable; - } - - /** - * Gets the button panel. - * - * @return the button panel - */ - public JPanel getButtonPanel() { - return buttonPanel; - } -} diff --git a/sources/prefs/editors/VSEditorFrame.java b/sources/prefs/editors/VSEditorFrame.java index 268afd3..de3f8fa 100644 --- a/sources/prefs/editors/VSEditorFrame.java +++ b/sources/prefs/editors/VSEditorFrame.java @@ -19,7 +19,7 @@ public class VSEditorFrame extends VSFrame implements ActionListener { private static final long serialVersionUID = 1L; /** The editor. */ - private VSBetterEditor editor; + private VSAbstractBetterEditor editor; /** The prefs. */ private VSPrefs prefs; @@ -31,7 +31,7 @@ public class VSEditorFrame extends VSFrame implements ActionListener { * @param relativeTo the relative to * @param editor the editor */ - public VSEditorFrame(VSPrefs prefs, Component relativeTo, VSBetterEditor editor) { + public VSEditorFrame(VSPrefs prefs, Component relativeTo, VSAbstractBetterEditor editor) { super(editor.getTitle(), relativeTo); this.prefs = prefs; this.editor = editor; diff --git a/sources/prefs/editors/VSProcessEditor.java b/sources/prefs/editors/VSProcessEditor.java index 664cafa..8666fbe 100644 --- a/sources/prefs/editors/VSProcessEditor.java +++ b/sources/prefs/editors/VSProcessEditor.java @@ -17,7 +17,7 @@ import prefs.VSPrefs; /** * The Class VSProcessEditor. */ -public class VSProcessEditor extends VSBetterEditor { +public class VSProcessEditor extends VSAbstractBetterEditor { private static final long serialVersionUID = 1L; /** The process. */ @@ -40,7 +40,7 @@ public class VSProcessEditor extends VSBetterEditor { } /* (non-Javadoc) - * @see prefs.editors.VSBetterEditor#addToButtonPanelFront(javax.swing.JPanel) + * @see prefs.editors.VSAbstractBetterEditor#addToButtonPanelFront(javax.swing.JPanel) */ protected void addToButtonPanelFront(JPanel buttonPanel) { JButton takeoverButton = new JButton( @@ -60,13 +60,13 @@ public class VSProcessEditor extends VSBetterEditor { String protocolString = " " + prefs.getString("lang.protocol"); for (String protocolClassname : editableProtocolsClassnames) { String protocolShortname = VSRegisteredEvents.getShortname(protocolClassname); - VSProtocol protocol = process.getProtocolObject(protocolClassname); + VSAbstractProtocol protocol = process.getProtocolObject(protocolClassname); addToEditor(protocolShortname + protocolString, protocolShortname, protocol); } } /* (non-Javadoc) - * @see prefs.editors.VSBetterEditor#actionPerformed(java.awt.event.ActionEvent) + * @see prefs.editors.VSAbstractBetterEditor#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); diff --git a/sources/prefs/editors/VSSimulatorEditor.java b/sources/prefs/editors/VSSimulatorEditor.java index 615a8ff..326ca95 100644 --- a/sources/prefs/editors/VSSimulatorEditor.java +++ b/sources/prefs/editors/VSSimulatorEditor.java @@ -14,7 +14,7 @@ import prefs.*; /** * The Class VSSimulatorEditor. */ -public class VSSimulatorEditor extends VSBetterEditor { +public class VSSimulatorEditor extends VSAbstractBetterEditor { private static final long serialVersionUID = 1L; /** The simulator frame. */ @@ -57,7 +57,7 @@ public class VSSimulatorEditor extends VSBetterEditor { } /* (non-Javadoc) - * @see prefs.editors.VSBetterEditor#addToButtonPanelFront(javax.swing.JPanel) + * @see prefs.editors.VSAbstractBetterEditor#addToButtonPanelFront(javax.swing.JPanel) */ protected void addToButtonPanelFront(JPanel buttonPanel) { if (TAKEOVER_BUTTON) { @@ -71,7 +71,7 @@ public class VSSimulatorEditor extends VSBetterEditor { } /* (non-Javadoc) - * @see prefs.editors.VSBetterEditor#actionPerformed(java.awt.event.ActionEvent) + * @see prefs.editors.VSAbstractBetterEditor#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); diff --git a/sources/protocols/VSAbstractProtocol.java b/sources/protocols/VSAbstractProtocol.java new file mode 100644 index 0000000..b726a2e --- /dev/null +++ b/sources/protocols/VSAbstractProtocol.java @@ -0,0 +1,178 @@ +/* + * VS is (c) 2008 by Paul C. Buetow + * vs@dev.buetow.org + */ +package protocols; + +import events.*; +import core.*; + +/** + * The Class VSAbstractProtocol. + */ +abstract public class VSAbstractProtocol extends VSAbstractEvent { + private static final long serialVersionUID = 1L; + + /** The protocol object is a server. */ + private boolean isServer; + + /** The protocol object is a client. */ + private boolean isClient; + + /** The current protocol object's context is a server. */ + private boolean currentContextIsServer; + + /** + * Send a message. + * + * @param message the message to send + */ + protected void sendMessage(VSMessage message) { + if (process == null) + return; + + process.increaseLamportTime(); + process.increaseVectorTime(); + message.init(process, getClassname()); + process.sendMessage(message); + } + + /** + * Checks if it's the incorrect protocol + * + * @param message the message to check against + * + * @return true, if is incorrect protocol + */ + private final boolean isIncorrectProtocol(VSMessage message) { + return !message.getProtocolClassname().equals(getClassname()); + } + + /* (non-Javadoc) + * @see events.VSAbstractEvent#onStart() + */ + public final void onStart() { + if (isClient) { + onClientStart(); + currentContextIsServer = false; + } + } + + /** + * On message recv. + * + * @param message the message + */ + public final void onMessageRecv(VSMessage message) { + if (isIncorrectProtocol(message)) + return; + + if (isServer) { + currentContextIsServer = true; + onServerRecv(message); + } + + if (isClient) { + currentContextIsServer = false; + onClientRecv(message); + } + } + + /** + * Checks if is server. + * + * @param isServer the is server + */ + public final void isServer(boolean isServer) { + this.isServer = isServer; + } + + /** + * Checks if is client. + * + * @param isClient the is client + */ + public final void isClient(boolean isClient) { + this.isClient = isClient; + } + + /** + * Reset. + */ + public void reset() { + if (isServer) { + currentContextIsServer = true; + isServer = false; + onServerReset(); + } + + if (isClient) { + currentContextIsServer = false; + isClient = false; + onClientReset(); + } + } + + /** + * On client start. + */ + abstract protected void onClientStart(); + + /** + * On client reset. + */ + abstract protected void onClientReset(); + + /** + * On client recv. + * + * @param message the message + */ + abstract protected void onClientRecv(VSMessage message); + + /** + * On server reset. + */ + abstract protected void onServerReset(); + + /** + * On server recv. + * + * @param message the message + */ + abstract protected void onServerRecv(VSMessage message); + + /** + * Gets the num processes. + * + * @return the num processes + */ + protected int getNumProcesses() { + if (process == null) + return 0; + + return process.getSimulationCanvas().getNumProcesses(); + } + + /* (non-Javadoc) + * @see prefs.VSPrefs#toString() + */ + public String toString() { + if (process == null) + return ""; + + StringBuffer buffer = new StringBuffer(); + + buffer.append(prefs.getString("lang.protocol")); + buffer.append(": "); + buffer.append(getShortname()); + buffer.append(" "); + + if (currentContextIsServer) + buffer.append(prefs.getString("lang.server")); + else + buffer.append(prefs.getString("lang.client")); + + return buffer.toString(); + } +} diff --git a/sources/protocols/VSProtocol.java b/sources/protocols/VSProtocol.java deleted file mode 100644 index 348f194..0000000 --- a/sources/protocols/VSProtocol.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * VS is (c) 2008 by Paul C. Buetow - * vs@dev.buetow.org - */ -package protocols; - -import events.*; -import core.*; - -// TODO: Auto-generated Javadoc -/** - * The Class VSProtocol. - */ -abstract public class VSProtocol extends VSEvent { - private static final long serialVersionUID = 1L; - - /** The is server. */ - private boolean isServer; - - /** The is client. */ - private boolean isClient; - - /** The current context is server. */ - private boolean currentContextIsServer; - - /** - * Send message. - * - * @param message the message - */ - protected void sendMessage(VSMessage message) { - if (process == null) - return; - - process.increaseLamportTime(); - process.increaseVectorTime(); - message.init(process, getClassname()); - process.sendMessage(message); - } - - /** - * Checks if is incorrect protocol. - * - * @param message the message - * - * @return true, if is incorrect protocol - */ - private final boolean isIncorrectProtocol(VSMessage message) { - return !message.getProtocolClassname().equals(getClassname()); - } - - /* (non-Javadoc) - * @see events.VSEvent#onStart() - */ - public final void onStart() { - if (isClient) { - onClientStart(); - currentContextIsServer = false; - } - } - - /** - * On message recv. - * - * @param message the message - */ - public final void onMessageRecv(VSMessage message) { - if (isIncorrectProtocol(message)) - return; - - if (isServer) { - currentContextIsServer = true; - onServerRecv(message); - } - - if (isClient) { - currentContextIsServer = false; - onClientRecv(message); - } - } - - /** - * Checks if is server. - * - * @param isServer the is server - */ - public final void isServer(boolean isServer) { - this.isServer = isServer; - } - - /** - * Checks if is client. - * - * @param isClient the is client - */ - public final void isClient(boolean isClient) { - this.isClient = isClient; - } - - /** - * Reset. - */ - public void reset() { - if (isServer) { - currentContextIsServer = true; - isServer = false; - onServerReset(); - } - - if (isClient) { - currentContextIsServer = false; - isClient = false; - onClientReset(); - } - } - - /** - * On client start. - */ - abstract protected void onClientStart(); - - /** - * On client reset. - */ - abstract protected void onClientReset(); - - /** - * On client recv. - * - * @param message the message - */ - abstract protected void onClientRecv(VSMessage message); - - /** - * On server reset. - */ - abstract protected void onServerReset(); - - /** - * On server recv. - * - * @param message the message - */ - abstract protected void onServerRecv(VSMessage message); - - /** - * Gets the num processes. - * - * @return the num processes - */ - protected int getNumProcesses() { - if (process == null) - return 0; - - return process.getSimulationCanvas().getNumProcesses(); - } - - /* (non-Javadoc) - * @see prefs.VSPrefs#toString() - */ - public String toString() { - if (process == null) - return ""; - - StringBuffer buffer = new StringBuffer(); - - buffer.append(prefs.getString("lang.protocol")); - buffer.append(": "); - buffer.append(getShortname()); - buffer.append(" "); - - if (currentContextIsServer) - buffer.append(prefs.getString("lang.server")); - else - buffer.append(prefs.getString("lang.client")); - - return buffer.toString(); - } -} diff --git a/sources/protocols/implementations/BerkelyTimeProtocol.java b/sources/protocols/implementations/BerkelyTimeProtocol.java index ded3d1b..9a52c4c 100644 --- a/sources/protocols/implementations/BerkelyTimeProtocol.java +++ b/sources/protocols/implementations/BerkelyTimeProtocol.java @@ -4,7 +4,7 @@ */ package protocols.implementations; -import protocols.VSProtocol; +import protocols.VSAbstractProtocol; import core.VSMessage; import java.util.ArrayList; @@ -14,7 +14,7 @@ import java.util.Vector; /** * The Class BerkelyTimeProtocol. */ -public class BerkelyTimeProtocol extends VSProtocol { +public class BerkelyTimeProtocol extends VSAbstractProtocol { private static final long serialVersionUID = 1L; /* Berkely Server variables */ @@ -40,7 +40,7 @@ public class BerkelyTimeProtocol extends VSProtocol { public BerkelyTimeProtocol() { setClassname(getClass().toString()); - /* Those prefs are editable through the VSProtocol VSEditor GUI. */ + /* Those prefs are editable through the VSAbstractProtocol VSAbstractEditor GUI. */ Vector vec = new Vector(); vec.add(2); vec.add(3); @@ -48,13 +48,13 @@ public class BerkelyTimeProtocol extends VSProtocol { } /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientReset() + * @see protocols.VSAbstractProtocol#onClientReset() */ protected void onClientReset() { processTimes.clear(); @@ -65,7 +65,7 @@ public class BerkelyTimeProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientStart() + * @see protocols.VSAbstractProtocol#onClientStart() */ protected void onClientStart() { peers.addAll(getVector("processPIDs")); @@ -76,7 +76,7 @@ public class BerkelyTimeProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ protected void onClientRecv(VSMessage recvMessage) { /* Ignore all protocol messages which are not a response message, e.g. itself */ @@ -145,13 +145,13 @@ public class BerkelyTimeProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerReset() + * @see protocols.VSAbstractProtocol#onServerReset() */ protected void onServerReset() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ protected void onServerRecv(VSMessage recvMessage) { if (recvMessage.getBoolean("isRequest")) { @@ -176,7 +176,7 @@ public class BerkelyTimeProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#toString() + * @see protocols.VSAbstractProtocol#toString() */ public String toString() { return super.toString(); diff --git a/sources/protocols/implementations/BroadcastSturmProtocol.java b/sources/protocols/implementations/BroadcastSturmProtocol.java index fafc732..49e183d 100644 --- a/sources/protocols/implementations/BroadcastSturmProtocol.java +++ b/sources/protocols/implementations/BroadcastSturmProtocol.java @@ -7,13 +7,13 @@ package protocols.implementations; import java.util.ArrayList; import core.VSMessage; -import protocols.VSProtocol; +import protocols.VSAbstractProtocol; // TODO: Auto-generated Javadoc /** * The Class BroadcastSturmProtocol. */ -public class BroadcastSturmProtocol extends VSProtocol { +public class BroadcastSturmProtocol extends VSAbstractProtocol { private static final long serialVersionUID = 1L; /** The sent messages. */ @@ -31,19 +31,19 @@ public class BroadcastSturmProtocol extends VSProtocol { } /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientReset() + * @see protocols.VSAbstractProtocol#onClientReset() */ protected void onClientReset() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientStart() + * @see protocols.VSAbstractProtocol#onClientStart() */ protected void onClientStart() { VSMessage message = new VSMessage(); @@ -53,20 +53,20 @@ public class BroadcastSturmProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ protected void onClientRecv(VSMessage recvMessage) { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerReset() + * @see protocols.VSAbstractProtocol#onServerReset() */ protected void onServerReset() { sentMessages.clear(); } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ protected void onServerRecv(VSMessage recvMessage) { if (!sentMessages.contains(recvMessage)) { @@ -79,7 +79,7 @@ public class BroadcastSturmProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#toString() + * @see protocols.VSAbstractProtocol#toString() */ public String toString() { return super.toString(); diff --git a/sources/protocols/implementations/DummyProtocol.java b/sources/protocols/implementations/DummyProtocol.java index 1a409da..929ace4 100644 --- a/sources/protocols/implementations/DummyProtocol.java +++ b/sources/protocols/implementations/DummyProtocol.java @@ -4,14 +4,14 @@ */ package protocols.implementations; -import protocols.VSProtocol; +import protocols.VSAbstractProtocol; import core.VSMessage; // TODO: Auto-generated Javadoc /** * The Class DummyProtocol. */ -public class DummyProtocol extends VSProtocol { +public class DummyProtocol extends VSAbstractProtocol { private static final long serialVersionUID = 1L; /** @@ -22,20 +22,20 @@ public class DummyProtocol extends VSProtocol { } /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientReset() + * @see protocols.VSAbstractProtocol#onClientReset() */ protected void onClientReset() { logg("onClientReset()"); } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientStart() + * @see protocols.VSAbstractProtocol#onClientStart() */ protected void onClientStart() { logg("onClientStart()"); @@ -49,7 +49,7 @@ public class DummyProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ protected void onClientRecv(VSMessage recvMessage) { logg("onClientRecv("+recvMessage+")"); @@ -61,21 +61,21 @@ public class DummyProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerReset() + * @see protocols.VSAbstractProtocol#onServerReset() */ protected void onServerReset() { logg("onClientReset()"); } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ protected void onServerRecv(VSMessage recvMessage) { logg("onServerRecv("+recvMessage+")"); } /* (non-Javadoc) - * @see protocols.VSProtocol#toString() + * @see protocols.VSAbstractProtocol#toString() */ public String toString() { return super.toString() + "; Dummy Test"; diff --git a/sources/protocols/implementations/ExternalTimeSyncProtocol.java b/sources/protocols/implementations/ExternalTimeSyncProtocol.java index e9e96a2..3430f98 100644 --- a/sources/protocols/implementations/ExternalTimeSyncProtocol.java +++ b/sources/protocols/implementations/ExternalTimeSyncProtocol.java @@ -5,13 +5,13 @@ package protocols.implementations; import core.VSMessage; -import protocols.VSProtocol; +import protocols.VSAbstractProtocol; // TODO: Auto-generated Javadoc /** * The Class ExternalTimeSyncProtocol. */ -public class ExternalTimeSyncProtocol extends VSProtocol { +public class ExternalTimeSyncProtocol extends VSAbstractProtocol { private static final long serialVersionUID = 1L; /** The request time. */ @@ -28,19 +28,19 @@ public class ExternalTimeSyncProtocol extends VSProtocol { } /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientReset() + * @see protocols.VSAbstractProtocol#onClientReset() */ protected void onClientReset() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientStart() + * @see protocols.VSAbstractProtocol#onClientStart() */ protected void onClientStart() { requestTime = process.getTime(); @@ -53,7 +53,7 @@ public class ExternalTimeSyncProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ protected void onClientRecv(VSMessage recvMessage) { if (!recvMessage.getBoolean("isServerResponse")) @@ -74,13 +74,13 @@ public class ExternalTimeSyncProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerReset() + * @see protocols.VSAbstractProtocol#onServerReset() */ protected void onServerReset() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ protected void onServerRecv(VSMessage recvMessage) { if (!recvMessage.getBoolean("isClientRequest")) @@ -94,7 +94,7 @@ public class ExternalTimeSyncProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#toString() + * @see protocols.VSAbstractProtocol#toString() */ public String toString() { return super.toString(); //+ "; " + prefs.getString("lang.requesttime") + ": " + requestTime; diff --git a/sources/protocols/implementations/InternalTimeSyncProtocol.java b/sources/protocols/implementations/InternalTimeSyncProtocol.java index 0b784a1..5676d58 100644 --- a/sources/protocols/implementations/InternalTimeSyncProtocol.java +++ b/sources/protocols/implementations/InternalTimeSyncProtocol.java @@ -5,13 +5,13 @@ package protocols.implementations; import core.VSMessage; -import protocols.VSProtocol; +import protocols.VSAbstractProtocol; // TODO: Auto-generated Javadoc /** * The Class InternalTimeSyncProtocol. */ -public class InternalTimeSyncProtocol extends VSProtocol { +public class InternalTimeSyncProtocol extends VSAbstractProtocol { private static final long serialVersionUID = 1L; /** The waiting for response. */ @@ -23,25 +23,25 @@ public class InternalTimeSyncProtocol extends VSProtocol { public InternalTimeSyncProtocol() { setClassname(getClass().toString()); - /* Those prefs are editable through the VSProtocol VSEditor GUI. t_min and t_max in milliseconds */ + /* Those prefs are editable through the VSAbstractProtocol VSAbstractEditor GUI. t_min and t_max in milliseconds */ initLong("t_min", 500, "Max. Übetragungszeit", "ms"); initLong("t_max", 2000, "Min. Übertragungszeit", "ms"); } /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientReset() + * @see protocols.VSAbstractProtocol#onClientReset() */ protected void onClientReset() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientStart() + * @see protocols.VSAbstractProtocol#onClientStart() */ protected void onClientStart() { waitingForResponse = true; @@ -53,7 +53,7 @@ public class InternalTimeSyncProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ protected void onClientRecv(VSMessage recvMessage) { /* Ignore all protocol messages which are not a response message, e.g. itself */ @@ -78,13 +78,13 @@ public class InternalTimeSyncProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerReset() + * @see protocols.VSAbstractProtocol#onServerReset() */ protected void onServerReset() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ protected void onServerRecv(VSMessage recvMessage) { /* Ignore all protocol messages which are not a request message, e.g. itself */ @@ -99,7 +99,7 @@ public class InternalTimeSyncProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#toString() + * @see protocols.VSAbstractProtocol#toString() */ public String toString() { return super.toString(); diff --git a/sources/protocols/implementations/OnePhaseCommitProtocol.java b/sources/protocols/implementations/OnePhaseCommitProtocol.java index 30c12f1..9c40493 100644 --- a/sources/protocols/implementations/OnePhaseCommitProtocol.java +++ b/sources/protocols/implementations/OnePhaseCommitProtocol.java @@ -6,18 +6,18 @@ package protocols.implementations; import java.util.Vector; -import protocols.VSProtocol; +import protocols.VSAbstractProtocol; import core.VSMessage; /** * The Class OnePhaseCommitProtocol. */ -public class OnePhaseCommitProtocol extends VSProtocol { +public class OnePhaseCommitProtocol extends VSAbstractProtocol { private static final long serialVersionUID = 1L; /* Client variables, coordinator */ - /* Server variables, peers */ + /* Client variables */ private boolean ackSent; /** @@ -36,19 +36,19 @@ public class OnePhaseCommitProtocol extends VSProtocol { } /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientReset() + * @see protocols.VSAbstractProtocol#onClientReset() */ protected void onClientReset() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientStart() + * @see protocols.VSAbstractProtocol#onClientStart() */ protected void onClientStart() { int numProcesses = getInteger("numProcesses"); @@ -58,27 +58,27 @@ public class OnePhaseCommitProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ protected void onClientRecv(VSMessage recvMessage) { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerReset() + * @see protocols.VSAbstractProtocol#onServerReset() */ protected void onServerReset() { ackSent = false; } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ protected void onServerRecv(VSMessage recvMessage) { } /* (non-Javadoc) - * @see protocols.VSProtocol#toString() + * @see protocols.VSAbstractProtocol#toString() */ public String toString() { return super.toString(); diff --git a/sources/protocols/implementations/PingPongProtocol.java b/sources/protocols/implementations/PingPongProtocol.java index 543b8df..167feb6 100644 --- a/sources/protocols/implementations/PingPongProtocol.java +++ b/sources/protocols/implementations/PingPongProtocol.java @@ -5,13 +5,13 @@ package protocols.implementations; import core.VSMessage; -import protocols.VSProtocol; +import protocols.VSAbstractProtocol; // TODO: Auto-generated Javadoc /** * The Class PingPongProtocol. */ -public class PingPongProtocol extends VSProtocol { +public class PingPongProtocol extends VSAbstractProtocol { private static final long serialVersionUID = 1L; /** The client counter. */ @@ -28,20 +28,20 @@ public class PingPongProtocol extends VSProtocol { } /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientReset() + * @see protocols.VSAbstractProtocol#onClientReset() */ protected void onClientReset() { clientCounter = 0; } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientStart() + * @see protocols.VSAbstractProtocol#onClientStart() */ protected void onClientStart() { VSMessage message = new VSMessage(); @@ -51,7 +51,7 @@ public class PingPongProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ protected void onClientRecv(VSMessage recvMessage) { if (!recvMessage.getBoolean("fromServer")) @@ -66,14 +66,14 @@ public class PingPongProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerReset() + * @see protocols.VSAbstractProtocol#onServerReset() */ protected void onServerReset() { serverCounter = 0; } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ protected void onServerRecv(VSMessage recvMessage) { if (!recvMessage.getBoolean("fromClient")) @@ -88,7 +88,7 @@ public class PingPongProtocol extends VSProtocol { } /* (non-Javadoc) - * @see protocols.VSProtocol#toString() + * @see protocols.VSAbstractProtocol#toString() */ public String toString() { return super.toString(); diff --git a/sources/protocols/implementations/TwoPhaseCommitProtocol.java b/sources/protocols/implementations/TwoPhaseCommitProtocol.java index 7bc079a..db0277c 100644 --- a/sources/protocols/implementations/TwoPhaseCommitProtocol.java +++ b/sources/protocols/implementations/TwoPhaseCommitProtocol.java @@ -4,13 +4,13 @@ */ package protocols.implementations; -import protocols.VSProtocol; +import protocols.VSAbstractProtocol; import core.VSMessage; /** * The Class TwoPhaseCommitProtocol */ -public class TwoPhaseCommitProtocol extends VSProtocol { +public class TwoPhaseCommitProtocol extends VSAbstractProtocol { private static final long serialVersionUID = 1L; /** @@ -21,43 +21,43 @@ public class TwoPhaseCommitProtocol extends VSProtocol { } /* (non-Javadoc) - * @see events.VSEvent#onInit() + * @see events.VSAbstractEvent#onInit() */ protected void onInit() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientReset() + * @see protocols.VSAbstractProtocol#onClientReset() */ protected void onClientReset() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientStart() + * @see protocols.VSAbstractProtocol#onClientStart() */ protected void onClientStart() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onClientRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onClientRecv(core.VSMessage) */ protected void onClientRecv(VSMessage recvMessage) { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerReset() + * @see protocols.VSAbstractProtocol#onServerReset() */ protected void onServerReset() { } /* (non-Javadoc) - * @see protocols.VSProtocol#onServerRecv(core.VSMessage) + * @see protocols.VSAbstractProtocol#onServerRecv(core.VSMessage) */ protected void onServerRecv(VSMessage recvMessage) { } /* (non-Javadoc) - * @see protocols.VSProtocol#toString() + * @see protocols.VSAbstractProtocol#toString() */ public String toString() { return super.toString(); diff --git a/sources/simulator/VSSimulator.java b/sources/simulator/VSSimulator.java index 2bb750a..1c120ed 100644 --- a/sources/simulator/VSSimulator.java +++ b/sources/simulator/VSSimulator.java @@ -568,7 +568,7 @@ public class VSSimulator extends JPanel { * @return the lang.process.removetask */ public VSTask createTask(VSProcess process, long time, boolean localTimedTask) { - VSEvent event = null; + VSAbstractEvent event = null; if (isClientRequest) { event = process.getProtocolObject(eventClassname); diff --git a/sources/simulator/VSSimulatorCanvas.java b/sources/simulator/VSSimulatorCanvas.java index 25ad889..f4e2044 100644 --- a/sources/simulator/VSSimulatorCanvas.java +++ b/sources/simulator/VSSimulatorCanvas.java @@ -1033,7 +1033,7 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi */ public void sendMessage(VSMessage message) { VSTask task = null; - VSEvent messageReceiveEvent = null; + VSAbstractEvent messageReceiveEvent = null; VSProcess sendingProcess = message.getSendingProcess(); long deliverTime, outageTime, durationTime; boolean recvOwn = prefs.getBoolean("sim.message.own.recv"); @@ -1085,11 +1085,11 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi editProcess(process); } else if (actionCommand.equals(prefs.getString("lang.process.crash"))) { - VSEvent event = new ProcessCrashEvent(); + VSAbstractEvent event = new ProcessCrashEvent(); taskManager.addTask(new VSTask(process.getGlobalTime(), process, event, VSTask.GLOBAL)); } else if (actionCommand.equals(prefs.getString("lang.process.recover"))) { - VSEvent event = new ProcessRecoverEvent(); + VSAbstractEvent event = new ProcessRecoverEvent(); taskManager.addTask(new VSTask(process.getGlobalTime(), process, event, VSTask.GLOBAL)); } else if (actionCommand.equals(prefs.getString("lang.process.remove"))) { -- cgit v1.2.3