summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-05-25 08:10:13 +0000
committerPaul Buetow <paul@buetow.org>2008-05-25 08:10:13 +0000
commitc015d586d22b69078b6da61858e5675793856b0b (patch)
treeefbc9881cf59363abef52a0beb5eedf9e81a224a
parent62fe28f0b0b0c9ebde18a6dc33907889ff3aa21b (diff)
JAutoDoc :)
-rw-r--r--sources/core/VSMessage.java76
-rw-r--r--sources/core/VSProcess.java343
-rw-r--r--sources/core/VSTask.java121
-rw-r--r--sources/core/VSTaskManager.java90
-rw-r--r--sources/core/time/VSLamportTime.java28
-rw-r--r--sources/core/time/VSTime.java16
-rw-r--r--sources/core/time/VSVectorTime.java39
-rw-r--r--sources/events/VSEvent.java70
-rw-r--r--sources/events/VSRegisteredEvents.java92
-rw-r--r--sources/events/implementations/ProcessCrashEvent.java15
-rw-r--r--sources/events/implementations/ProcessRecoverEvent.java15
-rw-r--r--sources/events/internal/MessageReceiveEvent.java21
-rw-r--r--sources/events/internal/ProtocolEvent.java45
-rw-r--r--sources/prefs/VSDefaultPrefs.java42
-rw-r--r--sources/prefs/VSPrefs.java596
-rw-r--r--sources/prefs/editors/VSBetterEditor.java55
-rw-r--r--sources/prefs/editors/VSColorChooser.java25
-rw-r--r--sources/prefs/editors/VSEditor.java253
-rw-r--r--sources/prefs/editors/VSEditorFrame.java30
-rw-r--r--sources/prefs/editors/VSEditorTable.java110
-rw-r--r--sources/prefs/editors/VSProcessEditor.java28
-rw-r--r--sources/prefs/editors/VSSimulatorEditor.java35
-rw-r--r--sources/protocols/VSProtocol.java78
-rw-r--r--sources/protocols/implementations/BerkelyTimeProtocol.java44
-rw-r--r--sources/protocols/implementations/BroadcastSturmProtocol.java36
-rw-r--r--sources/protocols/implementations/DummyProtocol.java33
-rw-r--r--sources/protocols/implementations/ExternalTimeSyncProtocol.java36
-rw-r--r--sources/protocols/implementations/InternalTimeSyncProtocol.java34
-rw-r--r--sources/protocols/implementations/PingPongProtocol.java36
-rw-r--r--sources/simulator/VSAbout.java29
-rw-r--r--sources/simulator/VSLogging.java74
-rw-r--r--sources/simulator/VSMain.java31
-rw-r--r--sources/simulator/VSSimulator.java405
-rw-r--r--sources/simulator/VSSimulatorCanvas.java402
-rw-r--r--sources/simulator/VSSimulatorFrame.java94
-rw-r--r--sources/utils/VSClassLoader.java16
-rw-r--r--sources/utils/VSFrame.java41
-rw-r--r--sources/utils/VSInfoArea.java20
-rw-r--r--sources/utils/VSPriorityQueue.java16
-rw-r--r--sources/utils/VSRandom.java24
-rw-r--r--sources/utils/VSTools.java24
-rw-r--r--sources/utils/VSTupel.java36
42 files changed, 3606 insertions, 48 deletions
diff --git a/sources/core/VSMessage.java b/sources/core/VSMessage.java
index 05c9e6a..a16d35b 100644
--- a/sources/core/VSMessage.java
+++ b/sources/core/VSMessage.java
@@ -1,45 +1,53 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package core;
import core.time.*;
import events.*;
import prefs.VSPrefs;
-/** This class represents a message which is send from one process to another process in the simulation.
+// TODO: Auto-generated Javadoc
+/**
+ * This class represents a message which is send from one process to another process in the simulation.
*/
public class VSMessage extends VSPrefs {
- /** Each message belongs to a specific protocol. This variable defined the class name of the protocol being used.
- */
+
+ /** Each message belongs to a specific protocol. This variable defined the class name of the protocol being used. */
private String protocolClassname;
- /** The default application preferences.
- */
+
+ /** The default application preferences. */
private VSPrefs prefs;
- /** A reference to the process who sent this message.
- */
+
+ /** A reference to the process who sent this message. */
private VSProcess sendingProcess;
- /** The vector time of the sending process after sending. The receiver process will use this vector time in order to update the local vector time.
- */
+
+ /** The vector time of the sending process after sending. The receiver process will use this vector time in order to update the local vector time. */
private VSVectorTime vectorTime;
- /** The lamport time of the sending process after sending. The receiver process will use this lamport time in order to update the local vector time.
- */
+
+ /** The lamport time of the sending process after sending. The receiver process will use this lamport time in order to update the local vector time. */
private long lamportTime;
- /** Each message has its own unique ID. The ID will show up in the logging window of the simulator as well.
- */
+
+ /** Each message has its own unique ID. The ID will show up in the logging window of the simulator as well. */
private long messageID;
- /** This counter is used in order to generate unique message ID's.
- */
+
+ /** This counter is used in order to generate unique message ID's. */
private static long messageCounter;
- /** The constructor of the message.
+ /**
+ * The constructor of the message.
*
- * @param protocolClassname The classname of the protocol this message
- * belongs to.
+ * @param protocolClassname The classname of the protocol this message
+ * belongs to.
*/
public VSMessage(String protocolClassname) {
this.protocolClassname = protocolClassname;
this.messageID = ++messageCounter;
}
- /** Initialized the message.
+ /**
+ * Initialized the message.
*
* @param process The sending process of this message.
*/
@@ -50,7 +58,7 @@ public class VSMessage extends VSPrefs {
vectorTime = sendingProcess.getVectorTime().getCopy();
}
- /**
+ /**
* Getter method.
*
* @return The protocol name of the message.
@@ -59,7 +67,8 @@ public class VSMessage extends VSPrefs {
return VSRegisteredEvents.getName(getProtocolClassname());
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The protocol classname of the message.
*/
@@ -67,7 +76,8 @@ public class VSMessage extends VSPrefs {
return protocolClassname;
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The ID of the message.
*/
@@ -75,7 +85,8 @@ public class VSMessage extends VSPrefs {
return messageID;
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The process which sent this message.
*/
@@ -83,7 +94,8 @@ public class VSMessage extends VSPrefs {
return sendingProcess;
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The lamport time of the sending process.
*/
@@ -91,7 +103,8 @@ public class VSMessage extends VSPrefs {
return lamportTime;
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The vector time of the sending process.
*/
@@ -99,7 +112,8 @@ public class VSMessage extends VSPrefs {
return vectorTime;
}
- /** String representation of the message object.
+ /**
+ * String representation of the message object.
*
* @return String representation of the message object.
*/
@@ -116,7 +130,8 @@ public class VSMessage extends VSPrefs {
return buffer.toString();
}
- /** Extended string representation of the message object.
+ /**
+ * Extended string representation of the message object.
*
* @return Extended string representation of the message object.
*/
@@ -124,16 +139,19 @@ public class VSMessage extends VSPrefs {
return toString() + "; " + super.toString();
}
- /** Compares two messages.
+ /**
+ * Compares two messages.
*
* @param message The message to compare with.
+ *
* @return true, if the messages have the same ID. Otherwise false.
*/
public boolean equals(VSMessage message) {
return messageID == message.getMessageID();
}
- /** For logging in the simulator's logging window!
+ /**
+ * For logging in the simulator's logging window!.
*
* @param message The message to logg.
*/
diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java
index 3773bd6..e4c7561 100644
--- a/sources/core/VSProcess.java
+++ b/sources/core/VSProcess.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package core;
import java.awt.*;
@@ -11,39 +15,97 @@ import protocols.*;
import simulator.*;
import utils.*;
+/**
+ * The Class VSProcess. A object of this class represents a process of a simulation.
+ */
public class VSProcess extends VSPrefs {
+
+ /** The protocols to reset if the simulation is over or the reset button has been pressed. */
private ArrayList<VSProtocol> protocolsToReset;
+
+ /** The crash history. represents all crashes of the process using the global simulation time. */
private ArrayList<Long> crashHistory;
+
+ /** The lamport time history. */
private ArrayList<VSLamportTime> lamportTimeHistory;
+
+ /** The vector time history. */
private ArrayList<VSVectorTime> vectorTimeHistory;
+
+ /** The crashed color. */
private Color crashedColor;;
+
+ /** The current color. */
private Color currentColor;
+
+ /** The tmp color. For internal usage. */
private Color tmpColor;
+
+ /** The logging object. */
private VSLogging logging;
+
+ /** The simulation's default prefs. */
private VSPrefs prefs;
+
+ /** The random generator of the process. */
private VSRandom random;
+
+ /** The simulation canvas. */
private VSSimulatorCanvas simulationCanvas;
+
+ /** The random crash task. May be null if there is no such random task. */
private VSTask randomCrashTask;
+
+ /** The vector time. */
private VSVectorTime vectorTime;
+
+ /** The process has crashed. But may be working again. */
private boolean hasCrashed;
+
+ /** The process has started. But may be paused or crashed.. */
private boolean hasStarted;
+
+ /** The process is crashed. */
private boolean isCrashed;
+
+ /** The process is highlighted. */
private boolean isHighlighted;
+
+ /** The process is paused. */
private boolean isPaused;
+
+ /** The time has been modified in a task. Needed by the task manager to calculate correct offsets. */
private boolean timeModified;
+
+ /** The clock offset. Used by the task manager and also by the process' clock variance. */
private double clockOffset;
+
+ /** The clock variance. */
private float clockVariance;
+
+ /** The process id. */
private int processID; // Represents the PID of a process
+
+ /** The process num. It is different to the process id. It represents the array index of the process. */
private int processNum; // Represents the array index of the process, for internal usage
+
+ /** The global time. */
private long globalTime;
+
+ /** The lamport time. */
private long lamportTime;
+
+ /** The local time. */
private long localTime;
+
+ /** The process counter. Needed for the unique process id's. */
private static int processCounter;
/* This array contains all Integer prefs of the process which should show
* up in the prefs menu! All keys which dont start with "sim." only show
* up in the extended prefs menu!
*/
+ /** The Constant DEFAULT_INTEGER_VALUE_KEYS. */
private static final String DEFAULT_INTEGER_VALUE_KEYS[] = {
"process.prob.crash",
"message.prob.outage",
@@ -53,12 +115,14 @@ public class VSProcess extends VSPrefs {
* up in the prefs menu! All keys which dont start with "sim." only show
* up in the extended prefs menu!
*/
+ /** The Constant DEFAULT_LONG_VALUE_KEYS. */
private static final String DEFAULT_LONG_VALUE_KEYS[] = {
"message.sendingtime.min",
"message.sendingtime.max",
};
- /* This array contains all Float prefs of the process which should show
+ /** The Constant DEFAULT_FLOAT_VALUE_KEYS. */
+ /** This array contains all Float prefs of the process which should show
* up in the prefs menu! All keys which dont start with "sim." only show
* up in the extended prefs menu!
*/
@@ -66,7 +130,8 @@ public class VSProcess extends VSPrefs {
"process.clock.variance",
};
- /* This array contains all Color prefs of the process which should show
+ /** The Constant DEFAULT_COLOR_VALUE_KEYS. */
+ /** This array contains all Color prefs of the process which should show
* up in the prefs menu! All keys which dont start with "sim." only show
* up in the extended prefs menu!
*/
@@ -78,13 +143,22 @@ public class VSProcess extends VSPrefs {
"col.process.crashed",
};
- /* This array contains all String prefs of the process which should show
+ /** The Constant DEFAULT_STRING_VALUE_KEYS. */
+ /** This array contains all String prefs of the process which should show
* up in the prefs menu! All keys which dont start with "sim." only show
* up in the extended prefs menu!
*/
private static final String DEFAULT_STRING_VALUE_KEYS[] = {
};
+ /**
+ * Instantiates a new process.
+ *
+ * @param prefs the simulation's default prefs
+ * @param processNum the process num
+ * @param simulationCanvas the simulation canvas
+ * @param logging the logging object
+ */
public VSProcess(VSPrefs prefs, int processNum, VSSimulatorCanvas simulationCanvas, VSLogging logging) {
this.protocolsToReset = new ArrayList<VSProtocol>();
this.processNum = processNum;
@@ -112,6 +186,9 @@ public class VSProcess extends VSPrefs {
createRandomCrashTask();
}
+ /**
+ * Inits the time formats.
+ */
private void initTimeFormats() {
lamportTime = 0;
lamportTimeHistory = new ArrayList<VSLamportTime>();
@@ -125,6 +202,9 @@ public class VSProcess extends VSPrefs {
vectorTime.add(new Long(0));
}
+ /**
+ * Reset time formats.
+ */
private void resetTimeFormats() {
lamportTime = 0;
lamportTimeHistory.clear();
@@ -140,7 +220,7 @@ public class VSProcess extends VSPrefs {
/**
- * Called from the VSProcessEditor, after finishing editing!
+ * Called from the VSProcessEditor, after finishing editing!.
*/
public synchronized void updateFromVSPrefs() {
setClockVariance(getFloat("process.clock.variance"));
@@ -151,13 +231,18 @@ public class VSProcess extends VSPrefs {
}
/**
- * Called from the VSProcessEditor, before starting editing!
+ * Called from the VSProcessEditor, before starting editing!.
*/
public synchronized void updatePrefs() {
setFloat("process.clock.variance", getClockVariance());
setLong("process.localtime", getTime());
}
+ /**
+ * Sync time. Using the clockOffset and clockVariance.
+ *
+ * @param globalTime the global time
+ */
public synchronized void syncTime(final long globalTime) {
final long currentGlobalTimestep = globalTime - this.globalTime;
this.globalTime = globalTime;
@@ -179,6 +264,11 @@ public class VSProcess extends VSPrefs {
localTime = 0;
}
+ /**
+ * Sets the current color.
+ *
+ * @param newColor the new current color
+ */
private void setCurrentColor(Color newColor) {
if (isHighlighted)
tmpColor = newColor;
@@ -186,17 +276,26 @@ public class VSProcess extends VSPrefs {
currentColor = newColor;
}
+ /**
+ * Highlights the process.
+ */
public synchronized void highlightOn() {
tmpColor = currentColor;
currentColor = getColor("col.process.highlight");
isHighlighted = true;
}
+ /**
+ * Unhighlights the process.
+ */
public synchronized void highlightOff() {
currentColor = tmpColor;
isHighlighted = false;
}
+ /**
+ * Resets the process.
+ */
public synchronized void reset() {
isPaused = true;
isCrashed = false;
@@ -212,6 +311,9 @@ public class VSProcess extends VSPrefs {
resetTimeFormats();
}
+ /**
+ * Creates the random crash task.
+ */
public void createRandomCrashTask() {
if (!isCrashed) {
VSTaskManager taskManager = simulationCanvas.getTaskManager();
@@ -236,41 +338,80 @@ public class VSProcess extends VSPrefs {
}
}
+ /**
+ * Adds the clock offset. This method is used by the task manager.
+ *
+ * @param add the clock offset to add.
+ */
public synchronized void addClockOffset(long add) {
this.clockOffset += add;
}
+ /**
+ * Play. Called by the simulation canvas.
+ */
public synchronized void play() {
isPaused = false;
setCurrentColor(getColor("col.process.running"));
}
+ /**
+ * Pause. Called by the simulation canvas.
+ */
public synchronized void pause() {
isPaused = true;
setCurrentColor(getColor("col.process.stopped"));
}
+ /**
+ * Finish. Called by the simulation canvas.
+ */
public synchronized void finish() {
isPaused = true;
setCurrentColor(getColor("col.process.default"));
}
+ /**
+ * Gets the process id.
+ *
+ * @return the process id
+ */
public synchronized int getProcessID() {
return processID;
}
+ /**
+ * Gets the process num.
+ *
+ * @return the process num
+ */
public synchronized int getProcessNum() {
return processNum;
}
+ /**
+ * Sets the process id.
+ *
+ * @param processID the new process id
+ */
public synchronized void setProcessID(int processID) {
this.processID = processID;
}
+ /**
+ * Gets the current process' color.
+ *
+ * @return the current color of the process.
+ */
public synchronized Color getColor() {
return currentColor;
}
+ /**
+ * Sets the local time.
+ *
+ * @param localTime the new local time.
+ */
public synchronized void setLocalTime(final long localTime) {
if (localTime >= 0)
this.localTime = localTime;
@@ -278,10 +419,20 @@ public class VSProcess extends VSPrefs {
this.localTime = 0;
}
+ /**
+ * Gets the process' local time.
+ *
+ * @return the process' local time
+ */
public synchronized long getTime() {
return localTime;
}
+ /**
+ * Sets the process' local time.
+ *
+ * @param time the new local time of the process.
+ */
public synchronized void setTime(final long time) {
if (time >= 0)
this.localTime = time;
@@ -291,10 +442,20 @@ public class VSProcess extends VSPrefs {
this.timeModified = true;
}
+ /**
+ * Checks if the process is crashed.
+ *
+ * @return true, if is crashed
+ */
public synchronized boolean isCrashed() {
return isCrashed;
}
+ /**
+ * Sets if the process is crashed.
+ *
+ * @param isCrashed true if the process is crashed.
+ */
public synchronized void isCrashed(boolean isCrashed) {
this.isCrashed = isCrashed;
crashHistory.add(new Long(globalTime));
@@ -302,34 +463,76 @@ public class VSProcess extends VSPrefs {
hasCrashed = true;
}
+ /**
+ * Checks if the process has crashed at least once during the current
+ * simulation.
+ *
+ * @return true, if yes
+ */
public synchronized boolean hasCrashed() {
return hasCrashed;
}
+ /**
+ * Gets the crashed color.
+ *
+ * @return the crashed color
+ */
public synchronized Color getCrashedColor() {
return crashedColor;
}
+ /**
+ * Checks if the time has been modified. by a task.
+ * This mehod is needed by the task manager.
+ *
+ * @return true, if yes
+ */
public synchronized boolean timeModified() {
return timeModified;
}
+ /**
+ * Sets if the time has been modified by a task.
+ *
+ * @param timeModified true, if it has been modified.
+ */
public synchronized void timeModified(boolean timeModified) {
this.timeModified = timeModified;
}
+ /**
+ * Gets the global time.
+ *
+ * @return the global time
+ */
public synchronized long getGlobalTime() {
return globalTime;
}
+ /**
+ * Sets the global time.
+ *
+ * @param globalTime the new global time
+ */
public synchronized void setGlobalTime(final long globalTime) {
this.globalTime = globalTime >= 0 ? globalTime : 0;
}
+ /**
+ * Gets the clock variance.
+ *
+ * @return the clock variance
+ */
public synchronized float getClockVariance() {
return clockVariance;
}
+ /**
+ * Sets the clock variance.
+ *
+ * @param clockVariance the new clock variance
+ */
public synchronized void setClockVariance(float clockVariance) {
/* If negative, only allow < 1 prefs */
if (clockVariance < 0) {
@@ -343,6 +546,11 @@ public class VSProcess extends VSPrefs {
this.clockVariance = clockVariance;
}
+ /**
+ * Gets the duration time.
+ *
+ * @return the duration time
+ */
public synchronized long getDurationTime() {
final long maxDurationTime = getLong("message.sendingtime.max");
final long minDurationTime = getLong("message.sendingtime.min");
@@ -359,6 +567,13 @@ public class VSProcess extends VSPrefs {
return minDurationTime + random.nextInt(diff+1);
}
+ /**
+ * Gets the a random message outage time.
+ *
+ * @param durationTime the duration time
+ *
+ * @return the a random message outage time
+ */
public synchronized long getARandomMessageOutageTime(final long durationTime) {
/* Check if the message will have an outage or not */
if (random.nextInt(100) < getInteger("message.prob.outage")) {
@@ -371,6 +586,11 @@ public class VSProcess extends VSPrefs {
return -1;
}
+ /**
+ * Gets the a random crash time.
+ *
+ * @return the a random crash time
+ */
private long getARandomCrashTime() {
/* Check if the process will crash or not */
if (random.nextInt(100) <= getInteger("process.prob.crash")) {
@@ -383,18 +603,36 @@ public class VSProcess extends VSPrefs {
return -1;
}
+ /**
+ * Gets the random crash task.
+ *
+ * @return the random crash task
+ */
public synchronized VSTask getCrashTask() {
return randomCrashTask;
}
+ /**
+ * Checks if is paused.
+ *
+ * @return true, if is paused
+ */
public synchronized boolean isPaused() {
return isPaused;
}
+ /**
+ * Increases the lamport time.
+ */
public void increaseLamportTime() {
setLamportTime(getLamportTime()+1);
}
+ /**
+ * Updates the lamport time.
+ *
+ * @param time the lamport time
+ */
public void updateLamportTime(long time) {
final long lamportTime = getLamportTime() + 1;
@@ -404,15 +642,30 @@ public class VSProcess extends VSPrefs {
setLamportTime(lamportTime);
}
+ /**
+ * Gets the lamport time.
+ *
+ * @return the lamport time.
+ */
public synchronized long getLamportTime() {
return lamportTime;
}
+ /**
+ * Sets the lamport time.
+ *
+ * @param lamportTime the new lamport time
+ */
public synchronized void setLamportTime(long lamportTime) {
this.lamportTime = lamportTime;
lamportTimeHistory.add(new VSLamportTime(globalTime, lamportTime));
}
+ /**
+ * Gets the lamport time history as an array.
+ *
+ * @return the lamport time history array
+ */
public synchronized VSTime[] getLamportTimeArray() {
final int size = lamportTimeHistory.size();
final VSTime[] arr = new VSLamportTime[size];
@@ -423,12 +676,20 @@ public class VSProcess extends VSPrefs {
return arr;
}
+ /**
+ * Increases the vector time.
+ */
public synchronized void increaseVectorTime() {
vectorTime.set(processNum, new Long(vectorTime.get(processNum).longValue()+1));
vectorTime.setGlobalTime(globalTime);
vectorTimeHistory.add(vectorTime.getCopy());
}
+ /**
+ * Updates the vector time.
+ *
+ * @param vectorTimeUpdate the vector time of the other process to use for the update
+ */
public synchronized void updateVectorTime(VSVectorTime vectorTimeUpdate) {
final int size = vectorTime.size();
@@ -443,10 +704,20 @@ public class VSProcess extends VSPrefs {
vectorTimeHistory.add(vectorTime.getCopy());
}
+ /**
+ * Gets the vector time.
+ *
+ * @return the vector time
+ */
public synchronized VSVectorTime getVectorTime() {
return vectorTime;
}
+ /**
+ * Gets the vector time history as an array.
+ *
+ * @return the vector time history array
+ */
public synchronized VSTime[] getVectorTimeArray() {
final int size = vectorTimeHistory.size();
final VSTime[] arr = new VSTime[size];
@@ -457,6 +728,11 @@ public class VSProcess extends VSPrefs {
return arr;
}
+ /**
+ * Gets the crash history array.
+ *
+ * @return the crash history array
+ */
public synchronized Long[] getCrashHistoryArray() {
final int size = crashHistory.size();
final Long[] arr = new Long[size];
@@ -467,6 +743,11 @@ public class VSProcess extends VSPrefs {
return arr;
}
+ /**
+ * Called by a task if the process sends a message.
+ *
+ * @param message the message to send.
+ */
public void sendMessage(VSMessage message) {
StringBuffer buffer = new StringBuffer();
buffer.append(prefs.getString("lang.message.sent"));
@@ -476,10 +757,18 @@ public class VSProcess extends VSPrefs {
simulationCanvas.sendMessage(message);
}
+ /**
+ * Logg a message to the logging area.
+ *
+ * @param message the message to logg
+ */
public void logg(String message) {
logging.logg(toString() + "; " + message, globalTime);
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#fillWithDefaults()
+ */
public void fillWithDefaults() {
prefs.copyIntegers(this, DEFAULT_INTEGER_VALUE_KEYS);
prefs.copyLongs(this, DEFAULT_LONG_VALUE_KEYS);
@@ -488,6 +777,9 @@ public class VSProcess extends VSPrefs {
prefs.copyStrings(this, DEFAULT_STRING_VALUE_KEYS);
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#toString()
+ */
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(prefs.getString("lang.process.id"));
@@ -508,6 +800,11 @@ public class VSProcess extends VSPrefs {
return buffer.toString();
}
+ /**
+ * The extended string representation of the process object.
+ *
+ * @return the extended string representation
+ */
public String toStringFull() {
StringBuffer buffer = new StringBuffer();
buffer.append(toString());
@@ -520,22 +817,48 @@ public class VSProcess extends VSPrefs {
return buffer.toString();
}
+ /**
+ * Equals. Checks, if both processes have the same process id.
+ *
+ * @param process the process to compare to
+ *
+ * @return true, if both processes are the same.
+ */
public boolean equals(VSProcess process) {
return process.getProcessID() == processID;
}
+ /**
+ * Gets the simulation canvas.
+ *
+ * @return the simulation canvas
+ */
public VSSimulatorCanvas getSimulationCanvas() {
return simulationCanvas;
}
+ /**
+ * Gets the simulation's default prefs.
+ *
+ * @return the default prefs
+ */
public VSPrefs getPrefs() {
return prefs;
}
+ /**
+ * Resets the process counter.
+ */
public static void resetProcessCounter() {
processCounter = 0;
}
+ /**
+ * Removes the process at the specified index.
+ * Needed in order to update the vector time and the local processNum.
+ *
+ * @param index the index the process has to get removed.
+ */
public void removeProcessAtIndex(int index) {
if (index < processNum)
--processNum;
@@ -545,12 +868,22 @@ public class VSProcess extends VSPrefs {
vectorTime.remove(index);
}
+ /**
+ * Added a process. Needed in order to update the vector time's size.
+ */
public void addedAProcess() {
vectorTime.add(new Long(0));
for (VSVectorTime vectorTime : vectorTimeHistory)
vectorTime.add(new Long(0));
}
+ /**
+ * Gets the protocol object.
+ *
+ * @param protocolClassname the protocol classname
+ *
+ * @return the protocol object
+ */
public VSProtocol getProtocolObject(String protocolClassname) {
VSProtocol protocol = null;
diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java
index e38c1de..43d9cb5 100644
--- a/sources/core/VSTask.java
+++ b/sources/core/VSTask.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package core;
import events.*;
@@ -6,18 +10,50 @@ import events.internal.*;
import prefs.VSPrefs;
import protocols.VSProtocol;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSTask.
+ */
public class VSTask implements Comparable {
+
+ /** The Constant LOCAL. */
public final static boolean LOCAL = true;
+
+ /** The Constant GLOBAL. */
public final static boolean GLOBAL = false;
+
+ /** The task time. */
private long taskTime;
+
+ /** The event. */
private VSEvent event;
+
+ /** The process. */
private VSProcess process;
+
+ /** The prefs. */
private VSPrefs prefs;
+
+ /** The is programmed. */
private boolean isProgrammed;
+
+ /** The is global timed. */
private boolean isGlobalTimed;
+
+ /** The task counter. */
private static int taskCounter;
+
+ /** The task num. */
private int taskNum;
+ /**
+ * Instantiates a new vS task.
+ *
+ * @param taskTime the task time
+ * @param process the process
+ * @param event the event
+ * @param isLocal the is local
+ */
public VSTask(long taskTime, VSProcess process, VSEvent event, boolean isLocal) {
this.process = process;
this.taskTime = taskTime > 0 ? taskTime : 0;
@@ -27,26 +63,58 @@ public class VSTask implements Comparable {
this.taskNum = ++taskCounter;
}
+ /**
+ * Gets the task num.
+ *
+ * @return the task num
+ */
public int getTaskNum() {
return taskNum;
}
+ /**
+ * Checks if is programmed.
+ *
+ * @param isProgrammed the is programmed
+ */
public void isProgrammed(boolean isProgrammed) {
this.isProgrammed = isProgrammed;
}
+ /**
+ * Checks if is programmed.
+ *
+ * @return true, if is programmed
+ */
public boolean isProgrammed() {
return isProgrammed;
}
+ /**
+ * Checks if is message receive event.
+ *
+ * @return true, if is message receive event
+ */
public boolean isMessageReceiveEvent() {
return event instanceof MessageReceiveEvent;
}
+ /**
+ * Checks if is process recover event.
+ *
+ * @return true, if is process recover event
+ */
public boolean isProcessRecoverEvent() {
return event instanceof ProcessRecoverEvent;
}
+ /**
+ * Checks if is protocol.
+ *
+ * @param protocol the protocol
+ *
+ * @return true, if is protocol
+ */
public boolean isProtocol(VSProtocol protocol) {
if (event instanceof VSProtocol)
return ((VSProtocol) event).equals(protocol);
@@ -54,6 +122,11 @@ public class VSTask implements Comparable {
return false;
}
+ /**
+ * Time over.
+ *
+ * @return true, if successful
+ */
public boolean timeOver() {
if (isGlobalTimed)
return taskTime < process.getGlobalTime();
@@ -61,6 +134,13 @@ public class VSTask implements Comparable {
return taskTime < process.getTime();
}
+ /**
+ * Equals.
+ *
+ * @param task the task
+ *
+ * @return true, if successful
+ */
public boolean equals(VSTask task) {
return taskNum == task.getTaskNum();
/*
@@ -71,36 +151,74 @@ public class VSTask implements Comparable {
*/
}
+ /**
+ * Checks if is process.
+ *
+ * @param process the process
+ *
+ * @return true, if is process
+ */
public boolean isProcess(VSProcess process) {
return this.process.equals(process);
}
+ /**
+ * Checks if is global timed.
+ *
+ * @return true, if is global timed
+ */
public boolean isGlobalTimed() {
return isGlobalTimed;
}
+ /**
+ * Gets the process.
+ *
+ * @return the process
+ */
public VSProcess getProcess() {
return process;
}
+ /**
+ * Run.
+ */
public void run() {
if (event.getProcess() == null)
event.init(process);
event.onStart();
}
+ /**
+ * Gets the task time.
+ *
+ * @return the task time
+ */
public long getTaskTime() {
return taskTime;
}
+ /**
+ * Gets the event.
+ *
+ * @return the event
+ */
public VSEvent getEvent() {
return event;
}
+ /**
+ * Logg.
+ *
+ * @param message the message
+ */
private void logg(String message) {
process.logg(message);
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(prefs.getString("lang.task"));
@@ -112,6 +230,9 @@ public class VSTask implements Comparable {
return buffer.toString();
}
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
public int compareTo(Object object) {
if (object instanceof VSTask) {
final VSTask task = (VSTask) object;
diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java
index cc2f262..272922f 100644
--- a/sources/core/VSTaskManager.java
+++ b/sources/core/VSTaskManager.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package core;
import java.util.*;
@@ -5,14 +9,35 @@ import java.util.*;
import prefs.*;
import utils.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSTaskManager.
+ */
public class VSTaskManager {
+
+ /** The tasks. */
private PriorityQueue<VSTask> tasks;
+
+ /** The global tasks. */
private PriorityQueue<VSTask> globalTasks;
+
+ /** The fullfilled programmed tasks. */
private LinkedList<VSTask> fullfilledProgrammedTasks;
+
+ /** The Constant PROGRAMMED. */
public final static boolean PROGRAMMED = true;
+
+ /** The Constant ONLY_ONCE. */
public final static boolean ONLY_ONCE = false;
+
+ /** The prefs. */
private VSPrefs prefs;
+ /**
+ * Instantiates a new vS task manager.
+ *
+ * @param prefs the prefs
+ */
public VSTaskManager(VSPrefs prefs) {
this.prefs = prefs;
this.tasks = new PriorityQueue<VSTask>();//100, comparator);
@@ -20,6 +45,13 @@ public class VSTaskManager {
this.fullfilledProgrammedTasks = new LinkedList<VSTask>();
}
+ /**
+ * Run tasks.
+ *
+ * @param step the step
+ * @param offset the offset
+ * @param lastGlobalTime the last global time
+ */
public synchronized void runTasks(final long step, final long offset, final long lastGlobalTime) {
VSTask task = null;
VSProcess process = null;
@@ -140,6 +172,9 @@ public class VSTaskManager {
} while (redo);
}
+ /**
+ * Reset.
+ */
public synchronized void reset() {
PriorityQueue<VSTask> tmp = tasks;
PriorityQueue<VSTask> tmp2 = globalTasks;
@@ -165,6 +200,11 @@ public class VSTaskManager {
}
}
+ /**
+ * Insert.
+ *
+ * @param task the task
+ */
private void insert(VSTask task) {
if (task.timeOver())
fullfilledProgrammedTasks.addLast(task);
@@ -176,15 +216,33 @@ public class VSTaskManager {
tasks.add(task);
}
+ /**
+ * Adds the task.
+ *
+ * @param task the task
+ */
public void addTask(VSTask task) {
addTask(task, VSTaskManager.ONLY_ONCE);
}
+ /**
+ * Adds the task.
+ *
+ * @param task the task
+ * @param isProgrammed the is programmed
+ */
public synchronized void addTask(VSTask task, boolean isProgrammed) {
task.isProgrammed(isProgrammed);
insert(task);
}
+ /**
+ * Removes the task.
+ *
+ * @param task the task
+ *
+ * @return true, if successful
+ */
public synchronized boolean removeTask(VSTask task) {
if (fullfilledProgrammedTasks.remove(task))
return true;
@@ -198,6 +256,11 @@ public class VSTaskManager {
return false;
}
+ /**
+ * Removes the tasks of.
+ *
+ * @param process the process
+ */
public synchronized void removeTasksOf(VSProcess process) {
ArrayList<VSTask> removeThose = new ArrayList<VSTask>();
for (VSTask task : fullfilledProgrammedTasks)
@@ -221,6 +284,11 @@ public class VSTaskManager {
tasks.remove(task);
}
+ /**
+ * Gets the local tasks.
+ *
+ * @return the local tasks
+ */
public synchronized VSPriorityQueue<VSTask> getLocalTasks() {
VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>();
@@ -235,6 +303,11 @@ public class VSTaskManager {
return processTasks;
}
+ /**
+ * Gets the global tasks.
+ *
+ * @return the global tasks
+ */
public synchronized VSPriorityQueue<VSTask> getGlobalTasks() {
VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>();
@@ -249,6 +322,13 @@ public class VSTaskManager {
return processTasks;
}
+ /**
+ * Gets the process local tasks.
+ *
+ * @param process the process
+ *
+ * @return the process local tasks
+ */
public synchronized VSPriorityQueue<VSTask> getProcessLocalTasks(VSProcess process) {
VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>();
@@ -263,6 +343,13 @@ public class VSTaskManager {
return processTasks;
}
+ /**
+ * Gets the process global tasks.
+ *
+ * @param process the process
+ *
+ * @return the process global tasks
+ */
public synchronized VSPriorityQueue<VSTask> getProcessGlobalTasks(VSProcess process) {
VSPriorityQueue<VSTask> processTasks = new VSPriorityQueue<VSTask>();
@@ -277,6 +364,9 @@ public class VSTaskManager {
return processTasks;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
public String toString() {
StringBuffer buffer = new StringBuffer();
diff --git a/sources/core/time/VSLamportTime.java b/sources/core/time/VSLamportTime.java
index 592507a..4ee5ebd 100644
--- a/sources/core/time/VSLamportTime.java
+++ b/sources/core/time/VSLamportTime.java
@@ -1,16 +1,23 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package core.time;
-/** This class defined how the lamport timestamps are represented.
+// TODO: Auto-generated Javadoc
+/**
+ * This class defined how the lamport timestamps are represented.
*/
public class VSLamportTime implements VSTime {
- /** Specified the global time of the lamport timestamp. It's used for correct painting in the simulator paint area.
- */
+
+ /** Specified the global time of the lamport timestamp. It's used for correct painting in the simulator paint area. */
private long globalTime;
- /** Specified the process' local lamport time.
- */
+
+ /** Specified the process' local lamport time. */
private long lamportTime;
- /** A simple constructor.
+ /**
+ * A simple constructor.
*
* @param globalTime The global time.
* @param lamportTime The local lamport time.
@@ -20,7 +27,8 @@ public class VSLamportTime implements VSTime {
this.lamportTime = lamportTime;
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The global time.
*/
@@ -28,7 +36,8 @@ public class VSLamportTime implements VSTime {
return globalTime;
}
- /** Getter method.
+ /**
+ * Getter method.
*
* @return The process' local lamport time.
*/
@@ -36,7 +45,8 @@ public class VSLamportTime implements VSTime {
return lamportTime;
}
- /** String representation.
+ /**
+ * String representation.
*
* @return The string representation of the lamport time.
*/
diff --git a/sources/core/time/VSTime.java b/sources/core/time/VSTime.java
index ce20ecc..0aebf4a 100644
--- a/sources/core/time/VSTime.java
+++ b/sources/core/time/VSTime.java
@@ -1,14 +1,24 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package core.time;
-/** This interface is a guidline for general time format classes.
+// TODO: Auto-generated Javadoc
+/**
+ * This interface is a guidline for general time format classes.
*/
public interface VSTime {
- /** Getter method.
+
+ /**
+ * Getter method.
*
* @return The global time.
*/
public long getGlobalTime();
- /** String representation.
+
+ /**
+ * String representation.
*
* @return The representation of the implementing object as a string.
*/
diff --git a/sources/core/time/VSVectorTime.java b/sources/core/time/VSVectorTime.java
index eb6c0aa..647eb7a 100644
--- a/sources/core/time/VSVectorTime.java
+++ b/sources/core/time/VSVectorTime.java
@@ -1,14 +1,34 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package core.time;
import java.util.ArrayList;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSVectorTime.
+ */
public class VSVectorTime extends ArrayList<Long> implements VSTime {
+
+ /** The global time. */
private long globalTime;
+ /**
+ * Instantiates a new vS vector time.
+ *
+ * @param globalTime the global time
+ */
public VSVectorTime(long globalTime) {
this.globalTime = globalTime;
}
+ /**
+ * To long array.
+ *
+ * @return the long[]
+ */
public long[] toLongArray() {
final int size = super.size();
final long[] arr = new long[size];
@@ -19,14 +39,27 @@ public class VSVectorTime extends ArrayList<Long> implements VSTime {
return arr;
}
+ /**
+ * Sets the global time.
+ *
+ * @param globalTime the new global time
+ */
public void setGlobalTime(long globalTime) {
this.globalTime = globalTime;
}
+ /* (non-Javadoc)
+ * @see core.time.VSTime#getGlobalTime()
+ */
public long getGlobalTime() {
return globalTime;
}
+ /**
+ * Gets the copy.
+ *
+ * @return the copy
+ */
public VSVectorTime getCopy() {
final VSVectorTime vectorTime = new VSVectorTime(globalTime);
final int size = super.size();
@@ -37,6 +70,9 @@ public class VSVectorTime extends ArrayList<Long> implements VSTime {
return vectorTime;
}
+ /* (non-Javadoc)
+ * @see java.util.AbstractCollection#toString()
+ */
public String toString() {
final int size = super.size();
final StringBuffer buffer = new StringBuffer();
@@ -49,6 +85,9 @@ public class VSVectorTime extends ArrayList<Long> implements VSTime {
return buffer.toString();
}
+ /* (non-Javadoc)
+ * @see java.util.ArrayList#get(int)
+ */
public Long get(int index) {
if (index >= super.size())
return new Long(0);
diff --git a/sources/events/VSEvent.java b/sources/events/VSEvent.java
index d058e33..c5cb5df 100644
--- a/sources/events/VSEvent.java
+++ b/sources/events/VSEvent.java
@@ -1,14 +1,35 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package events;
import core.VSProcess;
import prefs.VSPrefs;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSEvent.
+ */
abstract public class VSEvent extends VSPrefs {
+
+ /** 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();
@@ -16,6 +37,11 @@ abstract public class VSEvent extends VSPrefs {
onInit();
}
+ /**
+ * Sets the classname.
+ *
+ * @param eventClassname the new classname
+ */
protected final void setClassname(String eventClassname) {
if (eventClassname.startsWith("class "))
eventClassname = eventClassname.substring(6);
@@ -23,18 +49,38 @@ abstract public class VSEvent extends VSPrefs {
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);
@@ -42,18 +88,42 @@ abstract public class VSEvent extends VSPrefs {
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 2643d6f..d41ffea 100644
--- a/sources/events/VSRegisteredEvents.java
+++ b/sources/events/VSRegisteredEvents.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package events;
import java.util.*;
@@ -6,13 +10,32 @@ import prefs.*;
import core.*;
import utils.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSRegisteredEvents.
+ */
public final class VSRegisteredEvents {
+
+ /** The event classnames. */
private static HashMap<String,String> eventClassnames;
+
+ /** The event shortnames. */
private static HashMap<String,String> eventShortnames;
+
+ /** The event names. */
private static HashMap<String,String> eventNames;
+
+ /** The editable protocols classnames. */
private static ArrayList<String> editableProtocolsClassnames;
+
+ /** The prefs. */
private static VSPrefs prefs;
+ /**
+ * Inits the.
+ *
+ * @param prefs_ the prefs_
+ */
public static void init(VSPrefs prefs_) {
prefs = prefs_;
eventNames = new HashMap<String, String>();
@@ -42,10 +65,20 @@ public final class VSRegisteredEvents {
}
}
+ /**
+ * Gets the editable protocols classnames.
+ *
+ * @return the editable protocols classnames
+ */
public static ArrayList<String> getEditableProtocolsClassnames() {
return editableProtocolsClassnames;
}
+ /**
+ * Gets the protocol names.
+ *
+ * @return the protocol names
+ */
public static Vector<String> getProtocolNames() {
Set<String> set = eventClassnames.keySet();
Vector<String> vector = new Vector<String>();
@@ -59,6 +92,11 @@ public final class VSRegisteredEvents {
return vector;
}
+ /**
+ * Gets the protocol classnames.
+ *
+ * @return the protocol classnames
+ */
public static Vector<String> getProtocolClassnames() {
Set<String> set = eventNames.keySet();
Vector<String> vector = new Vector<String>();
@@ -72,6 +110,11 @@ public final class VSRegisteredEvents {
return vector;
}
+ /**
+ * Gets the non protocol names.
+ *
+ * @return the non protocol names
+ */
public static Vector<String> getNonProtocolNames() {
Set<String> set = eventClassnames.keySet();
Vector<String> vector = new Vector<String>();
@@ -85,6 +128,11 @@ public final class VSRegisteredEvents {
return vector;
}
+ /**
+ * Gets the non protocol classnames.
+ *
+ * @return the non protocol classnames
+ */
public static Vector<String> getNonProtocolClassnames() {
Set<String> set = eventNames.keySet();
Vector<String> vector = new Vector<String>();
@@ -98,18 +146,47 @@ public final class VSRegisteredEvents {
return vector;
}
+ /**
+ * Gets the classname.
+ *
+ * @param eventName the event name
+ *
+ * @return the classname
+ */
public static String getClassname(String eventName) {
return eventClassnames.get(eventName);
}
+ /**
+ * Gets the name.
+ *
+ * @param eventClassname the event classname
+ *
+ * @return the name
+ */
public static String getName(String eventClassname) {
return eventNames.get(eventClassname);
}
+ /**
+ * Gets the shortname.
+ *
+ * @param eventClassname the event classname
+ *
+ * @return the shortname
+ */
public static String getShortname(String eventClassname) {
return eventShortnames.get(eventClassname);
}
+ /**
+ * Creates the event instance by classname.
+ *
+ * @param eventClassname the event classname
+ * @param process the process
+ *
+ * @return the vS event
+ */
public static VSEvent createEventInstanceByClassname(String eventClassname, VSProcess process) {
final Object protocolObj = new VSClassLoader().newInstance(eventClassname);
@@ -122,10 +199,25 @@ public final class VSRegisteredEvents {
return null;
}
+ /**
+ * Creates the event instance by name.
+ *
+ * @param eventName the event name
+ * @param process the process
+ *
+ * @return the vS event
+ */
public static VSEvent createEventInstanceByName(String eventName, VSProcess process) {
return createEventInstanceByClassname(eventClassnames.get(eventName), process);
}
+ /**
+ * Register event.
+ *
+ * @param eventClassname the event classname
+ * @param eventName the event name
+ * @param eventShortname the event shortname
+ */
private static void registerEvent(String eventClassname, String eventName, String eventShortname) {
if (eventShortname == null)
eventShortname = eventName;
diff --git a/sources/events/implementations/ProcessCrashEvent.java b/sources/events/implementations/ProcessCrashEvent.java
index c8a9348..e55d18a 100644
--- a/sources/events/implementations/ProcessCrashEvent.java
+++ b/sources/events/implementations/ProcessCrashEvent.java
@@ -1,12 +1,27 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package events.implementations;
import events.VSEvent;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class ProcessCrashEvent.
+ */
public class ProcessCrashEvent extends VSEvent {
+
+ /* (non-Javadoc)
+ * @see events.VSEvent#onInit()
+ */
protected void onInit() {
setClassname(getClass().toString());
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onStart()
+ */
public void onStart() {
if (!process.isCrashed()) {
process.isCrashed(true);
diff --git a/sources/events/implementations/ProcessRecoverEvent.java b/sources/events/implementations/ProcessRecoverEvent.java
index 00b2164..cae67cb 100644
--- a/sources/events/implementations/ProcessRecoverEvent.java
+++ b/sources/events/implementations/ProcessRecoverEvent.java
@@ -1,12 +1,27 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package events.implementations;
import events.VSEvent;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class ProcessRecoverEvent.
+ */
public class ProcessRecoverEvent extends VSEvent {
+
+ /* (non-Javadoc)
+ * @see events.VSEvent#onInit()
+ */
protected void onInit() {
setClassname(getClass().toString());
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onStart()
+ */
public void onStart() {
if (process.isCrashed()) {
process.isCrashed(false);
diff --git a/sources/events/internal/MessageReceiveEvent.java b/sources/events/internal/MessageReceiveEvent.java
index b59c779..0b4af83 100644
--- a/sources/events/internal/MessageReceiveEvent.java
+++ b/sources/events/internal/MessageReceiveEvent.java
@@ -1,20 +1,41 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package events.internal;
import core.VSMessage;
import events.VSEvent;
import protocols.VSProtocol;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class MessageReceiveEvent.
+ */
public class MessageReceiveEvent extends VSEvent {
+
+ /** The message. */
private VSMessage message;
+ /**
+ * Instantiates a new message receive event.
+ *
+ * @param message the message
+ */
public MessageReceiveEvent(VSMessage message) {
this.message = message;
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onInit()
+ */
protected void onInit() {
setClassname(getClass().toString());
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onStart()
+ */
public void onStart() {
String eventName = message.getName();
String protocolClassname = message.getProtocolClassname();
diff --git a/sources/events/internal/ProtocolEvent.java b/sources/events/internal/ProtocolEvent.java
index 0cece54..b29a828 100644
--- a/sources/events/internal/ProtocolEvent.java
+++ b/sources/events/internal/ProtocolEvent.java
@@ -1,37 +1,82 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package events.internal;
import events.*;
import protocols.VSProtocol;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class ProtocolEvent.
+ */
public class ProtocolEvent extends VSEvent {
+
+ /** The protocol classname. */
private String protocolClassname;
+
+ /** The is client protocol. */
private boolean isClientProtocol; /* true = client, false = server */
+
+ /** The is protocol activation. */
private boolean isProtocolActivation; /* true = activate, false = deactivate */
+ /* (non-Javadoc)
+ * @see events.VSEvent#onInit()
+ */
protected void onInit() {
setClassname(getClass().toString());
}
+ /**
+ * Checks if is client protocol.
+ *
+ * @param isClientProtocol the is client protocol
+ */
public void isClientProtocol(boolean isClientProtocol) {
this.isClientProtocol = isClientProtocol;
}
+ /**
+ * Checks if is client protocol.
+ *
+ * @return true, if is client protocol
+ */
public boolean isClientProtocol() {
return isClientProtocol;
}
+ /**
+ * Checks if is protocol activation.
+ *
+ * @param isProtocolActivation the is protocol activation
+ */
public void isProtocolActivation(boolean isProtocolActivation) {
this.isProtocolActivation = isProtocolActivation;
}
+ /**
+ * Checks if is protocol activation.
+ *
+ * @return true, if is protocol activation
+ */
public boolean isProtocolActivation() {
return isProtocolActivation;
}
+ /**
+ * Sets the protocol classname.
+ *
+ * @param protocolClassname the new protocol classname
+ */
public void setProtocolClassname(String protocolClassname) {
this.protocolClassname = protocolClassname;
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onStart()
+ */
public void onStart() {
VSProtocol protocol = process.getProtocolObject(protocolClassname);
diff --git a/sources/prefs/VSDefaultPrefs.java b/sources/prefs/VSDefaultPrefs.java
index f41692b..5363967 100644
--- a/sources/prefs/VSDefaultPrefs.java
+++ b/sources/prefs/VSDefaultPrefs.java
@@ -1,19 +1,43 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package prefs;
import java.awt.Color;
import java.awt.event.KeyEvent;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSDefaultPrefs.
+ */
public class VSDefaultPrefs extends VSPrefs {
+
+ /**
+ * Inits the.
+ *
+ * @return the vS prefs
+ */
public static VSPrefs init() {
return init(VSPrefs.PREFERENCES_FILENAME);
}
+ /**
+ * Inits the.
+ *
+ * @param fileName the file name
+ *
+ * @return the vS prefs
+ */
public static VSPrefs init(String fileName) {
VSPrefs prefs = new VSDefaultPrefs();
prefs.fillWithDefaults();
return prefs;
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#fillWithDefaults()
+ */
public void fillWithDefaults() {
super.clear();
fillDefaultBooleans();
@@ -24,6 +48,9 @@ public class VSDefaultPrefs extends VSPrefs {
fillDefaultStrings();
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#fillDefaultStrings()
+ */
public void fillDefaultStrings() {
initString("lang.about", "About");
initString("lang.about.info!", "Dieses Programm wurde von Paul Bütow im Rahmen der Diplomarbeit \"Objektorientierte Entwicklung eines GUI-basierten Tools für die ereignisbasierte Simulation verteilter Systeme\" bei Prof. Dr.-Ing. Oßmann erstellt. Dieses Programm stellt noch keinesfalls eine fertige Version dar, da es sich noch in Entwicklung befindet und die Diplomarbeit erst mitte August abgeschlossen sein wird! Bei Fehlern bitte eine kurze Mail mitsamt Fehlerbeschreibung an paul@buetow.org schicken! Dieser Simulator wird später außerdem unter einer open source Linzenz (wahrscheinlich der GNU General Public License) freigegeben!");
@@ -129,6 +156,9 @@ public class VSDefaultPrefs extends VSPrefs {
initString("lang.window.new", "Neues Fenster");
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#fillDefaultIntegers()
+ */
public void fillDefaultIntegers() {
/* Simulation prefs */
initInteger("sim.process.num", 3, "Anzahl der Prozesse", 1, 6);
@@ -168,18 +198,27 @@ public class VSDefaultPrefs extends VSPrefs {
initIntegerUnit("div.window.ysize", 768, "Hauptfenster Y-Achse", 600, 2400, "px");
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#fillDefaultFloats()
+ */
public void fillDefaultFloats() {
/* Simulation prefs */
initFloat("process.clock.variance", 0, "Uhrabweichung");
initFloat("sim.clock.speed", 0.5f, "Simulationsgeschwindigkeit");
}
+ /**
+ * Fill default longs.
+ */
public void fillDefaultLongs() {
/* Simulation prefs */
initLongUnit("message.sendingtime.min", 500, "Minimale Übertragungszeit", "ms");
initLongUnit("message.sendingtime.max", 2000, "Maximale Übertragungszeit", "ms");
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#fillDefaultColors()
+ */
public void fillDefaultColors() {
/* Internal prefs */
initColor("col.background", new Color(0xFF, 0xFF, 0xFF));
@@ -196,6 +235,9 @@ public class VSDefaultPrefs extends VSPrefs {
initColor("col.message.lost", new Color(0xFF, 0x00, 0x00));
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#fillDefaultBooleans()
+ */
public void fillDefaultBooleans() {
//initBoolean("message.broadcast", false, "Nachrichten sind immer Broadcasts");
initBoolean("sim.mode.expert", false, "Expertenmodus aktivieren");
diff --git a/sources/prefs/VSPrefs.java b/sources/prefs/VSPrefs.java
index 7211219..65dfcde 100644
--- a/sources/prefs/VSPrefs.java
+++ b/sources/prefs/VSPrefs.java
@@ -1,55 +1,139 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package prefs;
import java.awt.Color;
import java.io.*;
import java.util.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSPrefs.
+ */
public abstract class VSPrefs implements Serializable {
+
+ /** The Constant BOOLEAN_PREFIX. */
public static final String BOOLEAN_PREFIX = "Boolean: ";
+
+ /** The Constant COLOR_PREFIX. */
public static final String COLOR_PREFIX = "Color: ";
+
+ /** The Constant FLOAT_PREFIX. */
public static final String FLOAT_PREFIX = "Float: ";
+
+ /** The Constant INTEGER_PREFIX. */
public static final String INTEGER_PREFIX = "Integer: ";
+
+ /** The Constant LONG_PREFIX. */
public static final String LONG_PREFIX = "Long: ";
+
+ /** The Constant STRING_PREFIX. */
public static final String STRING_PREFIX = "String: ";
+
+ /** The color prefs. */
private HashMap<String,Color> colorPrefs;
+
+ /** The float prefs. */
private HashMap<String,Float> floatPrefs;
+
+ /** The integer prefs. */
private HashMap<String,Integer> integerPrefs;
+
+ /** The long prefs. */
private HashMap<String,Long> longPrefs;
+
+ /** The setting restriction prefs. */
private HashMap<String,SettingRestriction> settingRestrictionPrefs;
+
+ /** The description prefs. */
private HashMap<String,String> descriptionPrefs;
+
+ /** The string prefs. */
private HashMap<String,String> stringPrefs;
+
+ /** The boolean prefs. */
private HashMap<String,Boolean> booleanPrefs;
+
+ /** The object prefs. */
private HashMap<String,Object> objectPrefs;
+
+ /** The units. */
private HashMap<String,String> units;
+
+ /** The Constant serialVersionUID. */
private static final long serialVersionUID = 4L;
+
+ /** The Constant PREFERENCES_FILENAME. */
protected final static String PREFERENCES_FILENAME = "vs.dat";
+
+ /** The id counter. */
private static long idCounter;
+
+ /** The id. */
protected long id;
+ /**
+ * The Class SettingRestriction.
+ */
public class SettingRestriction implements Serializable {
}
+ /**
+ * The Class IntegerSettingRestriction.
+ */
public class IntegerSettingRestriction extends SettingRestriction {
+
+ /** The min value. */
private int minValue;
+
+ /** The max value. */
private int maxValue;
+ /**
+ * Instantiates a new integer setting restriction.
+ *
+ * @param minValue the min value
+ * @param maxValue the max value
+ */
public IntegerSettingRestriction(int minValue, int maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
}
+ /**
+ * Gets the min value.
+ *
+ * @return the min value
+ */
public int getMinValue() {
return minValue;
}
+ /**
+ * Gets the max value.
+ *
+ * @return the max value
+ */
public int getMaxValue() {
return maxValue;
}
}
+ /**
+ * The Class StringSettingRestriction.
+ */
public class StringSettingRestriction extends SettingRestriction {
+
+ /** The possible selections. */
Vector<String> possibleSelections;
+ /**
+ * Instantiates a new string setting restriction.
+ *
+ * @param possibleSelections the possible selections
+ */
public StringSettingRestriction(String [] possibleSelections) {
this.possibleSelections = new Vector<String>();
@@ -57,11 +141,19 @@ public abstract class VSPrefs implements Serializable {
this.possibleSelections.add(elem);
}
+ /**
+ * Gets the possible selections.
+ *
+ * @return the possible selections
+ */
public Vector<String> getPossibleSelections() {
return possibleSelections;
}
}
+ /**
+ * Instantiates a new vS prefs.
+ */
public VSPrefs() {
colorPrefs = new HashMap<String,Color>();
descriptionPrefs = new HashMap<String,String>();
@@ -76,6 +168,9 @@ public abstract class VSPrefs implements Serializable {
id = ++idCounter;
}
+ /**
+ * Clear.
+ */
protected synchronized void clear() {
colorPrefs.clear();
floatPrefs.clear();
@@ -88,6 +183,13 @@ public abstract class VSPrefs implements Serializable {
settingRestrictionPrefs.clear();
}
+ /**
+ * Gets the object.
+ *
+ * @param key the key
+ *
+ * @return the object
+ */
public synchronized Object getObject(String key) {
Object val = objectPrefs.get(key);
@@ -100,14 +202,33 @@ public abstract class VSPrefs implements Serializable {
return val;
}
+ /**
+ * Removes the object.
+ *
+ * @param key the key
+ */
public synchronized void removeObject(String key) {
objectPrefs.remove(key);
}
+ /**
+ * Object exists.
+ *
+ * @param key the key
+ *
+ * @return true, if successful
+ */
public synchronized boolean objectExists(String key) {
return null != objectPrefs.get(key);
}
+ /**
+ * Gets the string.
+ *
+ * @param key the key
+ *
+ * @return the string
+ */
public synchronized String getString(String key) {
String val = stringPrefs.get(key);
@@ -120,6 +241,13 @@ public abstract class VSPrefs implements Serializable {
return val;
}
+ /**
+ * Gets the integer obj.
+ *
+ * @param key the key
+ *
+ * @return the integer obj
+ */
public synchronized Integer getIntegerObj(String key) {
Integer val = integerPrefs.get(key);
@@ -132,10 +260,24 @@ public abstract class VSPrefs implements Serializable {
return val;
}
+ /**
+ * Gets the integer.
+ *
+ * @param key the key
+ *
+ * @return the integer
+ */
public int getInteger(String key) {
return getIntegerObj(key).intValue();
}
+ /**
+ * Gets the float obj.
+ *
+ * @param key the key
+ *
+ * @return the float obj
+ */
public synchronized Float getFloatObj(String key) {
Float val = floatPrefs.get(key);
@@ -148,10 +290,24 @@ public abstract class VSPrefs implements Serializable {
return val;
}
+ /**
+ * Gets the float.
+ *
+ * @param key the key
+ *
+ * @return the float
+ */
public float getFloat(String key) {
return getFloatObj(key).floatValue();
}
+ /**
+ * Gets the long obj.
+ *
+ * @param key the key
+ *
+ * @return the long obj
+ */
public synchronized Long getLongObj(String key) {
Long val = longPrefs.get(key);
@@ -164,10 +320,24 @@ public abstract class VSPrefs implements Serializable {
return val;
}
+ /**
+ * Gets the long.
+ *
+ * @param key the key
+ *
+ * @return the long
+ */
public long getLong(String key) {
return getLongObj(key).longValue();
}
+ /**
+ * Gets the boolean obj.
+ *
+ * @param key the key
+ *
+ * @return the boolean obj
+ */
public synchronized Boolean getBooleanObj(String key) {
Boolean val = booleanPrefs.get(key);
@@ -177,10 +347,24 @@ public abstract class VSPrefs implements Serializable {
return val;
}
+ /**
+ * Gets the boolean.
+ *
+ * @param key the key
+ *
+ * @return the boolean
+ */
public boolean getBoolean(String key) {
return getBooleanObj(key).booleanValue();
}
+ /**
+ * Gets the color.
+ *
+ * @param key the key
+ *
+ * @return the color
+ */
public synchronized Color getColor(String key) {
Color color = colorPrefs.get(key);
@@ -193,239 +377,600 @@ public abstract class VSPrefs implements Serializable {
return color;
}
+ /**
+ * Gets the description.
+ *
+ * @param key the key
+ *
+ * @return the description
+ */
public synchronized String getDescription(String key) {
return descriptionPrefs.get(key);
}
+ /**
+ * Gets the unit.
+ *
+ * @param key the key
+ *
+ * @return the unit
+ */
public synchronized String getUnit(String key) {
return units.get(key);
}
+ /**
+ * Gets the restriction.
+ *
+ * @param key the key
+ *
+ * @return the restriction
+ */
public synchronized SettingRestriction getRestriction(String key) {
return settingRestrictionPrefs.get(key);
}
+ /**
+ * Gets the string key set.
+ *
+ * @return the string key set
+ */
public synchronized Set<String> getStringKeySet() {
return stringPrefs.keySet();
}
+ /**
+ * Gets the integer key set.
+ *
+ * @return the integer key set
+ */
public synchronized Set<String> getIntegerKeySet() {
return integerPrefs.keySet();
}
+ /**
+ * Gets the float key set.
+ *
+ * @return the float key set
+ */
public synchronized Set<String> getFloatKeySet() {
return floatPrefs.keySet();
}
+ /**
+ * Gets the long key set.
+ *
+ * @return the long key set
+ */
public synchronized Set<String> getLongKeySet() {
return longPrefs.keySet();
}
+ /**
+ * Gets the boolean key set.
+ *
+ * @return the boolean key set
+ */
public synchronized Set<String> getBooleanKeySet() {
return booleanPrefs.keySet();
}
+ /**
+ * Gets the color key set.
+ *
+ * @return the color key set
+ */
public synchronized Set<String> getColorKeySet() {
return colorPrefs.keySet();
}
+ /**
+ * Sets the object.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setObject(String key, Object val) {
objectPrefs.put(key, val);
}
+ /**
+ * Sets the string.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setString(String key, String val) {
stringPrefs.put(key, val);
}
+ /**
+ * Sets the integer.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setInteger(String key, Integer val) {
integerPrefs.put(key, val);
}
+ /**
+ * Sets the color.
+ *
+ * @param key the key
+ * @param color the color
+ */
public synchronized void setColor(String key, Color color) {
colorPrefs.put(key, color);
}
+ /**
+ * Sets the int.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setInt(String key, int val) {
integerPrefs.put(key, new Integer(val));
}
+ /**
+ * Sets the float.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setFloat(String key, float val) {
floatPrefs.put(key, new Float(val));
}
+ /**
+ * Sets the float.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setFloat(String key, Float val) {
floatPrefs.put(key, val);
}
+ /**
+ * Sets the long.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setLong(String key, long val) {
longPrefs.put(key, new Long(val));
}
+ /**
+ * Sets the long.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setLong(String key, Long val) {
longPrefs.put(key, val);
}
+ /**
+ * Sets the boolean.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setBoolean(String key, boolean val) {
booleanPrefs.put(key, new Boolean(val));
}
+ /**
+ * Sets the boolean.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setBoolean(String key, Boolean val) {
booleanPrefs.put(key, val);
}
+ /**
+ * Inits the string.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void initString(String key, String val) {
if (!stringPrefs.containsKey(key))
stringPrefs.put(key, val);
}
+ /**
+ * Inits the integer.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void initInteger(String key, Integer val) {
if (!integerPrefs.containsKey(key))
integerPrefs.put(key, val);
}
+ /**
+ * Inits the integer.
+ *
+ * @param key the key
+ * @param val the val
+ */
public void initInteger(String key, int val) {
initInteger(key, new Integer(val));
}
+ /**
+ * Inits the long.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void initLong(String key, Long val) {
if (!longPrefs.containsKey(key))
longPrefs.put(key, val);
}
+ /**
+ * Inits the long.
+ *
+ * @param key the key
+ * @param val the val
+ */
public void initLong(String key, int val) {
initLong(key, new Long(val));
}
+ /**
+ * Inits the float.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void initFloat(String key, Float val) {
if (!floatPrefs.containsKey(key))
floatPrefs.put(key, val);
}
+ /**
+ * Inits the float.
+ *
+ * @param key the key
+ * @param val the val
+ */
public void initFloat(String key, float val) {
initFloat(key, new Float(val));
}
+ /**
+ * Sets the long if unset.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void setLongIfUnset(String key, Long val) {
if (!longPrefs.containsKey(key))
longPrefs.put(key, val);
}
+ /**
+ * Sets the long if unset.
+ *
+ * @param key the key
+ * @param val the val
+ */
public void setLongIfUnset(String key, long val) {
setLongIfUnset(key, new Long(val));
}
+ /**
+ * Inits the boolean.
+ *
+ * @param key the key
+ * @param val the val
+ */
public synchronized void initBoolean(String key, Boolean val) {
if (!booleanPrefs.containsKey(key))
booleanPrefs.put(key, val);
}
+ /**
+ * Inits the boolean.
+ *
+ * @param key the key
+ * @param val the val
+ */
public void initBoolean(String key, boolean val) {
initBoolean(key, new Boolean(val));
}
+ /**
+ * Inits the color.
+ *
+ * @param key the key
+ * @param color the color
+ */
public synchronized void initColor(String key, Color color) {
if (!colorPrefs.containsKey(key))
colorPrefs.put(key, color);
}
+ /**
+ * Sets the description if unset.
+ *
+ * @param key the key
+ * @param descr the descr
+ */
public synchronized void setDescriptionIfUnset(String key, String descr) {
if (descr == null || descriptionPrefs.containsKey(key))
return;
descriptionPrefs.put(key, descr);
}
+ /**
+ * Sets the restriction.
+ *
+ * @param key the key
+ * @param settingRestriction the setting restriction
+ */
public synchronized void setRestriction(String key, SettingRestriction settingRestriction) {
settingRestrictionPrefs.put(key, settingRestriction);
}
+ /**
+ * Sets the unit.
+ *
+ * @param key the key
+ * @param unit the unit
+ */
public synchronized void setUnit(String key, String unit) {
units.put(key, unit);
}
+ /**
+ * Inits the string.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ */
public void initString(String key, String val, String descr) {
initString(key, val);
setDescriptionIfUnset(STRING_PREFIX + key, descr);
}
+ /**
+ * Sets the long if unset.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ */
public void setLongIfUnset(String key, long val, String descr) {
setLongIfUnset(key, val);
setDescriptionIfUnset(LONG_PREFIX + key, descr);
}
+ /**
+ * Inits the boolean.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ */
public void initBoolean(String key, boolean val, String descr) {
initBoolean(key, val);
setDescriptionIfUnset(BOOLEAN_PREFIX + key, descr);
}
+ /**
+ * Inits the boolean unit.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ * @param unit the unit
+ */
public void initBooleanUnit(String key, boolean val, String descr, String unit) {
initBoolean(key, val, descr);
setUnit(BOOLEAN_PREFIX + key, unit);
}
+ /**
+ * Inits the integer.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ * @param r the r
+ */
public void initInteger(String key, Integer val, String descr, IntegerSettingRestriction r) {
initInteger(key, val);
setDescriptionIfUnset(INTEGER_PREFIX + key, descr);
setRestriction(INTEGER_PREFIX + key, r);
}
+ /**
+ * Inits the integer.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ * @param minValue the min value
+ * @param maxValue the max value
+ */
public void initInteger(String key, Integer val, String descr, int minValue, int maxValue) {
initInteger(key, val, descr, new IntegerSettingRestriction(minValue, maxValue));
}
+ /**
+ * Inits the integer.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ * @param r the r
+ */
public void initInteger(String key, int val, String descr, IntegerSettingRestriction r) {
initInteger(key, new Integer(val), descr, r);
}
+ /**
+ * Inits the integer.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ * @param minValue the min value
+ * @param maxValue the max value
+ */
public void initInteger(String key, int val, String descr, int minValue, int maxValue) {
initInteger(key, new Integer(val), descr, minValue, maxValue);
}
+ /**
+ * Inits the integer unit.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ * @param minValue the min value
+ * @param maxValue the max value
+ * @param unit the unit
+ */
public void initIntegerUnit(String key, int val, String descr, int minValue, int maxValue, String unit) {
initInteger(key, new Integer(val), descr, minValue, maxValue);
setUnit(INTEGER_PREFIX + key, unit);
}
+ /**
+ * Inits the long.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ */
public void initLong(String key, Long val, String descr) {
initLong(key, val);
setDescriptionIfUnset(LONG_PREFIX + key, descr);
}
+ /**
+ * Inits the long.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ */
public void initLong(String key, int val, String descr) {
initLong(key, new Long(val), descr);
}
+ /**
+ * Inits the long unit.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ * @param unit the unit
+ */
public void initLongUnit(String key, int val, String descr, String unit) {
initLong(key, new Long(val), descr);
setUnit(LONG_PREFIX + key, unit);
}
+ /**
+ * Inits the float.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ */
public void initFloat(String key, Float val, String descr) {
initFloat(key, val);
setDescriptionIfUnset(FLOAT_PREFIX + key, descr);
}
+ /**
+ * Inits the float.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ */
public void initFloat(String key, float val, String descr) {
initFloat(key, new Float(val), descr);
}
+ /**
+ * Inits the float unit.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ * @param unit the unit
+ */
public void initFloatUnit(String key, float val, String descr, String unit) {
initFloat(key, new Float(val), descr);
setUnit(FLOAT_PREFIX + key, unit);
}
+ /**
+ * Inits the color.
+ *
+ * @param key the key
+ * @param val the val
+ * @param descr the descr
+ */
public void initColor(String key, Color val, String descr) {
initColor(key, val);
setDescriptionIfUnset(COLOR_PREFIX + key, descr);
}
+ /**
+ * Fill default strings.
+ */
public void fillDefaultStrings() {}
+
+ /**
+ * Fill default integers.
+ */
public void fillDefaultIntegers() {}
+
+ /**
+ * Fill default floats.
+ */
public void fillDefaultFloats() {}
+
+ /**
+ * Fill default colors.
+ */
public void fillDefaultColors() {}
+
+ /**
+ * Fill default booleans.
+ */
public void fillDefaultBooleans() {}
+
+ /**
+ * Fill with defaults.
+ */
public void fillWithDefaults() {}
+ /**
+ * Write object.
+ *
+ * @param objectOutputStream the object output stream
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
public synchronized void writeObject(ObjectOutputStream objectOutputStream)
throws IOException {
objectOutputStream.writeObject(booleanPrefs);
@@ -437,6 +982,14 @@ public abstract class VSPrefs implements Serializable {
objectOutputStream.writeObject(units);
}
+ /**
+ * Read object.
+ *
+ * @param objectInputStream the object input stream
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws ClassNotFoundException the class not found exception
+ */
@SuppressWarnings("unchecked") public synchronized void readObject(ObjectInputStream objectInputStream)
throws IOException, ClassNotFoundException {
booleanPrefs = (HashMap<String,Boolean>) objectInputStream.readObject();
@@ -485,32 +1038,65 @@ public abstract class VSPrefs implements Serializable {
}
*/
+ /**
+ * Copy integers.
+ *
+ * @param copyInto the copy into
+ * @param keys the keys
+ */
public void copyIntegers(VSPrefs copyInto, String[] keys) {
for (String key : keys)
copyInto.initInteger(key, getInteger(key), getDescription(INTEGER_PREFIX + key),
(IntegerSettingRestriction) getRestriction(INTEGER_PREFIX + key));
}
+ /**
+ * Copy longs.
+ *
+ * @param copyInto the copy into
+ * @param keys the keys
+ */
public void copyLongs(VSPrefs copyInto, String[] keys) {
for (String key : keys)
copyInto.initLong(key, getLong(key), getDescription(LONG_PREFIX + key));
}
+ /**
+ * Copy floats.
+ *
+ * @param copyInto the copy into
+ * @param keys the keys
+ */
public void copyFloats(VSPrefs copyInto, String[] keys) {
for (String key : keys)
copyInto.initFloat(key, getFloat(key), getDescription(FLOAT_PREFIX + key));
}
+ /**
+ * Copy strings.
+ *
+ * @param copyInto the copy into
+ * @param keys the keys
+ */
public void copyStrings(VSPrefs copyInto, String[] keys) {
for (String key : keys)
copyInto.initString(key, getString(key), getDescription(STRING_PREFIX + key));
}
+ /**
+ * Copy colors.
+ *
+ * @param copyInto the copy into
+ * @param keys the keys
+ */
public void copyColors(VSPrefs copyInto, String[] keys) {
for (String key : keys)
copyInto.initColor(key, getColor(key), getDescription(COLOR_PREFIX + key));
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
public String toString() {
String descr = "";
@@ -557,10 +1143,20 @@ public abstract class VSPrefs implements Serializable {
return descr;
}
+ /**
+ * Gets the iD.
+ *
+ * @return the iD
+ */
public long getID() {
return id;
}
+ /**
+ * Checks if is empty.
+ *
+ * @return true, if is empty
+ */
public boolean isEmpty() {
if (!colorPrefs.isEmpty())
return false;
diff --git a/sources/prefs/editors/VSBetterEditor.java b/sources/prefs/editors/VSBetterEditor.java
index 289749d..211e8ed 100644
--- a/sources/prefs/editors/VSBetterEditor.java
+++ b/sources/prefs/editors/VSBetterEditor.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package prefs.editors;
import java.awt.*;
@@ -7,26 +11,58 @@ import javax.swing.*;
import prefs.*;
import utils.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSBetterEditor.
+ */
public abstract class VSBetterEditor extends VSEditor {
+
+ /** The content pane. */
private Container contentPane;
+
+ /** The info area. */
private VSInfoArea infoArea;
+
+ /** The title. */
private String title;
+ /**
+ * Instantiates a new vS better 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));
@@ -43,10 +79,24 @@ public abstract class VSBetterEditor extends VSEditor {
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();
@@ -54,6 +104,11 @@ public abstract class VSBetterEditor extends VSEditor {
super.actionPerformed(e);
}
+ /**
+ * Gets the info area.
+ *
+ * @return the info area
+ */
protected VSInfoArea getInfoArea() {
return infoArea;
}
diff --git a/sources/prefs/editors/VSColorChooser.java b/sources/prefs/editors/VSColorChooser.java
index 8d2009d..d7d5692 100644
--- a/sources/prefs/editors/VSColorChooser.java
+++ b/sources/prefs/editors/VSColorChooser.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package prefs.editors;
import java.awt.*;
@@ -6,12 +10,30 @@ import javax.swing.event.*;
import prefs.VSPrefs;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSColorChooser.
+ */
public class VSColorChooser extends JPanel implements ChangeListener {
+
+ /** The color chooser. */
protected JColorChooser colorChooser;
+
+ /** The color. */
private Color color;
+
+ /** The val field. */
private JTextField valField;
+
+ /** The prefs. */
private VSPrefs prefs;
+ /**
+ * Instantiates a new vS color chooser.
+ *
+ * @param prefs the prefs
+ * @param valField the val field
+ */
public VSColorChooser(VSPrefs prefs, JTextField valField) {
super(new BorderLayout());
this.prefs = prefs;
@@ -26,6 +48,9 @@ public class VSColorChooser extends JPanel implements ChangeListener {
add(colorChooser, BorderLayout.CENTER);
}
+ /* (non-Javadoc)
+ * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
+ */
public void stateChanged(ChangeEvent e) {
Color newColor = colorChooser.getColor();
valField.setBackground(newColor);
diff --git a/sources/prefs/editors/VSEditor.java b/sources/prefs/editors/VSEditor.java
index 32f2150..8eda1e0 100644
--- a/sources/prefs/editors/VSEditor.java
+++ b/sources/prefs/editors/VSEditor.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package prefs.editors;
import java.awt.*;
@@ -8,66 +12,171 @@ import java.util.*;
import utils.*;
import prefs.VSPrefs;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSEditor.
+ */
public abstract class VSEditor implements ActionListener {
+
+ /** The boolean keys. */
private ArrayList<String> booleanKeys;
+
+ /** The color keys. */
private ArrayList<String> colorKeys;
+
+ /** The float keys. */
private ArrayList<String> floatKeys;
+
+ /** The integer keys. */
private ArrayList<String> integerKeys;
+
+ /** The long keys. */
private ArrayList<String> longKeys;
+
+ /** The string keys. */
private ArrayList<String> stringKeys;
+
+ /** The boolean fields. */
private HashMap<String,JCheckBox> booleanFields;
+
+ /** The integer fields. */
private HashMap<String,JComboBox> integerFields;
+
+ /** The color fields. */
private HashMap<String,JTextField> colorFields;
+
+ /** The float fields. */
private HashMap<String,JTextField> floatFields;
+
+ /** The long fields. */
private HashMap<String,JTextField> longFields;
+
+ /** The string fields. */
private HashMap<String,JTextField> stringFields;
+
+ /** The prefs to edit map. */
private HashMap<String,VSPrefs> 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 vS editor.
+ *
+ * @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;
@@ -94,6 +203,13 @@ public abstract class VSEditor implements ActionListener {
fillEditPanel(prefsToEdit);
}
+ /**
+ * Filter keys.
+ *
+ * @param set the set
+ *
+ * @return the array list< string>
+ */
private ArrayList<String> filterKeys(Set<String> set) {
ArrayList<String> filtered = new ArrayList<String>();
boolean expertMode = prefs.getBoolean("sim.mode.expert");
@@ -110,6 +226,11 @@ public abstract class VSEditor implements ActionListener {
return filtered;
}
+ /**
+ * Creates the button panel.
+ *
+ * @return the j panel
+ */
private JPanel createButtonPanel() {
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(Color.WHITE);
@@ -126,6 +247,14 @@ public abstract class VSEditor implements ActionListener {
return buttonPanel;
}
+ /**
+ * Creates the unit panel.
+ *
+ * @param comp the comp
+ * @param key the key
+ *
+ * @return the j panel
+ */
private JPanel createUnitPanel(Component comp, String key) {
JPanel unitPanel = new JPanel(new GridBagLayout());
unitPanel.setBackground(Color.WHITE);
@@ -147,6 +276,11 @@ public abstract class VSEditor implements ActionListener {
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));
@@ -159,6 +293,15 @@ public abstract class VSEditor implements ActionListener {
return editPanel;
}
+ /**
+ * Creates the integer component.
+ *
+ * @param fullKey the full key
+ * @param key the key
+ * @param prefsToEdit the prefs to edit
+ *
+ * @return the vS tupel< string, component, j combo box>
+ */
protected VSTupel<String,Component,JComboBox> createIntegerComponent(String fullKey, String key, VSPrefs prefsToEdit) {
String descr = prefsToEdit.getDescription(fullKey);
String label = descr == null ? fullKey : descr;
@@ -186,6 +329,15 @@ public abstract class VSEditor implements ActionListener {
return new VSTupel<String,Component,JComboBox>(label, createUnitPanel(valComboBox, fullKey), valComboBox);
}
+ /**
+ * Creates the boolean component.
+ *
+ * @param fullKey the full key
+ * @param key the key
+ * @param prefsToEdit the prefs to edit
+ *
+ * @return the vS tupel< string, component, j check box>
+ */
protected VSTupel<String,Component,JCheckBox> createBooleanComponent(String fullKey, String key, VSPrefs prefsToEdit) {
final String activated = prefs.getString("lang.activated");
String descr = prefsToEdit.getDescription(fullKey);
@@ -196,6 +348,15 @@ public abstract class VSEditor implements ActionListener {
return new VSTupel<String,Component,JCheckBox>(label, createUnitPanel(valField, fullKey), valField);
}
+ /**
+ * Creates the long component.
+ *
+ * @param fullKey the full key
+ * @param key the key
+ * @param prefsToEdit the prefs to edit
+ *
+ * @return the vS tupel< string, component, j text field>
+ */
protected VSTupel<String,Component,JTextField> createLongComponent(String fullKey, String key, VSPrefs prefsToEdit) {
String descr = prefsToEdit.getDescription(fullKey);
String label = descr == null ? fullKey : descr;
@@ -212,6 +373,15 @@ public abstract class VSEditor implements ActionListener {
return new VSTupel<String,Component,JTextField>(label, createUnitPanel(valField, fullKey), valField);
}
+ /**
+ * Creates the float component.
+ *
+ * @param fullKey the full key
+ * @param key the key
+ * @param prefsToEdit the prefs to edit
+ *
+ * @return the vS tupel< string, component, j text field>
+ */
protected VSTupel<String,Component,JTextField> createFloatComponent(String fullKey, String key, VSPrefs prefsToEdit) {
String descr = prefsToEdit.getDescription(fullKey);
String label = descr == null ? fullKey : descr;
@@ -228,6 +398,15 @@ public abstract class VSEditor implements ActionListener {
return new VSTupel<String,Component,JTextField>(label, createUnitPanel(valField, fullKey), valField);
}
+ /**
+ * Creates the color component.
+ *
+ * @param fullKey the full key
+ * @param key the key
+ * @param prefsToEdit the prefs to edit
+ *
+ * @return the vS tupel< string, component, j text field>
+ */
protected VSTupel<String,Component,JTextField> createColorComponent(String fullKey, String key, final VSPrefs prefsToEdit) {
String descr = prefsToEdit.getDescription(fullKey);
String label = descr == null ? fullKey : descr;
@@ -260,6 +439,15 @@ public abstract class VSEditor implements ActionListener {
return new VSTupel<String,Component,JTextField>(label, createUnitPanel(valField, fullKey), valField);
}
+ /**
+ * Creates the string component.
+ *
+ * @param fullKey the full key
+ * @param key the key
+ * @param prefsToEdit the prefs to edit
+ *
+ * @return the vS tupel< string, component, j text field>
+ */
protected VSTupel<String,Component,JTextField> createStringComponent(String fullKey, String key, VSPrefs prefsToEdit) {
String descr = prefsToEdit.getDescription(fullKey);
String label = descr == null ? fullKey : descr;
@@ -276,6 +464,11 @@ public abstract class VSEditor implements ActionListener {
return new VSTupel<String,Component,JTextField>(label, createUnitPanel(valField, fullKey), valField);
}
+ /**
+ * Fill edit panel.
+ *
+ * @param prefsToEdit the prefs to edit
+ */
private void fillEditPanel(VSPrefs prefsToEdit) {
HashMap<String,Component> components = new HashMap<String,Component>();
HashMap<String,String> labels = new HashMap<String,String>();
@@ -398,6 +591,13 @@ public abstract class VSEditor implements ActionListener {
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 + ")";
@@ -459,19 +659,42 @@ public abstract class VSEditor implements ActionListener {
}
}
+ /**
+ * 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 resetEditPanel() {
for (String key : integerKeys) {
JComboBox valComboBox = integerFields.get(key);
@@ -510,6 +733,10 @@ public abstract class VSEditor implements ActionListener {
}
/**
+ * Gets the keys.
+ *
+ * @param key the key
+ *
* @return [0] := key, [1] := prefsKey
*/
private String[] getKeys(String key) {
@@ -523,6 +750,9 @@ public abstract class VSEditor implements ActionListener {
return keys;
}
+ /**
+ * Save prefs.
+ */
protected void savePrefs() {
boolean expertMode = prefs.getBoolean("sim.mode.expert");
@@ -585,6 +815,11 @@ public abstract class VSEditor implements ActionListener {
expertModeChanged = expertMode != prefs.getBoolean("sim.mode.expert");
}
+ /**
+ * Expert mode changed.
+ *
+ * @return true, if successful
+ */
public boolean expertModeChanged() {
boolean ret = expertModeChanged;
@@ -594,6 +829,9 @@ public abstract class VSEditor implements ActionListener {
return ret;
}
+ /* (non-Javadoc)
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
@@ -605,14 +843,29 @@ public abstract class VSEditor implements ActionListener {
}
}
+ /**
+ * 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 bd98938..18a5eb6 100644
--- a/sources/prefs/editors/VSEditorFrame.java
+++ b/sources/prefs/editors/VSEditorFrame.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package prefs.editors;
import java.awt.*;
@@ -7,10 +11,25 @@ import javax.swing.*;
import prefs.*;
import utils.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSEditorFrame.
+ */
public class VSEditorFrame extends VSFrame implements ActionListener {
+
+ /** The editor. */
private VSBetterEditor editor;
+
+ /** The prefs. */
private VSPrefs prefs;
+ /**
+ * Instantiates a new vS editor frame.
+ *
+ * @param prefs the prefs
+ * @param relativeTo the relative to
+ * @param editor the editor
+ */
public VSEditorFrame(VSPrefs prefs, Component relativeTo, VSBetterEditor editor) {
super(editor.getTitle(), relativeTo);
this.prefs = prefs;
@@ -18,6 +37,9 @@ public class VSEditorFrame extends VSFrame implements ActionListener {
init();
}
+ /**
+ * Inits the.
+ */
private void init() {
editor.setFrame(this);
fillButtonPanel(editor.getButtonPanel());
@@ -29,6 +51,11 @@ public class VSEditorFrame extends VSFrame implements ActionListener {
setVisible(true);
}
+ /**
+ * Fill button panel.
+ *
+ * @param buttonPanel the button panel
+ */
private void fillButtonPanel(JPanel buttonPanel) {
JButton okButton = new JButton(
prefs.getString("lang.ok"));
@@ -44,6 +71,9 @@ public class VSEditorFrame extends VSFrame implements ActionListener {
buttonPanel.repaint();
}
+ /* (non-Javadoc)
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
diff --git a/sources/prefs/editors/VSEditorTable.java b/sources/prefs/editors/VSEditorTable.java
index 27c422f..b641f33 100644
--- a/sources/prefs/editors/VSEditorTable.java
+++ b/sources/prefs/editors/VSEditorTable.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package prefs.editors;
import java.util.*;
@@ -9,58 +13,127 @@ import javax.swing.text.*;
import prefs.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSEditorTable.
+ */
public class VSEditorTable extends JTable {
+
+ /** The Constant MIN_ROWS. */
private static final int MIN_ROWS = 20;
+
+ /** The prefs. */
private VSPrefs prefs;
+
+ /** The nodes. */
private ArrayList<VSNode> nodes;
+
+ /** The model. */
private VSEditorTableModel model;
+ /**
+ * The Class VSNode.
+ */
private class VSNode {
+
+ /** The key. */
private String key;
+
+ /** The comp. */
private Component comp;
+ /**
+ * Instantiates a new vS node.
+ *
+ * @param key the key
+ */
public VSNode(String key) {
this.key = key;
}
+ /**
+ * Instantiates a new vS node.
+ *
+ * @param key the key
+ * @param comp the comp
+ */
public VSNode(String key, Component comp) {
this.key = key;
this.comp = comp;
}
+ /**
+ * Gets the key.
+ *
+ * @return the key
+ */
public String getKey() {
return key;
}
+ /**
+ * Gets the component.
+ *
+ * @return the component
+ */
public Component getComponent() {
return comp;
}
+ /**
+ * Gets the renderer component.
+ *
+ * @return the renderer component
+ */
public Component getRendererComponent() {
return comp;
}
+ /**
+ * Checks if is separator.
+ *
+ * @return true, if is separator
+ */
public boolean isSeparator() {
return comp == null;
}
}
+ /**
+ * The Class VSEditorTableModel.
+ */
private class VSEditorTableModel extends AbstractTableModel implements TableCellRenderer {
+
+ /**
+ * Instantiates a new vS editor table model.
+ */
public VSEditorTableModel() {
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.AbstractTableModel#getColumnName(int)
+ */
public String getColumnName(int col) {
return "";
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getRowCount()
+ */
public int getRowCount() {
return nodes.size();
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getColumnCount()
+ */
public int getColumnCount() {
return 2;
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getValueAt(int, int)
+ */
public Object getValueAt(int row, int col) {
VSNode node = nodes.get(row);
@@ -77,6 +150,9 @@ public class VSEditorTable extends JTable {
return node.getComponent();
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
+ */
public boolean isCellEditable(int row, int col) {
if (col == 0)
return false;
@@ -87,9 +163,15 @@ public class VSEditorTable extends JTable {
return true;
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int)
+ */
public void setValueAt(Object value, int row, int col) {
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
+ */
public Component getTableCellRendererComponent(JTable table,
Object object, boolean isSelected, boolean hasFocus, int
row, int col) {
@@ -119,18 +201,32 @@ public class VSEditorTable extends JTable {
}
}
+ /**
+ * The Class VSTableCellEditor.
+ */
private class VSTableCellEditor extends AbstractCellEditor implements TableCellEditor {
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int)
+ */
public Component getTableCellEditorComponent(JTable table, Object object,
boolean isSelected, int row, int col) {
return nodes.get(row).getComponent();
}
+ /* (non-Javadoc)
+ * @see javax.swing.CellEditor#getCellEditorValue()
+ */
public Object getCellEditorValue() {
return new String("");
}
}
+ /**
+ * Instantiates a new vS editor table.
+ *
+ * @param prefs the prefs
+ */
public VSEditorTable(VSPrefs prefs) {
this.prefs = prefs;
this.nodes = new ArrayList<VSNode>();
@@ -151,14 +247,28 @@ public class VSEditorTable extends JTable {
col.sizeWidthToFit();
}
+ /**
+ * Adds the variable.
+ *
+ * @param key the key
+ * @param comp the comp
+ */
public void addVariable(String key, Component comp) {
nodes.add(new VSNode(key, comp));
}
+ /**
+ * Adds the separator.
+ *
+ * @param text the text
+ */
public void addSeparator(String text) {
nodes.add(new VSNode(text));
}
+ /**
+ * Fire table data changed.
+ */
public void fireTableDataChanged() {
model.fireTableDataChanged();
}
diff --git a/sources/prefs/editors/VSProcessEditor.java b/sources/prefs/editors/VSProcessEditor.java
index bbd256f..e17f89a 100644
--- a/sources/prefs/editors/VSProcessEditor.java
+++ b/sources/prefs/editors/VSProcessEditor.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package prefs.editors;
import java.awt.event.*;
@@ -9,9 +13,24 @@ import protocols.*;
import events.*;
import prefs.VSPrefs;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSProcessEditor.
+ */
public class VSProcessEditor extends VSBetterEditor {
+
+ /** The process. */
private VSProcess process;
+
+ /** The TAKEOVE r_ button. */
public static boolean TAKEOVER_BUTTON;
+
+ /**
+ * Instantiates a new vS process editor.
+ *
+ * @param prefs the prefs
+ * @param process the process
+ */
public VSProcessEditor(VSPrefs prefs, VSProcess process) {
super(prefs, process, prefs.getString("lang.name") + " - " + prefs.getString("lang.prefs.process"));;
this.process = process;
@@ -19,6 +38,9 @@ public class VSProcessEditor extends VSBetterEditor {
makeProtocolVariablesEditable();
}
+ /* (non-Javadoc)
+ * @see prefs.editors.VSBetterEditor#addToButtonPanelFront(javax.swing.JPanel)
+ */
protected void addToButtonPanelFront(JPanel buttonPanel) {
JButton takeoverButton = new JButton(
prefs.getString("lang.takeover"));
@@ -27,6 +49,9 @@ public class VSProcessEditor extends VSBetterEditor {
buttonPanel.add(takeoverButton);
}
+ /**
+ * Make protocol variables editable.
+ */
protected void makeProtocolVariablesEditable() {
ArrayList<String> editableProtocolsClassnames =
VSRegisteredEvents.getEditableProtocolsClassnames();
@@ -39,6 +64,9 @@ public class VSProcessEditor extends VSBetterEditor {
}
}
+ /* (non-Javadoc)
+ * @see prefs.editors.VSBetterEditor#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 36593ac..1264377 100644
--- a/sources/prefs/editors/VSSimulatorEditor.java
+++ b/sources/prefs/editors/VSSimulatorEditor.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package prefs.editors;
import java.awt.event.*;
@@ -6,12 +10,31 @@ import javax.swing.*;
import simulator.*;
import prefs.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSSimulatorEditor.
+ */
public class VSSimulatorEditor extends VSBetterEditor {
+
+ /** The simulator frame. */
private VSSimulatorFrame simulatorFrame;
+
+ /** The simulation. */
private VSSimulator simulation;
+
+ /** The TAKEOVE r_ button. */
public static boolean TAKEOVER_BUTTON;
+
+ /** The dont start new simulation. */
private boolean dontStartNewSimulation;
+ /**
+ * Instantiates a new vS simulator editor.
+ *
+ * @param prefs the prefs
+ * @param simulatorFrame the simulator frame
+ * @param simulation the simulation
+ */
public VSSimulatorEditor(VSPrefs prefs, VSSimulatorFrame simulatorFrame, VSSimulator simulation) {
super(prefs, prefs, prefs.getString("lang.name")
+ " - " + prefs.getString("lang.prefs"));
@@ -20,12 +43,21 @@ public class VSSimulatorEditor extends VSBetterEditor {
this.simulation = simulation;
}
+ /**
+ * Instantiates a new vS simulator editor.
+ *
+ * @param prefs the prefs
+ * @param simulatorFrame the simulator frame
+ */
public VSSimulatorEditor(VSPrefs prefs, VSSimulatorFrame simulatorFrame) {
super(prefs, prefs, prefs.getString("lang.name")
+ " - " + prefs.getString("lang.prefs"));
this.simulatorFrame = simulatorFrame;
}
+ /* (non-Javadoc)
+ * @see prefs.editors.VSBetterEditor#addToButtonPanelFront(javax.swing.JPanel)
+ */
protected void addToButtonPanelFront(JPanel buttonPanel) {
if (TAKEOVER_BUTTON) {
TAKEOVER_BUTTON = false;
@@ -37,6 +69,9 @@ public class VSSimulatorEditor extends VSBetterEditor {
}
}
+ /* (non-Javadoc)
+ * @see prefs.editors.VSBetterEditor#actionPerformed(java.awt.event.ActionEvent)
+ */
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
diff --git a/sources/protocols/VSProtocol.java b/sources/protocols/VSProtocol.java
index 3b25d04..b3ebfe6 100644
--- a/sources/protocols/VSProtocol.java
+++ b/sources/protocols/VSProtocol.java
@@ -1,13 +1,32 @@
+/*
+ * 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 {
+
+ /** 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;
@@ -18,10 +37,20 @@ abstract public class VSProtocol extends VSEvent {
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();
@@ -29,6 +58,11 @@ abstract public class VSProtocol extends VSEvent {
}
}
+ /**
+ * On message recv.
+ *
+ * @param message the message
+ */
public final void onMessageRecv(VSMessage message) {
if (isIncorrectProtocol(message))
return;
@@ -44,14 +78,27 @@ abstract public class VSProtocol extends VSEvent {
}
}
+ /**
+ * 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;
@@ -66,12 +113,40 @@ abstract public class VSProtocol extends VSEvent {
}
}
+ /**
+ * 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;
@@ -79,6 +154,9 @@ abstract public class VSProtocol extends VSEvent {
return process.getSimulationCanvas().getNumProcesses();
}
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#toString()
+ */
public String toString() {
if (process == null)
return "";
diff --git a/sources/protocols/implementations/BerkelyTimeProtocol.java b/sources/protocols/implementations/BerkelyTimeProtocol.java
index 20acc22..7326ac5 100644
--- a/sources/protocols/implementations/BerkelyTimeProtocol.java
+++ b/sources/protocols/implementations/BerkelyTimeProtocol.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package protocols.implementations;
import protocols.VSProtocol;
@@ -5,18 +9,29 @@ import core.VSMessage;
import java.util.HashMap;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class BerkelyTimeProtocol.
+ */
public class BerkelyTimeProtocol extends VSProtocol {
/* Berkely Server variables */
/* Integer: Process ID, Long: Local time of the process */
+ /** The process times. */
private HashMap<Integer,Long> processTimes = new HashMap<Integer,Long>();
/* Integer: Process ID, Long: Time of receiving the response from the process */
+ /** The recv times. */
private HashMap<Integer,Long> recvTimes = new HashMap<Integer,Long>();
/* Integer: Process ID, Long: Calculated process times (using the RTT) */
+ /** The real times rtt. */
private HashMap<Integer,Long> realTimesRTT = new HashMap<Integer,Long>();
/* Time the request/response has started */
+ /** The request time. */
private long requestTime;
+ /**
+ * Instantiates a new berkely time protocol.
+ */
public BerkelyTimeProtocol() {
setClassname(getClass().toString());
@@ -24,15 +39,24 @@ public class BerkelyTimeProtocol extends VSProtocol {
setInteger("numProcesses", 0);
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onInit()
+ */
protected void onInit() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientReset()
+ */
protected void onClientReset() {
processTimes.clear();
recvTimes.clear();
realTimesRTT.clear();
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientStart()
+ */
protected void onClientStart() {
requestTime = process.getTime();
VSMessage message = new VSMessage(getClassname());
@@ -40,6 +64,9 @@ public class BerkelyTimeProtocol extends VSProtocol {
sendMessage(message);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientRecv(core.VSMessage)
+ */
protected void onClientRecv(VSMessage recvMessage) {
/* Ignore all protocol messages which are not a response message, e.g. itself */
if (!recvMessage.getBoolean("isResponse"))
@@ -64,7 +91,9 @@ public class BerkelyTimeProtocol extends VSProtocol {
}
/**
- * Calculate the new average time
+ * Calculate the new average time.
+ *
+ * @return the long
*/
private long calculateAverageTime() {
long sum = 0;
@@ -82,7 +111,9 @@ public class BerkelyTimeProtocol extends VSProtocol {
}
/**
- * Sends to all clients a value to justify their local clocks
+ * Sends to all clients a value to justify their local clocks.
+ *
+ * @param avgTime the avg time
*/
private void sendJustifyRequests(long avgTime) {
for (Integer processID : processTimes.keySet()) {
@@ -96,9 +127,15 @@ public class BerkelyTimeProtocol extends VSProtocol {
}
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerReset()
+ */
protected void onServerReset() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerRecv(core.VSMessage)
+ */
protected void onServerRecv(VSMessage recvMessage) {
if (recvMessage.getBoolean("isRequest")) {
VSMessage message = new VSMessage(getClassname());
@@ -121,6 +158,9 @@ public class BerkelyTimeProtocol extends VSProtocol {
}
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#toString()
+ */
public String toString() {
return super.toString();
}
diff --git a/sources/protocols/implementations/BroadcastSturmProtocol.java b/sources/protocols/implementations/BroadcastSturmProtocol.java
index 165a2f3..9efd347 100644
--- a/sources/protocols/implementations/BroadcastSturmProtocol.java
+++ b/sources/protocols/implementations/BroadcastSturmProtocol.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package protocols.implementations;
import java.util.ArrayList;
@@ -5,21 +9,41 @@ import java.util.ArrayList;
import core.VSMessage;
import protocols.VSProtocol;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class BroadcastSturmProtocol.
+ */
public class BroadcastSturmProtocol extends VSProtocol {
+
+ /** The sent messages. */
private ArrayList<VSMessage> sentMessages;
+
+ /** The broadcast count. */
private static int broadcastCount;
+ /**
+ * Instantiates a new broadcast sturm protocol.
+ */
public BroadcastSturmProtocol() {
setClassname(getClass().toString());
sentMessages = new ArrayList<VSMessage>();
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onInit()
+ */
protected void onInit() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientReset()
+ */
protected void onClientReset() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientStart()
+ */
protected void onClientStart() {
VSMessage message = new VSMessage(getClassname());
message.setInteger("Broadcast", broadcastCount++);
@@ -27,13 +51,22 @@ public class BroadcastSturmProtocol extends VSProtocol {
sendMessage(message);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientRecv(core.VSMessage)
+ */
protected void onClientRecv(VSMessage recvMessage) {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerReset()
+ */
protected void onServerReset() {
sentMessages.clear();
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerRecv(core.VSMessage)
+ */
protected void onServerRecv(VSMessage recvMessage) {
if (!sentMessages.contains(recvMessage)) {
VSMessage message = new VSMessage(getClassname());
@@ -44,6 +77,9 @@ public class BroadcastSturmProtocol extends VSProtocol {
}
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#toString()
+ */
public String toString() {
return super.toString();
}
diff --git a/sources/protocols/implementations/DummyProtocol.java b/sources/protocols/implementations/DummyProtocol.java
index a7beb19..50690b3 100644
--- a/sources/protocols/implementations/DummyProtocol.java
+++ b/sources/protocols/implementations/DummyProtocol.java
@@ -1,20 +1,41 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package protocols.implementations;
import protocols.VSProtocol;
import core.VSMessage;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class DummyProtocol.
+ */
public class DummyProtocol extends VSProtocol {
+
+ /**
+ * Instantiates a new dummy protocol.
+ */
public DummyProtocol() {
setClassname(getClass().toString());
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onInit()
+ */
protected void onInit() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientReset()
+ */
protected void onClientReset() {
logg("onClientReset()");
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientStart()
+ */
protected void onClientStart() {
logg("onClientStart()");
@@ -26,6 +47,9 @@ public class DummyProtocol extends VSProtocol {
sendMessage(message);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientRecv(core.VSMessage)
+ */
protected void onClientRecv(VSMessage recvMessage) {
logg("onClientRecv("+recvMessage+")");
@@ -35,14 +59,23 @@ public class DummyProtocol extends VSProtocol {
float f = recvMessage.getFloat("A float");
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerReset()
+ */
protected void onServerReset() {
logg("onClientReset()");
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerRecv(core.VSMessage)
+ */
protected void onServerRecv(VSMessage recvMessage) {
logg("onServerRecv("+recvMessage+")");
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#toString()
+ */
public String toString() {
return super.toString() + "; Dummy Test";
}
diff --git a/sources/protocols/implementations/ExternalTimeSyncProtocol.java b/sources/protocols/implementations/ExternalTimeSyncProtocol.java
index 5a55d89..63edcaf 100644
--- a/sources/protocols/implementations/ExternalTimeSyncProtocol.java
+++ b/sources/protocols/implementations/ExternalTimeSyncProtocol.java
@@ -1,22 +1,46 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package protocols.implementations;
import core.VSMessage;
import protocols.VSProtocol;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class ExternalTimeSyncProtocol.
+ */
public class ExternalTimeSyncProtocol extends VSProtocol {
+
+ /** The request time. */
private long requestTime;
+
+ /** The waiting for response. */
private boolean waitingForResponse;
+ /**
+ * Instantiates a new external time sync protocol.
+ */
public ExternalTimeSyncProtocol() {
setClassname(getClass().toString());
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onInit()
+ */
protected void onInit() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientReset()
+ */
protected void onClientReset() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientStart()
+ */
protected void onClientStart() {
requestTime = process.getTime();
waitingForResponse = true;
@@ -27,6 +51,9 @@ public class ExternalTimeSyncProtocol extends VSProtocol {
sendMessage(message);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientRecv(core.VSMessage)
+ */
protected void onClientRecv(VSMessage recvMessage) {
if (!recvMessage.getBoolean("isServerResponse"))
return;
@@ -45,9 +72,15 @@ public class ExternalTimeSyncProtocol extends VSProtocol {
process.setTime(newTime);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerReset()
+ */
protected void onServerReset() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerRecv(core.VSMessage)
+ */
protected void onServerRecv(VSMessage recvMessage) {
if (!recvMessage.getBoolean("isClientRequest"))
return;
@@ -59,6 +92,9 @@ public class ExternalTimeSyncProtocol extends VSProtocol {
sendMessage(message);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#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 ff9c4e3..2f9a84c 100644
--- a/sources/protocols/implementations/InternalTimeSyncProtocol.java
+++ b/sources/protocols/implementations/InternalTimeSyncProtocol.java
@@ -1,11 +1,24 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package protocols.implementations;
import core.VSMessage;
import protocols.VSProtocol;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class InternalTimeSyncProtocol.
+ */
public class InternalTimeSyncProtocol extends VSProtocol {
+
+ /** The waiting for response. */
private boolean waitingForResponse;
+ /**
+ * Instantiates a new internal time sync protocol.
+ */
public InternalTimeSyncProtocol() {
setClassname(getClass().toString());
@@ -14,12 +27,21 @@ public class InternalTimeSyncProtocol extends VSProtocol {
setLong("t_max", 2000);
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onInit()
+ */
protected void onInit() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientReset()
+ */
protected void onClientReset() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientStart()
+ */
protected void onClientStart() {
waitingForResponse = true;
@@ -29,6 +51,9 @@ public class InternalTimeSyncProtocol extends VSProtocol {
sendMessage(message);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientRecv(core.VSMessage)
+ */
protected void onClientRecv(VSMessage recvMessage) {
/* Ignore all protocol messages which are not a response message, e.g. itself */
if (!recvMessage.getBoolean("isServerResponse"))
@@ -51,9 +76,15 @@ public class InternalTimeSyncProtocol extends VSProtocol {
process.setTime(newTime);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerReset()
+ */
protected void onServerReset() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerRecv(core.VSMessage)
+ */
protected void onServerRecv(VSMessage recvMessage) {
/* Ignore all protocol messages which are not a request message, e.g. itself */
if (!recvMessage.getBoolean("isClientRequest"))
@@ -66,6 +97,9 @@ public class InternalTimeSyncProtocol extends VSProtocol {
sendMessage(message);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#toString()
+ */
public String toString() {
return super.toString();
}
diff --git a/sources/protocols/implementations/PingPongProtocol.java b/sources/protocols/implementations/PingPongProtocol.java
index a2886f9..5df152f 100644
--- a/sources/protocols/implementations/PingPongProtocol.java
+++ b/sources/protocols/implementations/PingPongProtocol.java
@@ -1,23 +1,47 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package protocols.implementations;
import core.VSMessage;
import protocols.VSProtocol;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class PingPongProtocol.
+ */
public class PingPongProtocol extends VSProtocol {
+
+ /** The client counter. */
private int clientCounter;
+
+ /** The server counter. */
private int serverCounter;
+ /**
+ * Instantiates a new ping pong protocol.
+ */
public PingPongProtocol() {
setClassname(getClass().toString());
}
+ /* (non-Javadoc)
+ * @see events.VSEvent#onInit()
+ */
protected void onInit() {
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientReset()
+ */
protected void onClientReset() {
clientCounter = 0;
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientStart()
+ */
protected void onClientStart() {
VSMessage message = new VSMessage(getClassname());
message.setBoolean("fromClient", true);
@@ -25,6 +49,9 @@ public class PingPongProtocol extends VSProtocol {
sendMessage(message);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onClientRecv(core.VSMessage)
+ */
protected void onClientRecv(VSMessage recvMessage) {
if (!recvMessage.getBoolean("fromServer"))
return;
@@ -37,10 +64,16 @@ public class PingPongProtocol extends VSProtocol {
sendMessage(message);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerReset()
+ */
protected void onServerReset() {
serverCounter = 0;
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#onServerRecv(core.VSMessage)
+ */
protected void onServerRecv(VSMessage recvMessage) {
if (!recvMessage.getBoolean("fromClient"))
return;
@@ -53,6 +86,9 @@ public class PingPongProtocol extends VSProtocol {
sendMessage(message);
}
+ /* (non-Javadoc)
+ * @see protocols.VSProtocol#toString()
+ */
public String toString() {
return super.toString();
}
diff --git a/sources/simulator/VSAbout.java b/sources/simulator/VSAbout.java
index 88ccbf0..4b33e82 100644
--- a/sources/simulator/VSAbout.java
+++ b/sources/simulator/VSAbout.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package simulator;
import java.awt.*;
@@ -7,9 +11,21 @@ import javax.swing.*;
import prefs.*;
import utils.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSAbout.
+ */
public class VSAbout extends VSFrame implements ActionListener {
+
+ /** The prefs. */
private VSPrefs prefs;
+ /**
+ * Instantiates a new vS about.
+ *
+ * @param prefs the prefs
+ * @param relativeTo the relative to
+ */
public VSAbout(VSPrefs prefs, Component relativeTo) {
super(prefs.getString("lang.name") + " - "
+ prefs.getString("lang.about"), relativeTo);
@@ -23,6 +39,11 @@ public class VSAbout extends VSFrame implements ActionListener {
}
+ /**
+ * Creates the content pane.
+ *
+ * @return the container
+ */
public Container createContentPane() {
Container contentPane = getContentPane();
@@ -36,6 +57,11 @@ public class VSAbout extends VSFrame implements ActionListener {
return contentPane;
}
+ /**
+ * Creates the button pane.
+ *
+ * @return the j panel
+ */
public JPanel createButtonPane() {
JPanel buttonPane = new JPanel();
buttonPane.setBackground(Color.WHITE);
@@ -50,6 +76,9 @@ public class VSAbout extends VSFrame implements ActionListener {
}
+ /* (non-Javadoc)
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
diff --git a/sources/simulator/VSLogging.java b/sources/simulator/VSLogging.java
index c303bec..fe76abc 100644
--- a/sources/simulator/VSLogging.java
+++ b/sources/simulator/VSLogging.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package simulator;
import java.util.*;
@@ -6,16 +10,39 @@ import javax.swing.*;
import utils.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSLogging.
+ */
public class VSLogging {
+
+ /** The logging area. */
private JTextArea loggingArea;
+
+ /** The filter text. */
private String filterText;
+
+ /** The pause lines. */
private ArrayList<StringBuffer> pauseLines;
+
+ /** The logging lines. */
private ArrayList<StringBuffer> loggingLines;
+
+ /** The simulation canvas. */
private VSSimulatorCanvas simulationCanvas;
+
+ /** The is filtered. */
private boolean isFiltered;
+
+ /** The is paused. */
private boolean isPaused;
+
+ /** The filter pattern. */
private Pattern filterPattern;
+ /**
+ * Instantiates a new vS logging.
+ */
public VSLogging() {
loggingArea = new JTextArea(0, 0);
loggingArea.setEditable(false);
@@ -26,14 +53,29 @@ public class VSLogging {
filterText = "";
}
+ /**
+ * Sets the simulation canvas.
+ *
+ * @param simulationCanvas the new simulation canvas
+ */
public void setSimulationCanvas(VSSimulatorCanvas simulationCanvas) {
this.simulationCanvas = simulationCanvas;
}
+ /**
+ * Gets the logging area.
+ *
+ * @return the logging area
+ */
public JTextArea getLoggingArea() {
return loggingArea;
}
+ /**
+ * Logg.
+ *
+ * @param message the message
+ */
public void logg(String message) {
if (simulationCanvas == null)
logg(message, 0);
@@ -41,6 +83,12 @@ public class VSLogging {
logg(message, simulationCanvas.getTime());
}
+ /**
+ * Logg.
+ *
+ * @param message the message
+ * @param time the time
+ */
public synchronized void logg(String message, long time) {
StringBuffer buffer = new StringBuffer();
buffer.append(VSTools.getTimeString(time));
@@ -53,6 +101,11 @@ public class VSLogging {
loggFiltered(buffer);
}
+ /**
+ * Checks if is paused.
+ *
+ * @param isPaused the is paused
+ */
public synchronized void isPaused(boolean isPaused) {
this.isPaused = isPaused;
@@ -64,6 +117,11 @@ public class VSLogging {
}
}
+ /**
+ * Logg filtered.
+ *
+ * @param buffer the buffer
+ */
private void loggFiltered(StringBuffer buffer) {
loggingLines.add(buffer);
if (!isFiltered) {
@@ -76,6 +134,11 @@ public class VSLogging {
}
}
+ /**
+ * Checks if is filtered.
+ *
+ * @param isFiltered the is filtered
+ */
public synchronized void isFiltered(boolean isFiltered) {
this.isFiltered = isFiltered;
@@ -85,17 +148,28 @@ public class VSLogging {
filter();
}
+ /**
+ * Sets the filter text.
+ *
+ * @param filterText the new filter text
+ */
public synchronized void setFilterText(String filterText) {
this.filterText = filterText;
filter();
}
+ /**
+ * Clear.
+ */
public synchronized void clear() {
loggingLines.clear();
pauseLines.clear();
loggingArea.setText("");
}
+ /**
+ * Filter.
+ */
private void filter() {
try {
filterPattern = Pattern.compile(filterText);
diff --git a/sources/simulator/VSMain.java b/sources/simulator/VSMain.java
index bdfd631..79a0a7e 100644
--- a/sources/simulator/VSMain.java
+++ b/sources/simulator/VSMain.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package simulator;
import java.awt.*;
@@ -7,20 +11,47 @@ import events.*;
import prefs.*;
import prefs.editors.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSMain.
+ */
public class VSMain {
+
+ /**
+ * Instantiates a new vS main.
+ *
+ * @param prefs the prefs
+ */
public VSMain(VSPrefs prefs) {
init(prefs, null);
}
+ /**
+ * Instantiates a new vS main.
+ *
+ * @param prefs the prefs
+ * @param relativeTo the relative to
+ */
public VSMain(VSPrefs prefs, Component relativeTo) {
init(prefs, relativeTo);
}
+ /**
+ * Inits the.
+ *
+ * @param prefs the prefs
+ * @param relativeTo the relative to
+ */
private void init(VSPrefs prefs, Component relativeTo) {
VSSimulatorFrame simulatorFrame = new VSSimulatorFrame(prefs, relativeTo);
new VSEditorFrame(prefs, relativeTo, new VSSimulatorEditor(prefs, simulatorFrame));
}
+ /**
+ * The main method.
+ *
+ * @param args the arguments
+ */
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(
diff --git a/sources/simulator/VSSimulator.java b/sources/simulator/VSSimulator.java
index 742bd27..c42b848 100644
--- a/sources/simulator/VSSimulator.java
+++ b/sources/simulator/VSSimulator.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package simulator;
import java.awt.*;
@@ -14,49 +18,142 @@ import prefs.*;
import prefs.editors.*;
import utils.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSSimulator.
+ */
public class VSSimulator extends JPanel {
+
+ /** The global text fields. */
private ArrayList<String> globalTextFields;
+
+ /** The local text fields. */
private ArrayList<String> localTextFields;
+
+ /** The create tasks. */
private ArrayList<VSCreateTask> createTasks;
+
+ /** The filter active check box. */
private JCheckBox filterActiveCheckBox;
+
+ /** The lamport active check box. */
private JCheckBox lamportActiveCheckBox;
+
+ /** The vector time active check box. */
private JCheckBox vectorTimeActiveCheckBox;
+
+ /** The global pid combo box. */
private JComboBox globalPIDComboBox;
+
+ /** The local pid combo box. */
private JComboBox localPIDComboBox;
+
+ /** The processes combo box. */
private JComboBox processesComboBox;
+
+ /** The global add panel. */
private JPanel globalAddPanel;
+
+ /** The local add panel. */
private JPanel localAddPanel;
+
+ /** The local panel. */
private JPanel localPanel;
+
+ /** The logging panel. */
private JPanel loggingPanel;
+
+ /** The tools panel. */
private JPanel toolsPanel;
+
+ /** The split pane1. */
private JSplitPane splitPane1;
+
+ /** The split pane h. */
private JSplitPane splitPaneH;
+
+ /** The split pane v. */
private JSplitPane splitPaneV;
+
+ /** The tabbed pane. */
private JTabbedPane tabbedPane;
+
+ /** The logging area. */
private JTextArea loggingArea;
+
+ /** The filter text field. */
private JTextField filterTextField;
+
+ /** The global text field. */
private JTextField globalTextField;
+
+ /** The local text field. */
private JTextField localTextField;
+
+ /** The thread. */
private Thread thread;
+
+ /** The logging. */
private VSLogging logging;
+
+ /** The menu item states. */
private VSMenuItemStates menuItemStates;
+
+ /** The prefs. */
private VSPrefs prefs;
+
+ /** The simulation canvas. */
private VSSimulatorCanvas simulationCanvas;
+
+ /** The simulator frame. */
private VSSimulatorFrame simulatorFrame;
+
+ /** The task manager. */
private VSTaskManager taskManager;
+
+ /** The task manager global model. */
private VSTaskManagerTableModel taskManagerGlobalModel;
+
+ /** The task manager local model. */
private VSTaskManagerTableModel taskManagerLocalModel;
+
+ /** The has started. */
private boolean hasStarted = false;
+
+ /** The last selected process num. */
private int lastSelectedProcessNum;
+
+ /** The simulation counter. */
private static int simulationCounter;
+
+ /** The simulation num. */
private static int simulationNum;
+ /**
+ * The Class VSMenuItemStates.
+ */
public class VSMenuItemStates {
+
+ /** The pause. */
private volatile boolean pause;
+
+ /** The replay. */
private volatile boolean replay;
+
+ /** The reset. */
private volatile boolean reset;
+
+ /** The start. */
private volatile boolean start;
+ /**
+ * Instantiates a new vS menu item states.
+ *
+ * @param pause the pause
+ * @param replay the replay
+ * @param reset the reset
+ * @param start the start
+ */
public VSMenuItemStates(boolean pause, boolean replay, boolean reset, boolean start) {
this.pause = pause;
this.replay = replay;
@@ -64,39 +161,85 @@ public class VSSimulator extends JPanel {
this.start = start;
}
+ /**
+ * Sets the pause.
+ *
+ * @param pause the new pause
+ */
public void setPause(boolean pause) {
this.pause = pause;
}
+ /**
+ * Sets the replay.
+ *
+ * @param replay the new replay
+ */
public void setReplay(boolean replay) {
this.replay = replay;
}
+ /**
+ * Sets the reset.
+ *
+ * @param reset the new reset
+ */
public void setReset(boolean reset) {
this.reset = reset;
}
+ /**
+ * Sets the start.
+ *
+ * @param start the new start
+ */
public void setStart(boolean start) {
this.start = start;
}
+ /**
+ * Gets the pause.
+ *
+ * @return the pause
+ */
public boolean getPause() {
return pause;
}
+ /**
+ * Gets the replay.
+ *
+ * @return the replay
+ */
public boolean getReplay() {
return replay;
}
+ /**
+ * Gets the reset.
+ *
+ * @return the reset
+ */
public boolean getReset() {
return reset;
}
+ /**
+ * Gets the start.
+ *
+ * @return the start
+ */
public boolean getStart() {
return start;
}
}
+ /**
+ * Instantiates a new vS simulator.
+ *
+ * @param prefs the prefs
+ * @param simulatorFrame the simulator frame
+ */
public VSSimulator(VSPrefs prefs, VSSimulatorFrame simulatorFrame) {
this.prefs = prefs;
this.simulatorFrame = simulatorFrame;
@@ -132,6 +275,9 @@ public class VSSimulator extends JPanel {
thread.start();
}
+ /**
+ * Fill content pane.
+ */
private void fillContentPane() {
loggingArea = logging.getLoggingArea();
@@ -167,7 +313,14 @@ public class VSSimulator extends JPanel {
this.add(splitPaneV);
}
+ /** The last expert state. */
private boolean lastExpertState;
+
+ /**
+ * Creates the tools panel.
+ *
+ * @return the j panel
+ */
private JPanel createToolsPanel() {
JPanel toolsPanel = new JPanel();
boolean expertMode = prefs.getBoolean("sim.mode.expert");
@@ -285,6 +438,11 @@ public class VSSimulator extends JPanel {
return toolsPanel;
}
+ /**
+ * Creates the process pane.
+ *
+ * @return the j panel
+ */
private JPanel createProcessPane() {
JPanel editPanel = new JPanel(new GridBagLayout());
boolean expertMode = prefs.getBoolean("sim.mode.expert");
@@ -366,6 +524,13 @@ public class VSSimulator extends JPanel {
return editPanel;
}
+ /**
+ * Creates the label panel.
+ *
+ * @param text the text
+ *
+ * @return the j panel
+ */
private JPanel createLabelPanel(String text) {
JPanel panel = new JPanel();
JLabel label = new JLabel(text);
@@ -374,6 +539,13 @@ public class VSSimulator extends JPanel {
return panel;
}
+ /**
+ * Creates the task label.
+ *
+ * @param localTasks the local tasks
+ *
+ * @return the j panel
+ */
private JPanel createTaskLabel(boolean localTasks) {
JPanel panel = new JPanel(new GridBagLayout());
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
@@ -394,23 +566,48 @@ public class VSSimulator extends JPanel {
return panel;
}
+ /**
+ * The Class VSCreateTask.
+ */
private class VSCreateTask {
+
+ /** The event classname. */
private String eventClassname;
+
+ /** The protocol classname. */
private String protocolClassname;
+
+ /** The shortname. */
private String shortname;
/* Those 3 values are for ProtocolEvent events */
+ /** The is protocol activation. */
private boolean isProtocolActivation;
+
+ /** The is protocol deactivation. */
private boolean isProtocolDeactivation;
+
+ /** The is client protocol. */
private boolean isClientProtocol;
/* Those values are for ProtocolClient onStart events */
+ /** The is client request. */
private boolean isClientRequest;
+ /**
+ * Instantiates a new vS create task.
+ *
+ * @param eventClassname the event classname
+ */
public VSCreateTask(String eventClassname) {
this.eventClassname = eventClassname;
}
+ /**
+ * Checks if is protocol activation.
+ *
+ * @param isProtocolActivation the is protocol activation
+ */
public void isProtocolActivation(boolean isProtocolActivation) {
this.isProtocolActivation = isProtocolActivation;
@@ -418,6 +615,11 @@ public class VSSimulator extends JPanel {
isProtocolDeactivation(false);
}
+ /**
+ * Checks if is protocol deactivation.
+ *
+ * @param isProtocolDeactivation the is protocol deactivation
+ */
public void isProtocolDeactivation(boolean isProtocolDeactivation) {
this.isProtocolDeactivation = isProtocolDeactivation;
@@ -425,22 +627,51 @@ public class VSSimulator extends JPanel {
isProtocolActivation(false);
}
+ /**
+ * Checks if is client protocol.
+ *
+ * @param isClientProtocol the is client protocol
+ */
public void isClientProtocol(boolean isClientProtocol) {
this.isClientProtocol = isClientProtocol;
}
+ /**
+ * Checks if is client request.
+ *
+ * @param isClientRequest the is client request
+ */
public void isClientRequest(boolean isClientRequest) {
this.isClientRequest = isClientRequest;
}
+ /**
+ * Sets the protocol classname.
+ *
+ * @param protocolClassname the new protocol classname
+ */
public void setProtocolClassname(String protocolClassname) {
this.protocolClassname = protocolClassname;
}
+ /**
+ * Sets the shortname.
+ *
+ * @param shortname the new shortname
+ */
public void setShortname(String shortname) {
this.shortname = shortname;
}
+ /**
+ * Creates the task.
+ *
+ * @param process the process
+ * @param time the time
+ * @param localTimedTask the local timed task
+ *
+ * @return the vS task
+ */
public VSTask createTask(VSProcess process, long time, boolean localTimedTask) {
VSEvent event = null;
@@ -466,17 +697,44 @@ public class VSSimulator extends JPanel {
}
}
+ /**
+ * The Class VSTaskManagerTableModel.
+ */
private class VSTaskManagerTableModel extends AbstractTableModel implements MouseListener {
+
+ /** The Constant LOCAL. */
public static final boolean LOCAL = true;
+
+ /** The Constant GLOBAL. */
public static final boolean GLOBAL = false;
+
+ /** The Constant ALL_PROCESSES. */
public static final boolean ALL_PROCESSES = true;
+
+ /** The Constant ONE_PROCESS. */
public static final boolean ONE_PROCESS = false;
+
+ /** The all processes. */
public boolean allProcesses;
+
+ /** The tasks. */
private VSPriorityQueue<VSTask> tasks;
+
+ /** The column names. */
private String columnNames[];
+
+ /** The num columns. */
private int numColumns;
+
+ /** The table. */
private JTable table;
+ /**
+ * Instantiates a new vS task manager table model.
+ *
+ * @param process the process
+ * @param localTask the local task
+ */
public VSTaskManagerTableModel(VSProcess process, boolean localTask) {
set(process, localTask, ONE_PROCESS);
columnNames = new String[3];
@@ -486,10 +744,22 @@ public class VSSimulator extends JPanel {
numColumns = 3;
}
+ /**
+ * Sets the table.
+ *
+ * @param table the new table
+ */
public void setTable(JTable table) {
this.table = table;
}
+ /**
+ * Sets the.
+ *
+ * @param process the process
+ * @param localTasks the local tasks
+ * @param allProcesses the all processes
+ */
public void set(VSProcess process, boolean localTasks, boolean allProcesses) {
this.allProcesses = allProcesses;
@@ -506,18 +776,30 @@ public class VSSimulator extends JPanel {
fireTableDataChanged();
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.AbstractTableModel#getColumnName(int)
+ */
public String getColumnName(int col) {
return columnNames[col];
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getRowCount()
+ */
public int getRowCount() {
return tasks == null ? 0 : tasks.size();
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getColumnCount()
+ */
public int getColumnCount() {
return numColumns;
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getValueAt(int, int)
+ */
public Object getValueAt(int row, int col) {
VSTask task = tasks.get(row);
@@ -531,19 +813,35 @@ public class VSSimulator extends JPanel {
return task.getEvent().getShortname();
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
+ */
public boolean isCellEditable(int row, int col) {
return false;
}
+ /* (non-Javadoc)
+ * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int)
+ */
public void setValueAt(Object value, int row, int col) {
fireTableDataChanged();
}
+ /**
+ * Adds the task.
+ *
+ * @param task the task
+ */
public void addTask(VSTask task) {
tasks.add(task);
fireTableDataChanged();
}
+ /**
+ * Removes the task at row.
+ *
+ * @param row the row
+ */
private void removeTaskAtRow(int row) {
VSTask task = tasks.get(row);
tasks.remove(task);
@@ -551,6 +849,9 @@ public class VSSimulator extends JPanel {
fireTableDataChanged();
}
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
+ */
public void mouseClicked(MouseEvent me) {
JTable source = (JTable) me.getSource();
final int row = source.rowAtPoint(me.getPoint());
@@ -575,12 +876,34 @@ public class VSSimulator extends JPanel {
}
}
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
+ */
public void mouseEntered(MouseEvent me) { }
+
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
+ */
public void mouseExited(MouseEvent me) { }
+
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
+ */
public void mousePressed(MouseEvent me) { }
+
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
+ */
public void mouseReleased(MouseEvent me) { }
}
+ /**
+ * Creates the task table.
+ *
+ * @param localTasks the local tasks
+ *
+ * @return the j table
+ */
private JTable createTaskTable(boolean localTasks) {
VSProcess process = getSelectedProcess();
VSTaskManagerTableModel model = new VSTaskManagerTableModel(process, localTasks);
@@ -609,6 +932,14 @@ public class VSSimulator extends JPanel {
return table;
}
+ /**
+ * Inits the add panel.
+ *
+ * @param panel the panel
+ * @param localTasks the local tasks
+ *
+ * @return the j panel
+ */
private JPanel initAddPanel(JPanel panel, final boolean localTasks) {
JPanel addPanel = new JPanel();
addPanel.setLayout(new BoxLayout(addPanel, BoxLayout.X_AXIS));
@@ -810,23 +1141,50 @@ public class VSSimulator extends JPanel {
return addPanel;
}
+ /**
+ * Gets the split size.
+ *
+ * @return the split size
+ */
public int getSplitSize() {
return splitPaneH.getDividerLocation();
}
+ /**
+ * Gets the paint size.
+ *
+ * @return the paint size
+ */
public int getPaintSize() {
return splitPaneV.getDividerLocation();
}
+ /**
+ * Gets the selected process num.
+ *
+ * @return the selected process num
+ */
private int getSelectedProcessNum() {
return processesComboBox.getSelectedIndex();
}
+ /**
+ * Gets the selected process.
+ *
+ * @return the selected process
+ */
private VSProcess getSelectedProcess() {
int processNum = getSelectedProcessNum();
return simulationCanvas.getProcess(processNum);
}
+ /**
+ * Gets the concerned processes.
+ *
+ * @param localTasks the local tasks
+ *
+ * @return the concerned processes
+ */
private ArrayList<VSProcess> getConcernedProcesses(boolean localTasks) {
int processNum = localTasks
? localPIDComboBox.getSelectedIndex()
@@ -841,6 +1199,9 @@ public class VSSimulator extends JPanel {
return arr;
}
+ /**
+ * Update task manager table.
+ */
public void updateTaskManagerTable() {
VSProcess process = getSelectedProcess();
boolean allProcesses = process == null;
@@ -848,6 +1209,9 @@ public class VSSimulator extends JPanel {
taskManagerGlobalModel.set(process, VSTaskManagerTableModel.GLOBAL, allProcesses);
}
+ /**
+ * Finish.
+ */
public void finish() {
menuItemStates.setStart(false);
menuItemStates.setPause(false);
@@ -856,27 +1220,55 @@ public class VSSimulator extends JPanel {
simulatorFrame.updateSimulationMenu();
}
+ /**
+ * Gets the simulation num.
+ *
+ * @return the simulation num
+ */
public int getSimulationNum() {
return simulationNum;
}
+ /**
+ * Gets the menu item states.
+ *
+ * @return the menu item states
+ */
public VSSimulator.VSMenuItemStates getMenuItemStates() {
return menuItemStates;
}
+ /**
+ * Gets the simulation canvas.
+ *
+ * @return the simulation canvas
+ */
public VSSimulatorCanvas getSimulationCanvas() {
return simulationCanvas;
}
+ /**
+ * Gets the simulator frame.
+ *
+ * @return the simulator frame
+ */
public VSSimulatorFrame getSimulatorFrame() {
return simulatorFrame;
}
+ /**
+ * Update from prefs.
+ */
public void updateFromPrefs() {
simulationCanvas.setBackground(prefs.getColor("col.background"));
simulationCanvas.updateFromPrefs();
}
+ /**
+ * Removes the process at index.
+ *
+ * @param index the index
+ */
public void removeProcessAtIndex(int index) {
if (lastSelectedProcessNum > index)
--lastSelectedProcessNum;
@@ -893,6 +1285,11 @@ public class VSSimulator extends JPanel {
updateTaskManagerTable();
}
+ /**
+ * Adds the process at index.
+ *
+ * @param index the index
+ */
public void addProcessAtIndex(int index) {
int processID = simulationCanvas.getProcess(index).getProcessID();
String processString = prefs.getString("lang.process");
@@ -907,6 +1304,9 @@ public class VSSimulator extends JPanel {
simulatorFrame.updateEditMenu();
}
+ /**
+ * Fire expert mode changed.
+ */
public void fireExpertModeChanged() {
boolean expertMode = prefs.getBoolean("sim.mode.expert");
@@ -945,6 +1345,11 @@ public class VSSimulator extends JPanel {
updateUI();
}
+ /**
+ * Gets the prefs.
+ *
+ * @return the prefs
+ */
public VSPrefs getPrefs() {
return prefs;
}
diff --git a/sources/simulator/VSSimulatorCanvas.java b/sources/simulator/VSSimulatorCanvas.java
index fb11fa5..2241883 100644
--- a/sources/simulator/VSSimulatorCanvas.java
+++ b/sources/simulator/VSSimulatorCanvas.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package simulator;
import java.awt.*;
@@ -14,80 +18,223 @@ import events.internal.*;
import prefs.*;
import prefs.editors.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSSimulatorCanvas.
+ */
public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionListener, MouseListener, HierarchyBoundsListener {
+
+ /** The highlighted process. */
private VSProcess highlightedProcess;
+
+ /** The simulation. */
private VSSimulator simulation;
+
+ /** The prefs. */
private VSPrefs prefs;
+
+ /** The logging. */
private VSLogging logging;
+
+ /** The num processes. */
private volatile int numProcesses;
+
+ /** The seconds spaceing. */
private int secondsSpaceing;
+
+ /** The thread sleep. */
private int threadSleep;
+
+ /** The until time. */
private long untilTime;
+
+ /** The is paused. */
private volatile boolean isPaused = true;
+
+ /** The is thread stopped. */
private volatile boolean isThreadStopped = false;
+
+ /** The is finished. */
private volatile boolean isFinished = false;
+
+ /** The is resetted. */
private volatile boolean isResetted = false;
+
+ /** The is anti aliased. */
private volatile boolean isAntiAliased = false;
+
+ /** The is anti aliased changed. */
private volatile boolean isAntiAliasedChanged = false;
+
+ /** The show lamport. */
private volatile boolean showLamport = false;
+
+ /** The show vector time. */
private volatile boolean showVectorTime = false;
+
+ /** The pause time. */
private volatile long pauseTime;
+
+ /** The start time. */
private volatile long startTime;
+
+ /** The time. */
private volatile long time;
+
+ /** The last time. */
private volatile long lastTime;
+
+ /** The task manager. */
private VSTaskManager taskManager;
+
+ /** The message lines. */
private LinkedList<VSMessageLine> messageLines;
+
+ /** The processes. */
private Vector<VSProcess> processes;
+
+ /** The clock speed. */
private double clockSpeed;
+
+ /** The clock offset. */
private double clockOffset;
+
+ /** The simulation time. */
private long simulationTime;
/* GFX buffering */
+ /** The strategy. */
private BufferStrategy strategy;
+
+ /** The g. */
private Graphics2D g;
/* Static constats */
+ /** The Constant LINE_WIDTH. */
private static final int LINE_WIDTH = 5;
+
+ /** The Constant SEPLINE_WIDTH. */
private static final int SEPLINE_WIDTH = 2;
+
+ /** The Constant XOFFSET. */
private static final int XOFFSET = 50;
+
+ /** The Constant YOFFSET. */
private static final int YOFFSET = 30;
+
+ /** The Constant YOUTER_SPACEING. */
private static final int YOUTER_SPACEING = 15;
+
+ /** The Constant YSEPLINE_SPACEING. */
private static final int YSEPLINE_SPACEING = 20;
+
+ /** The Constant TEXT_SPACEING. */
private static final int TEXT_SPACEING = 10;
+
+ /** The Constant ROW_HEIGHT. */
private static final int ROW_HEIGHT = 14;
/* Constats, which have to get calculated once after start */
+ /** The processline color. */
private Color processlineColor;
+
+ /** The process secondline color. */
private Color processSecondlineColor;
+
+ /** The process sepline color. */
private Color processSeplineColor;
+
+ /** The message arrived color. */
private Color messageArrivedColor;
+
+ /** The message sending color. */
private Color messageSendingColor;
+
+ /** The message lost color. */
private Color messageLostColor;
+
+ /** The background color. */
private Color backgroundColor;
+ /** The message line counter. */
private long messageLineCounter;
+
+ /**
+ * The Class VSMessageLine.
+ */
private class VSMessageLine {
+
+ /** The receiver process. */
private VSProcess receiverProcess;
+
+ /** The color. */
private Color color;
+
+ /** The send time. */
private long sendTime;
+
+ /** The recv time. */
private long recvTime;
+
+ /** The sender num. */
private int senderNum;
+
+ /** The receiver num. */
private int receiverNum;
+
+ /** The offset1. */
private int offset1;
+
+ /** The offset2. */
private int offset2;
+
+ /** The is arrived. */
private boolean isArrived;
+
+ /** The is lost. */
private boolean isLost;
+
+ /** The x1. */
private double x1;
+
+ /** The y1. */
private double y1;
+
+ /** The x2. */
private double x2;
+
+ /** The y2. */
private double y2;
+
+ /** The x. */
private double x;
+
+ /** The y. */
private double y;
+
+ /** The outage time. */
private long outageTime;
+
+ /** The z. */
private long z;
+
+ /** The message line num. */
private long messageLineNum;
+
+ /** The task. */
private VSTask task;
+ /**
+ * Instantiates a new vS message line.
+ *
+ * @param receiverProcess the receiver process
+ * @param sendTime the send time
+ * @param recvTime the recv time
+ * @param outageTime the outage time
+ * @param senderNum the sender num
+ * @param receiverNum the receiver num
+ * @param task the task
+ */
public VSMessageLine(VSProcess receiverProcess, long sendTime, long recvTime, long outageTime, int senderNum , int receiverNum, VSTask task) {
this.receiverProcess = receiverProcess;
this.sendTime = sendTime;
@@ -116,6 +263,9 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
paint();
}
+ /**
+ * Recalc on change.
+ */
public void recalcOnChange() {
x1 = getTimeXPosition(sendTime);
y1 = getProcessYPosition(senderNum+1) + offset1;
@@ -129,6 +279,12 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
+ /**
+ * Draw.
+ *
+ * @param g the g
+ * @param globalTime the global time
+ */
public void draw(final Graphics2D g, final long globalTime) {
if (isArrived) {
g.setColor(color);
@@ -159,6 +315,13 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Removes the process at index.
+ *
+ * @param index the index
+ *
+ * @return true, if successful
+ */
public boolean removeProcessAtIndex(int index) {
if (index == receiverNum || index == senderNum)
return true;
@@ -174,19 +337,43 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
return false;
}
+ /**
+ * Gets the message line num.
+ *
+ * @return the message line num
+ */
public long getMessageLineNum() {
return messageLineNum;
}
+ /**
+ * Equals.
+ *
+ * @param line the line
+ *
+ * @return true, if successful
+ */
public boolean equals(VSMessageLine line) {
return messageLineNum == line.getMessageLineNum();
}
+ /**
+ * Gets the task.
+ *
+ * @return the task
+ */
public VSTask getTask() {
return task;
}
}
+ /**
+ * Instantiates a new vS simulator canvas.
+ *
+ * @param prefs the prefs
+ * @param simulation the simulation
+ * @param logging the logging
+ */
public VSSimulatorCanvas(VSPrefs prefs, VSSimulator simulation, VSLogging logging) {
this.prefs = prefs;
this.simulation = simulation;
@@ -207,22 +394,46 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
addHierarchyBoundsListener(this);
}
+ /** The x paint size. */
double xPaintSize;
+
+ /** The paint size. */
double paintSize;
+
+ /** The y distance. */
double yDistance;
+
+ /** The global time x position. */
double globalTimeXPosition;
+ /** The xoffset_plus_xpaintsize. */
int xoffset_plus_xpaintsize;
+
+ /** The xpaintsize_dividedby_untiltime. */
double xpaintsize_dividedby_untiltime;
+
+ /** The paint processes offset. */
int paintProcessesOffset;
+ /** The paint secondlines seconds. */
int paintSecondlinesSeconds;
+
+ /** The paint secondlines line. */
int paintSecondlinesLine[] = new int[4];
+
+ /** The paint secondlines y string pos1. */
int paintSecondlinesYStringPos1;
+
+ /** The paint secondlines y string pos2. */
int paintSecondlinesYStringPos2;
+
+ /** The paint global time y position. */
int paintGlobalTimeYPosition;
/* This method contains very ugly code. But this has to be in order to gain performance! */
+ /**
+ * Recalc on change.
+ */
private void recalcOnChange() {
processlineColor = prefs.getColor("col.process.line");
processSecondlineColor = prefs.getColor("col.process.secondline");
@@ -274,6 +485,12 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Update simulation.
+ *
+ * @param globalTime the global time
+ * @param lastGlobalTime the last global time
+ */
private void updateSimulation(final long globalTime, final long lastGlobalTime) {
if (isPaused || isFinished)
return;
@@ -302,6 +519,9 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Paint.
+ */
public void paint() {
while (getBufferStrategy() == null) {
createBufferStrategy(3);
@@ -341,6 +561,12 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Paint processes.
+ *
+ * @param g the g
+ * @param globalTime the global time
+ */
private void paintProcesses(Graphics2D g, long globalTime) {
/* First paint the horizontal process timelines
* Second paint the processes
@@ -400,6 +626,15 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Paint time.
+ *
+ * @param g the g
+ * @param times the times
+ * @param process the process
+ * @param yStart the y start
+ * @param distance the distance
+ */
private void paintTime(final Graphics2D g, final VSTime times[], final VSProcess process,
final int yStart, final int distance) {
@@ -439,6 +674,11 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Paint secondlines.
+ *
+ * @param g the g
+ */
private void paintSecondlines(Graphics2D g) {
g.setColor(processSecondlineColor);
@@ -459,6 +699,12 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Paint global time.
+ *
+ * @param g the g
+ * @param globalTime the global time
+ */
private void paintGlobalTime(Graphics2D g, long globalTime) {
g.setColor(processSeplineColor);
final int xOffset = (int) globalTimeXPosition;
@@ -471,6 +717,13 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
g.drawString(globalTime+"ms", xPoints[1]+1, yPoints[0]+TEXT_SPACEING);
}
+ /**
+ * Gets the process at y pos.
+ *
+ * @param yPos the y pos
+ *
+ * @return the process at y pos
+ */
private VSProcess getProcessAtYPos(int yPos) {
final int reachDistance = (int) (yDistance/3);
int y = YOFFSET + YOUTER_SPACEING + YSEPLINE_SPACEING;
@@ -489,10 +742,24 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
return null;
}
+ /**
+ * Gets the time x position.
+ *
+ * @param time the time
+ *
+ * @return the time x position
+ */
private double getTimeXPosition(long time) {
return XOFFSET + xpaintsize_dividedby_untiltime * time;
}
+ /**
+ * Gets the process y position.
+ *
+ * @param i the i
+ *
+ * @return the process y position
+ */
private int getProcessYPosition(int i) {
int y;
@@ -506,26 +773,58 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
return y * (i - 1) + YOFFSET + YOUTER_SPACEING + YSEPLINE_SPACEING;
}
+ /**
+ * Gets the time.
+ *
+ * @return the time
+ */
public long getTime() {
return simulationTime;
}
+ /**
+ * Gets the until time.
+ *
+ * @return the until time
+ */
public long getUntilTime() {
return untilTime;
}
+ /**
+ * Gets the start time.
+ *
+ * @return the start time
+ */
public long getStartTime() {
return startTime;
}
+ /**
+ * Gets the task manager.
+ *
+ * @return the task manager
+ */
public VSTaskManager getTaskManager() {
return taskManager;
}
+ /**
+ * Gets the num processes.
+ *
+ * @return the num processes
+ */
public int getNumProcesses() {
return numProcesses;
}
+ /**
+ * Gets the process.
+ *
+ * @param processNum the process num
+ *
+ * @return the process
+ */
public VSProcess getProcess(int processNum) {
if (processNum >= processes.size())
return null;
@@ -533,6 +832,9 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
return processes.get(processNum);
}
+ /* (non-Javadoc)
+ * @see java.lang.Runnable#run()
+ */
public void run() {
while (true) {
while (!isThreadStopped && (isPaused || isFinished || isResetted)) {
@@ -572,6 +874,9 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Play.
+ */
public void play() {
logging.logg(prefs.getString("lang.simulation.started"));
final long currentTime = System.currentTimeMillis();
@@ -600,6 +905,9 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
paint();
}
+ /**
+ * Finish.
+ */
public void finish() {
synchronized (processes) {
for (VSProcess p : processes)
@@ -613,6 +921,9 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
paint();
}
+ /**
+ * Pause.
+ */
public void pause() {
isPaused = true;
synchronized (processes) {
@@ -626,6 +937,9 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
paint();
}
+ /**
+ * Reset.
+ */
public void reset() {
if (!isResetted) {
logging.logg(prefs.getString("lang.simulation.resetted"));
@@ -661,26 +975,49 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Stop thread.
+ */
public void stopThread() {
isThreadStopped = true;
}
+ /**
+ * Checks if is thread stopped.
+ *
+ * @return true, if is thread stopped
+ */
public boolean isThreadStopped() {
return isThreadStopped;
}
+ /**
+ * Show lamport.
+ *
+ * @param showLamport the show lamport
+ */
public void showLamport(boolean showLamport) {
this.showLamport = showLamport;
if (isPaused)
paint();
}
+ /**
+ * Show vector time.
+ *
+ * @param showVectorTime the show vector time
+ */
public void showVectorTime(boolean showVectorTime) {
this.showVectorTime = showVectorTime;
if (isPaused)
paint();
}
+ /**
+ * Checks if is anti aliased.
+ *
+ * @param isAntiAliased the is anti aliased
+ */
public void isAntiAliased(boolean isAntiAliased) {
this.isAntiAliased = isAntiAliased;
this.isAntiAliasedChanged = true;
@@ -688,6 +1025,11 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
paint();
}
+ /**
+ * Send message.
+ *
+ * @param message the message
+ */
public void sendMessage(VSMessage message) {
VSTask task = null;
VSEvent messageReceiveEvent = null;
@@ -728,6 +1070,9 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
+ */
public void mouseClicked(MouseEvent me) {
final VSProcess process = getProcessAtYPos(me.getY());
@@ -799,11 +1144,21 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Edits the process.
+ *
+ * @param processNum the process num
+ */
public void editProcess(int processNum) {
VSProcess process = processes.get(processNum);
editProcess(process);
}
+ /**
+ * Edits the process.
+ *
+ * @param process the process
+ */
public void editProcess(VSProcess process) {
if (process != null) {
process.updatePrefs();
@@ -812,8 +1167,14 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
+ */
public void mouseEntered(MouseEvent e) { }
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
+ */
public void mouseExited(MouseEvent e) {
if (highlightedProcess != null) {
highlightedProcess.highlightOff();
@@ -822,15 +1183,27 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
+ */
public void mousePressed(MouseEvent e) {
}
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
+ */
public void mouseReleased(MouseEvent e) {
}
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
+ */
public void mouseDragged(MouseEvent e) {
}
+ /* (non-Javadoc)
+ * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
+ */
public void mouseMoved(MouseEvent e) {
VSProcess p = getProcessAtYPos(e.getY());
@@ -861,12 +1234,23 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
paint();
}
+ /* (non-Javadoc)
+ * @see java.awt.event.HierarchyBoundsListener#ancestorMoved(java.awt.event.HierarchyEvent)
+ */
public void ancestorMoved(HierarchyEvent e) { }
+ /* (non-Javadoc)
+ * @see java.awt.event.HierarchyBoundsListener#ancestorResized(java.awt.event.HierarchyEvent)
+ */
public void ancestorResized(HierarchyEvent e) {
recalcOnChange();
}
+ /**
+ * Gets the processes array.
+ *
+ * @return the processes array
+ */
public ArrayList<VSProcess> getProcessesArray() {
ArrayList<VSProcess> arr = new ArrayList<VSProcess>();
@@ -878,6 +1262,9 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
return arr;
}
+ /**
+ * Update from prefs.
+ */
public void updateFromPrefs() {
untilTime = prefs.getInteger("sim.seconds") * 1000;
clockSpeed = prefs.getFloat("sim.clock.speed");
@@ -893,6 +1280,11 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
recalcOnChange();
}
+ /**
+ * Removes the process.
+ *
+ * @param process the process
+ */
private void removeProcess(VSProcess process) {
if (numProcesses == 1) {
simulation.getSimulatorFrame().removeSimulation(simulation);
@@ -925,12 +1317,22 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi
}
}
+ /**
+ * Creates the process.
+ *
+ * @param processNum the process num
+ *
+ * @return the vS process
+ */
private VSProcess createProcess(int processNum) {
VSProcess process = new VSProcess(prefs, processNum, this, logging);
logging.logg(prefs.getString("lang.process.new") + "; " + process);
return process;
}
+ /**
+ * Adds the process.
+ */
private void addProcess() {
numProcesses = processes.size() + 1;
VSProcess newProcess = createProcess(processes.size());
diff --git a/sources/simulator/VSSimulatorFrame.java b/sources/simulator/VSSimulatorFrame.java
index 4c77ad1..ccb1efe 100644
--- a/sources/simulator/VSSimulatorFrame.java
+++ b/sources/simulator/VSSimulatorFrame.java
@@ -1,3 +1,7 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package simulator;
import java.awt.*;
@@ -11,25 +15,67 @@ import prefs.*;
import prefs.editors.*;
import utils.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSSimulatorFrame.
+ */
public class VSSimulatorFrame extends VSFrame implements ActionListener {
+
+ /** The pause item. */
private JMenuItem pauseItem;
+
+ /** The replay item. */
private JMenuItem replayItem;
+
+ /** The reset item. */
private JMenuItem resetItem;
+
+ /** The start item. */
private JMenuItem startItem;
+
+ /** The pause button. */
private JButton pauseButton;
+
+ /** The replay button. */
private JButton replayButton;
+
+ /** The reset button. */
private JButton resetButton;
+
+ /** The start button. */
private JButton startButton;
+
+ /** The menu edit. */
private JMenu menuEdit;
+
+ /** The menu file. */
private JMenu menuFile;
+
+ /** The menu simulation. */
private JMenu menuSimulation;
+
+ /** The tool bar. */
private JToolBar toolBar;
+
+ /** The prefs. */
private VSPrefs prefs;
+
+ /** The simulations. */
private Vector<VSSimulator> simulations;
+
+ /** The current simulation. */
private VSSimulator currentSimulation;
+
+ /** The tabbed pane. */
private JTabbedPane tabbedPane;
//private JSlider speedSlider;
+ /**
+ * Instantiates a new vS simulator frame.
+ *
+ * @param prefs the prefs
+ * @param relativeTo the relative to
+ */
public VSSimulatorFrame(VSPrefs prefs, Component relativeTo) {
super(prefs.getString("lang.name"), relativeTo);
this.prefs = prefs;
@@ -54,6 +100,11 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener {
menuSimulation.setEnabled(false);
}
+ /**
+ * Creates the menu bar.
+ *
+ * @return the j menu bar
+ */
private JMenuBar createMenuBar() {
/* File menu */
menuFile = new JMenu(prefs.getString("lang.file"));
@@ -161,6 +212,11 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener {
return mainMenuBar;
}
+ /**
+ * Creates the content pane.
+ *
+ * @return the container
+ */
private Container createContentPane() {
Container pane = getContentPane();
tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT);
@@ -180,6 +236,9 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener {
return pane;
}
+ /**
+ * Update edit menu.
+ */
public void updateEditMenu() {
menuEdit.removeAll();
@@ -221,6 +280,9 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener {
}
/* updateSimulationMenu can be called from concurrent threads */
+ /**
+ * Update simulation menu.
+ */
public synchronized void updateSimulationMenu() {
VSSimulator.VSMenuItemStates menuItemState = currentSimulation.getMenuItemStates();
@@ -235,6 +297,9 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener {
startButton.setEnabled(menuItemState.getStart());
}
+ /* (non-Javadoc)
+ * @see java.awt.Window#dispose()
+ */
public void dispose() {
synchronized (simulations) {
for (VSSimulator simulation : simulations)
@@ -243,6 +308,9 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener {
super.dispose();
}
+ /* (non-Javadoc)
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
String sourceText = null;
@@ -310,6 +378,11 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener {
}
}
+ /**
+ * Adds the simulation.
+ *
+ * @param simulation the simulation
+ */
public void addSimulation(VSSimulator simulation) {
simulation.setLayout(new GridLayout(1, 1, 3, 3));
simulation.setMinimumSize(new Dimension(0, 0));
@@ -327,6 +400,11 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener {
}
}
+ /**
+ * Removes the simulation.
+ *
+ * @param simulationToRemove the simulation to remove
+ */
public void removeSimulation(VSSimulator simulationToRemove) {
if (simulations.size() == 1) {
dispose();
@@ -338,14 +416,30 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener {
}
}
+ /**
+ * Removes the current simulation.
+ */
private void removeCurrentSimulation() {
removeSimulation(currentSimulation);
}
+ /**
+ * Gets the current simulation.
+ *
+ * @return the current simulation
+ */
public VSSimulator getCurrentSimulation() {
return currentSimulation;
}
+ /**
+ * Gets the image icon.
+ *
+ * @param name the name
+ * @param descr the descr
+ *
+ * @return the image icon
+ */
private ImageIcon getImageIcon(String name, String descr) {
java.net.URL imageURL = getClass().getResource("/icons/"+name);
diff --git a/sources/utils/VSClassLoader.java b/sources/utils/VSClassLoader.java
index 3091fec..8d4f784 100644
--- a/sources/utils/VSClassLoader.java
+++ b/sources/utils/VSClassLoader.java
@@ -1,8 +1,24 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package utils;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSClassLoader.
+ */
public class VSClassLoader extends ClassLoader {
+
+ /**
+ * New instance.
+ *
+ * @param classname the classname
+ *
+ * @return the object
+ */
public Object newInstance(String classname) {
Object object = null;
diff --git a/sources/utils/VSFrame.java b/sources/utils/VSFrame.java
index 608011b..ad2b54c 100644
--- a/sources/utils/VSFrame.java
+++ b/sources/utils/VSFrame.java
@@ -1,30 +1,65 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package utils;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSFrame.
+ */
public class VSFrame extends JFrame {
+
+ /** The Constant X_LOCATION_OFFSET. */
private final static int X_LOCATION_OFFSET = 40;
+
+ /** The Constant Y_LOCATION_OFFSET. */
private final static int Y_LOCATION_OFFSET = 80;
+
+ /** The parent. */
private Component parent;
+
+ /** The dispose. */
private boolean dispose;
+ /**
+ * Instantiates a new vS frame.
+ *
+ * @param title the title
+ * @param parent the parent
+ */
public VSFrame(String title, Component parent) {
super(title);
init(parent);
}
+ /**
+ * Instantiates a new vS frame.
+ *
+ * @param title the title
+ */
public VSFrame(String title) {
super(title);
init(null);
}
+ /**
+ * Inits the.
+ *
+ * @param parent the parent
+ */
private void init(Component parent) {
this.parent = parent;
this.dispose = false;
}
+ /**
+ * Dispose with parent.
+ */
public void disposeWithParent() {
if (!dispose && parent != null && parent instanceof Window) {
Window window = (Window) parent;
@@ -37,6 +72,9 @@ public class VSFrame extends JFrame {
dispose = true;
}
+ /**
+ * Sets the correct location.
+ */
private void setCorrectLocation() {
int x = 0, y = 0;
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
@@ -62,6 +100,9 @@ public class VSFrame extends JFrame {
super.setLocation(x, y);
}
+ /* (non-Javadoc)
+ * @see java.awt.Window#setSize(int, int)
+ */
public void setSize(int width, int height) {
super.setSize(width, height);
setCorrectLocation();
diff --git a/sources/utils/VSInfoArea.java b/sources/utils/VSInfoArea.java
index c1afd42..241b8f8 100644
--- a/sources/utils/VSInfoArea.java
+++ b/sources/utils/VSInfoArea.java
@@ -1,19 +1,39 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package utils;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSInfoArea.
+ */
public class VSInfoArea extends JTextPane {
+
+ /**
+ * Instantiates a new vS info area.
+ */
public VSInfoArea() {
init();
}
+ /**
+ * Instantiates a new vS info area.
+ *
+ * @param text the text
+ */
public VSInfoArea(String text) {
setText(text);
init();
}
+ /**
+ * Inits the.
+ */
private void init() {
setOpaque(false);
setBorder(null);
diff --git a/sources/utils/VSPriorityQueue.java b/sources/utils/VSPriorityQueue.java
index dd46a6e..7458a54 100644
--- a/sources/utils/VSPriorityQueue.java
+++ b/sources/utils/VSPriorityQueue.java
@@ -1,8 +1,24 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package utils;
import java.util.PriorityQueue;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSPriorityQueue.
+ */
public final class VSPriorityQueue<T> extends PriorityQueue<T> {
+
+ /**
+ * Gets the.
+ *
+ * @param index the index
+ *
+ * @return the t
+ */
public T get(int index) {
int i = 0;
diff --git a/sources/utils/VSRandom.java b/sources/utils/VSRandom.java
index 4f23e7e..088da4f 100644
--- a/sources/utils/VSRandom.java
+++ b/sources/utils/VSRandom.java
@@ -1,16 +1,40 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package utils;
import java.util.Random;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSRandom.
+ */
public final class VSRandom extends Random {
+
+ /**
+ * Instantiates a new vS random.
+ *
+ * @param seedAdd the seed add
+ */
public VSRandom(long seedAdd) {
super(seedAdd*System.currentTimeMillis()+seedAdd);
}
+ /* (non-Javadoc)
+ * @see java.util.Random#nextInt()
+ */
public int nextInt() {
return Math.abs(super.nextInt());
}
+ /**
+ * Next long.
+ *
+ * @param mod the mod
+ *
+ * @return the long
+ */
public long nextLong(long mod) {
return Math.abs((super.nextLong() + System.currentTimeMillis()) % mod);
}
diff --git a/sources/utils/VSTools.java b/sources/utils/VSTools.java
index b1eab28..a6c34a0 100644
--- a/sources/utils/VSTools.java
+++ b/sources/utils/VSTools.java
@@ -1,7 +1,23 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package utils;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSTools.
+ */
public final class VSTools {
+
+ /**
+ * Gets the time string.
+ *
+ * @param time the time
+ *
+ * @return the time string
+ */
public static String getTimeString(long time) {
String ret = ""+time;
@@ -10,6 +26,14 @@ public final class VSTools {
return ret + "ms";
}
+
+ /**
+ * Gets the string time.
+ *
+ * @param string the string
+ *
+ * @return the string time
+ */
public static long getStringTime(String string) {
try {
/* Ignore the "ms" postfix */
diff --git a/sources/utils/VSTupel.java b/sources/utils/VSTupel.java
index f2c6f87..2fea87a 100644
--- a/sources/utils/VSTupel.java
+++ b/sources/utils/VSTupel.java
@@ -1,24 +1,60 @@
+/*
+ * VS is (c) 2008 by Paul C. Buetow
+ * vs@dev.buetow.org
+ */
package utils;
+// TODO: Auto-generated Javadoc
+/**
+ * The Class VSTupel.
+ */
public final class VSTupel<A,B,C> {
+
+ /** The a. */
private A a;
+
+ /** The b. */
private B b;
+
+ /** The c. */
private C c;
+ /**
+ * Instantiates a new vS tupel.
+ *
+ * @param a the a
+ * @param b the b
+ * @param c the c
+ */
public VSTupel(A a, B b, C c) {
this.a = a;
this.b = b;
this.c = c;
}
+ /**
+ * Gets the a.
+ *
+ * @return the a
+ */
public A getA() {
return a;
}
+ /**
+ * Gets the b.
+ *
+ * @return the b
+ */
public B getB() {
return b;
}
+ /**
+ * Gets the c.
+ *
+ * @return the c
+ */
public C getC() {
return c;
}