diff options
| author | Paul Buetow <paul@buetow.org> | 2008-06-11 09:48:10 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-06-11 09:48:10 +0000 |
| commit | 0e2e70d5a393024f3ae4a3a3560b4df51075000a (patch) | |
| tree | 27c659d282bec3508304d5fa80a34a1662185950 | |
| parent | 412a1ac0e6311fe39452ae41b6eada4ef17cce34 (diff) | |
More javadoc.
Several bugfixes.
New feauture: Boolean: sim.periodic
A lot of more which i forgot!
41 files changed, 696 insertions, 330 deletions
diff --git a/LaTeX/VERSION b/LaTeX/VERSION index df90c3c..9c283d5 100644 --- a/LaTeX/VERSION +++ b/LaTeX/VERSION @@ -1 +1 @@ -385 +UUID: diff --git a/LaTeX/chapters/titlepage.tex b/LaTeX/chapters/titlepage.tex index f0af26a..48b22f6 100644 --- a/LaTeX/chapters/titlepage.tex +++ b/LaTeX/chapters/titlepage.tex @@ -49,7 +49,7 @@ {\large Prof. Dr. rer. nat. Heinrich Fassbender} {durch\\[0.5cm]} - {\large\bfseries cand. Diplom-Inform. (FH) Paul C. B\"{u}tow\\[0.3cm] } + {\large\bfseries Cand. Inform. (FH) Paul C. B\"{u}tow\\[0.3cm] } {Matthiashofstr. 15\\} {D-52064 Aachen\\} \end{center} diff --git a/LaTeX/diplomarbeit.pdf b/LaTeX/diplomarbeit.pdf Binary files differindex 56a9ba8..81b3d66 100644 --- a/LaTeX/diplomarbeit.pdf +++ b/LaTeX/diplomarbeit.pdf diff --git a/Makefile b/Makefile deleted file mode 100644 index eb5d1f4..0000000 --- a/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -all: - ant compile -clean: - ant clean -test: - ant test -replace: - find ./sources -name '*.java' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \ - w .tmp" {} && mv -f .tmp {}' \; -stats: - find . -name \*.java | xargs wc -l @@ -1,4 +1,5 @@ Must do: + Color copy constructor in prefs.VSPrefs.copyColors Reliable Multicast Helper: Print warning if not activated protocol while doing a protocol request @@ -5,7 +5,6 @@ <property name="sources" location="sources" /> <property name="dist" location="dist" /> <property name="classes" location="classes" /> - <!-- <property name="contrib" location="contrib" /> --> <target name="init"> <tstamp /> @@ -52,7 +51,6 @@ <target name="testdist" depends="dist,rundist" /> <target name="test" depends="compile,run" /> - <target name="javadoc" description="Generate Javadocs"> <mkdir dir="${basedir}/javadoc/"/> <javadoc destdir="${basedir}/javadoc/"> diff --git a/docs/SERIALIZATION_NOTES.txt b/docs/SERIALIZATION_NOTES.txt index 99cd0fb..44ad0a4 100644 --- a/docs/SERIALIZATION_NOTES.txt +++ b/docs/SERIALIZATION_NOTES.txt @@ -1,5 +1,3 @@ -TODO: RESET BEFORE DESERIALIZATION - VSSerialize prefs(=VSPrefs).serialize writeObject(...) diff --git a/scripts/beforecommit.sh b/scripts/beforecommit.sh new file mode 100755 index 0000000..a06ee8f --- /dev/null +++ b/scripts/beforecommit.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# +# Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +./scripts/formatthecode.sh +./scripts/checklinelengths.sh + diff --git a/scripts/checklinelengths.sh b/scripts/checklinelengths.sh new file mode 100755 index 0000000..cf98cd8 --- /dev/null +++ b/scripts/checklinelengths.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# +# Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +MAXLEN=80 + +for i in `find ./sources -name \*.java | grep -v VSDefaultPrefs.java` +do + awk -v MAXLEN=$MAXLEN -v file=$i '{ + if (length > MAXLEN) + print file " line " NR " is " length " chars long " + }' $i +done diff --git a/scripts/formatthecode.sh b/scripts/formatthecode.sh new file mode 100755 index 0000000..5733c31 --- /dev/null +++ b/scripts/formatthecode.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# +# Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +find ./sources -name \*.java | xargs astyle --style=java --mode=java -n diff --git a/scripts/printstatistics.sh b/scripts/printstatistics.sh new file mode 100755 index 0000000..ca356b5 --- /dev/null +++ b/scripts/printstatistics.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# +# Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +find ./sources -name \*.java | xargs wc -l diff --git a/scripts/replaceastring.sh b/scripts/replaceastring.sh new file mode 100755 index 0000000..6b50b83 --- /dev/null +++ b/scripts/replaceastring.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# +# Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +FROM=$1 +INTO=$2 + +echo "Replaceing $FROM with $INTO" + +find ./sources -name \*.java -exec sh -c "sed -n 's/$FROM/$INTO/g; \ + w .tmp' {} && mv -f .tmp {}" \; diff --git a/sources/core/VSMessage.java b/sources/core/VSMessage.java index 99c5ce7..1f1ad5b 100644 --- a/sources/core/VSMessage.java +++ b/sources/core/VSMessage.java @@ -28,8 +28,8 @@ import events.*; import prefs.VSPrefs; /** - * This class represents a message which is send from one process to another - * process in the simulator. + * An object of this class represents a message which is sent from one process + * to another process in the simulator. * * @author Paul C. Buetow */ diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java index c1323e8..9ca04e6 100644 --- a/sources/core/VSTask.java +++ b/sources/core/VSTask.java @@ -99,7 +99,7 @@ public class VSTask implements Comparable, VSSerializable { * Instantiates a new task during a deserialization. * * @param serialize the serialize object - * @param process the object input stream + * @param objectInputStream The input stream */ public VSTask(VSSerialize serialize, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { @@ -154,11 +154,29 @@ public class VSTask implements Comparable, VSSerializable { } /** + * Checks if the task is using an "internal event". + * + * @return true, if the task is using an internal event + */ + public boolean hasInternalEvent() { + return event instanceof VSAbstractInternalEvent; + } + + /** + * Checks if the task should not get serialized. + * + * @return true, if the task should not get serialized + */ + public boolean hasNotSerializableEvent() { + return event instanceof VSNotSerializable; + } + + /** * Checks if the task is a message receive event. * * @return true, if it is a message receive event */ - public boolean isVSMessageReceiveEvent() { + public boolean hasMessageReceiveEvent() { return event instanceof VSMessageReceiveEvent; } @@ -167,7 +185,7 @@ public class VSTask implements Comparable, VSSerializable { * * @return true, if it is a process recover event */ - public boolean isProcessRecoverEvent() { + public boolean hasProcessRecoverEvent() { return event instanceof VSProcessRecoverEvent; } @@ -366,6 +384,13 @@ public class VSTask implements Comparable, VSSerializable { objectOutputStream.writeObject(new Boolean(false)); objectOutputStream.writeObject(new Integer(process.getProcessNum())); + + if (event.getClassname() == null) + event.init(process); + + if (VSSerialize.DEBUG) + System.out.println("Serializing: " + event.getClassname()); + objectOutputStream.writeObject(event.getClassname()); objectOutputStream.writeObject(new Integer(event.getID())); event.serialize(serialize, objectOutputStream); diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java index d4ee83c..471b54f 100644 --- a/sources/core/VSTaskManager.java +++ b/sources/core/VSTaskManager.java @@ -32,10 +32,9 @@ import simulator.*; import utils.*; /** - * The class VSTaskManager. The task manager is responsible that all tasks - * will get fullfilled in the correct order. Please also read the javadoc - * of the VSTask class. It describes the difference between local and global - * timed tasks. + * The class VSTaskManager, it is responsible that all tasks will get + * fullfilled in the correct order. Please also read the javadoc of the VSTask + * class. It describes the difference between local and global timed tasks. * * @author Paul C. Buetow */ @@ -125,7 +124,7 @@ public class VSTaskManager implements VSSerializable { globalTasks.poll(); redo = true; - if (process.isCrashed() && !task.isProcessRecoverEvent()) { + if (process.isCrashed() && !task.hasProcessRecoverEvent()) { if (task.isProgrammed()) fullfilledProgrammedTasks.add(task); continue; @@ -186,7 +185,7 @@ public class VSTaskManager implements VSSerializable { redo = true; if (process.isCrashed() && - !task.isProcessRecoverEvent()) { + !task.hasProcessRecoverEvent()) { if (task.isProgrammed()) fullfilledProgrammedTasks.add(task); continue; @@ -506,28 +505,34 @@ public class VSTaskManager implements VSSerializable { /** For later backwards compatibility, to add more stuff */ objectOutputStream.writeObject(new Boolean(false)); - ArrayList<VSTask> tasks = new ArrayList<VSTask>(); + ArrayList<VSTask> serializeThoseTasks = new ArrayList<VSTask>(); - for (VSTask task : fullfilledProgrammedTasks) - tasks.add(task); + for (VSTask task : fullfilledProgrammedTasks) { + if (!task.hasNotSerializableEvent()) + serializeThoseTasks.add(task); + } - for (VSTask task : this.globalTasks) - tasks.add(task); + for (VSTask task : globalTasks) { + if (!task.hasNotSerializableEvent()) + serializeThoseTasks.add(task); + } ArrayList<VSProcess> processes = simulatorCanvas.getProcesses(); synchronized (processes) { for (VSProcess process : processes) { VSPriorityQueue<VSTask> localTasks = process.getTasks(); - ArrayList<VSTask> tasks_ = new ArrayList<VSTask>(); - for (VSTask task : localTasks) - tasks.add(task); + for (VSTask task : localTasks) { + if (!task.hasNotSerializableEvent()) + serializeThoseTasks.add(task); + } } } - objectOutputStream.writeObject(new Integer(tasks.size())); - for (VSTask task : tasks) - task.serialize(serialize, objectOutputStream); + objectOutputStream.writeObject( + new Integer(serializeThoseTasks.size())); + for (VSTask task : serializeThoseTasks) + task.serialize(serialize, objectOutputStream); /** For later backwards compatibility, to add more stuff */ objectOutputStream.writeObject(new Boolean(false)); diff --git a/sources/core/time/VSLamportTime.java b/sources/core/time/VSLamportTime.java index aab598a..165adfc 100644 --- a/sources/core/time/VSLamportTime.java +++ b/sources/core/time/VSLamportTime.java @@ -24,8 +24,7 @@ package core.time; /** - * The class VSLamportTime. This class defined how the lamport - * timestamps are represented. + * The class VSLamportTime, defines how the lamport timestamps are represented. * * @author Paul C. Buetow */ diff --git a/sources/core/time/VSVectorTime.java b/sources/core/time/VSVectorTime.java index 1c30af6..ebd5438 100644 --- a/sources/core/time/VSVectorTime.java +++ b/sources/core/time/VSVectorTime.java @@ -26,8 +26,7 @@ package core.time; import java.util.ArrayList; /** - * The class VSVectorTime. This class defined how the vector - * timestamps are represented. + * The class VSVectorTime, defined how the vector timestamps are represented. * * @author Paul C. Buetow */ diff --git a/sources/events/internal/VSAbstractInternalEvent.java b/sources/events/internal/VSAbstractInternalEvent.java new file mode 100644 index 0000000..10a23b7 --- /dev/null +++ b/sources/events/internal/VSAbstractInternalEvent.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * All icons of the icons/ folder are under a Creative Commons + * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa. + * + * The icon's homepage is http://code.google.com/p/ultimate-gnome/ + */ + +package events.internal; + +import java.io.*; + +import events.VSAbstractEvent; +import serialize.VSSerialize; + +/** + * The class VSAbstractInternalEvent, this class if for destinguishing between + * internal and non-internal events. Internal usage only. + * + * @author Paul C. Buetow + */ +abstract public class VSAbstractInternalEvent extends VSAbstractEvent { + /** The serial version uid */ + private static final long serialVersionUID = 1L; + + /* (non-Javadoc) + * @see serialize.VSSerializable#serialize(serialize.VSSerialize, + * java.io.ObjectOutputStream) + */ + public synchronized void serialize(VSSerialize serialize, + ObjectOutputStream objectOutputStream) + throws IOException { + super.serialize(serialize, objectOutputStream); + + /** For later backwards compatibility, to add more stuff */ + objectOutputStream.writeObject(new Boolean(false)); + + /** For later backwards compatibility, to add more stuff */ + objectOutputStream.writeObject(new Boolean(false)); + } + + /* (non-Javadoc) + * @see serialize.VSSerializable#deserialize(serialize.VSSerialize, + * java.io.ObjectInputStream) + */ + @SuppressWarnings("unchecked") + public synchronized void deserialize(VSSerialize serialize, + ObjectInputStream objectInputStream) + throws IOException, ClassNotFoundException { + super.deserialize(serialize, objectInputStream); + + if (VSSerialize.DEBUG) + System.out.println("Deserializing: VSAbstractInternalEvent"); + + /** For later backwards compatibility, to add more stuff */ + objectInputStream.readObject(); + + } +} diff --git a/sources/events/internal/VSMessageReceiveEvent.java b/sources/events/internal/VSMessageReceiveEvent.java index 8972ce5..072c2d6 100644 --- a/sources/events/internal/VSMessageReceiveEvent.java +++ b/sources/events/internal/VSMessageReceiveEvent.java @@ -26,9 +26,8 @@ package events.internal; import java.io.*; import core.VSMessage; -import events.VSAbstractEvent; import protocols.VSAbstractProtocol; -import serialize.VSSerialize; +import serialize.VSNotSerializable; /** * The class VSMessageReceiveEvent. This event is used if a process receives @@ -36,7 +35,8 @@ import serialize.VSSerialize; * * @author Paul C. Buetow */ -public class VSMessageReceiveEvent extends VSAbstractEvent { +public class VSMessageReceiveEvent extends VSAbstractInternalEvent +implements VSNotSerializable { /** The serioal version uid */ private static final long serialVersionUID = 1L; @@ -109,41 +109,4 @@ public class VSMessageReceiveEvent extends VSAbstractEvent { return true; } - - /* (non-Javadoc) - * @see serialize.VSSerializable#serialize(serialize.VSSerialize, - * java.io.ObjectOutputStream) - */ - public synchronized void serialize(VSSerialize serialize, - ObjectOutputStream objectOutputStream) - throws IOException { - super.serialize(serialize, objectOutputStream); - - /** For later backwards compatibility, to add more stuff */ - objectOutputStream.writeObject(new Boolean(false)); - - /** For later backwards compatibility, to add more stuff */ - objectOutputStream.writeObject(new Boolean(false)); - } - - /* (non-Javadoc) - * @see serialize.VSSerializable#deserialize(serialize.VSSerialize, - * java.io.ObjectInputStream) - */ - @SuppressWarnings("unchecked") - public synchronized void deserialize(VSSerialize serialize, - ObjectInputStream objectInputStream) - throws IOException, ClassNotFoundException { - super.deserialize(serialize, objectInputStream); - - if (VSSerialize.DEBUG) - System.out.println("Deserializing: VSProtocolEvent"); - - /** For later backwards compatibility, to add more stuff */ - objectInputStream.readObject(); - - /** For later backwards compatibility, to add more stuff */ - objectInputStream.readObject(); - - } } diff --git a/sources/events/internal/VSProtocolEvent.java b/sources/events/internal/VSProtocolEvent.java index 8d6b2dd..ba110c0 100644 --- a/sources/events/internal/VSProtocolEvent.java +++ b/sources/events/internal/VSProtocolEvent.java @@ -30,7 +30,7 @@ import protocols.VSAbstractProtocol; import serialize.VSSerialize; /** - * The class VSProtocolEvent. This event is used if a protocol (server or + * The class VSProtocolEvent, this event is used if a protocol (server or * client part) of a process gets enabled or disabled, an object of this class * can be for 4 different purporses! Activation of the client protocol, * deactivation of the client protocol, activation of the server protocol, @@ -38,7 +38,7 @@ import serialize.VSSerialize; * * @author Paul C. Buetow */ -public class VSProtocolEvent extends VSAbstractEvent { +public class VSProtocolEvent extends VSAbstractInternalEvent { /** The serial version uid */ private static final long serialVersionUID = 1L; diff --git a/sources/events/internal/VSProtocolScheduleEvent.java b/sources/events/internal/VSProtocolScheduleEvent.java index 99ae020..3c334be 100644 --- a/sources/events/internal/VSProtocolScheduleEvent.java +++ b/sources/events/internal/VSProtocolScheduleEvent.java @@ -27,16 +27,17 @@ import java.io.*; import events.*; import protocols.VSAbstractProtocol; -import serialize.VSSerialize; +import serialize.*; /** - * The class VSProtocolScheduleEvent. This event is used if a protocol (which + * The class VSProtocolScheduleEvent, this event is used if a protocol (which * is a subclass of VSAbstractProtocol) reschedules itself to run again on a * specific time. * * @author Paul C. Buetow */ -public class VSProtocolScheduleEvent extends VSAbstractEvent { +public class VSProtocolScheduleEvent extends VSAbstractInternalEvent +implements VSNotSerializable { /** The serial version uid */ private static final long serialVersionUID = 1L; diff --git a/sources/prefs/2DOCUMENT b/sources/prefs/2DOCUMENT deleted file mode 100644 index e69de29..0000000 --- a/sources/prefs/2DOCUMENT +++ /dev/null diff --git a/sources/prefs/VSDefaultPrefs.java b/sources/prefs/VSDefaultPrefs.java index bbf3c5f..e8ac8b5 100644 --- a/sources/prefs/VSDefaultPrefs.java +++ b/sources/prefs/VSDefaultPrefs.java @@ -27,9 +27,14 @@ import java.awt.Color; import java.awt.event.KeyEvent; /** - * The class VSDefaultPrefs. + * The class VSDefaultPrefs, makes sure that the simulator has its default + * configuration values. (Btw: This is the only class which is allowed to have + * code lines which are longer than 80 chars!) + * + * @author Paul C. Buetow */ public class VSDefaultPrefs extends VSPrefs { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** @@ -256,5 +261,6 @@ public class VSDefaultPrefs extends VSPrefs { initBoolean("sim.message.own.recv", false, "Prozesse empfangen eigene Nachrichten"); initBoolean("sim.message.prob.mean", true, "Mittelwerte der Nachrichtausfallw'k. bilden"); initBoolean("sim.messages.relevant", true, "Nur alle relevanten Nachrichten ausliefern"); + initBoolean("sim.periodic", false, "Simulation periodisch wiederholen"); } } diff --git a/sources/prefs/VSPrefs.java b/sources/prefs/VSPrefs.java index f17732c..e9ede88 100644 --- a/sources/prefs/VSPrefs.java +++ b/sources/prefs/VSPrefs.java @@ -30,7 +30,10 @@ import java.util.*; import serialize.*; /** - * The class VSPrefs. + * The class VSPrefs, this class is for dynamic data storage. It can hold + * various different types such as Boolean, Floats, Integers, Strings, Colors. + * + * @author Paul C. Buetow */ public class VSPrefs implements VSSerializable { /** The Constant BOOLEAN_PREFIX. */ @@ -90,9 +93,6 @@ public class VSPrefs implements VSSerializable { /** 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 int idCounter; @@ -201,7 +201,8 @@ public class VSPrefs implements VSSerializable { * @param key the key * @param settingRestriction the setting restriction */ - public synchronized void initRestriction(String key, VSPrefsRestriction settingRestriction) { + public synchronized void initRestriction(String key, + VSPrefsRestriction settingRestriction) { restrictions.put(key, settingRestriction); } @@ -589,7 +590,8 @@ public class VSPrefs implements VSSerializable { * @param descr the descr * @param r the restriction */ - public void initInteger(String key, int val, String descr, VSPrefsRestriction.VSIntegerPrefRestriction r) { + public void initInteger(String key, int val, String descr, + VSPrefsRestriction.VSIntegerPrefsRestriction r) { initInteger(key, val, descr); initRestriction(INTEGER_PREFIX + key, r); } @@ -602,7 +604,9 @@ public class VSPrefs implements VSSerializable { * @param descr the descr * @param r the restriction */ - public void initInteger(String key, int val, String descr, VSPrefsRestriction.VSIntegerPrefRestriction r, String unit) { + public void initInteger(String key, int val, String descr, + VSPrefsRestriction.VSIntegerPrefsRestriction r, + String unit) { initInteger(key, val, descr, r); initUnit(INTEGER_PREFIX + key, unit); } @@ -616,9 +620,11 @@ public class VSPrefs implements VSSerializable { * @param minValue the min value * @param maxValue the max value */ - public void initInteger(String key, int val, String descr, int minValue, int maxValue) { + public void initInteger(String key, int val, String descr, int minValue, + int maxValue) { initInteger(key, val, descr, - new VSPrefsRestriction.VSIntegerPrefRestriction(minValue, maxValue)); + new VSPrefsRestriction.VSIntegerPrefsRestriction( + minValue, maxValue)); } /** @@ -631,7 +637,8 @@ public class VSPrefs implements VSSerializable { * @param maxValue the max value * @param unit the unit */ - public void initInteger(String key, int val, String descr, int minValue, int maxValue, String unit) { + public void initInteger(String key, int val, String descr, int minValue, + int maxValue, String unit) { initInteger(key, val, descr, minValue, maxValue); initUnit(INTEGER_PREFIX + key, unit); } @@ -716,7 +723,8 @@ public class VSPrefs implements VSSerializable { * @param val the val * @param descr the descr */ - public void initVector(String key, Vector<Integer> val, String descr, String unit) { + public void initVector(String key, Vector<Integer> val, String descr, + String unit) { initVector(key, val, descr); initUnit(VECTOR_PREFIX + key, unit); } @@ -932,11 +940,6 @@ public class VSPrefs implements VSSerializable { */ public void fillWithDefaults() {} - @SuppressWarnings("unchecked") - public synchronized void readObject(ObjectInputStream objectInputStream) - throws IOException, ClassNotFoundException { - } - /* (non-Javadoc) * @see serialize.VSSerializable#serialize(serialize.VSSerialize, * java.io.ObjectOutputStream) @@ -974,16 +977,23 @@ public class VSPrefs implements VSSerializable { /** For later backwards compatibility, to add more stuff */ objectInputStream.readObject(); - booleanPrefs = (HashMap<String,Boolean>) objectInputStream.readObject(); - colorPrefs = (HashMap<String,Color>) objectInputStream.readObject(); + booleanPrefs = (HashMap<String,Boolean>) + objectInputStream.readObject(); + colorPrefs = (HashMap<String,Color>) + objectInputStream.readObject(); descriptionPrefs = (HashMap<String,String>) objectInputStream.readObject(); - floatPrefs = (HashMap<String,Float>) objectInputStream.readObject(); - integerPrefs = (HashMap<String,Integer>) objectInputStream.readObject(); - longPrefs = (HashMap<String,Long>) objectInputStream.readObject(); + floatPrefs = (HashMap<String,Float>) + objectInputStream.readObject(); + integerPrefs = (HashMap<String,Integer>) + objectInputStream.readObject(); + longPrefs = (HashMap<String,Long>) + objectInputStream.readObject(); restrictions = new HashMap<String,VSPrefsRestriction>(); - stringPrefs = (HashMap<String,String>) objectInputStream.readObject(); - units = (HashMap<String,String>) objectInputStream.readObject(); + stringPrefs = (HashMap<String,String>) + objectInputStream.readObject(); + units = (HashMap<String,String>) + objectInputStream.readObject(); vectorPrefs = (HashMap<String,Vector<Integer>>) objectInputStream.readObject(); @@ -992,7 +1002,7 @@ public class VSPrefs implements VSSerializable { } /** - * Copy integers. + * Copies integers into another VSPrefs object. * * @param copyInto the copy into * @param keys the keys @@ -1002,13 +1012,13 @@ public class VSPrefs implements VSSerializable { copyInto.initInteger(key, getInteger(key), getDescription(INTEGER_PREFIX + key), - (VSPrefsRestriction.VSIntegerPrefRestriction) + (VSPrefsRestriction.VSIntegerPrefsRestriction) getRestriction(INTEGER_PREFIX + key), getUnit(INTEGER_PREFIX + key)); } /** - * Copy longs. + * Copies longs into another VSPrefs object. * * @param copyInto the copy into * @param keys the keys @@ -1021,7 +1031,7 @@ public class VSPrefs implements VSSerializable { } /** - * Copy floats. + * Copies floats into another VSPrefs object. * * @param copyInto the copy into * @param keys the keys @@ -1034,7 +1044,7 @@ public class VSPrefs implements VSSerializable { } /** - * Copy strings. + * Copies strings into another VSPrefs object. * * @param copyInto the copy into * @param keys the keys @@ -1046,7 +1056,7 @@ public class VSPrefs implements VSSerializable { } /** - * Copy colors. + * Copies color references into another VSPrefs object. * * @param copyInto the copy into * @param keys the keys @@ -1058,7 +1068,7 @@ public class VSPrefs implements VSSerializable { } /** - * Copy colors. + * Copies colors. * * @param copyInto the copy into * @param keys the keys @@ -1135,9 +1145,9 @@ public class VSPrefs implements VSSerializable { } /** - * Checks if is empty. + * Checks if the prefs are empty. * - * @return true, if is empty + * @return true, if empty */ public boolean isEmpty() { if (!colorPrefs.isEmpty()) @@ -1165,9 +1175,9 @@ public class VSPrefs implements VSSerializable { } /** - * Return all full keys + * Returns all full keys. * - * @return Allf ull keys + * @return All full keys */ public ArrayList<String> getAllFullKeys() { ArrayList<String> allKeys = new ArrayList<String>(); diff --git a/sources/prefs/VSPrefsRestriction.java b/sources/prefs/VSPrefsRestriction.java index 5a716bd..f66246c 100644 --- a/sources/prefs/VSPrefsRestriction.java +++ b/sources/prefs/VSPrefsRestriction.java @@ -33,9 +33,9 @@ public class VSPrefsRestriction implements Serializable { private static final long serialVersionUID = 1L; /** - * The class VSIntegerPrefRestriction. + * The class VSIntegerPrefsRestriction. */ - public static class VSIntegerPrefRestriction extends VSPrefsRestriction { + public static class VSIntegerPrefsRestriction extends VSPrefsRestriction { private static final long serialVersionUID = 1L; /** The min value. */ private int minValue; @@ -49,7 +49,7 @@ public class VSPrefsRestriction implements Serializable { * @param minValue the min value * @param maxValue the max value */ - public VSIntegerPrefRestriction(int minValue, int maxValue) { + public VSIntegerPrefsRestriction(int minValue, int maxValue) { this.minValue = minValue; this.maxValue = maxValue; } diff --git a/sources/prefs/editors/2DOCUMENT b/sources/prefs/editors/2DOCUMENT deleted file mode 100644 index e69de29..0000000 --- a/sources/prefs/editors/2DOCUMENT +++ /dev/null diff --git a/sources/prefs/editors/VSAbstractBetterEditor.java b/sources/prefs/editors/VSAbstractBetterEditor.java index 47ae1a7..8779e56 100644 --- a/sources/prefs/editors/VSAbstractBetterEditor.java +++ b/sources/prefs/editors/VSAbstractBetterEditor.java @@ -30,11 +30,13 @@ import javax.swing.*; import prefs.*; import utils.*; -// TODO: Auto-generated Javadoc /** - * The class VSAbstractBetterEditor. + * The class VSAbstractBetterEditor, is an improved VSAbstractEditor. + * + * @author Paul C. Buetow */ public abstract class VSAbstractBetterEditor extends VSAbstractEditor { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** The content pane. */ @@ -47,13 +49,14 @@ public abstract class VSAbstractBetterEditor extends VSAbstractEditor { private String title; /** - * Instantiates a new lang.process.removebetter editor. + * An simple constructor. * * @param prefs the prefs * @param prefsToEdit the prefs to edit * @param title the title */ - public VSAbstractBetterEditor(VSPrefs prefs, VSPrefs prefsToEdit, String title) { + public VSAbstractBetterEditor(VSPrefs prefs, VSPrefs prefsToEdit, + String title) { super(prefs, prefsToEdit); this.title = title; this.contentPane = createContentPane(); @@ -100,12 +103,14 @@ public abstract class VSAbstractBetterEditor extends VSAbstractEditor { } /* (non-Javadoc) - * @see prefs.editors.VSAbstractEditor#addToButtonPanelFront(javax.swing.JPanel) + * @see prefs.editors.VSAbstractEditor#addToButtonPanelFront( + * javax.swing.JPanel) */ protected void addToButtonPanelFront(JPanel buttonPanel) { } /* (non-Javadoc) - * @see prefs.editors.VSAbstractEditor#addToButtonPanelLast(javax.swing.JPanel) + * @see prefs.editors.VSAbstractEditor#addToButtonPanelLast( + * javax.swing.JPanel) */ protected void addToButtonPanelLast(JPanel buttonPanel) { } @@ -115,11 +120,11 @@ public abstract class VSAbstractBetterEditor extends VSAbstractEditor { protected void addToEditTableLast() { } /* (non-Javadoc) - * @see prefs.editors.VSAbstractEditor#actionPerformed(java.awt.event.ActionEvent) + * @see prefs.editors.VSAbstractEditor#actionPerformed( + * java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { //String actionCommand = e.getActionCommand(); - /* More action in the super class!!! */ super.actionPerformed(e); } diff --git a/sources/prefs/editors/VSAbstractEditor.java b/sources/prefs/editors/VSAbstractEditor.java index f4d913a..a3f5fe3 100644 --- a/sources/prefs/editors/VSAbstractEditor.java +++ b/sources/prefs/editors/VSAbstractEditor.java @@ -31,11 +31,14 @@ import java.util.*; import utils.*; import prefs.*; -// TODO: Auto-generated Javadoc /** - * The class VSAbstractEditor. + * The class VSAbstractEditor, an object of this class is used in order to + * edit a VSPrefs object. + * + * @author Paul C. Buetow */ public abstract class VSAbstractEditor implements ActionListener { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** The boolean keys. */ @@ -117,7 +120,7 @@ public abstract class VSAbstractEditor implements ActionListener { public static final int SIMULATION_PREFERENCES = 1; /** - * Instantiates a new lang.process.removeeditor. + * The standard constructor. * * @param prefs the prefs * @param prefsToEdit the prefs to edit @@ -127,14 +130,14 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Adds the to button panel front. + * Adds components to the front of the button panel . * * @param buttonPanel the button panel */ abstract protected void addToButtonPanelFront(JPanel buttonPanel); /** - * Adds the to button panel last. + * Adds components to last of the button panel. * * @param buttonPanel the button panel */ @@ -146,7 +149,7 @@ public abstract class VSAbstractEditor implements ActionListener { abstract protected void addToEditTableLast(); /** - * Sets the prefs. + * Sets the default prefs. * * @param prefs the new prefs */ @@ -164,7 +167,7 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Sets the frame. + * Sets the frame being used by the editor, if any. * * @param frame the new frame */ @@ -182,7 +185,8 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Dispose frame if exists. + * The given editors frame will get disposed if the "OK" button has been + * pressed. This can only happen if the editor has its own frame. */ protected void disposeFrameIfExists() { if (frame != null) @@ -190,7 +194,8 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Dispose frame with parent if exists. + * The given editors frame will get disposed if its parent component + * disposes. This can only happen if the editor has its own frame. */ protected void disposeFrameWithParentIfExists() { if (frame != null) @@ -198,7 +203,7 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Inits the. + * Inits the editor. * * @param prefs the prefs * @param prefsToEdit the prefs to edit @@ -232,11 +237,11 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Filter keys. + * Filters out all keys to edit. * - * @param set the set + * @param set the set which contains all keys of a given hash * - * @return the array list< string> + * @return the filtered keys */ private ArrayList<String> filterKeys(Set<String> set) { ArrayList<String> filtered = new ArrayList<String>(); @@ -257,7 +262,7 @@ public abstract class VSAbstractEditor implements ActionListener { /** * Creates the button panel. * - * @return the j panel + * @return the panel */ private JPanel createButtonPanel() { JPanel buttonPanel = new JPanel(); @@ -281,9 +286,10 @@ public abstract class VSAbstractEditor implements ActionListener { * @param comp the comp * @param key the key * - * @return the j panel + * @return the panel */ - private JPanel createUnitPanel(VSPrefs prefsToEdit, Component comp, String fullKey) { + private JPanel createUnitPanel(VSPrefs prefsToEdit, Component comp, + String fullKey) { JPanel unitPanel = new JPanel(new GridBagLayout()); unitPanel.setBackground(Color.WHITE); unitPanel.setBorder(null); @@ -307,7 +313,7 @@ public abstract class VSAbstractEditor implements ActionListener { /** * Creates the edit panel. * - * @return the j panel + * @return the panel */ private JPanel createEditPanel() { JPanel editPanel = new JPanel(); @@ -328,20 +334,24 @@ public abstract class VSAbstractEditor implements ActionListener { * @param key the key * @param prefsToEdit the prefs to edit * - * @return the lang.process.removetupel< string, component, j combo box> + * @return the tupel representing the component */ - protected VSTupel<String,Component,JComboBox> createIntegerComponent(String fullKey, String key, VSPrefs prefsToEdit) { + protected VSTupel<String,Component,JComboBox> createIntegerComponent( + String fullKey, String key, VSPrefs prefsToEdit) { String descr = prefsToEdit.getDescription(fullKey); String label = descr == null ? fullKey : descr; Integer integer = prefsToEdit.getInteger(key); Integer initialSelection[] = { integer }; JComboBox valComboBox = new JComboBox(initialSelection); - VSPrefsRestriction settingRestriction = prefsToEdit.getRestriction(fullKey); + VSPrefsRestriction settingRestriction = + prefsToEdit.getRestriction(fullKey); int minValue, maxValue; if (settingRestriction != null) { - VSPrefsRestriction.VSIntegerPrefRestriction integerVSPrefsRestriction = - (VSPrefsRestriction.VSIntegerPrefRestriction) settingRestriction; + VSPrefsRestriction.VSIntegerPrefsRestriction + integerVSPrefsRestriction = + (VSPrefsRestriction.VSIntegerPrefsRestriction) + settingRestriction; minValue = integerVSPrefsRestriction.getMinValue(); maxValue = integerVSPrefsRestriction.getMaxValue(); @@ -355,7 +365,8 @@ public abstract class VSAbstractEditor implements ActionListener { valComboBox.setBorder(null); return new VSTupel<String,Component,JComboBox>(label, - createUnitPanel(prefsToEdit, valComboBox, fullKey), valComboBox); + createUnitPanel(prefsToEdit, valComboBox, fullKey), + valComboBox); } /** @@ -364,8 +375,11 @@ public abstract class VSAbstractEditor implements ActionListener { * @param fullKey the full key * @param key the key * @param prefsToEdit the prefs to edit + * + * @return the tupel representing the component */ - protected VSTupel<String,Component,JTextField> createVectorComponent(String fullKey, String key, VSPrefs prefsToEdit) { + protected VSTupel<String,Component,JTextField> createVectorComponent( + String fullKey, String key, VSPrefs prefsToEdit) { String descr = prefsToEdit.getDescription(fullKey); String label = descr == null ? fullKey : descr; @@ -385,11 +399,13 @@ public abstract class VSAbstractEditor implements ActionListener { * @param key the key * @param prefsToEdit the prefs to edit */ - protected VSTupel<String,Component,JCheckBox> createBooleanComponent(String fullKey, String key, VSPrefs prefsToEdit) { + protected VSTupel<String,Component,JCheckBox> createBooleanComponent( + String fullKey, String key, VSPrefs prefsToEdit) { final String activated = prefs.getString("lang.activated"); String descr = prefsToEdit.getDescription(fullKey); String label = descr == null ? fullKey : descr; - JCheckBox valField = new JCheckBox(activated, prefsToEdit.getBoolean(key)); + JCheckBox valField = new JCheckBox(activated, + prefsToEdit.getBoolean(key)); valField.setBackground(Color.WHITE); valField.setBorder(null); return new VSTupel<String,Component,JCheckBox>(label, @@ -403,9 +419,10 @@ public abstract class VSAbstractEditor implements ActionListener { * @param key the key * @param prefsToEdit the prefs to edit * - * @return the lang.process.removetupel< string, component, j text field> + * @return the tupel representing the component */ - protected VSTupel<String,Component,JTextField> createLongComponent(String fullKey, String key, VSPrefs prefsToEdit) { + protected VSTupel<String,Component,JTextField> createLongComponent( + String fullKey, String key, VSPrefs prefsToEdit) { String descr = prefsToEdit.getDescription(fullKey); String label = descr == null ? fullKey : descr; JTextField valField = new JTextField(VALUE_FIELD_COLS); @@ -429,9 +446,10 @@ public abstract class VSAbstractEditor implements ActionListener { * @param key the key * @param prefsToEdit the prefs to edit * - * @return the lang.process.removetupel< string, component, j text field> + * @return the tupel representing the component */ - protected VSTupel<String,Component,JTextField> createFloatComponent(String fullKey, String key, VSPrefs prefsToEdit) { + protected VSTupel<String,Component,JTextField> createFloatComponent( + String fullKey, String key, VSPrefs prefsToEdit) { String descr = prefsToEdit.getDescription(fullKey); String label = descr == null ? fullKey : descr; JTextField valField = new JTextField(VALUE_FIELD_COLS); @@ -455,9 +473,10 @@ public abstract class VSAbstractEditor implements ActionListener { * @param key the key * @param prefsToEdit the prefs to edit * - * @return the lang.process.removetupel< string, component, j text field> + * @return the tupel representing the component */ - protected VSTupel<String,Component,JTextField> createColorComponent(String fullKey, String key, final VSPrefs prefsToEdit) { + protected VSTupel<String,Component,JTextField> createColorComponent( + String fullKey, String key, final VSPrefs prefsToEdit) { String descr = prefsToEdit.getDescription(fullKey); String label = descr == null ? fullKey : descr; final JTextField valField = new JTextField(VALUE_FIELD_COLS); @@ -477,7 +496,8 @@ public abstract class VSAbstractEditor implements ActionListener { "lang.colorchooser"),parentFrame); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - JComponent colorChooserPane = new VSColorChooser(prefs, valField); + JComponent colorChooserPane = new VSColorChooser(prefs, + valField); colorChooserPane.setOpaque(true); frame.setContentPane(colorChooserPane); @@ -497,9 +517,10 @@ public abstract class VSAbstractEditor implements ActionListener { * @param key the key * @param prefsToEdit the prefs to edit * - * @return the lang.process.removetupel< string, component, j text field> + * @return the tupel representing the component */ - protected VSTupel<String,Component,JTextField> createStringComponent(String fullKey, String key, VSPrefs prefsToEdit) { + protected VSTupel<String,Component,JTextField> createStringComponent( + String fullKey, String key, VSPrefs prefsToEdit) { String descr = prefsToEdit.getDescription(fullKey); String label = descr == null ? fullKey : descr; JTextField valField = new JTextField(VALUE_FIELD_COLS); @@ -517,7 +538,7 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Fill edit panel. + * Fills the edit panel. * * @param prefsToEdit the prefs to edit */ @@ -545,7 +566,8 @@ public abstract class VSAbstractEditor implements ActionListener { for (String key : booleanKeys) { String fullKey = VSPrefs.BOOLEAN_PREFIX + key; - VSTupel<String,Component,JCheckBox> tupel = createBooleanComponent(fullKey, key, prefsToEdit); + VSTupel<String,Component,JCheckBox> tupel = + createBooleanComponent(fullKey, key, prefsToEdit); labels.put(fullKey, tupel.getA()); components.put(fullKey, tupel.getB()); booleanFields.put(key, tupel.getC()); @@ -553,7 +575,8 @@ public abstract class VSAbstractEditor implements ActionListener { for (String key : longKeys) { String fullKey = VSPrefs.LONG_PREFIX + key; - VSTupel<String,Component,JTextField> tupel = createLongComponent(fullKey, key, prefsToEdit); + VSTupel<String,Component,JTextField> tupel = + createLongComponent(fullKey, key, prefsToEdit); labels.put(fullKey, tupel.getA()); components.put(fullKey, tupel.getB()); longFields.put(key, tupel.getC()); @@ -562,7 +585,8 @@ public abstract class VSAbstractEditor implements ActionListener { for (String key : floatKeys) { String fullKey = VSPrefs.FLOAT_PREFIX + key; - VSTupel<String,Component,JTextField> tupel = createFloatComponent(fullKey, key, prefsToEdit); + VSTupel<String,Component,JTextField> tupel = + createFloatComponent(fullKey, key, prefsToEdit); labels.put(fullKey, tupel.getA()); components.put(fullKey, tupel.getB()); floatFields.put(key, tupel.getC()); @@ -571,7 +595,8 @@ public abstract class VSAbstractEditor implements ActionListener { for (String key : colorKeys) { String fullKey = VSPrefs.COLOR_PREFIX + key; - VSTupel<String,Component,JTextField> tupel = createColorComponent(fullKey, key, prefsToEdit); + VSTupel<String,Component,JTextField> tupel = + createColorComponent(fullKey, key, prefsToEdit); labels.put(fullKey, tupel.getA()); components.put(fullKey, tupel.getB()); colorFields.put(key, tupel.getC()); @@ -579,7 +604,8 @@ public abstract class VSAbstractEditor implements ActionListener { for (String key : stringKeys) { String fullKey = VSPrefs.STRING_PREFIX + key; - VSTupel<String,Component,JTextField> tupel = createStringComponent(fullKey, key, prefsToEdit); + VSTupel<String,Component,JTextField> tupel = + createStringComponent(fullKey, key, prefsToEdit); labels.put(fullKey, tupel.getA()); components.put(fullKey, tupel.getB()); stringFields.put(key, tupel.getC()); @@ -597,7 +623,8 @@ public abstract class VSAbstractEditor implements ActionListener { flag = true; addSeparator(prefs.getString("lang.prefs.simulator")); } - addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); + addVariable(labels.get(fullKey), components.get(fullKey), + prefsToEdit); } } @@ -610,9 +637,11 @@ public abstract class VSAbstractEditor implements ActionListener { if (this instanceof VSProcessEditor) addSeparator(prefs.getString("lang.prefs.process")); else - addSeparator(prefs.getString("lang.prefs.process.defaults")); + addSeparator(prefs.getString( + "lang.prefs.process.defaults")); } - addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); + addVariable(labels.get(fullKey), components.get(fullKey), + prefsToEdit); } } @@ -623,11 +652,14 @@ public abstract class VSAbstractEditor implements ActionListener { if (!flag) { flag = true; if (this instanceof VSProcessEditor) - addSeparator(prefs.getString("lang.prefs.message")); + addSeparator(prefs.getString( + "lang.prefs.message")); else - addSeparator(prefs.getString("lang.prefs.message.defaults")); + addSeparator(prefs.getString( + "lang.prefs.message.defaults")); } - addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); + addVariable(labels.get(fullKey), components.get(fullKey), + prefsToEdit); } } @@ -639,7 +671,8 @@ public abstract class VSAbstractEditor implements ActionListener { flag = true; addSeparator(prefs.getString("lang.prefs.color")); } - addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); + addVariable(labels.get(fullKey), components.get(fullKey), + prefsToEdit); } } @@ -651,7 +684,8 @@ public abstract class VSAbstractEditor implements ActionListener { flag = true; addSeparator(prefs.getString("lang.prefs.diverse")); } - addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit); + addVariable(labels.get(fullKey), components.get(fullKey), + prefsToEdit); } } @@ -659,7 +693,18 @@ public abstract class VSAbstractEditor implements ActionListener { editTable.fireTableDataChanged(); } - private ArrayList<String> filterOut(Set<String> set, ArrayList<String> filter, String prefix) { + /** + * Filters out stuff. + * + * @param set The set to filter stuff out from + * @param filter Only return elemens of the filter which are in the set + * @param prefix The prefix to use + * + * @return The filtered keys + */ + private ArrayList<String> filterOut(Set<String> set, + ArrayList<String> filter, + String prefix) { ArrayList<String> ret = new ArrayList<String>(); for (String key : set) { @@ -672,25 +717,39 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Adds the to editor. + * Adds the to editor more variables. * * @param label the label * @param prefsKey the prefs key * @param prefsToAdd the prefs to add * @param addOnlyThisVariables only add variables which are in this list */ - protected void addToEditor(String label, String prefsKey, VSPrefs prefsToAdd, ArrayList<String> addOnlyThisVariables) { + protected void addToEditor(String label, String prefsKey, + VSPrefs prefsToAdd, + ArrayList<String> addOnlyThisVariables) { addSeparator(label); prefsKey = "(" + prefsKey + ")"; ArrayList<String> fullKeys = new ArrayList<String>(); - fullKeys.addAll(filterOut(prefsToAdd.getIntegerKeySet(), addOnlyThisVariables, VSPrefs.INTEGER_PREFIX)); - fullKeys.addAll(filterOut(prefsToAdd.getVectorKeySet(), addOnlyThisVariables, VSPrefs.VECTOR_PREFIX)); - fullKeys.addAll(filterOut(prefsToAdd.getFloatKeySet(), addOnlyThisVariables, VSPrefs.FLOAT_PREFIX)); - fullKeys.addAll(filterOut(prefsToAdd.getLongKeySet(), addOnlyThisVariables, VSPrefs.LONG_PREFIX)); - fullKeys.addAll(filterOut(prefsToAdd.getBooleanKeySet(), addOnlyThisVariables, VSPrefs.BOOLEAN_PREFIX)); - fullKeys.addAll(filterOut(prefsToAdd.getStringKeySet(), addOnlyThisVariables, VSPrefs.STRING_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getIntegerKeySet(), + addOnlyThisVariables, + VSPrefs.INTEGER_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getVectorKeySet(), + addOnlyThisVariables, + VSPrefs.VECTOR_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getFloatKeySet(), + addOnlyThisVariables, + VSPrefs.FLOAT_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getLongKeySet(), + addOnlyThisVariables, + VSPrefs.LONG_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getBooleanKeySet(), + addOnlyThisVariables, + VSPrefs.BOOLEAN_PREFIX)); + fullKeys.addAll(filterOut(prefsToAdd.getStringKeySet(), + addOnlyThisVariables, + VSPrefs.STRING_PREFIX)); Collections.sort(fullKeys); @@ -738,12 +797,11 @@ public abstract class VSAbstractEditor implements ActionListener { this.stringFields.put(prefsKey+key, tupel.getC()); addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd); } - } } /** - * Adds the separator. + * Adds a separator. * * @param label the label */ @@ -752,7 +810,7 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Adds the variable. + * Adds a variable. * * @param label the label * @param component the component @@ -763,14 +821,15 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Adds the variable. + * Adds a 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) { + private void addVariable(String prefsKey, String label, + Component component, VSPrefs prefs) { prefsToEditMap.put(prefsKey, prefs); editTable.addVariable(label, component); } @@ -787,7 +846,8 @@ public abstract class VSAbstractEditor implements ActionListener { for (String key : booleanKeys) { String keys[] = getKeys(key); JCheckBox valField = booleanFields.get(key); - valField.setSelected(prefsToEditMap.get(keys[1]).getBoolean(keys[0])); + valField.setSelected(prefsToEditMap.get( + keys[1]).getBoolean(keys[0])); } for (String key : vectorKeys) { @@ -811,7 +871,8 @@ public abstract class VSAbstractEditor implements ActionListener { for (String key : colorKeys) { String keys[] = getKeys(key); JTextField valField = colorFields.get(key); - valField.setBackground(prefsToEditMap.get(keys[1]).getColor(keys[0])); + valField.setBackground(prefsToEditMap.get( + keys[1]).getColor(keys[0])); } for (String key : stringKeys) { @@ -840,7 +901,7 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Save prefs. + * Saves the prefs. */ protected void savePrefs() { boolean expertMode = prefs.getBoolean("sim.mode.expert"); @@ -848,7 +909,9 @@ public abstract class VSAbstractEditor implements ActionListener { for (String key : integerKeys) { String keys[] = getKeys(key); JComboBox valComboBox = integerFields.get(key); - prefsToEditMap.get(keys[1]).setInteger(keys[0], (Integer) valComboBox.getSelectedItem()); + prefsToEditMap.get( + keys[1]).setInteger(keys[0], + (Integer) valComboBox.getSelectedItem()); } for (String key : vectorKeys) { @@ -862,13 +925,15 @@ public abstract class VSAbstractEditor implements ActionListener { } catch (exceptions.VSParseIntegerVectorException e) { } - valField.setText(""+prefsToEditMap.get(keys[1]).getVector(keys[0])); + valField.setText(""+ + prefsToEditMap.get(keys[1]).getVector(keys[0])); } for (String key : booleanKeys) { String keys[] = getKeys(key); JCheckBox valField = booleanFields.get(key); - prefsToEditMap.get(keys[1]).setBoolean(keys[0], valField.isSelected()); + prefsToEditMap.get(keys[1]).setBoolean( + keys[0], valField.isSelected()); } for (String key : floatKeys) { @@ -880,7 +945,8 @@ public abstract class VSAbstractEditor implements ActionListener { prefsToEditMap.get(keys[1]).setFloat(keys[0], val); } catch (NumberFormatException e) { - valField.setText(""+prefsToEditMap.get(keys[1]).getFloat(keys[0])); + valField.setText(""+ + prefsToEditMap.get(keys[1]).getFloat(keys[0])); } } @@ -893,14 +959,16 @@ public abstract class VSAbstractEditor implements ActionListener { prefsToEditMap.get(keys[1]).setLong(keys[0], val); } catch (NumberFormatException e) { - valField.setText(""+prefsToEditMap.get(keys[1]).getLong(keys[0])); + valField.setText(""+ + prefsToEditMap.get(keys[1]).getLong(keys[0])); } } for (String key : colorKeys) { String keys[] = getKeys(key); JTextField valField = colorFields.get(key); - prefsToEditMap.get(keys[1]).setColor(keys[0], valField.getBackground()); + prefsToEditMap.get(keys[1]).setColor( + keys[0], valField.getBackground()); } for (String key : stringKeys) { @@ -913,9 +981,9 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Expert mode changed. + * Check if the expert mode has changed. * - * @return true, if successful + * @return true, if it has changed. false, if it has not changed. */ public boolean expertModeChanged() { boolean ret = expertModeChanged; @@ -927,7 +995,8 @@ public abstract class VSAbstractEditor implements ActionListener { } /* (non-Javadoc) - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + * @see java.awt.event.ActionListener#actionPerformed( + * java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); @@ -941,18 +1010,18 @@ public abstract class VSAbstractEditor implements ActionListener { } /** - * Gets the edits the panel. + * Gets the edit panel * - * @return the edits the panel + * @return the edit panel */ public JPanel getEditPanel() { return editPanel; } /** - * Gets the edits the table. + * Gets the edit table * - * @return the edits the table + * @return the edit table */ public VSEditorTable getEditTable() { return editTable; diff --git a/sources/prefs/editors/VSColorChooser.java b/sources/prefs/editors/VSColorChooser.java index 0a66215..96aaf53 100644 --- a/sources/prefs/editors/VSColorChooser.java +++ b/sources/prefs/editors/VSColorChooser.java @@ -29,11 +29,13 @@ import javax.swing.event.*; import prefs.VSPrefs; -// TODO: Auto-generated Javadoc /** - * The class VSColorChooser. + * The class VSColorChooser, is for selecting a color within an editor. + * + * @author Paul C. Buetow */ public class VSColorChooser extends JPanel implements ChangeListener { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** The color chooser. */ @@ -45,18 +47,14 @@ public class VSColorChooser extends JPanel implements ChangeListener { /** The val field. */ private JTextField valField; - /** The prefs. */ - //private VSPrefs prefs; - /** - * Instantiates a new lang.process.removecolor chooser. + * Instantiates a new VSColorChooser object. * * @param prefs the prefs * @param valField the val field */ public VSColorChooser(VSPrefs prefs, JTextField valField) { super(new BorderLayout()); - //this.prefs = prefs; this.color = valField.getBackground(); this.valField = valField; @@ -69,7 +67,8 @@ public class VSColorChooser extends JPanel implements ChangeListener { } /* (non-Javadoc) - * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent) + * @see javax.swing.event.ChangeListener#stateChanged( + * javax.swing.event.ChangeEvent) */ public void stateChanged(ChangeEvent e) { Color newColor = colorChooser.getColor(); diff --git a/sources/prefs/editors/VSEditorFrame.java b/sources/prefs/editors/VSEditorFrame.java index bb81221..332c8a5 100644 --- a/sources/prefs/editors/VSEditorFrame.java +++ b/sources/prefs/editors/VSEditorFrame.java @@ -30,11 +30,14 @@ import javax.swing.*; import prefs.*; import utils.*; -// TODO: Auto-generated Javadoc /** - * The class VSEditorFrame. + * The class VSEditorFrame, this is a wrapper around an VSAbstractEditor + * object, which should be displayed in its own frame. + * + * @author Paul C. Buetow */ public class VSEditorFrame extends VSFrame implements ActionListener { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** The editor. */ @@ -44,13 +47,14 @@ public class VSEditorFrame extends VSFrame implements ActionListener { private VSPrefs prefs; /** - * Instantiates a new lang.process.removeeditor frame. + * Instantiates a new VSEditorFrame object. * * @param prefs the prefs * @param relativeTo the relative to * @param editor the editor */ - public VSEditorFrame(VSPrefs prefs, Component relativeTo, VSAbstractBetterEditor editor) { + public VSEditorFrame(VSPrefs prefs, Component relativeTo, + VSAbstractBetterEditor editor) { super(editor.getTitle(), relativeTo); this.prefs = prefs; this.editor = editor; @@ -58,7 +62,7 @@ public class VSEditorFrame extends VSFrame implements ActionListener { } /** - * Inits the. + * Inits the VSEditorFrame object. */ private void init() { editor.setFrame(this); @@ -72,7 +76,7 @@ public class VSEditorFrame extends VSFrame implements ActionListener { } /** - * Fill button panel. + * Fills the button panel. * * @param buttonPanel the button panel */ @@ -92,7 +96,8 @@ public class VSEditorFrame extends VSFrame implements ActionListener { } /* (non-Javadoc) - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + * @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 770ebdd..bb171dd 100644 --- a/sources/prefs/editors/VSEditorTable.java +++ b/sources/prefs/editors/VSEditorTable.java @@ -33,11 +33,14 @@ import javax.swing.text.*; import prefs.*; -// TODO: Auto-generated Javadoc /** - * The class VSEditorTable. + * The class VSEditorTable, each VSAbstractEditor uses an object of this class + * for displaying all editable items! + * + * @author Paul C. Buetow */ -public class VSEditorTable extends JTable { /* implements Serializable */ +public class VSEditorTable extends JTable { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** The Constant MIN_ROWS. */ @@ -55,7 +58,9 @@ public class VSEditorTable extends JTable { /* implements Serializable */ /** * The class VSNode. */ - private class VSNode implements Serializable { + private class VSNode { + /** The serial version uid */ + private static final long serialVersionUID = 1L; /** The key. */ private String key; @@ -64,7 +69,7 @@ public class VSEditorTable extends JTable { /* implements Serializable */ private Component comp; /** - * Instantiates a new lang.process.removenode. + * Instantiates a new VSNode object. * * @param key the key */ @@ -73,7 +78,7 @@ public class VSEditorTable extends JTable { /* implements Serializable */ } /** - * Instantiates a new lang.process.removenode. + * Instantiates a new VSNode object. * * @param key the key * @param comp the comp @@ -111,43 +116,21 @@ public class VSEditorTable extends JTable { /* implements Serializable */ } /** - * Checks if is separator. + * Checks if it is a separator. * * @return true, if is separator */ public boolean isSeparator() { return comp == null; } - - /** - * 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 { - } - - /** - * 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 { - } } /** - * The class VSEditorTableModel. + * The class VSEditorTableModel, it is the model of a VSEditorTable. */ - private class VSEditorTableModel extends AbstractTableModel implements TableCellRenderer { + private class VSEditorTableModel extends AbstractTableModel + implements TableCellRenderer { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** @@ -210,13 +193,16 @@ public class VSEditorTable extends JTable { /* implements Serializable */ } /* (non-Javadoc) - * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int) + * @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) + * @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 @@ -248,16 +234,22 @@ public class VSEditorTable extends JTable { /* implements Serializable */ } /** - * The class VSTableCellEditor. + * The class VSTableCellEditor, is the editor of the VSEditorTable */ - private class VSTableCellEditor extends AbstractCellEditor implements TableCellEditor { + private class VSTableCellEditor extends AbstractCellEditor + implements TableCellEditor { + /** The serial version uid */ private static final long serialVersionUID = 1L; /* (non-Javadoc) - * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int) + * @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) { + public Component getTableCellEditorComponent(JTable table, + Object object, + boolean isSelected, + int row, + int col) { return nodes.get(row).getComponent(); } @@ -270,7 +262,7 @@ public class VSEditorTable extends JTable { /* implements Serializable */ } /** - * Instantiates a new lang.process.removeeditor table. + * Instantiates a new VSEditorTable object. * * @param prefs the prefs */ @@ -314,7 +306,7 @@ public class VSEditorTable extends JTable { /* implements Serializable */ } /** - * Fire table data changed. + * Fires that the table data has changed. */ public void fireTableDataChanged() { model.fireTableDataChanged(); diff --git a/sources/prefs/editors/VSProcessEditor.java b/sources/prefs/editors/VSProcessEditor.java index 38d5c4e..904bfff 100644 --- a/sources/prefs/editors/VSProcessEditor.java +++ b/sources/prefs/editors/VSProcessEditor.java @@ -33,9 +33,12 @@ import events.*; import prefs.VSPrefs; /** - * The class VSProcessEditor. + * The class VSProcessEditor, is for editing a VSProcess object. + * + * @author Paul C. Buetow */ public class VSProcessEditor extends VSAbstractBetterEditor { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** The process. */ @@ -45,20 +48,22 @@ public class VSProcessEditor extends VSAbstractBetterEditor { public static boolean TAKEOVER_BUTTON; /** - * Instantiates a new lang.process.removeprocess editor. + * Instantiates a new VSProcessEditor object. * * @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"));; + super(prefs, process, prefs.getString("lang.name") + " - " + + prefs.getString("lang.prefs.process"));; this.process = process; disposeFrameWithParentIfExists(); makeProtocolVariablesEditable(); } /* (non-Javadoc) - * @see prefs.editors.VSAbstractBetterEditor#addToButtonPanelFront(javax.swing.JPanel) + * @see prefs.editors.VSAbstractBetterEditor#addToButtonPanelFront( + * javax.swing.JPanel) */ protected void addToButtonPanelFront(JPanel buttonPanel) { JButton takeoverButton = new JButton( @@ -80,23 +85,33 @@ public class VSProcessEditor extends VSAbstractBetterEditor { String serverString = " " + prefs.getString("lang.server"); for (String protocolClassname : editableProtocolsClassnames) { - String protocolShortname = VSRegisteredEvents.getShortnameByClassname(protocolClassname); - VSAbstractProtocol protocol = process.getProtocolObject(protocolClassname); + String protocolShortname = + VSRegisteredEvents.getShortnameByClassname( + protocolClassname); + VSAbstractProtocol protocol = + process.getProtocolObject(protocolClassname); protocol.onClientInit(); protocol.onServerInit(); - ArrayList<String> clientVariables = VSRegisteredEvents.getProtocolClientVariables(protocolClassname); + ArrayList<String> clientVariables = + VSRegisteredEvents.getProtocolClientVariables( + protocolClassname); if (clientVariables != null) - addToEditor(protocolShortname + clientString, protocolShortname, protocol, clientVariables); + addToEditor(protocolShortname + clientString, + protocolShortname, protocol, clientVariables); - ArrayList<String> serverVariables = VSRegisteredEvents.getProtocolServerVariables(protocolClassname); + ArrayList<String> serverVariables = + VSRegisteredEvents.getProtocolServerVariables( + protocolClassname); if (serverVariables != null) - addToEditor(protocolShortname + serverString, protocolShortname, protocol, serverVariables); + addToEditor(protocolShortname + serverString, + protocolShortname, protocol, serverVariables); } } /* (non-Javadoc) - * @see prefs.editors.VSAbstractBetterEditor#actionPerformed(java.awt.event.ActionEvent) + * @see prefs.editors.VSAbstractBetterEditor#actionPerformed( + * java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); diff --git a/sources/prefs/editors/VSSimulatorEditor.java b/sources/prefs/editors/VSSimulatorEditor.java index a8d3705..d900692 100644 --- a/sources/prefs/editors/VSSimulatorEditor.java +++ b/sources/prefs/editors/VSSimulatorEditor.java @@ -29,15 +29,19 @@ import javax.swing.*; import simulator.*; import prefs.*; -// TODO: Auto-generated Javadoc /** - * The class VSSimulatorEditor. + * The class VSSimulatorEditor, is for editing a VSSimulator object. + * + * @author Paul C. Buetow */ public class VSSimulatorEditor extends VSAbstractBetterEditor { + /** The serial version uid */ private static final long serialVersionUID = 1L; + /** The constant OPENED_NEW_WINDOW */ public static final boolean OPENED_NEW_WINDOW = true; + /** The constant OPENED_NEW_TAB */ public static final boolean OPENED_NEW_TAB = false; /** The simulator frame. */ @@ -56,7 +60,7 @@ public class VSSimulatorEditor extends VSAbstractBetterEditor { private boolean openedNewWindow; /** - * Instantiates a new lang.process.removesimulator editor. + * Instantiates a new VSSimulatorEditor object. * * @param prefs the prefs * @param simulatorFrame the simulator frame @@ -72,7 +76,7 @@ public class VSSimulatorEditor extends VSAbstractBetterEditor { } /** - * Instantiates a new lang.process.removesimulator editor. + * Instantiates a new VSSimulatorEditor object. * * @param prefs the prefs * @param simulatorFrame the simulator frame @@ -86,7 +90,8 @@ public class VSSimulatorEditor extends VSAbstractBetterEditor { } /* (non-Javadoc) - * @see prefs.editors.VSAbstractBetterEditor#addToButtonPanelFront(javax.swing.JPanel) + * @see prefs.editors.VSAbstractBetterEditor#addToButtonPanelFront( + * javax.swing.JPanel) */ protected void addToButtonPanelFront(JPanel buttonPanel) { if (TAKEOVER_BUTTON) { @@ -100,7 +105,8 @@ public class VSSimulatorEditor extends VSAbstractBetterEditor { } /* (non-Javadoc) - * @see prefs.editors.VSAbstractBetterEditor#actionPerformed(java.awt.event.ActionEvent) + * @see prefs.editors.VSAbstractBetterEditor#actionPerformed( + * java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); @@ -125,7 +131,8 @@ public class VSSimulatorEditor extends VSAbstractBetterEditor { simulator.fireExpertModeChanged(); } if (!dontStartNewSimulator) - simulatorFrame.addSimulator(new VSSimulator(prefsToEdit, simulatorFrame)); + simulatorFrame.addSimulator(new VSSimulator(prefsToEdit, + simulatorFrame)); else if (simulator != null) simulator.updateFromPrefs(); diff --git a/sources/protocols/VSAbstractProtocol.java b/sources/protocols/VSAbstractProtocol.java index 39d338a..7c3cd2e 100644 --- a/sources/protocols/VSAbstractProtocol.java +++ b/sources/protocols/VSAbstractProtocol.java @@ -33,7 +33,10 @@ import serialize.*; import utils.*; /** - * The class VSAbstractProtocol. + * The class VSAbstractProtocol, this class defined the basic framework of a + * protocol. + * + * @author Paul C. Buetow */ abstract public class VSAbstractProtocol extends VSAbstractEvent { /** The serial version uid */ @@ -69,12 +72,18 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { /** The protocol's client schedules */ private ArrayList<VSTask> clientSchedules = new ArrayList<VSTask>(); + /** + * A simple constructor. + * + * @param hasOnServerStart true, if the protocol uses an onServerStart + * method. false, if the protocol uses an onClientStart method instead. + */ public VSAbstractProtocol(boolean hasOnServerStart) { this.hasOnServerStart = hasOnServerStart; } /** - * Send a message. + * Sends a message. * * @param message the message to send */ @@ -223,7 +232,8 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { /** * Checks how the protocol will start * - * @return true, if this protocol uses onServerStart instead of onClientStart + * @return true, if this protocol uses onServerStart instead of + * onClientStart */ public final boolean hasOnServerStart() { return hasOnServerStart; @@ -266,32 +276,31 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { } /** - * Reset. + * Resets the protocol. */ public void reset() { - //if (isServer) { currentContextIsServer(true); isServer = false; onServerReset(); serverSchedules.clear(); - //} - //if (isClient) { currentContextIsServer(false); isClient = false; onClientReset(); clientSchedules.clear(); - //} } /** - * Reschedules the protocol for a new time and runs onClientSchedule or onServerSchedule + * Reschedules the protocol for a new time and runs onClientSchedule or + * onServerSchedule * * @param time The process' local time to run the schedule at. */ public final void scheduleAt(long time) { - VSAbstractEvent scheduleEvent = new VSProtocolScheduleEvent(this, currentContextIsServer); - VSTask scheduleTask = new VSTask(time, process, scheduleEvent, VSTask.LOCAL); + VSAbstractEvent scheduleEvent = + new VSProtocolScheduleEvent(this, currentContextIsServer); + VSTask scheduleTask = + new VSTask(time, process, scheduleEvent, VSTask.LOCAL); if (currentContextIsServer) serverSchedules.add(scheduleTask); else @@ -304,10 +313,12 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { */ public final void removeSchedules() { if (currentContextIsServer) { - process.getSimulatorCanvas().getTaskManager().removeAllTasks(serverSchedules); + process.getSimulatorCanvas(). + getTaskManager().removeAllTasks(serverSchedules); serverSchedules.clear(); } else { - process.getSimulatorCanvas().getTaskManager().removeAllTasks(clientSchedules); + process.getSimulatorCanvas(). + getTaskManager().removeAllTasks(clientSchedules); clientSchedules.clear(); } } diff --git a/sources/serialize/VSNotSerializable.java b/sources/serialize/VSNotSerializable.java new file mode 100644 index 0000000..e5cb79c --- /dev/null +++ b/sources/serialize/VSNotSerializable.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * All icons of the icons/ folder are under a Creative Commons + * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa. + * + * The icon's homepage is http://code.google.com/p/ultimate-gnome/ + */ + +package serialize; + +/** + * The Interface VSNotSerializable, this interface has no methods given and is + * being used to distinguish if the simulator should not serialize an object + * of the implementing class. + * + * @author Paul C. Buetow + */ +public interface VSNotSerializable { +} diff --git a/sources/serialize/VSSerializable.java b/sources/serialize/VSSerializable.java index a4affe9..a134909 100644 --- a/sources/serialize/VSSerializable.java +++ b/sources/serialize/VSSerializable.java @@ -26,7 +26,10 @@ package serialize; import java.io.*; /** - * The Interface VSSerializable, + * The Interface VSSerializable, all classes which take part of the serialize/ + * deserialize proces are implementing this interface. It is preferred over the + * standard Serializable interface of Java because we want not serialize the + * whole class tree of each class but certain variables only! * * @author Paul C. Buetow */ @@ -44,7 +47,7 @@ public interface VSSerializable { * Deserializes * * @param serialize The serialize object - * @param objectOutputStream The object input stream + * @param objectInputStream The object input stream */ public void deserialize(VSSerialize serialize, ObjectInputStream objectInputStream) diff --git a/sources/serialize/VSSerialize.java b/sources/serialize/VSSerialize.java index dfdb05b..f893e6b 100644 --- a/sources/serialize/VSSerialize.java +++ b/sources/serialize/VSSerialize.java @@ -31,7 +31,8 @@ import prefs.*; import simulator.*; /** - * The class VSSerialize, this class helps do deserialize a saved simulator! + * The class VSSerialize, this class helps do serialize/deserialize a saved + * simulator! * * @author Paul C. Buetow */ @@ -39,7 +40,7 @@ public final class VSSerialize { /** The serial version uid */ private static final long serialVersionUID = 1L; - /** True if debugg mode of deserialization */ + /** True if debug mode of serialization/deserialization */ public static final boolean DEBUG = true; /** The last filename used for saveing/opening*/ diff --git a/sources/simulator/VSMain.java b/sources/simulator/VSMain.java index 0df4a41..7088f65 100644 --- a/sources/simulator/VSMain.java +++ b/sources/simulator/VSMain.java @@ -69,9 +69,10 @@ public class VSMain { VSSimulatorFrame simulatorFrame = new VSSimulatorFrame(prefs, relativeTo); - new VSEditorFrame(prefs, relativeTo, - new VSSimulatorEditor(prefs, simulatorFrame, - VSSimulatorEditor.OPENED_NEW_WINDOW)); + VSSimulatorEditor editor = + new VSSimulatorEditor(prefs, simulatorFrame, + VSSimulatorEditor.OPENED_NEW_WINDOW); + new VSEditorFrame(prefs, relativeTo, editor); } /** diff --git a/sources/simulator/VSSimulator.java b/sources/simulator/VSSimulator.java index 1f8f986..2c25867 100644 --- a/sources/simulator/VSSimulator.java +++ b/sources/simulator/VSSimulator.java @@ -1083,11 +1083,11 @@ public class VSSimulator extends JPanel implements VSSerializable { */ private void updateProcessesComboBox() { int numProcesses = simulatorCanvas.getNumProcesses(); - String processString = prefs.getString("lang.process"); for (int i = 0; i < numProcesses; ++i) { int processID = simulatorCanvas.getProcess(i).getProcessID(); + System.out.println("FOO " + processID + " index " + i); processesComboBox.removeItemAt(i); localPIDComboBox.removeItemAt(i); diff --git a/sources/simulator/VSSimulatorCanvas.java b/sources/simulator/VSSimulatorCanvas.java index b521fc7..039b624 100644 --- a/sources/simulator/VSSimulatorCanvas.java +++ b/sources/simulator/VSSimulatorCanvas.java @@ -86,7 +86,7 @@ public class VSSimulatorCanvas extends Canvas private volatile boolean hasThreadStopped = false; /** The simulator is finished. */ - private volatile boolean isFinished = false; + private volatile boolean hasFinished = false; /** The simulator is resetted. */ private volatile boolean isResetted = false; @@ -567,7 +567,7 @@ public class VSSimulatorCanvas extends Canvas finalPrefs.getString("lang.process.crash")); if (process == null || process.isCrashed() || isPaused || - time == 0 || isFinished) + time == 0 || hasFinished) item.setEnabled(false); else item.addActionListener(actionListener); @@ -577,7 +577,7 @@ public class VSSimulatorCanvas extends Canvas finalPrefs.getString("lang.process.recover")); if (process == null || !process.isCrashed() || isPaused || - time == 0 || isFinished) + time == 0 || hasFinished) item.setEnabled(false); else item.addActionListener(actionListener); @@ -748,7 +748,7 @@ public class VSSimulatorCanvas extends Canvas * @param lastGlobalTime the last global time */ private void updateSimulator(long globalTime, long lastGlobalTime) { - if (isPaused || isFinished) + if (isPaused || hasFinished) return; long lastSimulatorTime = simulatorTime; @@ -1142,7 +1142,7 @@ public class VSSimulatorCanvas extends Canvas */ public void run() { while (true) { - while (!hasThreadStopped && (isPaused || isFinished || + while (!hasThreadStopped && (isPaused || hasFinished || isResetted)) { try { Thread.sleep(100); @@ -1195,8 +1195,8 @@ public class VSSimulatorCanvas extends Canvas if (isResetted) isResetted = false; - else if (isFinished) - isFinished = false; + else if (hasFinished) + hasFinished = false; if (isPaused) { isPaused = false; @@ -1221,9 +1221,15 @@ public class VSSimulatorCanvas extends Canvas } simulator.finish(); - isFinished = true; + hasFinished = true; logging.logg(prefs.getString("lang.simulator.finished")); paint(); + + if (prefs.getBoolean("sim.periodic")) { + VSSimulatorFrame simulatorFrame = simulator.getSimulatorFrame(); + simulatorFrame.resetCurrentSimulator(); + simulatorFrame.startCurrentSimulator(); + } } /** @@ -1250,7 +1256,7 @@ public class VSSimulatorCanvas extends Canvas isResetted = true; isPaused = false; - isFinished = false; + hasFinished = false; startTime = System.currentTimeMillis(); time = 0; lastTime = 0; @@ -1564,6 +1570,24 @@ public class VSSimulatorCanvas extends Canvas } } + /** + * Checks if the simulation is paused. + * + * @return true, if the simulation is paused + */ + boolean isPaused() { + return isPaused; + } + + /** + * Checks if the simulation has finished + * + * @return true, if the simulation has finished + */ + boolean hasFinished() { + return hasFinished; + } + /* (non-Javadoc) * @see serialize.VSSerializable#serialize(serialize.VSSerialize, * java.io.ObjectOutputStream) diff --git a/sources/simulator/VSSimulatorFrame.java b/sources/simulator/VSSimulatorFrame.java index 1fb5cab..caf06cb 100644 --- a/sources/simulator/VSSimulatorFrame.java +++ b/sources/simulator/VSSimulatorFrame.java @@ -149,21 +149,35 @@ public class VSSimulatorFrame extends VSFrame { } else if (sourceText.equals( finalPrefs.getString("lang.save"))) { + VSSimulatorCanvas simulatorCanvas = + currentSimulator.getSimulatorCanvas(); + boolean flag = !simulatorCanvas.isPaused() + && !simulatorCanvas.hasFinished(); + + if (flag) + pauseCurrentSimulator(); - pauseCurrentSimulator(); - resetCurrentSimulator(); VSSerialize serialize = new VSSerialize(); serialize.saveSimulator(VSSerialize.LAST_FILENAME, currentSimulator); + if (flag) + startCurrentSimulator(); } else if (sourceText.equals( finalPrefs.getString("lang.saveas"))) { + VSSimulatorCanvas simulatorCanvas = + currentSimulator.getSimulatorCanvas(); + boolean flag = !simulatorCanvas.isPaused() + && !simulatorCanvas.hasFinished(); + if (flag) + pauseCurrentSimulator(); - pauseCurrentSimulator(); - resetCurrentSimulator(); VSSerialize serialize = new VSSerialize(); serialize.saveSimulator(currentSimulator); + if (flag) + startCurrentSimulator(); + } else if (sourceText.equals( finalPrefs.getString("lang.about"))) { new VSAbout(finalPrefs, VSSimulatorFrame.this); @@ -174,14 +188,7 @@ public class VSSimulatorFrame extends VSFrame { } else if (sourceText.equals( finalPrefs.getString("lang.start"))) { - VSMenuItemStates menuItemState = - currentSimulator.getMenuItemStates(); - menuItemState.setStart(false); - menuItemState.setPause(true); - menuItemState.setReset(false); - menuItemState.setReplay(true); - currentSimulator.getSimulatorCanvas().play(); - updateSimulatorMenu(); + startCurrentSimulator(); } else if (sourceText.equals( finalPrefs.getString("lang.pause"))) { @@ -537,6 +544,20 @@ public class VSSimulatorFrame extends VSFrame { } /** + * Starts the current simulator + */ + public void startCurrentSimulator() { + VSMenuItemStates menuItemState = + currentSimulator.getMenuItemStates(); + menuItemState.setStart(false); + menuItemState.setPause(true); + menuItemState.setReset(false); + menuItemState.setReplay(true); + currentSimulator.getSimulatorCanvas().play(); + updateSimulatorMenu(); + } + + /** * Pauses the current simulator */ public void pauseCurrentSimulator() { |
