package net.sf.openrocket.preset.xml;
-import net.sf.openrocket.material.Material;
-import net.sf.openrocket.preset.ComponentPreset;
-import net.sf.openrocket.preset.InvalidComponentPresetException;
-import net.sf.openrocket.startup.Application;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringWriter;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import net.sf.openrocket.material.Material;
+import net.sf.openrocket.preset.ComponentPreset;
+import net.sf.openrocket.preset.InvalidComponentPresetException;
+import net.sf.openrocket.startup.Application;
+
/**
* The active manager class that is the entry point for reading and writing *.orc files.
*/
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
StringWriter sw = new StringWriter();
+ // We're going to sort the initial data since that makes the output much easier on the eyes.
+
+ Collections.sort(theMaterialList, new Comparator<Material>() {
+
+ @Override
+ public int compare(Material o1, Material o2) {
+ return o1.getName().compareTo( o2.getName() );
+ }
+
+ });
+
+ Collections.sort(thePresetList, new Comparator<ComponentPreset>() {
+
+ @Override
+ public int compare(ComponentPreset o1, ComponentPreset o2) {
+ int manucmp = o1.getManufacturer().getSimpleName().compareTo( o2.getManufacturer().getSimpleName() );
+
+ if ( manucmp != 0 ) {
+ return manucmp;
+ }
+
+ return o1.getPartNo().compareTo( o2.getPartNo());
+ }
+
+ });
+
marshaller.marshal(toOpenRocketComponentDTO(theMaterialList, thePresetList), sw);
return sw.toString();