summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-06-01 19:28:00 +0000
committerPaul Buetow <paul@buetow.org>2008-06-01 19:28:00 +0000
commit00120474f64906e34fa79ce6ac8eede521c320d5 (patch)
tree88146a9507716ba40f10b01d55e14670a364f605
parent9a0fc6463ac1bca1ec05056fb4f84163d1e9fc26 (diff)
initial complete serialization support
-rw-r--r--sources/core/VSProcess.java60
-rw-r--r--sources/core/VSTask.java71
-rw-r--r--sources/core/VSTaskManager.java99
-rw-r--r--sources/events/VSAbstractEvent.java35
-rw-r--r--sources/prefs/VSPrefs.java6
-rw-r--r--sources/protocols/VSAbstractProtocol.java35
-rw-r--r--sources/simulator/VSSimulator.java72
-rw-r--r--sources/simulator/VSSimulatorCanvas.java82
-rw-r--r--sources/simulator/VSSimulatorFrame.java38
-rw-r--r--sources/utils/VSDeserializationHelper.java116
10 files changed, 591 insertions, 23 deletions
diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java
index 31bbab6..023e017 100644
--- a/sources/core/VSProcess.java
+++ b/sources/core/VSProcess.java
@@ -24,6 +24,7 @@
package core;
import java.awt.*;
+import java.io.*;
import java.util.*;
import core.time.*;
@@ -40,7 +41,7 @@ import utils.*;
*
* @author Paul C. Buetow
*/
-public class VSProcess extends VSPrefs {
+public class VSProcess extends VSPrefs implements Serializable {
/** The data serialization id. */
private static final long serialVersionUID = 1L;
@@ -198,7 +199,22 @@ public class VSProcess extends VSPrefs {
*/
public VSProcess(VSPrefs prefs, int processNum,
VSSimulatorCanvas simulatorCanvas, VSLogging logging) {
- this.protocolsToReset = new ArrayList<VSAbstractProtocol>();
+ init(prefs, processNum, simulatorCanvas, logging);
+ }
+
+ /**
+ * Inits a the process.
+ *
+ * @param prefs the simulator's default prefs
+ * @param processNum the process num
+ * @param simulatorCanvas the simulator canvas
+ * @param logging the logging object
+ */
+ private void init(VSPrefs prefs, int processNum,
+ VSSimulatorCanvas simulatorCanvas, VSLogging logging) {
+ /* May be not null if called from deserialization */
+ if (protocolsToReset == null)
+ this.protocolsToReset = new ArrayList<VSAbstractProtocol>();
this.processNum = processNum;
this.prefs = prefs;
this.simulatorCanvas = simulatorCanvas;
@@ -992,4 +1008,44 @@ public class VSProcess extends VSPrefs {
return protocol;
}
+
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#writeObject()
+ */
+ public synchronized void writeObject(ObjectOutputStream objectOutputStream)
+ throws IOException {
+ super.writeObject(objectOutputStream);
+ objectOutputStream.writeObject(new Integer(processNum));
+ objectOutputStream.writeObject(protocolsToReset);
+ }
+
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#readObject()
+ */
+ @SuppressWarnings("unchecked")
+ public synchronized void readObject(ObjectInputStream objectInputStream)
+ throws IOException, ClassNotFoundException {
+ super.readObject(objectInputStream);
+
+ if (VSDeserializationHelper.DEBUG)
+ System.out.println("Deserializing: VSProcess");
+
+ VSLogging logging = (VSLogging)
+ VSDeserializationHelper.getObject("logging");
+ VSSimulatorCanvas simulatorCanvas = (VSSimulatorCanvas)
+ VSDeserializationHelper.getObject(
+ "simulatorCanvas");
+ VSPrefs prefs = (VSPrefs) VSDeserializationHelper.getObject("prefs");
+
+ Integer processNum = (Integer) objectInputStream.readObject();
+ this.protocolsToReset = (ArrayList<VSAbstractProtocol>)
+ objectInputStream.readObject();
+
+ for (VSAbstractProtocol protocol : protocolsToReset)
+ setObject(protocol.getClassname(), protocol);
+
+ VSDeserializationHelper.setObject(processNum.intValue(),
+ "process", this);
+ init(prefs, processNum.intValue(), simulatorCanvas, logging);
+ }
}
diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java
index d1e122e..d27a9a4 100644
--- a/sources/core/VSTask.java
+++ b/sources/core/VSTask.java
@@ -23,11 +23,14 @@
package core;
+import java.io.*;
+
import events.*;
import events.implementations.*;
import events.internal.*;
import prefs.VSPrefs;
import protocols.VSAbstractProtocol;
+import utils.*;
/**
* The class VSTask, an object of this class represents a task to do or done.
@@ -38,7 +41,7 @@ import protocols.VSAbstractProtocol;
*
* @author Paul C. Buetow
*/
-public class VSTask implements Comparable {
+public class VSTask implements Comparable, Serializable {
/** The serial version uid */
private static final long serialVersionUID = 1L;
@@ -88,9 +91,24 @@ public class VSTask implements Comparable {
*/
public VSTask(long taskTime, VSProcess process, VSAbstractEvent event,
boolean isLocal) {
+ init(taskTime, process, event, isLocal);
+ }
+
+ /**
+ * Inits the task
+ *
+ * @param taskTime the task time
+ * @param process the process
+ * @param event the event
+ * @param isLocal the taks is local timed
+ */
+ private void init(long taskTime, VSProcess process, VSAbstractEvent event,
+ boolean isLocal) {
this.process = process;
this.taskTime = taskTime > 0 ? taskTime : 0;
- this.event = event;
+ /* May be not null if called from deserialization */
+ if (event == null)
+ this.event = event;
this.prefs = process.getPrefs();
this.isGlobalTimed = !isLocal;
this.taskNum = ++taskCounter;
@@ -319,5 +337,54 @@ public class VSTask implements Comparable {
return 0;
}
+
+ /**
+ * 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(event);
+ objectOutputStream.writeObject(new Integer(process.getProcessNum()));
+ objectOutputStream.writeObject(new Integer(taskNum));
+ objectOutputStream.writeObject(new Long(taskTime));
+ objectOutputStream.writeObject(new Boolean(isGlobalTimed));
+ objectOutputStream.writeObject(new Boolean(isProgrammed));
+ }
+
+ /**
+ * 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 {
+ if (VSDeserializationHelper.DEBUG)
+ System.out.println("Deserializing: VSTask");
+
+ this.event = (VSAbstractEvent) objectInputStream.readObject();
+ Integer processNum = (Integer) objectInputStream.readObject();
+ Integer taskNum = (Integer) objectInputStream.readObject();
+ Long taskTime = (Long) objectInputStream.readObject();
+ Boolean isGlobalTimed = (Boolean) objectInputStream.readObject();
+ Boolean isProgrammed = (Boolean) objectInputStream.readObject();
+
+ VSDeserializationHelper.setObject(taskNum.intValue(), "task", this);
+
+ VSProcess process = (VSProcess) VSDeserializationHelper.getObject(
+ processNum.intValue(), "process");
+
+ init(taskTime.longValue(), process, event,
+ !isGlobalTimed.booleanValue());
+
+ this.isProgrammed = isProgrammed.booleanValue();
+ }
}
diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java
index 620d115..a63db51 100644
--- a/sources/core/VSTaskManager.java
+++ b/sources/core/VSTaskManager.java
@@ -23,6 +23,7 @@
package core;
+import java.io.*;
import java.util.*;
import prefs.*;
@@ -37,7 +38,7 @@ import utils.*;
*
* @author Paul C. Buetow
*/
-public class VSTaskManager {
+public class VSTaskManager implements Serializable {
/** The seriao version uid */
private static final long serialVersionUID = 1L;
@@ -60,14 +61,29 @@ public class VSTaskManager {
private VSPrefs prefs;
/**
- * Instantiates a new lang.process.removetask manager.
+ * Instantiates a new task manager object.
*
* @param prefs the simulator's default prefs
+ * @param simulatorCanvas the simulator canvas
*/
public VSTaskManager(VSPrefs prefs, VSSimulatorCanvas simulatorCanvas) {
+ init(prefs, simulatorCanvas);
+ }
+
+ /**
+ * Inits the task manager.
+ *
+ * @param prefs the simulator's default prefs
+ * @param simulatorCanvas the simulator canvas
+ */
+ private void init(VSPrefs prefs, VSSimulatorCanvas simulatorCanvas) {
this.prefs = prefs;
this.simulatorCanvas = simulatorCanvas;
- this.globalTasks = new PriorityQueue<VSTask>();
+
+ /* May be not null if called from deserialization */
+ if (globalTasks == null)
+ this.globalTasks = new PriorityQueue<VSTask>();
+
this.fullfilledProgrammedTasks = new LinkedList<VSTask>();
}
@@ -476,4 +492,81 @@ public class VSTaskManager {
return descr + ")";
}
+
+ /**
+ * 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 {
+ VSPriorityQueue<VSTask> temp = new VSPriorityQueue<VSTask>();
+
+ for (VSTask task : fullfilledProgrammedTasks)
+ if (task.isGlobalTimed())
+ temp.add(task);
+
+ for (VSTask task : globalTasks)
+ temp.add(task);
+
+ ArrayList<VSProcess> processes = simulatorCanvas.getProcesses();
+ HashMap<Integer, ArrayList<VSTask>> map =
+ new HashMap<Integer, ArrayList<VSTask>>();
+
+ synchronized (processes) {
+ for (VSProcess process : processes) {
+ VSPriorityQueue<VSTask> tasks = process.getTasks();
+ ArrayList<VSTask> tasks_ = new ArrayList<VSTask>();
+ for (VSTask task : tasks)
+ tasks_.add(task);
+ map.put(new Integer(process.getProcessNum()), tasks_);
+ }
+ }
+
+ objectOutputStream.writeObject(temp);
+ objectOutputStream.writeObject(map);
+ }
+
+ /**
+ * 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 {
+ if (VSDeserializationHelper.DEBUG)
+ System.out.println("Deserializing: VSTaskManager");
+
+ VSPrefs prefs = (VSPrefs) VSDeserializationHelper.getObject("prefs");
+ VSSimulatorCanvas simulatorCanvas = (VSSimulatorCanvas)
+ VSDeserializationHelper.getObject(
+ "prefs");
+ this.globalTasks = (PriorityQueue<VSTask>)
+ objectInputStream.readObject();
+
+ HashMap<Integer, ArrayList<VSTask>> map =
+ (HashMap<Integer, ArrayList<VSTask>>)
+ objectInputStream.readObject();
+
+ Set<Integer> set = map.keySet();
+ for (Integer processNum : set) {
+ VSProcess process = (VSProcess) VSDeserializationHelper.getObject(
+ processNum.intValue(),
+ "process");
+
+ ArrayList<VSTask> tasks = (ArrayList<VSTask>) map.get(processNum);
+ VSPriorityQueue<VSTask> tasks_ = process.getTasks();
+
+ for (VSTask task: tasks)
+ tasks_.add(task);
+ }
+
+ init(prefs, simulatorCanvas);
+ }
}
diff --git a/sources/events/VSAbstractEvent.java b/sources/events/VSAbstractEvent.java
index 15b742f..9a4062e 100644
--- a/sources/events/VSAbstractEvent.java
+++ b/sources/events/VSAbstractEvent.java
@@ -23,8 +23,11 @@
package events;
+import java.io.*;
+
import core.VSProcess;
import prefs.VSPrefs;
+import utils.*;
/**
* The class VSAbstractEvent. This abstract class defines the basic framework
@@ -160,4 +163,36 @@ abstract public class VSAbstractEvent extends VSPrefs {
* takes place.
*/
abstract public void onStart();
+
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#writeObject()
+ */
+ public synchronized void writeObject(ObjectOutputStream objectOutputStream)
+ throws IOException {
+ super.writeObject(objectOutputStream);
+ objectOutputStream.writeObject(new Integer(super.getID()));
+ //objectOutputStream.writeObject(new Integer(process.getProcessNum()));
+ objectOutputStream.writeObject(eventShortname);
+ objectOutputStream.writeObject(eventClassname);
+ }
+
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#readObject()
+ */
+ @SuppressWarnings("unchecked")
+ public synchronized void readObject(ObjectInputStream objectInputStream)
+ throws IOException, ClassNotFoundException {
+ super.readObject(objectInputStream);
+
+ if (VSDeserializationHelper.DEBUG)
+ System.out.println("Deserializing: VSAbstractEvent");
+
+ Integer id = (Integer) objectInputStream.readObject();
+ //Integer processNum = (Integer) objectInputStream.readObject();
+ this.eventShortname = (String) objectInputStream.readObject();
+ this.eventClassname = (String) objectInputStream.readObject();
+
+ VSDeserializationHelper.setObject(id.intValue(),
+ "event", this);
+ }
}
diff --git a/sources/prefs/VSPrefs.java b/sources/prefs/VSPrefs.java
index b4a9f73..6143e68 100644
--- a/sources/prefs/VSPrefs.java
+++ b/sources/prefs/VSPrefs.java
@@ -92,10 +92,10 @@ public class VSPrefs implements Serializable {
protected final static String PREFERENCES_FILENAME = "vs.dat";
/** The id counter. */
- private static long idCounter;
+ private static int idCounter;
/** The id. */
- protected long id;
+ protected int id;
/**
* Instantiates a new lang.process.removeprefs.
@@ -1142,7 +1142,7 @@ public class VSPrefs implements Serializable {
*
* @return the iD
*/
- public long getID() {
+ public int getID() {
return id;
}
diff --git a/sources/protocols/VSAbstractProtocol.java b/sources/protocols/VSAbstractProtocol.java
index ea3eec2..3398b2c 100644
--- a/sources/protocols/VSAbstractProtocol.java
+++ b/sources/protocols/VSAbstractProtocol.java
@@ -23,18 +23,25 @@
package protocols;
+import java.io.*;
import java.util.ArrayList;
-import events.internal.*;
-import events.*;
import core.*;
+import events.*;
+import events.internal.*;
+import utils.*;
/**
* The class VSAbstractProtocol.
*/
abstract public class VSAbstractProtocol extends VSAbstractEvent {
+ /** The serial version uid */
private static final long serialVersionUID = 1L;
+
+ /** The protocol has an onServerStart method */
protected static final boolean HAS_ON_SERVER_START = true;
+
+ /** The protocol has an onClientStart method */
protected static final boolean HAS_ON_CLIENT_START = false;
/** True, if onServerStart is used, false if onClientStart is used */
@@ -375,4 +382,28 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent {
return buffer.toString();
}
+
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#writeObject()
+ */
+ public synchronized void writeObject(ObjectOutputStream objectOutputStream)
+ throws IOException {
+ super.writeObject(objectOutputStream);
+ objectOutputStream.writeObject(new Boolean(hasOnServerStart));
+ }
+
+ /* (non-Javadoc)
+ * @see prefs.VSPrefs#readObject()
+ */
+ @SuppressWarnings("unchecked")
+ public synchronized void readObject(ObjectInputStream objectInputStream)
+ throws IOException, ClassNotFoundException {
+ super.readObject(objectInputStream);
+
+ if (VSDeserializationHelper.DEBUG)
+ System.out.println("Deserializing: VSAbstractProtocol");
+
+ this.hasOnServerStart = ((Boolean)
+ objectInputStream.readObject()).booleanValue();
+ }
}
diff --git a/sources/simulator/VSSimulator.java b/sources/simulator/VSSimulator.java
index 3ae6a3c..d3456b1 100644
--- a/sources/simulator/VSSimulator.java
+++ b/sources/simulator/VSSimulator.java
@@ -25,6 +25,7 @@ package simulator;
import java.awt.*;
import java.awt.event.*;
+import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
@@ -44,7 +45,7 @@ import utils.*;
*
* @author Paul C. Buetow
*/
-public class VSSimulator extends JPanel {
+public class VSSimulator extends JPanel implements Serializable {
/** the serial version uid */
private static final long serialversionuid = 1l;
@@ -382,17 +383,32 @@ public class VSSimulator extends JPanel {
* @param simulatorFrame the simulator frame
*/
public VSSimulator(VSPrefs prefs, VSSimulatorFrame simulatorFrame) {
+ init(prefs, simulatorFrame);
+ }
+
+ /**
+ * inits the VSSimulator object.
+ *
+ * @param prefs the prefs
+ * @param simulatorFrame the simulator frame
+ */
+ private void init(VSPrefs prefs, VSSimulatorFrame simulatorFrame) {
this.prefs = prefs;
this.simulatorFrame = simulatorFrame;
- this.logging = new VSLogging();
this.simulatorNum = ++simulatorCounter;
this.menuItemStates = new VSMenuItemStates(false, false, false, true);
this.localTextFields = new ArrayList<String>();
this.globalTextFields = new ArrayList<String>();
+ /* Not null if init has been called from the deserialization */
+ if (logging == null)
+ this.logging = new VSLogging();
+
logging.logg(prefs.getString("lang.simulator.new"));
+
fillContentPane();
updateFromPrefs();
+
splitPaneH.setDividerLocation(
prefs.getInteger("div.window.splitsize"));
@@ -425,7 +441,10 @@ public class VSSimulator extends JPanel {
splitPaneH = new JSplitPane();
splitPaneV = new JSplitPane();
- simulatorCanvas = new VSSimulatorCanvas(prefs, this, logging);
+ /* Not null if init has been called from the deserialization */
+ if (simulatorCanvas == null)
+ simulatorCanvas = new VSSimulatorCanvas(prefs, this, logging);
+
taskManager = simulatorCanvas.getTaskManager();
logging.setSimulatorCanvas(simulatorCanvas);
@@ -1196,4 +1215,51 @@ public class VSSimulator extends JPanel {
public VSPrefs getPrefs() {
return prefs;
}
+
+ /**
+ * 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(prefs);
+ objectOutputStream.writeObject(simulatorCanvas);
+ }
+
+ /**
+ * 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 {
+ if (VSDeserializationHelper.DEBUG)
+ System.out.println("Deserializing: VSSimulator");
+
+ VSDeserializationHelper.setObject("simulator", this);
+
+ VSSimulatorFrame simulatorFrame = (VSSimulatorFrame)
+ VSDeserializationHelper.getObject(
+ "simulatorFrame");
+
+ // TODO: Merge prefs!?!
+ VSPrefs prefs = (VSPrefs) objectInputStream.readObject();
+ VSDeserializationHelper.setObject("prefs", prefs);
+
+ this.logging = new VSLogging();
+ VSDeserializationHelper.setObject("logging", logging);
+
+ this.simulatorCanvas =
+ (VSSimulatorCanvas) objectInputStream.readObject();
+ VSDeserializationHelper.setObject("simulatorCanvas", simulatorCanvas);
+
+ init(prefs, simulatorFrame);
+ }
}
diff --git a/sources/simulator/VSSimulatorCanvas.java b/sources/simulator/VSSimulatorCanvas.java
index b0ac461..d6bc5d2 100644
--- a/sources/simulator/VSSimulatorCanvas.java
+++ b/sources/simulator/VSSimulatorCanvas.java
@@ -26,6 +26,7 @@ package simulator;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
+import java.io.*;
import java.util.*;
import javax.swing.*;
@@ -36,6 +37,7 @@ import events.implementations.*;
import events.internal.*;
import prefs.*;
import prefs.editors.*;
+import utils.*;
/**
* The class VSSimulatorCanvas. An instance of this object represents the
@@ -46,7 +48,9 @@ import prefs.editors.*;
*
* @author Paul C. Buetow
*/
-public class VSSimulatorCanvas extends Canvas implements Runnable {
+public class VSSimulatorCanvas extends Canvas
+ implements Runnable, Serializable {
+
/** The serial version uid */
private static final long serialVersionUID = 1L;
@@ -471,19 +475,39 @@ public class VSSimulatorCanvas extends Canvas implements Runnable {
*/
public VSSimulatorCanvas(VSPrefs prefs, VSSimulator simulator,
VSLogging logging) {
+ init(prefs, simulator, logging);
+ }
+
+ /**
+ * Instantiates inits the VSSimulatorCanvas object.
+ *
+ * @param prefs the prefs
+ * @param simulator the simulator
+ * @param logging the logging
+ */
+ private void init(VSPrefs prefs, VSSimulator simulator,
+ VSLogging logging) {
this.prefs = prefs;
this.simulator = simulator;
this.logging = logging;
- this.taskManager = new VSTaskManager(prefs, this);
this.messageLines = new LinkedList<VSMessageLine>();
this.messageLinesToRemove = new LinkedList<VSMessageLine>();
- this.processes = new ArrayList<VSProcess>();
- numProcesses = prefs.getInteger("sim.process.num");
- updateFromPrefs();
+ /* May be not null if called from deserialization */
+ if (taskManager == null)
+ this.taskManager = new VSTaskManager(prefs, this);
+
+ /* May be not null if called from deserialization */
+ if (processes == null) {
+ this.processes = new ArrayList<VSProcess>();
+
+ numProcesses = prefs.getInteger("sim.process.num");
+
+ for (int i = 0; i < numProcesses; ++i)
+ processes.add(createProcess(i));
+ }
- for (int i = 0; i < numProcesses; ++i)
- processes.add(createProcess(i));
+ updateFromPrefs();
final VSPrefs finalPrefs = prefs;
addMouseListener(new MouseListener() {
@@ -1520,4 +1544,48 @@ public class VSSimulatorCanvas extends Canvas implements Runnable {
simulator.addProcessAtIndex(processes.size()-1);
}
}
+
+ /**
+ * 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 {
+ synchronized (processes) {
+ objectOutputStream.writeObject(processes);
+ }
+ objectOutputStream.writeObject(taskManager);
+ }
+
+ /**
+ * 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 {
+ if (VSDeserializationHelper.DEBUG)
+ System.out.println("Deserializing: VSSimulatorCanvas");
+
+ VSPrefs prefs = (VSPrefs) VSDeserializationHelper.getObject("prefs");
+ VSSimulator simulator =
+ (VSSimulator) VSDeserializationHelper.getObject("simulator");
+ VSLogging logging =
+ (VSLogging) VSDeserializationHelper.getObject("logging");
+
+ this.processes = (ArrayList<VSProcess>) objectInputStream.readObject();
+ this.numProcesses = processes.size();
+
+ this.taskManager = (VSTaskManager) objectInputStream.readObject();
+ VSDeserializationHelper.setObject("taskManager", taskManager);
+
+ init(prefs, simulator, logging);
+ }
}
diff --git a/sources/simulator/VSSimulatorFrame.java b/sources/simulator/VSSimulatorFrame.java
index 890eb28..f5ef5af 100644
--- a/sources/simulator/VSSimulatorFrame.java
+++ b/sources/simulator/VSSimulatorFrame.java
@@ -25,6 +25,7 @@ package simulator;
import java.awt.*;
import java.awt.event.*;
+import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
@@ -41,7 +42,7 @@ import utils.*;
*
* @author Paul C. Buetow
*/
-public class VSSimulatorFrame extends VSFrame {
+public class VSSimulatorFrame extends VSFrame implements Serializable {
/** The serial version uid */
private static final long serialVersionUID = 1L;
@@ -507,4 +508,39 @@ public class VSSimulatorFrame extends VSFrame {
return new ImageIcon(imageURL, descr);
}
+
+ /**
+ * 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(currentSimulator);
+ }
+
+ /**
+ * 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 {
+ if (VSDeserializationHelper.DEBUG)
+ System.out.println("Deserializing: VSSimulatorFrame");
+
+ VSDeserializationHelper.init();
+ VSDeserializationHelper.setObject("simulatorFrame", this);
+
+ currentSimulator = (VSSimulator) objectInputStream.readObject();
+
+ VSDeserializationHelper.destroy();
+ addSimulator(currentSimulator);
+ }
}
diff --git a/sources/utils/VSDeserializationHelper.java b/sources/utils/VSDeserializationHelper.java
new file mode 100644
index 0000000..b8ae65b
--- /dev/null
+++ b/sources/utils/VSDeserializationHelper.java
@@ -0,0 +1,116 @@
+/*
+ * 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 utils;
+
+import java.util.HashMap;
+
+/**
+ * The class VSDeserializationHelper, this static class helps do deserialize
+ * a saved simulator!
+ *
+ * @author Paul C. Buetow
+ */
+public final class VSDeserializationHelper {
+ /** The serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /** True if debugg mode of deserialization */
+ public static final boolean DEBUG = true;
+
+ /** For temp object storage */
+ private static HashMap<String,Object> objects;
+
+ /**
+ * Initializes the helper.
+ */
+ public static void init() {
+ objects = new HashMap<String,Object>();
+ }
+
+ /**
+ * Destroys the helper.
+ */
+ public static void destroy() {
+ objects = null;
+ }
+
+ /**
+ * Sets an object.
+ *
+ * @param key The object key
+ * @param object The object itself
+ */
+ public static void setObject(String key, Object object) {
+ objects.put(key, object);
+ }
+
+ /**
+ * Sets an object.
+ *
+ * @param num The object number
+ * @param key The object key
+ * @param object The object itself
+ */
+ public static void setObject(int num, String key, Object object) {
+ objects.put(key + ":" + num, object);
+ }
+
+ /**
+ * Gets an object.
+ *
+ * @param num The object number
+ * @param key The object key
+ *
+ * @return The object itself
+ */
+ public static Object getObject(int num, String key) {
+ Object object = objects.get(key + ":" + num);
+
+ if (object == null) {
+ System.err.println("No such deserialization helper key "
+ + key + ":" + num);
+ System.exit(1);
+ }
+
+ return object;
+ }
+
+ /**
+ * Gets an object.
+ *
+ * @param key The object key
+ *
+ * @return The object itself
+ */
+ public static Object getObject(String key) {
+ Object object = objects.get(key);
+
+ if (object == null) {
+ System.err.println("No such deserialization helper key " + key);
+ System.exit(1);
+ }
+
+ return object;
+ }
+}