diff options
| author | Paul Buetow <paul@buetow.org> | 2008-06-01 22:45:59 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-06-01 22:45:59 +0000 |
| commit | 293c73f50f87b3d73d3947a9f79430b23ec4ddba (patch) | |
| tree | 129ece28dcda9d17bb6e0fc417d8b25bb82dac4c /sources/serialize/VSSerialize.java | |
| parent | 8086082daaed71ee9105c156e3a1e8e63caf1990 (diff) | |
better serialization
Diffstat (limited to 'sources/serialize/VSSerialize.java')
| -rw-r--r-- | sources/serialize/VSSerialize.java | 83 |
1 files changed, 51 insertions, 32 deletions
diff --git a/sources/serialize/VSSerialize.java b/sources/serialize/VSSerialize.java index b3bd18b..b659879 100644 --- a/sources/serialize/VSSerialize.java +++ b/sources/serialize/VSSerialize.java @@ -21,12 +21,13 @@ * The icon's homepage is http://code.google.com/p/ultimate-gnome/ */ -package utils; +package serialize; import java.io.*; import java.util.HashMap; -import simulator.VSSimulator; +import prefs.*; +import simulator.*; /** * The class VSSerialize, this static class helps do deserialize @@ -47,21 +48,34 @@ public final class VSSerialize { /** For temp object storage */ private static HashMap<String,Object> objects; + /** Holds the current VSSerialize object */ + private static VSSerialize serialize; + /** * Creates the VSSerialize object. */ public VSSerialize() { - init(); + init(); } /** * Initializes the helper. */ private void init() { + this.serialize = this; objects = new HashMap<String,Object>(); } /** + * Gets the current VSSerialize object. + * + * @return The current serialize object + */ + public static VSSerialize getSerialize() { + return serialize; + } + + /** * Sets an object. * * @param key The object key @@ -120,47 +134,52 @@ public final class VSSerialize { return object; } - /** - * Saves the given simulator to the given filename. - * - * @param filename The filename - * @param simulator The simulator - */ + /** + * Saves the given simulator to the given filename. + * + * @param filename The filename + * @param simulator The simulator + */ public void saveSimulator(String filename, VSSimulator simulator) { try { - FileOutputStream fileOutputStream = - new FileOutputStream(filename); - ObjectOutputStream objectOutputStream = - new ObjectOutputStream(fileOutputStream); + FileOutputStream fileOutputStream = + new FileOutputStream(filename); + ObjectOutputStream objectOutputStream = + new ObjectOutputStream(fileOutputStream); - objectOutputStream.writeObject(simulator.getPrefs()); - simulator.serialize(this); + VSPrefs prefs = simulator.getPrefs(); + prefs.serialize(this, objectOutputStream); + simulator.serialize(this, objectOutputStream); } catch (IOException e) { e.printStackTrace(); } } - /** - * Opens a simulator from the given filename. - * - * @param filename The filename. - * @param simulatorFrame The simulator frame - * - * @return The simulator object, and null if no success - */ + /** + * Opens a simulator from the given filename. + * + * @param filename The filename. + * @param simulatorFrame The simulator frame + * + * @return The simulator object, and null if no success + */ public VSSimulator openSimulator(String filename, - VSSimulatorFrame simulatorFrame) { + VSSimulatorFrame simulatorFrame) { + VSSimulator simulator = null; try { - FileInputStream fileInputStream = - new FileInputStream(filename); - ObjectInputStream objectInputStream = - new ObjectInputStream(fileInputStream); - - VSPrefs prefs = (VSPrefs) objectInputStream.readObject(); - simulator = new VSSimulator(prefs, simulatorFrame); - simulator.deserialize(this); + FileInputStream fileInputStream = + new FileInputStream(filename); + ObjectInputStream objectInputStream = + new ObjectInputStream(fileInputStream); + + VSPrefs prefs = new VSPrefs(); + prefs.deserialize(this, objectInputStream); + this.setObject("prefs", prefs); + + simulator = new VSSimulator(prefs, simulatorFrame); + simulator.deserialize(this, objectInputStream); } catch (Exception e) { e.printStackTrace(); |
