bug fixes and rocket optimization
[debian/openrocket] / src / net / sf / openrocket / file / openrocket / OpenRocketLoader.java
index 3b7b23d955888e5d0fd97c32967a79b8fd99830a..a487e48c3c6988b76b96bb1b1b1f9b6356437757 100644 (file)
@@ -14,15 +14,18 @@ import net.sf.openrocket.aerodynamics.WarningSet;
 import net.sf.openrocket.database.Databases;
 import net.sf.openrocket.document.OpenRocketDocument;
 import net.sf.openrocket.document.Simulation;
-import net.sf.openrocket.document.StorageOptions;
 import net.sf.openrocket.document.Simulation.Status;
+import net.sf.openrocket.document.StorageOptions;
 import net.sf.openrocket.file.RocketLoadException;
 import net.sf.openrocket.file.RocketLoader;
 import net.sf.openrocket.file.simplesax.ElementHandler;
 import net.sf.openrocket.file.simplesax.PlainTextHandler;
 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.motor.MotorDigest;
+import net.sf.openrocket.motor.ThrustCurveMotor;
 import net.sf.openrocket.rocketcomponent.BodyComponent;
 import net.sf.openrocket.rocketcomponent.BodyTube;
 import net.sf.openrocket.rocketcomponent.Bulkhead;
@@ -32,7 +35,9 @@ import net.sf.openrocket.rocketcomponent.Clusterable;
 import net.sf.openrocket.rocketcomponent.EllipticalFinSet;
 import net.sf.openrocket.rocketcomponent.EngineBlock;
 import net.sf.openrocket.rocketcomponent.ExternalComponent;
+import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
 import net.sf.openrocket.rocketcomponent.FinSet;
+import net.sf.openrocket.rocketcomponent.FinSet.TabRelativePosition;
 import net.sf.openrocket.rocketcomponent.FreeformFinSet;
 import net.sf.openrocket.rocketcomponent.IllegalFinPointException;
 import net.sf.openrocket.rocketcomponent.InnerTube;
@@ -49,6 +54,7 @@ import net.sf.openrocket.rocketcomponent.ReferenceType;
 import net.sf.openrocket.rocketcomponent.RingComponent;
 import net.sf.openrocket.rocketcomponent.Rocket;
 import net.sf.openrocket.rocketcomponent.RocketComponent;
+import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
 import net.sf.openrocket.rocketcomponent.ShockCord;
 import net.sf.openrocket.rocketcomponent.Stage;
 import net.sf.openrocket.rocketcomponent.Streamer;
@@ -58,15 +64,15 @@ import net.sf.openrocket.rocketcomponent.ThicknessRingComponent;
 import net.sf.openrocket.rocketcomponent.Transition;
 import net.sf.openrocket.rocketcomponent.TrapezoidFinSet;
 import net.sf.openrocket.rocketcomponent.TubeCoupler;
-import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
-import net.sf.openrocket.rocketcomponent.FinSet.TabRelativePosition;
-import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
 import net.sf.openrocket.simulation.FlightData;
 import net.sf.openrocket.simulation.FlightDataBranch;
+import net.sf.openrocket.simulation.FlightDataType;
 import net.sf.openrocket.simulation.FlightEvent;
-import net.sf.openrocket.simulation.SimulationConditions;
 import net.sf.openrocket.simulation.FlightEvent.Type;
+import net.sf.openrocket.simulation.GUISimulationConditions;
+import net.sf.openrocket.startup.Application;
 import net.sf.openrocket.unit.UnitGroup;
+import net.sf.openrocket.util.BugException;
 import net.sf.openrocket.util.Coordinate;
 import net.sf.openrocket.util.LineStyle;
 import net.sf.openrocket.util.Reflection;
@@ -85,29 +91,33 @@ import org.xml.sax.SAXException;
  * 
  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
  */
