Change OpenRocketComponentSaver unmarshal function to return the whole OpenRocketComponentDTO instead of just the contained components. This gives the ComponentPresetEditor a change to grab the Materials in the file for use in the ui.

This commit is contained in:
Kevin Ruland 2012-06-06 18:03:43 +00:00
parent 00dfe40706
commit 909aa211d0
3 changed files with 8 additions and 6 deletions

View File

@ -5,7 +5,7 @@ import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -38,7 +38,7 @@ import net.sf.openrocket.material.Material;
import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.preset.loader.MaterialHolder;
import net.sf.openrocket.preset.loader.RocksimComponentFileTranslator;
import net.sf.openrocket.preset.xml.OpenRocketComponentLoader;
import net.sf.openrocket.preset.xml.OpenRocketComponentDTO;
import net.sf.openrocket.preset.xml.OpenRocketComponentSaver;
import net.sf.openrocket.startup.Application;
@ -352,7 +352,9 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
List<ComponentPreset> presets = null;
if (file.getName().toLowerCase().endsWith(".orc")) {
presets = (List<ComponentPreset>) new OpenRocketComponentLoader().load(new FileInputStream(file), file.getName());
OpenRocketComponentDTO fileContents = new OpenRocketComponentSaver().unmarshalFromOpenRocketComponent(new FileReader(file));
editContext.setMaterialsLoaded( new MaterialHolder(fileContents.asMaterialList()) );
presets = fileContents.asComponentPresets();
}
else {
if (file.getName().toLowerCase().endsWith(".csv")) {

View File

@ -28,7 +28,7 @@ public class OpenRocketComponentLoader implements Loader<ComponentPreset> {
try {
List<ComponentPreset> presets;
presets = new OpenRocketComponentSaver().unmarshalFromOpenRocketComponent( new InputStreamReader (stream));
presets = (new OpenRocketComponentSaver().unmarshalFromOpenRocketComponent( new InputStreamReader (stream))).asComponentPresets();
for( ComponentPreset preset : presets ) {
if ( favorites.contains(preset.preferenceKey())) {
preset.setFavorite(true);

View File

@ -109,9 +109,9 @@ public class OpenRocketComponentSaver {
* @throws InvalidComponentPresetException
*
*/
public List<ComponentPreset> unmarshalFromOpenRocketComponent(Reader is) throws JAXBException,
public OpenRocketComponentDTO unmarshalFromOpenRocketComponent(Reader is) throws JAXBException,
InvalidComponentPresetException {
return fromOpenRocketComponent(is).asComponentPresets();
return fromOpenRocketComponent(is);
}
/**