From 00120474f64906e34fa79ce6ac8eede521c320d5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 1 Jun 2008 19:28:00 +0000 Subject: initial complete serialization support --- sources/simulator/VSSimulator.java | 72 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) (limited to 'sources/simulator/VSSimulator.java') 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(); this.globalTextFields = new ArrayList(); + /* 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); + } } -- cgit v1.2.3