-
 public class OpenRocketLoader extends RocketLoader {
+       private static final LogHelper log = Application.getLogger();
+       
        
        @Override
        public OpenRocketDocument loadFromStream(InputStream source) throws RocketLoadException,
                        IOException {
+               log.info("Loading .ork file");
+               
                InputSource xmlSource = new InputSource(source);
                OpenRocketHandler handler = new OpenRocketHandler();
-
                
+
                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()) {
+               for (Simulation s : doc.getSimulations()) {
                        if (s.getStatus() == Simulation.Status.EXTERNAL ||
                                        s.getStatus() == Simulation.Status.NOT_SIMULATED)
                                continue;
@@ -118,37 +128,38 @@ public class OpenRocketLoader extends RocketLoader {
                        FlightDataBranch branch = s.getSimulatedData().getBranch(0);
                        if (branch == null)
                                continue;
-                       List<Double> list = branch.get(FlightDataBranch.TYPE_TIME);
+                       List<Double> list = branch.get(FlightDataType.TYPE_TIME);
                        if (list == null)
                                continue;
                        
                        double previousTime = Double.NaN;
-                       for (double time: list) {
+                       for (double time : list) {
                                if (time - previousTime < timeSkip)
-                                       timeSkip = time-previousTime;
+                                       timeSkip = time - previousTime;
                                previousTime = time;
                        }
                }
                // Round value
-               timeSkip = Math.rint(timeSkip*100)/100;
-
+               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 = { "0.9", "1.0", "1.1" };
-
+       public static final String[] SUPPORTED_VERSIONS = { "0.9", "1.0", "1.1", "1.2" };
+       
 
        ////////  Component constructors
        static final HashMap<String, Constructor<? extends RocketComponent>> constructors = new HashMap<String, Constructor<? extends RocketComponent>>();
@@ -162,7 +173,7 @@ 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]));
@@ -179,11 +190,11 @@ class DocumentConfig {
                        constructors.put("stage", Stage.class.getConstructor(new Class<?>[0]));
                        
                } catch (NoSuchMethodException e) {
-                       throw new RuntimeException(
+                       throw new BugException(
                                        "Error in constructing the 'constructors' HashMap.");
                }
        }
-
+       
 
        ////////  Parameter setters
        /*
@@ -220,23 +231,23 @@ class DocumentConfig {
                setters.put("ExternalComponent:material", new MaterialSetter(
                                Reflection.findMethodStatic(ExternalComponent.class, "setMaterial", Material.class),
                                Material.Type.BULK));
-                               
+               
                // BodyComponent
                setters.put("BodyComponent:length", new DoubleSetter(
                                Reflection.findMethodStatic(BodyComponent.class, "setLength", double.class)));
                
                // SymmetricComponent
                setters.put("SymmetricComponent:thickness", new DoubleSetter(
-                               Reflection.findMethodStatic(SymmetricComponent.class,"setThickness", double.class), 
-                               "filled", 
-                               Reflection.findMethodStatic(SymmetricComponent.class,"setFilled", boolean.class)));
+                               Reflection.findMethodStatic(SymmetricComponent.class, "setThickness", double.class),
+                               "filled",
+                               Reflection.findMethodStatic(SymmetricComponent.class, "setFilled", boolean.class)));
                
                // BodyTube
                setters.put("BodyTube:radius", new DoubleSetter(
-                               Reflection.findMethodStatic(BodyTube.class, "setRadius", double.class), 
+                               Reflection.findMethodStatic(BodyTube.class, "setOuterRadius", double.class),
                                "auto",
-                               Reflection.findMethodStatic(BodyTube.class,"setRadiusAutomatic", boolean.class)));
-                               
+                               Reflection.findMethodStatic(BodyTube.class, "setOuterRadiusAutomatic", boolean.class)));
+               
                // Transition
                setters.put("Transition:shape", new EnumSetter<Transition.Shape>(
                                Reflection.findMethodStatic(Transition.class, "setType", Transition.Shape.class),
@@ -245,7 +256,7 @@ class DocumentConfig {
                                Reflection.findMethodStatic(Transition.class, "setClipped", boolean.class)));
                setters.put("Transition:shapeparameter", new DoubleSetter(
                                Reflection.findMethodStatic(Transition.class, "setShapeParameter", double.class)));
-                               
+               
                setters.put("Transition:foreradius", new DoubleSetter(
                                Reflection.findMethodStatic(Transition.class, "setForeRadius", double.class),
                                "auto",
@@ -254,7 +265,7 @@ class DocumentConfig {
                                Reflection.findMethodStatic(Transition.class, "setAftRadius", double.class),
                                "auto",
                                Reflection.findMethodStatic(Transition.class, "setAftRadiusAutomatic", boolean.class)));
-
+               
                setters.put("Transition:foreshoulderradius", new DoubleSetter(
                                Reflection.findMethodStatic(Transition.class, "setForeShoulderRadius", double.class)));
                setters.put("Transition:foreshoulderlength", new DoubleSetter(
@@ -284,14 +295,14 @@ class DocumentConfig {
                setters.put("FinSet:fincount", new IntSetter(
                                Reflection.findMethodStatic(FinSet.class, "setFinCount", int.class)));
                setters.put("FinSet:rotation", new DoubleSetter(
-                               Reflection.findMethodStatic(FinSet.class, "setBaseRotation", double.class), Math.PI/180.0));
+                               Reflection.findMethodStatic(FinSet.class, "setBaseRotation", double.class), Math.PI / 180.0));
                setters.put("FinSet:thickness", new DoubleSetter(
                                Reflection.findMethodStatic(FinSet.class, "setThickness", double.class)));
                setters.put("FinSet:crosssection", new EnumSetter<FinSet.CrossSection>(
                                Reflection.findMethodStatic(FinSet.class, "setCrossSection", FinSet.CrossSection.class),
                                FinSet.CrossSection.class));
                setters.put("FinSet:cant", new DoubleSetter(
-                               Reflection.findMethodStatic(FinSet.class, "setCantAngle", double.class), Math.PI/180.0));
+                               Reflection.findMethodStatic(FinSet.class, "setCantAngle", double.class), Math.PI / 180.0));
                setters.put("FinSet:tabheight", new DoubleSetter(
                                Reflection.findMethodStatic(FinSet.class, "setTabHeight", double.class)));
                setters.put("FinSet:tablength", new DoubleSetter(
@@ -307,7 +318,7 @@ class DocumentConfig {
                                Reflection.findMethodStatic(TrapezoidFinSet.class, "setSweep", double.class)));
                setters.put("TrapezoidFinSet:height", new DoubleSetter(
                                Reflection.findMethodStatic(TrapezoidFinSet.class, "setHeight", double.class)));
-
+               
                // EllipticalFinSet
                setters.put("EllipticalFinSet:rootchord", new DoubleSetter(
                                Reflection.findMethodStatic(EllipticalFinSet.class, "setLength", double.class)));
@@ -318,14 +329,14 @@ class DocumentConfig {
                
                // LaunchLug
                setters.put("LaunchLug:radius", new DoubleSetter(
-                               Reflection.findMethodStatic(LaunchLug.class, "setRadius", double.class)));
+                               Reflection.findMethodStatic(LaunchLug.class, "setOuterRadius", double.class)));
                setters.put("LaunchLug:length", new DoubleSetter(
                                Reflection.findMethodStatic(LaunchLug.class, "setLength", double.class)));
                setters.put("LaunchLug:thickness", new DoubleSetter(
                                Reflection.findMethodStatic(LaunchLug.class, "setThickness", double.class)));
                setters.put("LaunchLug:radialdirection", new DoubleSetter(
                                Reflection.findMethodStatic(LaunchLug.class, "setRadialDirection", double.class),
-                               Math.PI/180.0));
+                               Math.PI / 180.0));
                
                // InternalComponent - nothing
                
@@ -346,13 +357,13 @@ class DocumentConfig {
                // ThicknessRingComponent - radius on separate components due to differing automatics
                setters.put("ThicknessRingComponent:thickness", new DoubleSetter(
                                Reflection.findMethodStatic(ThicknessRingComponent.class, "setThickness", double.class)));
-
+               
                // EngineBlock
                setters.put("EngineBlock:outerradius", new DoubleSetter(
                                Reflection.findMethodStatic(EngineBlock.class, "setOuterRadius", double.class),
                                "auto",
                                Reflection.findMethodStatic(EngineBlock.class, "setOuterRadiusAutomatic", boolean.class)));
-
+               
                // TubeCoupler
                setters.put("TubeCoupler:outerradius", new DoubleSetter(
                                Reflection.findMethodStatic(TubeCoupler.class, "setOuterRadius", double.class),
@@ -389,7 +400,7 @@ class DocumentConfig {
                                "auto",
                                Reflection.findMethodStatic(CenteringRing.class, "setOuterRadiusAutomatic", boolean.class)));
                
-               
+
                // MassObject
                setters.put("MassObject:packedlength", new DoubleSetter(
                                Reflection.findMethodStatic(MassObject.class, "setLength", double.class)));
@@ -438,7 +449,7 @@ class DocumentConfig {
                setters.put("Parachute:linematerial", new MaterialSetter(
                                Reflection.findMethodStatic(Parachute.class, "setLineMaterial", Material.class),
                                Material.Type.LINE));
-
+               
                // Streamer
                setters.put("Streamer:striplength", new DoubleSetter(
                                Reflection.findMethodStatic(Streamer.class, "setStripLength", double.class)));
@@ -470,13 +481,13 @@ class DocumentConfig {
         * @param enumClass             the class of the enum.
         * @return                              the found enum value, or <code>null</code>.
         */
-       public static <T extends Enum<T>> Enum<T> findEnum(String name, 
+       public static <T extends Enum<T>> Enum<T> findEnum(String name,
                        Class<? extends Enum<T>> enumClass) {
                
                if (name == null)
                        return null;
                name = name.trim();
-               for (Enum<T> e: enumClass.getEnumConstants()) {
+               for (Enum<T> e : enumClass.getEnumConstants()) {
                        if (e.name().toLowerCase().replace("_", "").equals(name)) {
                                return e;
                        }
@@ -517,7 +528,7 @@ class DocumentConfig {
  */
 class OpenRocketHandler extends ElementHandler {
        private OpenRocketContentHandler handler = null;
-
+       
        /**
         * Return the OpenRocketDocument read from the file, or <code>null</code> if a document
         * has not been read yet.
@@ -527,24 +538,24 @@ class OpenRocketHandler extends ElementHandler {
        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");
@@ -564,11 +575,11 @@ class OpenRocketHandler extends ElementHandler {
                        str += ", attempting to read file anyway.";
                        warnings.add(str);
                }
-
+               
                handler = new OpenRocketContentHandler();
                return handler;
        }
-
+       
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) throws SAXException {
@@ -577,7 +588,7 @@ class OpenRocketHandler extends ElementHandler {
                super.closeElement(element, attributes, content, warnings);
        }
        
-       
+
 }
 
 
@@ -587,26 +598,26 @@ class OpenRocketHandler extends ElementHandler {
 class OpenRocketContentHandler extends ElementHandler {
        private final OpenRocketDocument doc;
        private final Rocket rocket;
-
+       
        private boolean rocketDefined = false;
        private boolean simulationsDefined = false;
-
+       
        public OpenRocketContentHandler() {
                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
@@ -628,9 +639,9 @@ class OpenRocketContentHandler extends ElementHandler {
                        simulationsDefined = true;
                        return new SimulationsHandler(doc);
                }
-
+               
                warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
-
+               
                return null;
        }
 }
@@ -644,15 +655,15 @@ class OpenRocketContentHandler extends ElementHandler {
  */
 class ComponentHandler extends ElementHandler {
        private final RocketComponent parent;
-
+       
        public ComponentHandler(RocketComponent parent) {
                this.parent = parent;
        }
-
+       
        @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);
@@ -660,20 +671,20 @@ class ComponentHandler extends ElementHandler {
                        warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
                        return null;
                }
-
+               
                RocketComponent c;
                try {
                        c = constructor.newInstance();
                } catch (InstantiationException e) {
-                       throw new RuntimeException("Error constructing component.", e);
+                       throw new BugException("Error constructing component.", e);
                } catch (IllegalAccessException e) {
-                       throw new RuntimeException("Error constructing component.", e);
+                       throw new BugException("Error constructing component.", e);
                } catch (InvocationTargetException e) {
-                       throw new RuntimeException("Error constructing component.", e);
+                       throw Reflection.handleWrappedException(e);
                }
-
+               
                parent.addChild(c);
-
+               
                return new ComponentParameterHandler(c);
        }
 }
@@ -686,11 +697,11 @@ class ComponentHandler extends ElementHandler {
  */
 class ComponentParameterHandler extends ElementHandler {
        private final RocketComponent component;
-
+       
        public ComponentParameterHandler(RocketComponent c) {
                this.component = c;
        }
-
+       
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
@@ -704,45 +715,44 @@ class ComponentParameterHandler extends ElementHandler {
                                warnings.add(Warning.fromString("Illegal component defined as motor mount."));
                                return null;
                        }
-                       return new MotorMountHandler((MotorMount)component);
+                       return new MotorMountHandler((MotorMount) component);
                }
                if (element.equals("finpoints")) {
                        if (!(component instanceof FreeformFinSet)) {
                                warnings.add(Warning.fromString("Illegal component defined for fin points."));
                                return null;
                        }
-                       return new FinSetPointHandler((FreeformFinSet)component);
+                       return new FinSetPointHandler((FreeformFinSet) component);
                }
                if (element.equals("motorconfiguration")) {
                        if (!(component instanceof Rocket)) {
                                warnings.add(Warning.fromString("Illegal component defined for motor configuration."));
                                return null;
                        }
-                       return new MotorConfigurationHandler((Rocket)component);
+                       return new MotorConfigurationHandler((Rocket) component);
                }
                
-               
+
                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;
                        Setter s = DocumentConfig.setters.get(setterKey);
                        if (s != null) {
                                // Setter found
-                               System.out.println("Calling with key "+setterKey);
                                s.set(component, content, attributes, warnings);
                                break;
                        }
@@ -778,11 +788,11 @@ class FinSetPointHandler extends ElementHandler {
                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) {
@@ -792,7 +802,7 @@ class FinSetPointHandler extends ElementHandler {
                try {
                        double x = Double.parseDouble(strx);
                        double y = Double.parseDouble(stry);
-                       coordinates.add(new Coordinate(x,y));
+                       coordinates.add(new Coordinate(x, y));
                } catch (NumberFormatException e) {
                        warnings.add(Warning.fromString("Illegal fin points specification, ignoring."));
                        return;
@@ -821,11 +831,11 @@ class MotorMountHandler extends ElementHandler {
                this.mount = mount;
                mount.setMotorMount(true);
        }
-
+       
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-
+               
                if (element.equals("motor")) {
                        motorHandler = new MotorHandler();
                        return motorHandler;
@@ -837,7 +847,7 @@ class MotorMountHandler extends ElementHandler {
                        return PlainTextHandler.INSTANCE;
                }
                
-               warnings.add(Warning.fromString("Unknown element '"+element+"' encountered, ignoring."));
+               warnings.add(Warning.fromString("Unknown element '" + element + "' encountered, ignoring."));
                return null;
        }
        
@@ -846,21 +856,21 @@ class MotorMountHandler extends ElementHandler {
        @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")) { 
+               
+               if (element.equals("ignitionevent")) {
                        MotorMount.IgnitionEvent event = null;
                        for (MotorMount.IgnitionEvent e : MotorMount.IgnitionEvent.values()) {
                                if (e.name().toLowerCase().replaceAll("_", "").equals(content)) {
@@ -869,13 +879,13 @@ class MotorMountHandler extends ElementHandler {
                                }
                        }
                        if (event == null) {
-                               warnings.add(Warning.fromString("Unknown ignition event type '"+content+"', ignoring."));
+                               warnings.add(Warning.fromString("Unknown ignition event type '" + content + "', ignoring."));
                                return;
                        }
                        mount.setIgnitionEvent(event);
                        return;
                }
-
+               
                if (element.equals("ignitiondelay")) {
                        double d;
                        try {
@@ -915,11 +925,11 @@ class MotorConfigurationHandler extends ElementHandler {
        public MotorConfigurationHandler(Rocket rocket) {
                this.rocket = rocket;
        }
-
+       
        @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;
@@ -928,17 +938,17 @@ class MotorConfigurationHandler extends ElementHandler {
                
                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);
@@ -967,6 +977,7 @@ class MotorHandler extends ElementHandler {
        private Motor.Type type = null;
        private String manufacturer = null;
        private String designation = null;
+       private String digest = null;
        private double diameter = Double.NaN;
        private double length = Double.NaN;
        private double delay = Double.NaN;
@@ -986,24 +997,68 @@ class MotorHandler extends ElementHandler {
                        warnings.add(Warning.fromString("No motor specified, ignoring."));
                        return null;
                }
-               Motor[] motors = Databases.findMotors(type, manufacturer, designation, diameter, length);
-               if (motors.length == 0) {
-                       String str = "No motor with designation '"+designation+"'";
+               
+               List<ThrustCurveMotor> motors = Application.getMotorSetDatabase().findMotors(type, manufacturer,
+                               designation, diameter, length);
+               
+               // No motors
+               if (motors.size() == 0) {
+                       String str = "No motor with designation '" + designation + "'";
                        if (manufacturer != null)
                                str += " for manufacturer '" + manufacturer + "'";
-                       warnings.add(Warning.fromString(str + " found."));
+                       str += " found.";
+                       warnings.add(str);
                        return null;
                }
-               if (motors.length > 1) {
-                       String str = "Multiple motors with designation '"+designation+"'";
+               
+               // One motor
+               if (motors.size() == 1) {
+                       ThrustCurveMotor m = motors.get(0);
+                       if (digest != null && !MotorDigest.digestMotor(m).equals(digest)) {
+                               String str = "Motor with designation '" + designation + "'";
+                               if (manufacturer != null)
+                                       str += " for manufacturer '" + manufacturer + "'";
+                               str += " has differing thrust curve than the original.";
+                               warnings.add(str);
+                       }
+                       return m;
+               }
+               
+               // Multiple motors, check digest for which one to use
+               if (digest != null) {
+                       
+                       // Check for motor with correct digest
+                       for (ThrustCurveMotor m : motors) {
+                               if (MotorDigest.digestMotor(m).equals(digest)) {
+                                       return m;
+                               }
+                       }
+                       String str = "Motor with designation '" + designation + "'";
+                       if (manufacturer != null)
+                               str += " for manufacturer '" + manufacturer + "'";
+                       str += " has differing thrust curve than the original.";
+                       warnings.add(str);
+                       
+               } else {
+                       
+                       // No digest, check for preferred digest (OpenRocket <= 1.1.0)
+                       // TODO: MEDIUM: This should only be done for document versions 1.1 and below
+                       for (ThrustCurveMotor m : motors) {
+                               if (PreferredMotorDigests.DIGESTS.contains(MotorDigest.digestMotor(m))) {
+                                       return m;
+                               }
+                       }
+                       
+                       String str = "Multiple motors with designation '" + designation + "'";
                        if (manufacturer != null)
                                str += " for manufacturer '" + manufacturer + "'";
-                       warnings.add(Warning.fromString(str + " found, one chosen arbitrarily."));
+                       str += " found, one chosen arbitrarily.";
+                       warnings.add(str);
+                       
                }
-               return motors[0];
+               return motors.get(0);
        }
        
-       
        /**
         * Return the delay to use for the motor.
         */
@@ -1015,7 +1070,7 @@ class MotorHandler extends ElementHandler {
                return delay;
        }
        
-
+       
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) throws SAXException {
@@ -1026,32 +1081,37 @@ class MotorHandler extends ElementHandler {
                        
                        // Motor type
                        type = null;
-                       for (Motor.Type t: Motor.Type.values()) {
-                               if (t.name().toLowerCase().equals(content)) {
+                       for (Motor.Type t : Motor.Type.values()) {
+                               if (t.name().toLowerCase().equals(content.trim())) {
                                        type = t;
                                        break;
                                }
                        }
                        if (type == null) {
-                               warnings.add(Warning.fromString("Unknown motor type '"+content+"', ignoring."));
+                               warnings.add(Warning.fromString("Unknown motor type '" + content + "', ignoring."));
                        }
                        
                } else if (element.equals("manufacturer")) {
                        
                        // Manufacturer
-                       manufacturer = content;
-
+                       manufacturer = content.trim();
+                       
                } else if (element.equals("designation")) {
                        
                        // Designation
-                       designation = content;
-
+                       designation = content.trim();
+                       
+               } else if (element.equals("digest")) {
+                       
+                       // Digest
+                       digest = content.trim();
+                       
                } else if (element.equals("diameter")) {
-               
+                       
                        // Diameter
                        diameter = Double.NaN;
                        try {
-                               diameter = Double.parseDouble(content);
+                               diameter = Double.parseDouble(content.trim());
                        } catch (NumberFormatException e) {
                                // Ignore
                        }
@@ -1060,12 +1120,13 @@ class MotorHandler extends ElementHandler {
                        }
                        
                } else if (element.equals("length")) {
-
+                       
                        // Length
                        length = Double.NaN;
                        try {
-                               length = Double.parseDouble(content);
-                       } catch (NumberFormatException ignore) { }
+                               length = Double.parseDouble(content.trim());
+                       } catch (NumberFormatException ignore) {
+                       }
                        
                        if (Double.isNaN(length)) {
                                warnings.add(Warning.fromString("Illegal motor diameter specified, ignoring."));
@@ -1079,15 +1140,16 @@ class MotorHandler extends ElementHandler {
                                delay = Motor.PLUGGED;
                        } else {
                                try {
-                                       delay = Double.parseDouble(content);
-                               } catch (NumberFormatException ignore) { }
+                                       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);
                }
@@ -1104,20 +1166,20 @@ class SimulationsHandler extends ElementHandler {
        public SimulationsHandler(OpenRocketDocument doc) {
                this.doc = doc;
        }
-
+       
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
                
                if (!element.equals("simulation")) {
-                       warnings.add("Unknown element '"+element+"', ignoring.");
+                       warnings.add("Unknown element '" + element + "', ignoring.");
                        return null;
                }
                
                handler = new SingleSimulationHandler(doc);
                return handler;
        }
-
+       
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) throws SAXException {
@@ -1125,11 +1187,11 @@ class SimulationsHandler extends ElementHandler {
                super.closeElement(element, attributes, content, warnings);
        }
        
-       
+
 }
 
 class SingleSimulationHandler extends ElementHandler {
-
+       
        private final OpenRocketDocument doc;
        
        private String name;
@@ -1144,12 +1206,12 @@ class SingleSimulationHandler extends ElementHandler {
        }
        
        
-       
+
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
                
-               if (element.equals("name") || element.equals("simulator") || 
+               if (element.equals("name") || element.equals("simulator") ||
                                element.equals("calculator") || element.equals("listener")) {
                        return PlainTextHandler.INSTANCE;
                } else if (element.equals("conditions")) {
@@ -1159,7 +1221,7 @@ class SingleSimulationHandler extends ElementHandler {
                        dataHandler = new FlightDataHandler();
                        return dataHandler;
                } else {
-                       warnings.add("Unknown element '"+element+"', ignoring.");
+                       warnings.add("Unknown element '" + element + "', ignoring.");
                        return null;
                }
        }
@@ -1181,13 +1243,13 @@ class SingleSimulationHandler extends ElementHandler {
                } 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) {
@@ -1195,12 +1257,12 @@ class SingleSimulationHandler extends ElementHandler {
                        status = Simulation.Status.OUTDATED;
                }
                
-               SimulationConditions conditions;
+               GUISimulationConditions conditions;
                if (conditionHandler != null) {
                        conditions = conditionHandler.getConditions();
                } else {
                        warnings.add("Simulation conditions not defined, using defaults.");
-                       conditions = new SimulationConditions(doc.getRocket());
+                       conditions = new GUISimulationConditions(doc.getRocket());
                }
                
                if (name == null)
@@ -1211,7 +1273,7 @@ class SingleSimulationHandler extends ElementHandler {
                        data = null;
                else
                        data = dataHandler.getFlightData();
-
+               
                Simulation simulation = new Simulation(doc.getRocket(), status, name,
                                conditions, listeners, data);
                
@@ -1222,14 +1284,14 @@ class SingleSimulationHandler extends ElementHandler {
 
 
 class SimulationConditionsHandler extends ElementHandler {
-       private SimulationConditions conditions;
+       private GUISimulationConditions conditions;
        private AtmosphereHandler atmosphereHandler;
        
        public SimulationConditionsHandler(Rocket rocket) {
-               conditions = new SimulationConditions(rocket);
+               conditions = new GUISimulationConditions(rocket);
        }
        
-       public SimulationConditions getConditions() {
+       public GUISimulationConditions getConditions() {
                return conditions;
        }
        
@@ -1241,8 +1303,8 @@ class SimulationConditionsHandler extends ElementHandler {
                        return atmosphereHandler;
                }
                return PlainTextHandler.INSTANCE;
-       }       
-
+       }
+       
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
@@ -1250,7 +1312,8 @@ class SimulationConditionsHandler extends ElementHandler {
                double d = Double.NaN;
                try {
                        d = Double.parseDouble(content);
-               } catch (NumberFormatException ignore) { }
+               } catch (NumberFormatException ignore) {
+               }
                
 
                if (element.equals("configid")) {
@@ -1269,13 +1332,13 @@ class SimulationConditionsHandler extends ElementHandler {
                        if (Double.isNaN(d)) {
                                warnings.add("Illegal launch rod angle defined, ignoring.");
                        } else {
-                               conditions.setLaunchRodAngle(d*Math.PI/180);
+                               conditions.setLaunchRodAngle(d * Math.PI / 180);
                        }
                } else if (element.equals("launchroddirection")) {
                        if (Double.isNaN(d)) {
                                warnings.add("Illegal launch rod direction defined, ignoring.");
                        } else {
-                               conditions.setLaunchRodDirection(d*Math.PI/180);
+                               conditions.setLaunchRodDirection(d * Math.PI / 180);
                        }
                } else if (element.equals("windaverage")) {
                        if (Double.isNaN(d)) {
@@ -1328,15 +1391,16 @@ class AtmosphereHandler extends ElementHandler {
                        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) { }
+               } catch (NumberFormatException ignore) {
+               }
                
                if (element.equals("basetemperature")) {
                        if (Double.isNaN(d)) {
@@ -1352,9 +1416,9 @@ class AtmosphereHandler extends ElementHandler {
                        super.closeElement(element, attributes, content, warnings);
                }
        }
-
        
-       public void storeSettings(SimulationConditions cond, WarningSet warnings) {
+       
+       public void storeSettings(GUISimulationConditions cond, WarningSet warnings) {
                if (!Double.isNaN(pressure)) {
                        cond.setLaunchPressure(pressure);
                }
@@ -1364,7 +1428,7 @@ class AtmosphereHandler extends ElementHandler {
                
                if ("isa".equals(model)) {
                        cond.setISAAtmosphere(true);
-               } else if ("extendedisa".equals(model)){
+               } else if ("extendedisa".equals(model)) {
                        cond.setISAAtmosphere(false);
                } else {
                        cond.setISAAtmosphere(true);
@@ -1380,7 +1444,7 @@ class FlightDataHandler extends ElementHandler {
        private FlightDataBranchHandler dataHandler;
        private WarningSet warningSet = new WarningSet();
        private List<FlightDataBranch> branches = new ArrayList<FlightDataBranch>();
-
+       
        private FlightData data;
        
        public FlightData getFlightData() {
@@ -1390,24 +1454,24 @@ class FlightDataHandler extends ElementHandler {
        @Override
        public ElementHandler openElement(String element, HashMap<String, String> attributes,
                        WarningSet warnings) {
-
+               
                if (element.equals("warning")) {
                        return PlainTextHandler.INSTANCE;
                }
                if (element.equals("databranch")) {
-                       if (attributes.get("name") == null || attributes.get("types")==null) {
+                       if (attributes.get("name") == null || attributes.get("types") == null) {
                                warnings.add("Illegal flight data definition, ignoring.");
                                return null;
                        }
-                       dataHandler =  new FlightDataBranchHandler(attributes.get("name"),
+                       dataHandler = new FlightDataBranchHandler(attributes.get("name"),
                                        attributes.get("types"));
                        return dataHandler;
                }
                
-               warnings.add("Unknown element '"+element+"' encountered, ignoring.");
+               warnings.add("Unknown element '" + element + "' encountered, ignoring.");
                return null;
        }
-
+       
        
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
@@ -1422,12 +1486,12 @@ class FlightDataHandler extends ElementHandler {
                        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 {
@@ -1439,55 +1503,64 @@ class FlightDataHandler extends ElementHandler {
                        double flightTime = Double.NaN;
                        double groundHitVelocity = Double.NaN;
                        
-                       try { 
+                       try {
                                maxAltitude = DocumentConfig.stringToDouble(attributes.get("maxaltitude"));
-                       } catch (NumberFormatException ignore) { }
-                       try { 
+                       } catch (NumberFormatException ignore) {
+                       }
+                       try {
                                maxVelocity = DocumentConfig.stringToDouble(attributes.get("maxvelocity"));
-                       } catch (NumberFormatException ignore) { }
-                       try { 
+                       } catch (NumberFormatException ignore) {
+                       }
+                       try {
                                maxAcceleration = DocumentConfig.stringToDouble(attributes.get("maxacceleration"));
-                       } catch (NumberFormatException ignore) { }
-                       try { 
+                       } catch (NumberFormatException ignore) {
+                       }
+                       try {
                                maxMach = DocumentConfig.stringToDouble(attributes.get("maxmach"));
-                       } catch (NumberFormatException ignore) { }
-                       try { 
+                       } catch (NumberFormatException ignore) {
+                       }
+                       try {
                                timeToApogee = DocumentConfig.stringToDouble(attributes.get("timetoapogee"));
-                       } catch (NumberFormatException ignore) { }
-                       try { 
+                       } catch (NumberFormatException ignore) {
+                       }
+                       try {
                                flightTime = DocumentConfig.stringToDouble(attributes.get("flighttime"));
-                       } catch (NumberFormatException ignore) { }
-                       try { 
-                               groundHitVelocity = 
-                                       DocumentConfig.stringToDouble(attributes.get("groundhitvelocity"));
-                       } catch (NumberFormatException ignore) { }
+                       } catch (NumberFormatException ignore) {
+                       }
+                       try {
+                               groundHitVelocity =
+                                               DocumentConfig.stringToDouble(attributes.get("groundhitvelocity"));
+                       } catch (NumberFormatException ignore) {
+                       }
                        
+                       // TODO: HIGH: Store and load launchRodVelocity
                        data = new FlightData(maxAltitude, maxVelocity, maxAcceleration, maxMach,
-                                       timeToApogee, flightTime, groundHitVelocity);
+                                       timeToApogee, flightTime, groundHitVelocity, Double.NaN);
                }
                
                data.getWarningSet().addAll(warningSet);
+               data.immute();
        }
        
-       
+
 }
 
 
 class FlightDataBranchHandler extends ElementHandler {
-       private final FlightDataBranch.Type[] types;
+       private final FlightDataType[] types;
        private final FlightDataBranch branch;
        
        public FlightDataBranchHandler(String name, String typeList) {
                String[] split = typeList.split(",");
-               types = new FlightDataBranch.Type[split.length];
-               for (int i=0; i < split.length; i++) {
-                       types[i] = FlightDataBranch.getType(split[i], UnitGroup.UNITS_NONE);
+               types = new FlightDataType[split.length];
+               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;
@@ -1496,17 +1569,17 @@ class FlightDataBranchHandler extends ElementHandler {
        @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.");
+               warnings.add("Unknown element '" + element + "' encountered, ignoring.");
                return null;
        }
        
-
+       
        @Override
        public void closeElement(String element, HashMap<String, String> attributes,
                        String content, WarningSet warnings) {
@@ -1527,19 +1600,19 @@ class FlightDataBranchHandler extends ElementHandler {
                                warnings.add("Illegal event specification, ignoring.");
                                return;
                        }
-
-                       branch.addEvent(time, new FlightEvent(type, time));
+                       
+                       branch.addEvent(new FlightEvent(type, time));
                        return;
                }
                
                if (!element.equals("datapoint")) {
-                       warnings.add("Unknown element '"+element+"' encountered, ignoring.");
+                       warnings.add("Unknown element '" + element + "' encountered, ignoring.");
                        return;
                }
-
-               // element == "datapoint"
                
+               // element == "datapoint"
                
+
                // Check line format
                String[] split = content.split(",");
                if (split.length != types.length) {
@@ -1549,7 +1622,7 @@ class FlightDataBranchHandler extends ElementHandler {
                
                // Parse the doubles
                double[] values = new double[split.length];
-               for (int i=0; i < values.length; i++) {
+               for (int i = 0; i < values.length; i++) {
                        try {
                                values[i] = DocumentConfig.stringToDouble(split[i]);
                        } catch (NumberFormatException e) {
@@ -1560,7 +1633,7 @@ class FlightDataBranchHandler extends ElementHandler {
                
                // Add point to branch
                branch.addPoint();
-               for (int i=0; i < types.length; i++) {
+               for (int i = 0; i < types.length; i++) {
                        branch.setValue(types[i], values[i]);
                }
        }
@@ -1570,7 +1643,6 @@ class FlightDataBranchHandler extends ElementHandler {
 
 
 
-
 /////////////////    Setters implementation
 
 
@@ -1592,11 +1664,12 @@ 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) {
                setMethod.invoke(c, s);
@@ -1606,11 +1679,12 @@ 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) {
                try {
@@ -1626,11 +1700,12 @@ 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) {
                
@@ -1654,7 +1729,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. 
@@ -1665,7 +1740,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.
@@ -1677,7 +1752,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.
@@ -1693,19 +1768,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);
@@ -1720,15 +1796,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);
@@ -1743,22 +1820,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);
        }
 }
@@ -1767,18 +1844,19 @@ 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;
@@ -1798,7 +1876,7 @@ class ColorSetter implements Setter {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
                        return;
                }
-
+               
                Color color = new Color(r, g, b);
                setMethod.invoke(c, color);
                
@@ -1813,12 +1891,13 @@ class ColorSetter implements Setter {
 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) {
                
@@ -1845,25 +1924,25 @@ class MaterialSetter implements Setter {
                        warnings.add(Warning.fromString("Illegal material specification, ignoring."));
                        return;
                }
-
+               
                // Parse thickness
-//             double thickness = 0;
-//             str = attributes.remove("thickness");
-//             try {
-//                     if (str != null)
-//                             thickness = Double.parseDouble(str);
-//             } catch (NumberFormatException e){
-//                     warnings.add(Warning.fromString("Illegal material specification, ignoring."));
-//                     return;
-//             }
-
+               //              double thickness = 0;
+               //              str = attributes.remove("thickness");
+               //              try {
+               //                      if (str != null)
+               //                              thickness = Double.parseDouble(str);
+               //              } catch (NumberFormatException e){
+               //                      warnings.add(Warning.fromString("Illegal material specification, ignoring."));
+               //                      return;
+               //              }
+               
                // Check type if specified
                str = attributes.remove("type");
-               if (str != null  &&  !type.name().toLowerCase().equals(str)) {
+               if (str != null && !type.name().toLowerCase().equals(str)) {
                        warnings.add(Warning.fromString("Illegal material type specified, ignoring."));
                        return;
                }
-
+               
                mat = Databases.findMaterial(type, name, density, false);
                
                setMethod.invoke(c, mat);
@@ -1874,11 +1953,12 @@ 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 type = (Position) DocumentConfig.findEnum(attributes.get("type"),
                                RocketComponent.Position.class);
                if (type == null) {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
@@ -1894,13 +1974,13 @@ class PositionSetter implements Setter {
                }
                
                if (c instanceof FinSet) {
-                       ((FinSet)c).setRelativePosition(type);
+                       ((FinSet) c).setRelativePosition(type);
                        c.setPositionValue(pos);
                } else if (c instanceof LaunchLug) {
-                       ((LaunchLug)c).setRelativePosition(type);
+                       ((LaunchLug) c).setRelativePosition(type);
                        c.setPositionValue(pos);
                } else if (c instanceof InternalComponent) {
-                       ((InternalComponent)c).setRelativePosition(type);
+                       ((InternalComponent) c).setRelativePosition(type);
                        c.setPositionValue(pos);
                } else {
                        warnings.add(Warning.FILE_INVALID_PARAMETER);
@@ -1911,11 +1991,11 @@ class PositionSetter implements Setter {
 
 
 class FinTabPositionSetter extends DoubleSetter {
-
+       
        public FinTabPositionSetter() {
                super(Reflection.findMethodStatic(FinSet.class, "setTabShift", double.class));
        }
-
+       
        @Override
        public void set(RocketComponent c, String s, HashMap<String, String> attributes,
                        WarningSet warnings) {
@@ -1923,15 +2003,15 @@ class FinTabPositionSetter extends DoubleSetter {
                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);
+               FinSet.TabRelativePosition position =
+                               (TabRelativePosition) DocumentConfig.findEnum(relative,
+                                               FinSet.TabRelativePosition.class);
                
                if (position != null) {
                        
-                       ((FinSet)c).setTabRelativePosition(position);
+                       ((FinSet) c).setTabRelativePosition(position);
                        
                } else {
                        if (relative == null) {
@@ -1943,13 +2023,14 @@ class FinTabPositionSetter extends DoubleSetter {
                
                super.set(c, s, attributes, warnings);
        }
-
        
+
 }
 
 
 class ClusterConfigurationSetter implements Setter {
-
+       
+       @Override
        public void set(RocketComponent component, String value, HashMap<String, String> attributes,
                        WarningSet warnings) {
                
@@ -1959,7 +2040,7 @@ class ClusterConfigurationSetter implements Setter {
                }
                
                ClusterConfiguration config = null;
-               for (ClusterConfiguration c: ClusterConfiguration.CONFIGURATIONS) {
+               for (ClusterConfiguration c : ClusterConfiguration.CONFIGURATIONS) {
                        if (c.getXMLName().equals(value)) {
                                config = c;
                                break;
@@ -1971,8 +2052,6 @@ class ClusterConfigurationSetter implements Setter {
                        return;
                }
                
-               ((Clusterable)component).setClusterConfiguration(config);
+               ((Clusterable) component).setClusterConfiguration(config);
        }
 }
-
-