]> git.gag.com Git - debian/openrocket/commitdiff
Added persistence of ComponentPresets in the ORK file. Bumped ORK file version numbe...
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Wed, 11 Apr 2012 17:36:50 +0000 (17:36 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Wed, 11 Apr 2012 17:36:50 +0000 (17:36 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@535 180e2498-e6e9-4542-8430-84ac67f01cd8

core/fileformat.txt
core/src/net/sf/openrocket/database/ComponentPresetDao.java
core/src/net/sf/openrocket/database/ComponentPresetDatabase.java
core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java
core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java
core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java
core/src/net/sf/openrocket/preset/ComponentPreset.java

index 0a3dbf03b88f1bf724fd9d826850cb6492e729a0..4ea6985c238689a82216b72a99c8c3613e71760c 100644 (file)
@@ -38,3 +38,5 @@ The following file format versions exist:
       deploymentvelocity attributes to <flightdata> element.  The motor
       digesting algorithm was changed.  Adds <separationevent> and
       <separationdelay> elements to stage components (except sustainer).
+
+1.5:  Introduced with OpenRocket 12.xx.  Added ComponentPresets.
\ No newline at end of file
index 905e7a888711b08aa954e9569ba0b86a68592d0c..8d79967f3c42b4c681b30fa2292939e9b6da42da 100644 (file)
@@ -26,4 +26,6 @@ public interface ComponentPresetDao {
 
        public void setFavorite( ComponentPreset preset, boolean favorite );
        
+       public List<ComponentPreset> find( String manufacturer, String partNo );
+       
 }
\ No newline at end of file
index bfb025dcf7735ecf43439f416d00d04afef1c058..50d32125055fee8b28b98d075020352e31a917a1 100644 (file)
@@ -129,6 +129,17 @@ public class ComponentPresetDatabase extends Database<ComponentPreset> implement
                return result;
        }
 
+       @Override
+       public List<ComponentPreset> find(String manufacturer, String partNo) {
+               List<ComponentPreset> presets = new ArrayList<ComponentPreset>();
+               for( ComponentPreset preset : list ) {
+                       if ( preset.getManufacturer().getSimpleName().equals(manufacturer) && preset.getPartNo().equals(partNo) ) {
+                               presets.add(preset);
+                       }
+               }
+               return presets;
+       }
+
        @Override
        public void setFavorite( ComponentPreset preset, boolean favorite ) {
                preset.setFavorite(favorite);
index b3b5999b359d2c739e96a81cb2a407d7f8214f34..7ad6c6af7714e1799406c3d3e962a7d234ffcedf 100644 (file)
@@ -184,6 +184,9 @@ public class OpenRocketSaver extends RocketSaver {
         */
        private int calculateNecessaryFileVersion(OpenRocketDocument document, StorageOptions opts) {
                /*
+                * File version 1.5 is requires for:
+                *  - saving designs using ComponentPrests
+                *  
                 * File version 1.4 is required for:
                 *  - saving simulation data
                 *  - saving motor data
@@ -195,6 +198,22 @@ public class OpenRocketSaver extends RocketSaver {
                 * Otherwise use version 1.0.
                 */
                
+               // Search the rocket for any ComponentPrests
+               {
+                       Rocket r = document.getRocket();
+                       Iterator<RocketComponent> componentIterator = r.iterator();
+                       boolean usesComponentPreset = false;
+                       while ( !usesComponentPreset && componentIterator.hasNext() ) {
+                               RocketComponent c = componentIterator.next();
+                               if ( c.getPresetComponent() != null ) {
+                                       usesComponentPreset = true;
+                               }
+                       }
+                       if ( usesComponentPreset ) {
+                               return FILE_VERSION_DIVISOR + 5;
+                       }
+               }
+               
                // Check if design has simulations defined (version 1.4)
                if (document.getSimulationCount() > 0) {
                        return FILE_VERSION_DIVISOR + 4;
index eee1dae68aadd6ae2daab91f0a45550134297cbb..6a112f55d63df91dd353e7f7d99b83a1d9331e9e 100644 (file)
@@ -28,6 +28,7 @@ import net.sf.openrocket.file.simplesax.SimpleSAX;
 import net.sf.openrocket.logging.LogHelper;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Motor;
+import net.sf.openrocket.preset.ComponentPreset;
 import net.sf.openrocket.rocketcomponent.BodyComponent;
 import net.sf.openrocket.rocketcomponent.BodyTube;
 import net.sf.openrocket.rocketcomponent.Bulkhead;
@@ -97,30 +98,30 @@ import org.xml.sax.SAXException;
  */
 public class OpenRocketLoader extends AbstractRocketLoader {
        private static final LogHelper log = Application.getLogger();
-       
-       
+
+
        @Override
        public OpenRocketDocument loadFromStream(InputStream source, MotorFinder motorFinder) throws RocketLoadException,
-                       IOException {
+       IOException {
                log.info("Loading .ork file");
                DocumentLoadingContext context = new DocumentLoadingContext();
                context.setMotorFinder(motorFinder);
-               
+
                InputSource xmlSource = new InputSource(source);
                OpenRocketHandler handler = new OpenRocketHandler(context);
-               
-               
+
+
                try {
                        SimpleSAX.readXML(xmlSource, handler, warnings);
                } catch (SAXException e) {
                        log.warn("Malformed XML in input");
                        throw new RocketLoadException("Malformed XML in input.", e);
                }
-               
-               
+
+
                OpenRocketDocument doc = handler.getDocument();
                doc.getDefaultConfiguration().setAllStages();
-               
+
                // Deduce suitable time skip
                double timeSkip = StorageOptions.SIMULATION_DATA_NONE;
                for (Simulation s : doc.getSimulations()) {
@@ -137,7 +138,7 @@ public class OpenRocketLoader extends AbstractRocketLoader {
                        List<Double> list = branch.get(FlightDataType.TYPE_TIME);
                        if (list == null)
                                continue;
-                       
+
                        double previousTime = Double.NaN;
                        for (double time : list) {
                                if (time - previousTime < timeSkip)
@@ -147,33 +148,33 @@ public class OpenRocketLoader extends AbstractRocketLoader {
                }
                // Round value
                timeSkip = Math.rint(timeSkip * 100) / 100;
-               
+
                doc.getDefaultStorageOptions().setSimulationTimeSkip(timeSkip);
                doc.getDefaultStorageOptions().setCompressionEnabled(false); // Set by caller if compressed
                doc.getDefaultStorageOptions().setExplicitlySet(false);
-               
+
                doc.clearUndo();
                log.info("Loading done");
                return doc;
        }
-       
+
 }
 
 
 
 class DocumentConfig {
-       
+
        /* Remember to update OpenRocketSaver as well! */
-       public static final String[] SUPPORTED_VERSIONS = { "1.0", "1.1", "1.2", "1.3", "1.4" };
-       
+       public static final String[] SUPPORTED_VERSIONS = { "1.0", "1.1", "1.2", "1.3", "1.4", "1.5" };
+
        /**
         * Divisor used in converting an integer version to the point-represented version.
         * The integer version divided by this value is the major version and the remainder is
         * the minor version.  For example 101 corresponds to file version "1.1".
         */
        public static final int FILE_VERSION_DIVISOR = 100;
-       
-       
+
+
        ////////  Component constructors
        static final HashMap<String, Constructor<? extends RocketComponent>> constructors = new HashMap<String, Constructor<? extends RocketComponent>>();
        static {
@@ -186,29 +187,29 @@ class DocumentConfig {
                        constructors.put("ellipticalfinset", EllipticalFinSet.class.getConstructor(new Class<?>[0]));
                        constructors.put("freeformfinset", FreeformFinSet.class.getConstructor(new Class<?>[0]));
                        constructors.put("launchlug", LaunchLug.class.getConstructor(new Class<?>[0]));
-                       
+
                        // Internal components
                        constructors.put("engineblock", EngineBlock.class.getConstructor(new Class<?>[0]));
                        constructors.put("innertube", InnerTube.class.getConstructor(new Class<?>[0]));
                        constructors.put("tubecoupler", TubeCoupler.class.getConstructor(new Class<?>[0]));
                        constructors.put("bulkhead", Bulkhead.class.getConstructor(new Class<?>[0]));
                        constructors.put("centeringring", CenteringRing.class.getConstructor(new Class<?>[0]));
-                       
+
                        constructors.put("masscomponent", MassComponent.class.getConstructor(new Class<?>[0]));
                        constructors.put("shockcord", ShockCord.class.getConstructor(new Class<?>[0]));
                        constructors.put("parachute", Parachute.class.getConstructor(new Class<?>[0]));
                        constructors.put("streamer", Streamer.class.getConstructor(new Class<?>[0]));
-                       
+
                        // Other
                        constructors.put("stage", Stage.class.getConstructor(new Class<?>[0]));
-                       
+
                } catch (NoSuchMethodException e) {
                        throw new BugException(
                                        "Error in constructing the 'constructors' HashMap.");
                }
        }
-       
-       
+
+
        ////////  Parameter setters
        /*
         * The keys are of the form Class:param, where Class is the class name and param
@@ -236,7 +237,9 @@ class DocumentConfig {
                                Reflection.findMethod(RocketComponent.class, "setOverrideSubcomponents", boolean.class)));
                setters.put("RocketComponent:comment", new StringSetter(
                                Reflection.findMethod(RocketComponent.class, "setComment", String.class)));
-               
+               setters.put("RocketComponent:preset", new ComponentPresetSetter(
+                               Reflection.findMethod(RocketComponent.class, "loadPreset", ComponentPreset.class)));
+
                // ExternalComponent
                setters.put("ExternalComponent:finish", new EnumSetter<Finish>(
                                Reflection.findMethod(ExternalComponent.class, "setFinish", Finish.class),
@@ -244,23 +247,23 @@ class DocumentConfig {
                setters.put("ExternalComponent:material", new MaterialSetter(
                                Reflection.findMethod(ExternalComponent.class, "setMaterial", Material.class),
                                Material.Type.BULK));
-               
+
                // BodyComponent
                setters.put("BodyComponent:length", new DoubleSetter(
                                Reflection.findMethod(BodyComponent.class, "setLength", double.class)));
-               
+
                // SymmetricComponent
                setters.put("SymmetricComponent:thickness", new DoubleSetter(
                                Reflection.findMethod(SymmetricComponent.class, "setThickness", double.class),
                                "filled",
                                Reflection.findMethod(SymmetricComponent.class, "setFilled", boolean.class)));
-               
+
                // BodyTube
                setters.put("BodyTube:radius", new DoubleSetter(
                                Reflection.findMethod(BodyTube.class, "setOuterRadius", double.class),
                                "auto",
                                Reflection.findMethod(BodyTube.class, "setOuterRadiusAutomatic", boolean.class)));
-               
+
                // Transition
                setters.put("Transition:shape", new EnumSetter<Transition.Shape>(
                                Reflection.findMethod(Transition.class, "setType", Transition.Shape.class),
@@ -269,7 +272,7 @@ class DocumentConfig {
                                Reflection.findMethod(Transition.class, "setClipped", boolean.class)));
                setters.put("Transition:shapeparameter", new DoubleSetter(
                                Reflection.findMethod(Transition.class, "setShapeParameter", double.class)));
-               
+
                setters.put("Transition:foreradius", new DoubleSetter(
                                Reflection.findMethod(Transition.class, "setForeRadius", double.class),
                                "auto",
@@ -278,7 +281,7 @@ class DocumentConfig {
                                Reflection.findMethod(Transition.class, "setAftRadius", double.class),
                                "auto",
                                Reflection.findMethod(Transition.class, "setAftRadiusAutomatic", boolean.class)));
-               
+
                setters.put("Transition:foreshoulderradius", new DoubleSetter(
                                Reflection.findMethod(Transition.class, "setForeShoulderRadius", double.class)));
                setters.put("Transition:foreshoulderlength", new DoubleSetter(
@@ -287,7 +290,7 @@ class DocumentConfig {
                                Reflection.findMethod(Transition.class, "setForeShoulderThickness", double.class)));
                setters.put("Transition:foreshouldercapped", new BooleanSetter(
                                Reflection.findMethod(Transition.class, "setForeShoulderCapped", boolean.class)));
-               
+
                setters.put("Transition:aftshoulderradius", new DoubleSetter(
                                Reflection.findMethod(Transition.class, "setAftShoulderRadius", double.class)));
                setters.put("Transition:aftshoulderlength", new DoubleSetter(
@@ -296,14 +299,14 @@ class DocumentConfig {
                                Reflection.findMethod(Transition.class, "setAftShoulderThickness", double.class)));
                setters.put("Transition:aftshouldercapped", new BooleanSetter(
                                Reflection.findMethod(Transition.class, "setAftShoulderCapped", boolean.class)));
-               
+
                // NoseCone - disable disallowed elements
                setters.put("NoseCone:foreradius", null);
                setters.put("NoseCone:foreshoulderradius", null);
                setters.put("NoseCone:foreshoulderlength", null);
                setters.put("NoseCone:foreshoulderthickness", null);
                setters.put("NoseCone:foreshouldercapped", null);
-               
+
                // FinSet
                setters.put("FinSet:fincount", new IntSetter(
                                Reflection.findMethod(FinSet.class, "setFinCount", int.class)));
@@ -321,7 +324,7 @@ class DocumentConfig {
                setters.put("FinSet:tablength", new DoubleSetter(
                                Reflection.findMethod(FinSet.class, "setTabLength", double.class)));
                setters.put("FinSet:tabposition", new FinTabPositionSetter());
-               
+
                // TrapezoidFinSet
                setters.put("TrapezoidFinSet:rootchord", new DoubleSetter(
                                Reflection.findMethod(TrapezoidFinSet.class, "setRootChord", double.class)));
@@ -331,15 +334,15 @@ class DocumentConfig {
                                Reflection.findMethod(TrapezoidFinSet.class, "setSweep", double.class)));
                setters.put("TrapezoidFinSet:height", new DoubleSetter(
                                Reflection.findMethod(TrapezoidFinSet.class, "setHeight", double.class)));
-               
+
                // EllipticalFinSet
                setters.put("EllipticalFinSet:rootchord", new DoubleSetter(
                                Reflection.findMethod(EllipticalFinSet.class, "setLength", double.class)));
                setters.put("EllipticalFinSet:height", new DoubleSetter(
                                Reflection.findMethod(EllipticalFinSet.class, "setHeight", double.class)));
-               
+
                // FreeformFinSet points handled as a special handler
-               
+
                // LaunchLug
                setters.put("LaunchLug:radius", new DoubleSetter(
                                Reflection.findMethod(LaunchLug.class, "setOuterRadius", double.class)));
@@ -350,14 +353,14 @@ class DocumentConfig {
                setters.put("LaunchLug:radialdirection", new DoubleSetter(
                                Reflection.findMethod(LaunchLug.class, "setRadialDirection", double.class),
                                Math.PI / 180.0));
-               
+
                // InternalComponent - nothing
-               
+
                // StructuralComponent
                setters.put("StructuralComponent:material", new MaterialSetter(
                                Reflection.findMethod(StructuralComponent.class, "setMaterial", Material.class),
                                Material.Type.BULK));
-               
+
                // RingComponent
                setters.put("RingComponent:length", new DoubleSetter(
                                Reflection.findMethod(RingComponent.class, "setLength", double.class)));
@@ -366,23 +369,23 @@ class DocumentConfig {
                setters.put("RingComponent:radialdirection", new DoubleSetter(
                                Reflection.findMethod(RingComponent.class, "setRadialDirection", double.class),
                                Math.PI / 180.0));
-               
+
                // ThicknessRingComponent - radius on separate components due to differing automatics
                setters.put("ThicknessRingComponent:thickness", new DoubleSetter(
                                Reflection.findMethod(ThicknessRingComponent.class, "setThickness", double.class)));
-               
+
                // EngineBlock
                setters.put("EngineBlock:outerradius", new DoubleSetter(
                                Reflection.findMethod(EngineBlock.class, "setOuterRadius", double.class),
                                "auto",
                                Reflection.findMethod(EngineBlock.class, "setOuterRadiusAutomatic", boolean.class)));
-               
+
                // TubeCoupler
                setters.put("TubeCoupler:outerradius", new DoubleSetter(
                                Reflection.findMethod(TubeCoupler.class, "setOuterRadius", double.class),
                                "auto",
                                Reflection.findMethod(TubeCoupler.class, "setOuterRadiusAutomatic", boolean.class)));
-               
+
                // InnerTube
                setters.put("InnerTube:outerradius", new DoubleSetter(
                                Reflection.findMethod(InnerTube.class, "setOuterRadius", double.class)));
@@ -392,9 +395,9 @@ class DocumentConfig {
                setters.put("InnerTube:clusterrotation", new DoubleSetter(
                                Reflection.findMethod(InnerTube.class, "setClusterRotation", double.class),
                                Math.PI / 180.0));
-               
+
                // RadiusRingComponent
-               
+
                // Bulkhead
                setters.put("RadiusRingComponent:innerradius", new DoubleSetter(
                                Reflection.findMethod(RadiusRingComponent.class, "setInnerRadius", double.class)));
@@ -402,7 +405,7 @@ class DocumentConfig {
                                Reflection.findMethod(Bulkhead.class, "setOuterRadius", double.class),
                                "auto",
                                Reflection.findMethod(Bulkhead.class, "setOuterRadiusAutomatic", boolean.class)));
-               
+
                // CenteringRing
                setters.put("CenteringRing:innerradius", new DoubleSetter(
                                Reflection.findMethod(CenteringRing.class, "setInnerRadius", double.class),
@@ -412,8 +415,8 @@ class DocumentConfig {
                                Reflection.findMethod(CenteringRing.class, "setOuterRadius", double.class),
                                "auto",
                                Reflection.findMethod(CenteringRing.class, "setOuterRadiusAutomatic", boolean.class)));
-               
-               
+
+
                // MassObject
                setters.put("MassObject:packedlength", new DoubleSetter(
                                Reflection.findMethod(MassObject.class, "setLength", double.class)));
@@ -424,18 +427,18 @@ class DocumentConfig {
                setters.put("MassObject:radialdirection", new DoubleSetter(
                                Reflection.findMethod(MassObject.class, "setRadialDirection", double.class),
                                Math.PI / 180.0));
-               
+
                // MassComponent
                setters.put("MassComponent:mass", new DoubleSetter(
                                Reflection.findMethod(MassComponent.class, "setComponentMass", double.class)));
-               
+
                // ShockCord
                setters.put("ShockCord:cordlength", new DoubleSetter(
                                Reflection.findMethod(ShockCord.class, "setCordLength", double.class)));
                setters.put("ShockCord:material", new MaterialSetter(
                                Reflection.findMethod(ShockCord.class, "setMaterial", Material.class),
                                Material.Type.LINE));
-               
+
                // RecoveryDevice
                setters.put("RecoveryDevice:cd", new DoubleSetter(
                                Reflection.findMethod(RecoveryDevice.class, "setCD", double.class),
@@ -451,7 +454,7 @@ class DocumentConfig {
                setters.put("RecoveryDevice:material", new MaterialSetter(
                                Reflection.findMethod(RecoveryDevice.class, "setMaterial", Material.class),
                                Material.Type.SURFACE));
-               
+
                // Parachute
                setters.put("Parachute:diameter", new DoubleSetter(
                                Reflection.findMethod(Parachute.class, "setDiameter", double.class)));
@@ -462,13 +465,13 @@ class DocumentConfig {
                setters.put("Parachute:linematerial", new MaterialSetter(
                                Reflection.findMethod(Parachute.class, "setLineMaterial", Material.class),
                                Material.Type.LINE));
-               
+
                // Streamer
                setters.put("Streamer:striplength", new DoubleSetter(
                                Reflection.findMethod(Streamer.class, "setStripLength", double.class)));
                setters.put("Streamer:stripwidth", new DoubleSetter(
                                Reflection.findMethod(Streamer.class, "setStripWidth", double.class)));
-               
+
                // Rocket
                // <motorconfiguration> handled by separate handler
                setters.put("Rocket:referencetype", new EnumSetter<ReferenceType>(
@@ -480,17 +483,17 @@ class DocumentConfig {
                                Reflection.findMethod(Rocket.class, "setDesigner", String.class)));
                setters.put("Rocket:revision", new StringSetter(
                                Reflection.findMethod(Rocket.class, "setRevision", String.class)));
-               
+
                // Stage
                setters.put("Stage:separationevent", new EnumSetter<Stage.SeparationEvent>(
                                Reflection.findMethod(Stage.class, "setSeparationEvent", Stage.SeparationEvent.class),
                                Stage.SeparationEvent.class));
                setters.put("Stage:separationdelay", new DoubleSetter(
                                Reflection.findMethod(Stage.class, "setSeparationDelay", double.class)));
-               
+
        }
-       
-       
+
+
        /**
         * Search for a enum value that has the corresponding name as an XML value.  The current
         * conversion from enum name to XML value is to lowercase the name and strip out all 
@@ -504,7 +507,7 @@ class DocumentConfig {
         */
        public static <T extends Enum<T>> Enum<T> findEnum(String name,
                        Class<? extends Enum<T>> enumClass) {
-               
+
                if (name == null)
                        return null;
                name = name.trim();
@@ -515,8 +518,8 @@ class DocumentConfig {
                }
                return null;
        }
-       
-       
+
+
        /**
         * Convert a string to a double including formatting specifications of the OpenRocket
         * file format.  This accepts all formatting that is valid for 
@@ -550,11 +553,11 @@ class DocumentConfig {
 class OpenRocketHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
        private OpenRocketContentHandler handler = null;
-       
+
        public OpenRocketHandler(DocumentLoadingContext context) {
                this.context = context;
        }
-       
+
        /**
         * Return the OpenRocketDocument read from the file, or <code>null</code> if a document
         * has not been read yet.
@@ -564,24 +567,24 @@ class OpenRocketHandler extends AbstractElementHandler {
        public OpenRocketDocument getDocument() {
                return handler.getDocument();
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                // Check for unknown elements
                if (!element.equals("openrocket")) {
                        warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
                        return null;
                }
-               
+
                // Check for first call
                if (handler != null) {
                        warnings.add(Warning.fromString("Multiple document elements found, ignoring later "
                                        + "ones."));
                        return null;
                }
-               
+
                // Check version number
                String version = null;
                String creator = attributes.remove("creator");
@@ -601,18 +604,18 @@ class OpenRocketHandler extends AbstractElementHandler {
                        str += ", attempting to read file anyway.";
                        warnings.add(str);
                }
-               
+
                context.setFileVersion(parseVersion(docVersion));
-               
+
                handler = new OpenRocketContentHandler(context);
                return handler;
        }
-       
-       
+
+
        private int parseVersion(String docVersion) {
                if (docVersion == null)
                        return 0;
-               
+
                Matcher m = Pattern.compile("^([0-9]+)\\.([0-9]+)$").matcher(docVersion);
                if (m.matches()) {
                        int major = Integer.parseInt(m.group(1));
@@ -622,7 +625,7 @@ class OpenRocketHandler extends AbstractElementHandler {
                        return 0;
                }
        }
-       
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) throws SAXException {
@@ -630,8 +633,8 @@ class OpenRocketHandler extends AbstractElementHandler {
                attributes.remove("creator");
                super.closeElement(element, attributes, content, warnings);
        }
-       
-       
+
+
 }
 
 
@@ -642,27 +645,27 @@ class OpenRocketContentHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
        private final OpenRocketDocument doc;
        private final Rocket rocket;
-       
+
        private boolean rocketDefined = false;
        private boolean simulationsDefined = false;
-       
+
        public OpenRocketContentHandler(DocumentLoadingContext context) {
                this.context = context;
                this.rocket = new Rocket();
                this.doc = new OpenRocketDocument(rocket);
        }
-       
-       
+
+
        public OpenRocketDocument getDocument() {
                if (!rocketDefined)
                        return null;
                return doc;
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                if (element.equals("rocket")) {
                        if (rocketDefined) {
                                warnings.add(Warning
@@ -673,7 +676,7 @@ class OpenRocketContentHandler extends AbstractElementHandler {
                        rocketDefined = true;
                        return new ComponentParameterHandler(rocket, context);
                }
-               
+
                if (element.equals("simulations")) {
                        if (simulationsDefined) {
                                warnings.add(Warning
@@ -684,9 +687,9 @@ class OpenRocketContentHandler extends AbstractElementHandler {
                        simulationsDefined = true;
                        return new SimulationsHandler(doc, context);
                }
-               
+
                warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
-               
+
                return null;
        }
 }
@@ -701,16 +704,16 @@ class OpenRocketContentHandler extends AbstractElementHandler {
 class ComponentHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
        private final RocketComponent parent;
-       
+
        public ComponentHandler(RocketComponent parent, DocumentLoadingContext context) {
                this.parent = parent;
                this.context = context;
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                // Attempt to construct new component
                Constructor<? extends RocketComponent> constructor = DocumentConfig.constructors
                                .get(element);
@@ -718,7 +721,7 @@ class ComponentHandler extends AbstractElementHandler {
                        warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
                        return null;
                }
-               
+
                RocketComponent c;
                try {
                        c = constructor.newInstance();
@@ -729,9 +732,9 @@ class ComponentHandler extends AbstractElementHandler {
                } catch (InvocationTargetException e) {
                        throw Reflection.handleWrappedException(e);
                }
-               
+
                parent.addChild(c);
-               
+
                return new ComponentParameterHandler(c, context);
        }
 }
@@ -745,16 +748,16 @@ class ComponentHandler extends AbstractElementHandler {
 class ComponentParameterHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
        private final RocketComponent component;
-       
+
        public ComponentParameterHandler(RocketComponent c, DocumentLoadingContext context) {
                this.component = c;
                this.context = context;
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                // Check for specific elements that contain other elements
                if (element.equals("subcomponents")) {
                        return new ComponentHandler(component, context);
@@ -780,22 +783,22 @@ class ComponentParameterHandler extends AbstractElementHandler {
                        }
                        return new MotorConfigurationHandler((Rocket) component, context);
                }
-               
-               
+
+
                return PlainTextHandler.INSTANCE;
        }
-       
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
-               
+
                if (element.equals("subcomponents") || element.equals("motormount") ||
                                element.equals("finpoints") || element.equals("motorconfiguration")) {
                        return;
                }
-               
+
                // Search for the correct setter class
-               
+
                Class<?> c;
                for (c = component.getClass(); c != null; c = c.getSuperclass()) {
                        String setterKey = c.getSimpleName() + ":" + element;
@@ -828,23 +831,23 @@ class FinSetPointHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
        private final FreeformFinSet finset;
        private final ArrayList<Coordinate> coordinates = new ArrayList<Coordinate>();
-       
+
        public FinSetPointHandler(FreeformFinSet finset, DocumentLoadingContext context) {
                this.finset = finset;
                this.context = context;
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
                return PlainTextHandler.INSTANCE;
        }
-       
-       
+
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) throws SAXException {
-               
+
                String strx = attributes.remove("x");
                String stry = attributes.remove("y");
                if (strx == null || stry == null) {
@@ -859,10 +862,10 @@ class FinSetPointHandler extends AbstractElementHandler {
                        warnings.add(Warning.fromString("Illegal fin points specification, ignoring."));
                        return;
                }
-               
+
                super.closeElement(element, attributes, content, warnings);
        }
-       
+
        @Override
        public void endHandler(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
@@ -879,51 +882,51 @@ class MotorMountHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
        private final MotorMount mount;
        private MotorHandler motorHandler;
-       
+
        public MotorMountHandler(MotorMount mount, DocumentLoadingContext context) {
                this.mount = mount;
                this.context = context;
                mount.setMotorMount(true);
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                if (element.equals("motor")) {
                        motorHandler = new MotorHandler(context);
                        return motorHandler;
                }
-               
+
                if (element.equals("ignitionevent") ||
                                element.equals("ignitiondelay") ||
                                element.equals("overhang")) {
                        return PlainTextHandler.INSTANCE;
                }
-               
+
                warnings.add(Warning.fromString("Unknown element '" + element + "' encountered, ignoring."));
                return null;
        }
-       
-       
-       
+
+
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) throws SAXException {
-               
+
                if (element.equals("motor")) {
                        String id = attributes.get("configid");
                        if (id == null || id.equals("")) {
                                warnings.add(Warning.fromString("Illegal motor specification, ignoring."));
                                return;
                        }
-                       
+
                        Motor motor = motorHandler.getMotor(warnings);
                        mount.setMotor(id, motor);
                        mount.setMotorDelay(id, motorHandler.getDelay(warnings));
                        return;
                }
-               
+
                if (element.equals("ignitionevent")) {
                        MotorMount.IgnitionEvent event = null;
                        for (MotorMount.IgnitionEvent e : MotorMount.IgnitionEvent.values()) {
@@ -939,7 +942,7 @@ class MotorMountHandler extends AbstractElementHandler {
                        mount.setIgnitionEvent(event);
                        return;
                }
-               
+
                if (element.equals("ignitiondelay")) {
                        double d;
                        try {
@@ -951,7 +954,7 @@ class MotorMountHandler extends AbstractElementHandler {
                        mount.setIgnitionDelay(d);
                        return;
                }
-               
+
                if (element.equals("overhang")) {
                        double d;
                        try {
@@ -963,7 +966,7 @@ class MotorMountHandler extends AbstractElementHandler {
                        mount.setMotorOverhang(d);
                        return;
                }
-               
+
                super.closeElement(element, attributes, content, warnings);
        }
 }
@@ -977,54 +980,54 @@ class MotorConfigurationHandler extends AbstractElementHandler {
        private final Rocket rocket;
        private String name = null;
        private boolean inNameElement = false;
-       
+
        public MotorConfigurationHandler(Rocket rocket, DocumentLoadingContext context) {
                this.rocket = rocket;
                this.context = context;
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                if (inNameElement || !element.equals("name")) {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                        return null;
                }
                inNameElement = true;
-               
+
                return PlainTextHandler.INSTANCE;
        }
-       
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
                name = content;
        }
-       
+
        @Override
        public void endHandler(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) throws SAXException {
-               
+
                String configid = attributes.remove("configid");
                if (configid == null || configid.equals("")) {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                        return;
                }
-               
+
                if (!rocket.addMotorConfigurationID(configid)) {
                        warnings.add("Duplicate motor configuration ID used.");
                        return;
                }
-               
+
                if (name != null && name.trim().length() > 0) {
                        rocket.setMotorConfigurationName(configid, name);
                }
-               
+
                if ("true".equals(attributes.remove("default"))) {
                        rocket.getDefaultConfiguration().setMotorConfigurationID(configid);
                }
-               
+
                super.closeElement(element, attributes, content, warnings);
        }
 }
@@ -1033,7 +1036,7 @@ class MotorConfigurationHandler extends AbstractElementHandler {
 class MotorHandler extends AbstractElementHandler {
        /** File version where latest digest format was introduced */
        private static final int MOTOR_DIGEST_VERSION = 104;
-       
+
        private final DocumentLoadingContext context;
        private Motor.Type type = null;
        private String manufacturer = null;
@@ -1042,26 +1045,26 @@ class MotorHandler extends AbstractElementHandler {
        private double diameter = Double.NaN;
        private double length = Double.NaN;
        private double delay = Double.NaN;
-       
+
        public MotorHandler(DocumentLoadingContext context) {
                this.context = context;
        }
-       
-       
+
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
                return PlainTextHandler.INSTANCE;
        }
-       
-       
+
+
        /**
         * Return the motor to use, or null.
         */
        public Motor getMotor(WarningSet warnings) {
                return context.getMotorFinder().findMotor(type, manufacturer, designation, diameter, length, digest, warnings);
        }
-       
+
        /**
         * Return the delay to use for the motor.
         */
@@ -1072,16 +1075,16 @@ class MotorHandler extends AbstractElementHandler {
                }
                return delay;
        }
-       
-       
+
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) throws SAXException {
-               
+
                content = content.trim();
-               
+
                if (element.equals("type")) {
-                       
+
                        // Motor type
                        type = null;
                        for (Motor.Type t : Motor.Type.values()) {
@@ -1093,26 +1096,26 @@ class MotorHandler extends AbstractElementHandler {
                        if (type == null) {
                                warnings.add(Warning.fromString("Unknown motor type '" + content + "', ignoring."));
                        }
-                       
+
                } else if (element.equals("manufacturer")) {
-                       
+
                        // Manufacturer
                        manufacturer = content.trim();
-                       
+
                } else if (element.equals("designation")) {
-                       
+
                        // Designation
                        designation = content.trim();
-                       
+
                } else if (element.equals("digest")) {
-                       
+
                        // Digest is used only for file versions saved using the same digest algorithm
                        if (context.getFileVersion() >= MOTOR_DIGEST_VERSION) {
                                digest = content.trim();
                        }
-                       
+
                } else if (element.equals("diameter")) {
-                       
+
                        // Diameter
                        diameter = Double.NaN;
                        try {
@@ -1123,22 +1126,22 @@ class MotorHandler extends AbstractElementHandler {
                        if (Double.isNaN(diameter)) {
                                warnings.add(Warning.fromString("Illegal motor diameter specified, ignoring."));
                        }
-                       
+
                } else if (element.equals("length")) {
-                       
+
                        // Length
                        length = Double.NaN;
                        try {
                                length = Double.parseDouble(content.trim());
                        } catch (NumberFormatException ignore) {
                        }
-                       
+
                        if (Double.isNaN(length)) {
                                warnings.add(Warning.fromString("Illegal motor diameter specified, ignoring."));
                        }
-                       
+
                } else if (element.equals("delay")) {
-                       
+
                        // Delay
                        delay = Double.NaN;
                        if (content.equals("none")) {
@@ -1148,18 +1151,18 @@ class MotorHandler extends AbstractElementHandler {
                                        delay = Double.parseDouble(content.trim());
                                } catch (NumberFormatException ignore) {
                                }
-                               
+
                                if (Double.isNaN(delay)) {
                                        warnings.add(Warning.fromString("Illegal motor delay specified, ignoring."));
                                }
-                               
+
                        }
-                       
+
                } else {
                        super.closeElement(element, attributes, content, warnings);
                }
        }
-       
+
 }
 
 
@@ -1168,58 +1171,58 @@ class SimulationsHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
        private final OpenRocketDocument doc;
        private SingleSimulationHandler handler;
-       
+
        public SimulationsHandler(OpenRocketDocument doc, DocumentLoadingContext context) {
                this.doc = doc;
                this.context = context;
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                if (!element.equals("simulation")) {
                        warnings.add("Unknown element '" + element + "', ignoring.");
                        return null;
                }
-               
+
                handler = new SingleSimulationHandler(doc, context);
                return handler;
        }
-       
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) throws SAXException {
                attributes.remove("status");
                super.closeElement(element, attributes, content, warnings);
        }
-       
-       
+
+
 }
 
 class SingleSimulationHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
-       
+
        private final OpenRocketDocument doc;
-       
+
        private String name;
-       
+
        private SimulationConditionsHandler conditionHandler;
        private FlightDataHandler dataHandler;
-       
+
        private final List<String> listeners = new ArrayList<String>();
-       
+
        public SingleSimulationHandler(OpenRocketDocument doc, DocumentLoadingContext context) {
                this.doc = doc;
                this.context = context;
        }
-       
-       
-       
+
+
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                if (element.equals("name") || element.equals("simulator") ||
                                element.equals("calculator") || element.equals("listener")) {
                        return PlainTextHandler.INSTANCE;
@@ -1234,11 +1237,11 @@ class SingleSimulationHandler extends AbstractElementHandler {
                        return null;
                }
        }
-       
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
-               
+
                if (element.equals("name")) {
                        name = content;
                } else if (element.equals("simulator")) {
@@ -1252,20 +1255,20 @@ class SingleSimulationHandler extends AbstractElementHandler {
                } else if (element.equals("listener") && content.trim().length() > 0) {
                        listeners.add(content.trim());
                }
-               
+
        }
-       
+
        @Override
        public void endHandler(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
-               
+
                String s = attributes.get("status");
                Simulation.Status status = (Status) DocumentConfig.findEnum(s, Simulation.Status.class);
                if (status == null) {
                        warnings.add("Simulation status unknown, assuming outdated.");
                        status = Simulation.Status.OUTDATED;
                }
-               
+
                SimulationOptions conditions;
                if (conditionHandler != null) {
                        conditions = conditionHandler.getConditions();
@@ -1273,19 +1276,19 @@ class SingleSimulationHandler extends AbstractElementHandler {
                        warnings.add("Simulation conditions not defined, using defaults.");
                        conditions = new SimulationOptions(doc.getRocket());
                }
-               
+
                if (name == null)
                        name = "Simulation";
-               
+
                FlightData data;
                if (dataHandler == null)
                        data = null;
                else
                        data = dataHandler.getFlightData();
-               
+
                Simulation simulation = new Simulation(doc.getRocket(), status, name,
                                conditions, listeners, data);
-               
+
                doc.addSimulation(simulation);
        }
 }
@@ -1296,18 +1299,18 @@ class SimulationConditionsHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
        private SimulationOptions conditions;
        private AtmosphereHandler atmosphereHandler;
-       
+
        public SimulationConditionsHandler(Rocket rocket, DocumentLoadingContext context) {
                this.context = context;
                conditions = new SimulationOptions(rocket);
                // Set up default loading settings (which may differ from the new defaults)
                conditions.setGeodeticComputation(GeodeticComputationStrategy.FLAT);
        }
-       
+
        public SimulationOptions getConditions() {
                return conditions;
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
@@ -1317,18 +1320,18 @@ class SimulationConditionsHandler extends AbstractElementHandler {
                }
                return PlainTextHandler.INSTANCE;
        }
-       
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
-               
+
                double d = Double.NaN;
                try {
                        d = Double.parseDouble(content);
                } catch (NumberFormatException ignore) {
                }
-               
-               
+
+
                if (element.equals("configid")) {
                        if (content.equals("")) {
                                conditions.setMotorConfigurationID(null);
@@ -1410,28 +1413,28 @@ class AtmosphereHandler extends AbstractElementHandler {
        private final String model;
        private double temperature = Double.NaN;
        private double pressure = Double.NaN;
-       
+
        public AtmosphereHandler(String model, DocumentLoadingContext context) {
                this.model = model;
                this.context = context;
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
                return PlainTextHandler.INSTANCE;
        }
-       
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) throws SAXException {
-               
+
                double d = Double.NaN;
                try {
                        d = Double.parseDouble(content);
                } catch (NumberFormatException ignore) {
                }
-               
+
                if (element.equals("basetemperature")) {
                        if (Double.isNaN(d)) {
                                warnings.add("Illegal base temperature specified, ignoring.");
@@ -1446,8 +1449,8 @@ class AtmosphereHandler extends AbstractElementHandler {
                        super.closeElement(element, attributes, content, warnings);
                }
        }
-       
-       
+
+
        public void storeSettings(SimulationOptions cond, WarningSet warnings) {
                if (!Double.isNaN(pressure)) {
                        cond.setLaunchPressure(pressure);
@@ -1455,7 +1458,7 @@ class AtmosphereHandler extends AbstractElementHandler {
                if (!Double.isNaN(temperature)) {
                        cond.setLaunchTemperature(temperature);
                }
-               
+
                if ("isa".equals(model)) {
                        cond.setISAAtmosphere(true);
                } else if ("extendedisa".equals(model)) {
@@ -1465,32 +1468,32 @@ class AtmosphereHandler extends AbstractElementHandler {
                        warnings.add("Unknown atmospheric model, using ISA.");
                }
        }
-       
+
 }
 
 
 class FlightDataHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
-       
+
        private FlightDataBranchHandler dataHandler;
        private WarningSet warningSet = new WarningSet();
        private List<FlightDataBranch> branches = new ArrayList<FlightDataBranch>();
-       
+
        private FlightData data;
-       
-       
+
+
        public FlightDataHandler(DocumentLoadingContext context) {
                this.context = context;
        }
-       
+
        public FlightData getFlightData() {
                return data;
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                if (element.equals("warning")) {
                        return PlainTextHandler.INSTANCE;
                }
@@ -1503,16 +1506,16 @@ class FlightDataHandler extends AbstractElementHandler {
                                        attributes.get("types"), context);
                        return dataHandler;
                }
-               
+
                warnings.add("Unknown element '" + element + "' encountered, ignoring.");
                return null;
        }
-       
-       
+
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
-               
+
                if (element.equals("databranch")) {
                        FlightDataBranch branch = dataHandler.getBranch();
                        if (branch.getLength() > 0) {
@@ -1522,12 +1525,12 @@ class FlightDataHandler extends AbstractElementHandler {
                        warningSet.add(Warning.fromString(content));
                }
        }
-       
-       
+
+
        @Override
        public void endHandler(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
-               
+
                if (branches.size() > 0) {
                        data = new FlightData(branches.toArray(new FlightDataBranch[0]));
                } else {
@@ -1540,7 +1543,7 @@ class FlightDataHandler extends AbstractElementHandler {
                        double groundHitVelocity = Double.NaN;
                        double launchRodVelocity = Double.NaN;
                        double deploymentVelocity = Double.NaN;
-                       
+
                        try {
                                maxAltitude = DocumentConfig.stringToDouble(attributes.get("maxaltitude"));
                        } catch (NumberFormatException ignore) {
@@ -1578,16 +1581,16 @@ class FlightDataHandler extends AbstractElementHandler {
                                deploymentVelocity = DocumentConfig.stringToDouble(attributes.get("deploymentvelocity"));
                        } catch (NumberFormatException ignore) {
                        }
-                       
+
                        data = new FlightData(maxAltitude, maxVelocity, maxAcceleration, maxMach,
                                        timeToApogee, flightTime, groundHitVelocity, launchRodVelocity, deploymentVelocity);
                }
-               
+
                data.getWarningSet().addAll(warningSet);
                data.immute();
        }
-       
-       
+
+
 }
 
 
@@ -1596,7 +1599,7 @@ class FlightDataBranchHandler extends AbstractElementHandler {
        private final DocumentLoadingContext context;
        private final FlightDataType[] types;
        private final FlightDataBranch branch;
-       
+
        public FlightDataBranchHandler(String name, String typeList, DocumentLoadingContext context) {
                this.context = context;
                String[] split = typeList.split(",");
@@ -1604,70 +1607,70 @@ class FlightDataBranchHandler extends AbstractElementHandler {
                for (int i = 0; i < split.length; i++) {
                        types[i] = FlightDataType.getType(split[i], UnitGroup.UNITS_NONE);
                }
-               
+
                // TODO: LOW: May throw an IllegalArgumentException
                branch = new FlightDataBranch(name, types);
        }
-       
+
        public FlightDataBranch getBranch() {
                branch.immute();
                return branch;
        }
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                if (element.equals("datapoint"))
                        return PlainTextHandler.INSTANCE;
                if (element.equals("event"))
                        return PlainTextHandler.INSTANCE;
-               
+
                warnings.add("Unknown element '" + element + "' encountered, ignoring.");
                return null;
        }
-       
-       
+
+
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
-               
+
                if (element.equals("event")) {
                        double time;
                        FlightEvent.Type type;
-                       
+
                        try {
                                time = DocumentConfig.stringToDouble(attributes.get("time"));
                        } catch (NumberFormatException e) {
                                warnings.add("Illegal event specification, ignoring.");
                                return;
                        }
-                       
+
                        type = (Type) DocumentConfig.findEnum(attributes.get("type"), FlightEvent.Type.class);
                        if (type == null) {
                                warnings.add("Illegal event specification, ignoring.");
                                return;
                        }
-                       
+
                        branch.addEvent(new FlightEvent(type, time));
                        return;
                }
-               
+
                if (!element.equals("datapoint")) {
                        warnings.add("Unknown element '" + element + "' encountered, ignoring.");
                        return;
                }
-               
+
                // element == "datapoint"
-               
-               
+
+
                // Check line format
                String[] split = content.split(",");
                if (split.length != types.length) {
                        warnings.add("Data point did not contain correct amount of values, ignoring point.");
                        return;
                }
-               
+
                // Parse the doubles
                double[] values = new double[split.length];
                for (int i = 0; i < values.length; i++) {
@@ -1678,7 +1681,7 @@ class FlightDataBranchHandler extends AbstractElementHandler {
                                return;
                        }
                }
-               
+
                // Add point to branch
                branch.addPoint();
                for (int i = 0; i < types.length; i++) {
@@ -1712,11 +1715,11 @@ interface Setter {
 ////  StringSetter - sets the value to the contained String
 class StringSetter implements Setter {
        private final Reflection.Method setMethod;
-       
+
        public StringSetter(Reflection.Method set) {
                setMethod = set;
        }
-       
+
        @Override
        public void set(RocketComponent c, String s, HashMap<String, String> attributes,
                        WarningSet warnings) {
@@ -1727,11 +1730,11 @@ class StringSetter implements Setter {
 ////  IntSetter - set an integer value
 class IntSetter implements Setter {
        private final Reflection.Method setMethod;
-       
+
        public IntSetter(Reflection.Method set) {
                setMethod = set;
        }
-       
+
        @Override
        public void set(RocketComponent c, String s, HashMap<String, String> attributes,
                        WarningSet warnings) {
@@ -1748,15 +1751,15 @@ class IntSetter implements Setter {
 //// BooleanSetter - set a boolean value
 class BooleanSetter implements Setter {
        private final Reflection.Method setMethod;
-       
+
        public BooleanSetter(Reflection.Method set) {
                setMethod = set;
        }
-       
+
        @Override
        public void set(RocketComponent c, String s, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                s = s.trim();
                if (s.equalsIgnoreCase("true")) {
                        setMethod.invoke(c, true);
@@ -1777,7 +1780,7 @@ class DoubleSetter implements Setter {
        private final String specialString;
        private final Reflection.Method specialMethod;
        private final double multiplier;
-       
+
        /**
         * Set only the double value.
         * @param set   set method for the double value. 
@@ -1788,7 +1791,7 @@ class DoubleSetter implements Setter {
                this.specialMethod = null;
                this.multiplier = 1.0;
        }
-       
+
        /**
         * Multiply with the given multiplier and set the double value.
         * @param set   set method for the double value.
@@ -1800,7 +1803,7 @@ class DoubleSetter implements Setter {
                this.specialMethod = null;
                this.multiplier = mul;
        }
-       
+
        /**
         * Set the double value, or if the value equals the special string, use the
         * special setter and set it to true.
@@ -1816,20 +1819,20 @@ class DoubleSetter implements Setter {
                this.specialMethod = specialMethod;
                this.multiplier = 1.0;
        }
-       
-       
+
+
        @Override
        public void set(RocketComponent c, String s, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                s = s.trim();
-               
+
                // Check for special case
                if (specialMethod != null && s.equalsIgnoreCase(specialString)) {
                        specialMethod.invoke(c, true);
                        return;
                }
-               
+
                // Normal case
                try {
                        double d = Double.parseDouble(s);
@@ -1844,16 +1847,16 @@ class DoubleSetter implements Setter {
 class OverrideSetter implements Setter {
        private final Reflection.Method setMethod;
        private final Reflection.Method enabledMethod;
-       
+
        public OverrideSetter(Reflection.Method set, Reflection.Method enabledMethod) {
                this.setMethod = set;
                this.enabledMethod = enabledMethod;
        }
-       
+
        @Override
        public void set(RocketComponent c, String s, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                try {
                        double d = Double.parseDouble(s);
                        setMethod.invoke(c, d);
@@ -1868,22 +1871,22 @@ class OverrideSetter implements Setter {
 class EnumSetter<T extends Enum<T>> implements Setter {
        private final Reflection.Method setter;
        private final Class<T> enumClass;
-       
+
        public EnumSetter(Reflection.Method set, Class<T> enumClass) {
                this.setter = set;
                this.enumClass = enumClass;
        }
-       
+
        @Override
        public void set(RocketComponent c, String name, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                Enum<?> setEnum = DocumentConfig.findEnum(name, enumClass);
                if (setEnum == null) {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                        return;
                }
-               
+
                setter.invoke(c, setEnum);
        }
 }
@@ -1892,24 +1895,24 @@ class EnumSetter<T extends Enum<T>> implements Setter {
 ////  ColorSetter  -  sets a Color value
 class ColorSetter implements Setter {
        private final Reflection.Method setMethod;
-       
+
        public ColorSetter(Reflection.Method set) {
                setMethod = set;
        }
-       
+
        @Override
        public void set(RocketComponent c, String s, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                String red = attributes.get("red");
                String green = attributes.get("green");
                String blue = attributes.get("blue");
-               
+
                if (red == null || green == null || blue == null) {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                        return;
                }
-               
+
                int r, g, b;
                try {
                        r = Integer.parseInt(red);
@@ -1919,45 +1922,109 @@ class ColorSetter implements Setter {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                        return;
                }
-               
+
                if (r < 0 || g < 0 || b < 0 || r > 255 || g > 255 || b > 255) {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                        return;
                }
-               
+
                Color color = new Color(r, g, b);
                setMethod.invoke(c, color);
-               
+
                if (!s.trim().equals("")) {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                }
        }
 }
 
+////ComponentPresetSetter  -  sets a ComponentPreset value
+class ComponentPresetSetter implements Setter {
+       private final Reflection.Method setMethod;
+
+       public ComponentPresetSetter(Reflection.Method set) {
+               this.setMethod = set;
+       }
+
+       @Override
+       public void set(RocketComponent c, String name, HashMap<String, String> attributes,
+                       WarningSet warnings) {
+// FIXME - probably need more data in the warning messages - like what component preset...
+               String manufacturerName = attributes.get("manufacturer");
+               if ( manufacturerName == null ) {
+                       warnings.add(Warning.fromString("Invalid ComponentPreset, no manufacturer specified.  Ignored"));
+                       return;
+               }
+
+               String productNo = attributes.get("partno");
+               if ( productNo == null ) {
+                       warnings.add(Warning.fromString("Invalid ComponentPreset, no partno specified.  Ignored"));
+                       return;
+               }
 
+               String digest = attributes.get("digest");
+               if ( digest == null ) {
+                       warnings.add(Warning.fromString("Invalid ComponentPreset, no digest specified."));
+               }
 
+               String type = attributes.get("type");
+               if ( type == null ) {
+                       warnings.add(Warning.fromString("Invalid ComponentPreset, no type specified."));
+               }
+
+               List<ComponentPreset> presets = Application.getComponentPresetDao().find( manufacturerName, productNo );
+
+               ComponentPreset matchingPreset = null;
+
+               for( ComponentPreset preset: presets ) {
+                       if ( digest != null && preset.getDigest().equals(digest) ) {
+                               // Found one with matching digest.  Take it.
+                               matchingPreset = preset;
+                               break;
+                       }
+                       if ( type != null && preset.getType().name().equals(type) && matchingPreset != null) {
+                               // Found the first one with matching type.
+                               matchingPreset = preset;
+                       }
+               }
+
+               // Was any found?
+               if ( matchingPreset == null ) {
+                       warnings.add(Warning.fromString("No matching ComponentPreset found"));
+                       return;
+               }
+               
+               if ( digest != null && !matchingPreset.getDigest().equals(digest) ) {
+                       warnings.add(Warning.fromString("ComponentPreset has wrong digest"));
+               }
+
+               setMethod.invoke(c, matchingPreset);
+       }
+}
+
+
+////MaterialSetter  -  sets a Material value
 class MaterialSetter implements Setter {
        private final Reflection.Method setMethod;
        private final Material.Type type;
-       
+
        public MaterialSetter(Reflection.Method set, Material.Type type) {
                this.setMethod = set;
                this.type = type;
        }
-       
+
        @Override
        public void set(RocketComponent c, String name, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                Material mat;
-               
+
                // Check name != ""
                name = name.trim();
                if (name.equals("")) {
                        warnings.add(Warning.fromString("Illegal material specification, ignoring."));
                        return;
                }
-               
+
                // Parse density
                double density;
                String str;
@@ -1972,7 +2039,7 @@ class MaterialSetter implements Setter {
                        warnings.add(Warning.fromString("Illegal material specification, ignoring."));
                        return;
                }
-               
+
                // Parse thickness
                //              double thickness = 0;
                //              str = attributes.remove("thickness");
@@ -1983,16 +2050,16 @@ class MaterialSetter implements Setter {
                //                      warnings.add(Warning.fromString("Illegal material specification, ignoring."));
                //                      return;
                //              }
-               
+
                // Check type if specified
                str = attributes.remove("type");
                if (str != null && !type.name().toLowerCase(Locale.ENGLISH).equals(str)) {
                        warnings.add(Warning.fromString("Illegal material type specified, ignoring."));
                        return;
                }
-               
+
                mat = Databases.findMaterial(type, name, density, false);
-               
+
                setMethod.invoke(c, mat);
        }
 }
@@ -2001,18 +2068,18 @@ class MaterialSetter implements Setter {
 
 
 class PositionSetter implements Setter {
-       
+
        @Override
        public void set(RocketComponent c, String value, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                RocketComponent.Position type = (Position) DocumentConfig.findEnum(attributes.get("type"),
                                RocketComponent.Position.class);
                if (type == null) {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                        return;
                }
-               
+
                double pos;
                try {
                        pos = Double.parseDouble(value);
@@ -2020,7 +2087,7 @@ class PositionSetter implements Setter {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                        return;
                }
-               
+
                if (c instanceof FinSet) {
                        ((FinSet) c).setRelativePosition(type);
                        c.setPositionValue(pos);
@@ -2033,34 +2100,34 @@ class PositionSetter implements Setter {
                } else {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                }
-               
+
        }
 }
 
 
 class FinTabPositionSetter extends DoubleSetter {
-       
+
        public FinTabPositionSetter() {
                super(Reflection.findMethod(FinSet.class, "setTabShift", double.class));
        }
-       
+
        @Override
        public void set(RocketComponent c, String s, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                if (!(c instanceof FinSet)) {
                        throw new IllegalStateException("FinTabPositionSetter called for component " + c);
                }
-               
+
                String relative = attributes.get("relativeto");
                FinSet.TabRelativePosition position =
                                (TabRelativePosition) DocumentConfig.findEnum(relative,
                                                FinSet.TabRelativePosition.class);
-               
+
                if (position != null) {
-                       
+
                        ((FinSet) c).setTabRelativePosition(position);
-                       
+
                } else {
                        if (relative == null) {
                                warnings.add("Required attribute 'relativeto' not found for fin tab position.");
@@ -2068,25 +2135,25 @@ class FinTabPositionSetter extends DoubleSetter {
                                warnings.add("Illegal attribute value '" + relative + "' encountered.");
                        }
                }
-               
+
                super.set(c, s, attributes, warnings);
        }
-       
-       
+
+
 }
 
 
 class ClusterConfigurationSetter implements Setter {
-       
+
        @Override
        public void set(RocketComponent component, String value, HashMap<String, String> attributes,
                        WarningSet warnings) {
-               
+
                if (!(component instanceof Clusterable)) {
                        warnings.add("Illegal component defined as cluster.");
                        return;
                }
-               
+
                ClusterConfiguration config = null;
                for (ClusterConfiguration c : ClusterConfiguration.CONFIGURATIONS) {
                        if (c.getXMLName().equals(value)) {
@@ -2094,12 +2161,12 @@ class ClusterConfigurationSetter implements Setter {
                                break;
                        }
                }
-               
+
                if (config == null) {
                        warnings.add("Illegal cluster configuration specified.");
                        return;
                }
-               
+
                ((Clusterable) component).setClusterConfiguration(config);
        }
 }
index bc58ff403f47e98de95ec30dce05348518e33433..516bcce8f54de2a9f6915c56b03e1c694fac9787 100644 (file)
@@ -9,6 +9,7 @@ import net.sf.openrocket.file.RocketSaver;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Motor;
 import net.sf.openrocket.motor.ThrustCurveMotor;
+import net.sf.openrocket.preset.ComponentPreset;
 import net.sf.openrocket.rocketcomponent.ComponentAssembly;
 import net.sf.openrocket.rocketcomponent.MotorMount;
 import net.sf.openrocket.rocketcomponent.Rocket;
@@ -19,15 +20,22 @@ import net.sf.openrocket.util.LineStyle;
 
 
 public class RocketComponentSaver {
-       
+
        protected RocketComponentSaver() {
                // Prevent instantiation from outside the package
        }
-       
+
        protected void addParams(net.sf.openrocket.rocketcomponent.RocketComponent c, List<String> elements) {
                elements.add("<name>" + RocketSaver.escapeXML(c.getName()) + "</name>");
-               
-               
+
+               ComponentPreset preset = c.getPresetComponent();
+               if ( preset != null ) {
+                       elements.add("<preset type=\"" + preset.getType() +
+                                       "\" manufacturer=\"" + preset.getManufacturer().getSimpleName() +
+                                       "\" partno=\"" + preset.getPartNo() + "\" digest=\"" + preset.getDigest() +"\"/>");
+               }
+
+
                // Save color and line style if significant
                if (!(c instanceof Rocket || c instanceof ComponentAssembly)) {
                        Color color = c.getColor();
@@ -35,23 +43,23 @@ public class RocketComponentSaver {
                                elements.add("<color red=\"" + color.getRed() + "\" green=\"" + color.getGreen()
                                                + "\" blue=\"" + color.getBlue() + "\"/>");
                        }
-                       
+
                        LineStyle style = c.getLineStyle();
                        if (style != null) {
                                // Type names currently equivalent to the enum names except for case.
                                elements.add("<linestyle>" + style.name().toLowerCase(Locale.ENGLISH) + "</linestyle>");
                        }
                }
-               
-               
+
+
                // Save position unless "AFTER"
                if (c.getRelativePosition() != RocketComponent.Position.AFTER) {
                        // The type names are currently equivalent to the enum names except for case.
                        String type = c.getRelativePosition().name().toLowerCase(Locale.ENGLISH);
                        elements.add("<position type=\"" + type + "\">" + c.getPositionValue() + "</position>");
                }
-               
-               
+
+
                // Overrides
                boolean overridden = false;
                if (c.isMassOverridden()) {
@@ -66,26 +74,26 @@ public class RocketComponentSaver {
                        elements.add("<overridesubcomponents>" + c.getOverrideSubcomponents()
                                        + "</overridesubcomponents>");
                }
-               
-               
+
+
                // Comment
                if (c.getComment().length() > 0) {
                        elements.add("<comment>" + RocketSaver.escapeXML(c.getComment()) + "</comment>");
                }
-               
+
        }
-       
-       
-       
-       
+
+
+
+
        protected final String materialParam(Material mat) {
                return materialParam("material", mat);
        }
-       
-       
+
+
        protected final String materialParam(String tag, Material mat) {
                String str = "<" + tag;
-               
+
                switch (mat.getType()) {
                case LINE:
                        str += " type=\"line\"";
@@ -99,27 +107,27 @@ public class RocketComponentSaver {
                default:
                        throw new BugException("Unknown material type: " + mat.getType());
                }
-               
+
                return str + " density=\"" + mat.getDensity() + "\">" + RocketSaver.escapeXML(mat.getName()) + "</" + tag + ">";
        }
-       
-       
+
+
        protected final List<String> motorMountParams(MotorMount mount) {
                if (!mount.isMotorMount())
                        return Collections.emptyList();
-               
+
                String[] motorConfigIDs = ((RocketComponent) mount).getRocket().getMotorConfigurationIDs();
                List<String> elements = new ArrayList<String>();
-               
+
                elements.add("<motormount>");
-               
+
                for (String id : motorConfigIDs) {
                        Motor motor = mount.getMotor(id);
-                       
+
                        // Nothing is stored if no motor loaded
                        if (motor == null)
                                continue;
-                       
+
                        elements.add("  <motor configid=\"" + id + "\">");
                        if (motor.getMotorType() != Motor.Type.UNKNOWN) {
                                elements.add("    <type>" + motor.getMotorType().name().toLowerCase(Locale.ENGLISH) + "</type>");
@@ -133,27 +141,27 @@ public class RocketComponentSaver {
                        elements.add("    <designation>" + RocketSaver.escapeXML(motor.getDesignation()) + "</designation>");
                        elements.add("    <diameter>" + motor.getDiameter() + "</diameter>");
                        elements.add("    <length>" + motor.getLength() + "</length>");
-                       
+
                        // Motor delay
                        if (mount.getMotorDelay(id) == Motor.PLUGGED) {
                                elements.add("    <delay>none</delay>");
                        } else {
                                elements.add("    <delay>" + mount.getMotorDelay(id) + "</delay>");
                        }
-                       
+
                        elements.add("  </motor>");
                }
-               
+
                elements.add("  <ignitionevent>"
                                + mount.getIgnitionEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
                                + "</ignitionevent>");
-               
+
                elements.add("  <ignitiondelay>" + mount.getIgnitionDelay() + "</ignitiondelay>");
                elements.add("  <overhang>" + mount.getMotorOverhang() + "</overhang>");
-               
+
                elements.add("</motormount>");
-               
+
                return elements;
        }
-       
+
 }
index 26ea12b214111feabcaf160d937192bdb0ccd18c..3da15e2642baf76cb0d73ed622bbbfd28b5ea050 100644 (file)
@@ -1,6 +1,13 @@
 package net.sf.openrocket.preset;
 
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import net.sf.openrocket.material.Material;
@@ -9,6 +16,7 @@ import net.sf.openrocket.rocketcomponent.BodyTube;
 import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
 import net.sf.openrocket.unit.UnitGroup;
 import net.sf.openrocket.util.BugException;
+import net.sf.openrocket.util.TextUtil;
 
 
 /**
@@ -21,37 +29,38 @@ import net.sf.openrocket.util.BugException;
  */
 // FIXME - Implement clone.
 public class ComponentPreset implements Comparable<ComponentPreset> {
-       
+
        private final TypedPropertyMap properties = new TypedPropertyMap();
-       
+
        private boolean favorite = false;
-       
+       private String digest = "";
+
        public enum Type {
                BODY_TUBE,
                NOSE_CONE;
 
                Type[] compatibleTypes;
-               
+
                Type () {
                        compatibleTypes = new Type[1];
                        compatibleTypes[0] = this;
                }
-               
+
                Type( Type ... t ) {
-                       
+
                        compatibleTypes = new Type[t.length+1];
                        compatibleTypes[0] = this;
                        for( int i=0; i<t.length; i++ ) {
                                compatibleTypes[i+1] = t[i];
                        }
                }
-               
+
                public Type[] getCompatibleTypes() {
                        return compatibleTypes;
                }
-               
+
        }
-       
+
        public final static TypedKey<Manufacturer> MANUFACTURER = new TypedKey<Manufacturer>("Manufacturer", Manufacturer.class);
        public final static TypedKey<String> PARTNO = new TypedKey<String>("PartNo",String.class);
        public final static TypedKey<Type> TYPE = new TypedKey<Type>("Type",Type.class);
@@ -63,7 +72,7 @@ public class ComponentPreset implements Comparable<ComponentPreset> {
        public final static TypedKey<Double> THICKNESS = new TypedKey<Double>("Thickness", Double.class, UnitGroup.UNITS_LENGTH);
        public final static TypedKey<Boolean> FILLED = new TypedKey<Boolean>("Filled", Boolean.class);
        public final static TypedKey<Double> MASS = new TypedKey<Double>("Mass", Double.class, UnitGroup.UNITS_MASS);
-       
+
        public final static Map<String, TypedKey<?>> keyMap = new HashMap<String, TypedKey<?>>();
        static {
                keyMap.put(MANUFACTURER.getName(), MANUFACTURER);
@@ -78,15 +87,15 @@ public class ComponentPreset implements Comparable<ComponentPreset> {
                keyMap.put(FILLED.getName(), FILLED);
                keyMap.put(MASS.getName(), MASS);
        }
-       
+
        public static ComponentPreset create( TypedPropertyMap props ) throws InvalidComponentPresetException {
-               
+
                ComponentPreset preset = new ComponentPreset();
                // First do validation.
                if ( !props.containsKey(TYPE)) {
                        throw new InvalidComponentPresetException("No Type specified " + props.toString() );
                }
-               
+
                if (!props.containsKey(MANUFACTURER)) {
                        throw new InvalidComponentPresetException("No Manufacturer specified " + props.toString() );
                }
@@ -96,25 +105,25 @@ public class ComponentPreset implements Comparable<ComponentPreset> {
                }
 
                preset.properties.putAll(props);
-               
+
                // Should check for various bits of each of the types.
                Type t = props.get(TYPE);
                switch ( t ) {
                case BODY_TUBE: {
-                       
+
                        if ( !props.containsKey(LENGTH) ) {
                                throw new InvalidComponentPresetException( "No Length specified for body tube preset " + props.toString());
                        }
-                       
+
                        BodyTube bt = new BodyTube();
-                       
+
                        bt.setLength(props.get(LENGTH));
-                       
+
                        // Need to verify contains 2 of OD, thickness, ID.  Compute the third.
                        boolean hasOd = props.containsKey(OUTER_DIAMETER);
                        boolean hasId = props.containsKey(INNER_DIAMETER);
                        boolean hasThickness = props.containsKey(THICKNESS);
-                       
+
                        if ( hasOd ) {
                                double outerRadius = props.get(OUTER_DIAMETER)/2.0;
                                double thickness = 0;
@@ -140,7 +149,7 @@ public class ComponentPreset implements Comparable<ComponentPreset> {
                        preset.properties.put(OUTER_DIAMETER, bt.getOuterRadius() *2.0);
                        preset.properties.put(INNER_DIAMETER, bt.getInnerRadius() *2.0);
                        preset.properties.put(THICKNESS, bt.getThickness());
-                       
+
                        // Need to translate Mass to Density.
                        if ( props.containsKey(MASS) ) {
                                String materialName = "TubeCustom";
@@ -150,35 +159,57 @@ public class ComponentPreset implements Comparable<ComponentPreset> {
                                Material m = Material.newMaterial(Material.Type.BULK, materialName, props.get(MASS)/bt.getComponentVolume(), false);
                                preset.properties.put(MATERIAL, m);
                        }
-                       
+
                        break;
                }
                case NOSE_CONE: {
                        break;
                }
                }
-               
+
+               preset.computeDigest();
+
                return preset;
 
        }
 
        // Private constructor to encourage use of factory.
        private ComponentPreset() {
-               
        }
-       
+
+       /**
+        * Convenience method to retrieve the Type of this ComponentPreset.
+        * 
+        * @return
+        */
+       public Type getType() {
+               return properties.get(TYPE);
+       }
+
+       /**
+        * Convenience method to retrieve the Manufacturer of this ComponentPreset.
+        * @return
+        */
        public Manufacturer getManufacturer() {
                return properties.get(MANUFACTURER);
        }
-       
+
+       /**
+        * Convenience method to retrieve the PartNo of this ComponentPreset.
+        * @return
+        */
        public String getPartNo() {
                return properties.get(PARTNO);
        }
-       
+
+       public String getDigest() {
+               return digest;
+       }
+
        public boolean has(Object key) {
                return properties.containsKey(key);
        }
-       
+
        public <T> T get(TypedKey<T> key) {
                T value = properties.get(key);
                if (value == null) {
@@ -186,7 +217,7 @@ public class ComponentPreset implements Comparable<ComponentPreset> {
                }
                return (T) value;
        }
-       
+
        public boolean isFavorite() {
                return favorite;
        }
@@ -200,7 +231,7 @@ public class ComponentPreset implements Comparable<ComponentPreset> {
                int manuCompare = this.getManufacturer().getSimpleName().compareTo(p2.getManufacturer().getSimpleName());
                if ( manuCompare != 0 )
                        return manuCompare;
-               
+
                int partNoCompare = this.getPartNo().compareTo(p2.getPartNo());
                return partNoCompare;
        }
@@ -209,9 +240,63 @@ public class ComponentPreset implements Comparable<ComponentPreset> {
        public String toString() {
                return get(MANUFACTURER).toString() + " " + get(PARTNO);
        }
-       
+
        public String preferenceKey() {
                return get(MANUFACTURER).toString() + "|" + get(PARTNO);
        }
-       
+
+       private void computeDigest() {
+
+               try {
+                       ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                       DataOutputStream os = new DataOutputStream(bos);
+
+                       List<TypedKey<?>> keys = new ArrayList<TypedKey<?>>( properties.keySet());
+
+                       Collections.sort(keys, new Comparator<TypedKey<?>>() {
+                               @Override
+                               public int compare( TypedKey<?> a, TypedKey<?> b ) {
+                                       return a.getName().compareTo(b.getName());
+                               }
+                       });
+
+                       for ( TypedKey<?> key : keys  ) {
+
+                               Object value = properties.get(key);
+
+                               os.writeBytes(key.getName());
+
+                               if ( key.getType() == Double.class ) {
+                                       Double d = (Double) value;
+                                       os.writeDouble(d);
+                               } else if (key.getType() == String.class ) {
+                                       String s = (String) value;
+                                       os.writeBytes(s);
+                               } else if (key.getType() == Manufacturer.class ) {
+                                       String s = ((Manufacturer)value).getSimpleName();
+                                       os.writeBytes(s);
+                               } else if ( key.getType() == Finish.class ) {
+                                       String s = ((Finish)value).name();
+                                       os.writeBytes(s);
+                               } else if ( key.getType() == Type.class ) {
+                                       String s = ((Type)value).name();
+                                       os.writeBytes(s);
+                               } else if ( key.getType() == Boolean.class ) {
+                                       Boolean b = (Boolean) value;
+                                       os.writeBoolean(b);
+                               } else if ( key.getType() == Material.class ) {
+                                       double d = ((Material)value).getDensity();
+                                       os.writeDouble(d);
+                               }
+
+                       }
+
+                       MessageDigest md5 = MessageDigest.getInstance("MD5");
+                       digest = TextUtil.hexString(md5.digest( bos.toByteArray() ));
+               }
+               catch ( Exception e ) {
+                       throw new BugException(e);
+               }
+       }
+
 }