From 293c73f50f87b3d73d3947a9f79430b23ec4ddba Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 1 Jun 2008 22:45:59 +0000 Subject: better serialization --- sources/prefs/VSPrefs.java | 85 ++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 56 deletions(-) (limited to 'sources/prefs/VSPrefs.java') diff --git a/sources/prefs/VSPrefs.java b/sources/prefs/VSPrefs.java index 6143e68..de1c249 100644 --- a/sources/prefs/VSPrefs.java +++ b/sources/prefs/VSPrefs.java @@ -27,10 +27,12 @@ import java.awt.Color; import java.io.*; import java.util.*; +import serialize.*; + /** * The class VSPrefs. */ -public class VSPrefs implements Serializable { +public class VSPrefs implements VSSerializable { /** The Constant BOOLEAN_PREFIX. */ public static final String BOOLEAN_PREFIX = "Boolean: "; @@ -930,14 +932,17 @@ public class VSPrefs implements Serializable { */ public void fillWithDefaults() {} - /** - * Write object. - * - * @param objectOutputStream the object output stream - * - * @throws IOException Signals that an I/O exception has occurred. + @SuppressWarnings("unchecked") + public synchronized void readObject(ObjectInputStream objectInputStream) + throws IOException, ClassNotFoundException { + } + + /* (non-Javadoc) + * @see serialize.VSSerializable#serialize(serialize.VSSerialize, + * java.io.ObjectOutputStream) */ - public synchronized void writeObject(ObjectOutputStream objectOutputStream) + public synchronized void serialize(VSSerialize serialize, + ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.writeObject(booleanPrefs); objectOutputStream.writeObject(colorPrefs); @@ -949,64 +954,28 @@ public class VSPrefs implements Serializable { objectOutputStream.writeObject(units); } - /** - * Read object. - * - * @param objectInputStream the object input stream - * - * @throws IOException Signals that an I/O exception has occurred. - * @throws ClassNotFoundException the class not found exception + /* (non-Javadoc) + * @see serialize.VSSerializable#deserialize(serialize.VSSerialize, + * java.io.ObjectInputStream) */ @SuppressWarnings("unchecked") - public synchronized void readObject(ObjectInputStream objectInputStream) + public synchronized void deserialize(VSSerialize serialize, + ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { booleanPrefs = (HashMap) objectInputStream.readObject(); colorPrefs = (HashMap) objectInputStream.readObject(); descriptionPrefs = new HashMap(); floatPrefs = (HashMap) objectInputStream.readObject(); integerPrefs = (HashMap) objectInputStream.readObject(); - vectorPrefs = (HashMap>) objectInputStream.readObject(); + vectorPrefs = (HashMap>) + objectInputStream.readObject(); longPrefs = (HashMap) objectInputStream.readObject(); restrictions = new HashMap(); stringPrefs = (HashMap) objectInputStream.readObject(); units = (HashMap) objectInputStream.readObject(); + objectPrefs.clear(); } - /* - public void saveFile(String filename) { - try { - FileOutputStream fileOutputStream = new FileOutputStream(filename); - ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); - objectOutputStream.writeObject(this); - - } catch (IOException e) { - e.printStackTrace(); - } - } - */ - - /* - public static VSPrefs openFile(String filename) { - VSPrefs prefs = null; - - try { - FileInputStream fileInputStream = new FileInputStream(filename); - ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); - prefs = (VSPrefs) objectInputStream.readObject(); - - prefs.fillDefaultStrings(); - prefs.fillDefaultIntegers(); - prefs.fillDefaultFloats(); - prefs.fillDefaultColors(); - - } catch (Exception e) { - e.printStackTrace(); - } - - return prefs; - } - */ - /** * Copy integers. * @@ -1016,8 +985,10 @@ public class VSPrefs implements Serializable { public void copyIntegers(VSPrefs copyInto, String[] keys) { for (String key : keys) copyInto.initInteger(key, - getInteger(key), getDescription(INTEGER_PREFIX + key), - (VSPrefsRestriction.VSIntegerPrefRestriction) getRestriction(INTEGER_PREFIX + key), + getInteger(key), + getDescription(INTEGER_PREFIX + key), + (VSPrefsRestriction.VSIntegerPrefRestriction) + getRestriction(INTEGER_PREFIX + key), getUnit(INTEGER_PREFIX + key)); } @@ -1067,7 +1038,8 @@ public class VSPrefs implements Serializable { */ public void copyColors(VSPrefs copyInto, String[] keys) { for (String key : keys) - copyInto.initColor(key, getColor(key), getDescription(COLOR_PREFIX + key)); + copyInto.initColor(key, getColor(key), + getDescription(COLOR_PREFIX + key)); } /** @@ -1078,7 +1050,8 @@ public class VSPrefs implements Serializable { */ public void copyBooleans(VSPrefs copyInto, String[] keys) { for (String key : keys) - copyInto.initBoolean(key, getBoolean(key), getDescription(BOOLEAN_PREFIX + key)); + copyInto.initBoolean(key, getBoolean(key), + getDescription(BOOLEAN_PREFIX + key)); } /* (non-Javadoc) -- cgit v1.2.3