Rework attachment loading. Construct a DocumentLoadingContext in
GenericLoader and pass into both OpenRocketLoader and RocksimLoader. the DocumentLoadingContext contains the OpenRocketDocument, MotorFinder, and AttachmentFactory.
This commit is contained in:
parent
48adc0b7bf
commit
593c639a06
@ -1,7 +0,0 @@
|
||||
package net.sf.openrocket.document;
|
||||
|
||||
public interface AttachmentFactory<T extends Attachment> {
|
||||
|
||||
public T getAttachment(String name);
|
||||
|
||||
}
|
@ -19,51 +19,49 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.sf.openrocket.appearance.DecalImage;
|
||||
import net.sf.openrocket.document.attachments.FileSystemAttachment;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.BugException;
|
||||
import net.sf.openrocket.util.FileUtils;
|
||||
|
||||
public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
||||
public class DecalRegistry {
|
||||
private static LogHelper log = Application.getLogger();
|
||||
|
||||
private final AttachmentFactory baseFactory;
|
||||
DecalRegistry() {
|
||||
|
||||
public DecalRegistry(AttachmentFactory baseFactory) {
|
||||
this.baseFactory = baseFactory;
|
||||
}
|
||||
|
||||
private Map<String, DecalImageImpl> registeredDecals = new HashMap<String, DecalImageImpl>();
|
||||
|
||||
public DecalImage getAttachment(String decalName) {
|
||||
DecalImageImpl d = registeredDecals.get(decalName);
|
||||
if (d == null) {
|
||||
Attachment attachment = baseFactory.getAttachment(decalName);
|
||||
d = new DecalImageImpl(attachment);
|
||||
registeredDecals.put(decalName, d);
|
||||
}
|
||||
public DecalImage getDecalImage(Attachment attachment) {
|
||||
String decalName = attachment.getName();
|
||||
DecalImageImpl d;
|
||||
if (attachment instanceof FileSystemAttachment) {
|
||||
File location = ((FileSystemAttachment) attachment).getLocation();
|
||||
d = findDecalForFile(location);
|
||||
if (d != null) {
|
||||
return d;
|
||||
}
|
||||
|
||||
public DecalImage getAttachment(File file) {
|
||||
|
||||
// See if this file is being used already
|
||||
DecalImageImpl decal = findDecalForFile(file);
|
||||
|
||||
if (decal != null) {
|
||||
return decal;
|
||||
}
|
||||
|
||||
// It's a new file, generate a name for it.
|
||||
String decalName = makeUniqueName(file.getName());
|
||||
decalName = makeUniqueName(location.getName());
|
||||
|
||||
Attachment attachment = baseFactory.getAttachment(decalName);
|
||||
decal = new DecalImageImpl(attachment);
|
||||
decal.setFileSystemLocation(file);
|
||||
d = new DecalImageImpl(decalName, attachment);
|
||||
d.setFileSystemLocation(location);
|
||||
|
||||
registeredDecals.put(decalName, decal);
|
||||
return decal;
|
||||
registeredDecals.put(decalName, d);
|
||||
return d;
|
||||
|
||||
} else {
|
||||
d = registeredDecals.get(decalName);
|
||||
if (d != null) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
d = new DecalImageImpl(attachment);
|
||||
registeredDecals.put(decalName, d);
|
||||
return d;
|
||||
}
|
||||
|
||||
public Collection<DecalImage> getDecalList() {
|
||||
@ -79,25 +77,31 @@ public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
||||
|
||||
private final Attachment delegate;
|
||||
|
||||
private String name;
|
||||
private File fileSystemLocation;
|
||||
|
||||
private DecalImageImpl(String name, Attachment delegate) {
|
||||
this.name = name;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
private DecalImageImpl(Attachment delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
return name != null ? name : delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getBytes() throws FileNotFoundException, IOException {
|
||||
return DecalRegistry.this.getDecal(this);
|
||||
return DecalRegistry.getDecal(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportImage(File file, boolean watchForChanges) throws IOException {
|
||||
DecalRegistry.this.exportDecal(this, file);
|
||||
DecalRegistry.exportDecal(this, file);
|
||||
this.fileSystemLocation = file;
|
||||
}
|
||||
|
||||
@ -111,7 +115,7 @@ public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -119,7 +123,7 @@ public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
||||
if (!(o instanceof DecalImageImpl)) {
|
||||
return -1;
|
||||
}
|
||||
return delegate.compareTo(((DecalImageImpl) o).delegate);
|
||||
return getName().compareTo(o.getName());
|
||||
}
|
||||
|
||||
}
|
||||
@ -133,7 +137,7 @@ public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
private InputStream getDecal(DecalImageImpl decal) throws FileNotFoundException, IOException {
|
||||
private static InputStream getDecal(DecalImageImpl decal) throws FileNotFoundException, IOException {
|
||||
|
||||
// First check if the decal is located on the file system
|
||||
File exportedFile = decal.getFileSystemLocation();
|
||||
@ -152,7 +156,7 @@ public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
||||
|
||||
}
|
||||
|
||||
private void exportDecal(DecalImageImpl decal, File selectedFile) throws IOException {
|
||||
private static void exportDecal(DecalImageImpl decal, File selectedFile) throws IOException {
|
||||
|
||||
try {
|
||||
InputStream is = decal.getBytes();
|
||||
|
@ -1,14 +1,14 @@
|
||||
package net.sf.openrocket.document;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sf.openrocket.appearance.DecalImage;
|
||||
import net.sf.openrocket.document.events.DocumentChangeEvent;
|
||||
import net.sf.openrocket.document.events.DocumentChangeListener;
|
||||
import net.sf.openrocket.document.events.SimulationChangeEvent;
|
||||
@ -60,9 +60,6 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
private final ArrayList<Simulation> simulations = new ArrayList<Simulation>();
|
||||
private ArrayList<CustomExpression> customExpressions = new ArrayList<CustomExpression>();
|
||||
|
||||
private final AttachmentFactory attachmentFactory;
|
||||
private final DecalRegistry decalRegistry;
|
||||
|
||||
/*
|
||||
* The undo/redo variables and mechanism are documented in doc/undo-redo-flow.*
|
||||
*/
|
||||
@ -95,36 +92,13 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
|
||||
private final StorageOptions storageOptions = new StorageOptions();
|
||||
|
||||
private final DecalRegistry decalRegistry = new DecalRegistry();
|
||||
|
||||
private final List<DocumentChangeListener> listeners = new ArrayList<DocumentChangeListener>();
|
||||
|
||||
OpenRocketDocument(Rocket rocket, File fileName, boolean isContainer) {
|
||||
OpenRocketDocument(Rocket rocket) {
|
||||
this.configuration = rocket.getDefaultConfiguration();
|
||||
this.rocket = rocket;
|
||||
AttachmentFactory attachments;
|
||||
if (isContainer) {
|
||||
try {
|
||||
attachments = new ZipFileAttachmentFactory(fileName.toURI().toURL());
|
||||
} catch (MalformedURLException mex) {
|
||||
attachments = new FileSystemAttachmentFactory(null);
|
||||
}
|
||||
} else {
|
||||
if (fileName == null) {
|
||||
attachments = new FileSystemAttachmentFactory(null);
|
||||
} else {
|
||||
attachments = new FileSystemAttachmentFactory(fileName.getParentFile());
|
||||
}
|
||||
}
|
||||
this.attachmentFactory = attachments;
|
||||
this.decalRegistry = new DecalRegistry(this.attachmentFactory);
|
||||
init();
|
||||
}
|
||||
|
||||
OpenRocketDocument(Rocket rocket, URL jarURL, boolean isContainer) {
|
||||
this.configuration = rocket.getDefaultConfiguration();
|
||||
this.rocket = rocket;
|
||||
this.attachmentFactory = isContainer ? new ZipFileAttachmentFactory(jarURL) : new FileSystemAttachmentFactory(null);
|
||||
this.decalRegistry = new DecalRegistry(this.attachmentFactory);
|
||||
init();
|
||||
}
|
||||
|
||||
@ -197,10 +171,6 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public DecalRegistry getDecalRegistry() {
|
||||
return decalRegistry;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
@ -209,7 +179,6 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSaved() {
|
||||
return rocket.getModID() == savedID;
|
||||
}
|
||||
@ -231,8 +200,15 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
}
|
||||
|
||||
|
||||
public Collection<DecalImage> getDecalList() {
|
||||
|
||||
return decalRegistry.getDecalList();
|
||||
|
||||
}
|
||||
|
||||
public DecalImage getDecalImage(Attachment a) {
|
||||
return decalRegistry.getDecalImage(a);
|
||||
}
|
||||
|
||||
public List<Simulation> getSimulations() {
|
||||
return simulations.clone();
|
||||
|
@ -1,8 +1,5 @@
|
||||
package net.sf.openrocket.document;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.Stage;
|
||||
@ -18,25 +15,19 @@ public class OpenRocketDocumentFactory {
|
||||
//// Sustainer
|
||||
stage.setName(trans.get("BasicFrame.StageName.Sustainer"));
|
||||
rocket.addChild(stage);
|
||||
OpenRocketDocument doc = new OpenRocketDocument(rocket, (File) null, false);
|
||||
OpenRocketDocument doc = new OpenRocketDocument(rocket);
|
||||
doc.setSaved(true);
|
||||
return doc;
|
||||
}
|
||||
|
||||
public static OpenRocketDocument createDocumentFromRocket(Rocket r) {
|
||||
OpenRocketDocument doc = new OpenRocketDocument(r, (File) null, false);
|
||||
OpenRocketDocument doc = new OpenRocketDocument(r);
|
||||
return doc;
|
||||
}
|
||||
|
||||
public static OpenRocketDocument createDocumentForFile(File filename, boolean isContainer) {
|
||||
public static OpenRocketDocument createEmptyRocket() {
|
||||
Rocket rocket = new Rocket();
|
||||
OpenRocketDocument doc = new OpenRocketDocument(rocket, filename, isContainer);
|
||||
return doc;
|
||||
}
|
||||
|
||||
public static OpenRocketDocument createDocumentForUrl(URL filename, boolean isContainer) {
|
||||
Rocket rocket = new Rocket();
|
||||
OpenRocketDocument doc = new OpenRocketDocument(rocket, filename, isContainer);
|
||||
OpenRocketDocument doc = new OpenRocketDocument(rocket);
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,10 @@ public class FileSystemAttachment extends BaseAttachment implements Attachment {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public File getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getBytes() throws FileNotFoundException, IOException {
|
||||
return new FileInputStream(location);
|
||||
|
@ -4,7 +4,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
|
||||
|
||||
public abstract class AbstractRocketLoader implements RocketLoader {
|
||||
@ -15,11 +14,11 @@ public abstract class AbstractRocketLoader implements RocketLoader {
|
||||
* Loads a rocket from the specified InputStream.
|
||||
*/
|
||||
@Override
|
||||
public final void load(OpenRocketDocument doc, InputStream source, MotorFinder motorFinder) throws RocketLoadException {
|
||||
public final void load(DocumentLoadingContext context, InputStream source) throws RocketLoadException {
|
||||
warnings.clear();
|
||||
|
||||
try {
|
||||
loadFromStream(doc, source, motorFinder);
|
||||
loadFromStream(context, source);
|
||||
} catch (RocketLoadException e) {
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
@ -35,8 +34,7 @@ public abstract class AbstractRocketLoader implements RocketLoader {
|
||||
*
|
||||
* @throws RocketLoadException if an error occurs during loading.
|
||||
*/
|
||||
protected abstract void loadFromStream(OpenRocketDocument doc, InputStream source, MotorFinder motorFinder) throws IOException,
|
||||
RocketLoadException;
|
||||
protected abstract void loadFromStream(DocumentLoadingContext context, InputStream source) throws IOException, RocketLoadException;
|
||||
|
||||
|
||||
|
||||
|
9
core/src/net/sf/openrocket/file/AttachmentFactory.java
Normal file
9
core/src/net/sf/openrocket/file/AttachmentFactory.java
Normal file
@ -0,0 +1,9 @@
|
||||
package net.sf.openrocket.file;
|
||||
|
||||
import net.sf.openrocket.document.Attachment;
|
||||
|
||||
public interface AttachmentFactory {
|
||||
|
||||
public Attachment getAttachment(String name);
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package net.sf.openrocket.file.openrocket.importt;
|
||||
package net.sf.openrocket.file;
|
||||
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.MotorFinder;
|
||||
|
||||
public class DocumentLoadingContext {
|
||||
|
||||
private int fileVersion;
|
||||
private MotorFinder motorFinder;
|
||||
private AttachmentFactory attachmentFactory = new FileSystemAttachmentFactory();
|
||||
private OpenRocketDocument document;
|
||||
|
||||
public int getFileVersion() {
|
||||
@ -33,4 +33,12 @@ public class DocumentLoadingContext {
|
||||
this.document = document;
|
||||
}
|
||||
|
||||
public AttachmentFactory getAttachmentFactory() {
|
||||
return attachmentFactory;
|
||||
}
|
||||
|
||||
public void setAttachmentFactory(AttachmentFactory attachmentFactory) {
|
||||
this.attachmentFactory = attachmentFactory;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package net.sf.openrocket.document;
|
||||
package net.sf.openrocket.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.openrocket.document.attachments.BaseAttachment;
|
||||
import net.sf.openrocket.document.Attachment;
|
||||
import net.sf.openrocket.document.attachments.FileSystemAttachment;
|
||||
|
||||
public class FileSystemAttachmentFactory implements AttachmentFactory<BaseAttachment> {
|
||||
public class FileSystemAttachmentFactory implements AttachmentFactory {
|
||||
|
||||
private final File baseDirectory;
|
||||
|
||||
@ -22,8 +22,12 @@ public class FileSystemAttachmentFactory implements AttachmentFactory<BaseAttach
|
||||
this.baseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
public Attachment getAttachment(File file) {
|
||||
return new FileSystemAttachment(file.getName(), file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseAttachment getAttachment(String name) {
|
||||
public Attachment getAttachment(String name) {
|
||||
|
||||
File file = new File(name);
|
||||
|
@ -5,6 +5,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
@ -44,8 +45,11 @@ public class GeneralRocketLoader {
|
||||
|
||||
private File baseFile;
|
||||
private URL jarURL;
|
||||
private boolean isContainer;
|
||||
|
||||
private final MotorFinder motorFinder;
|
||||
private AttachmentFactory attachmentFactory;
|
||||
private final OpenRocketDocument doc = OpenRocketDocumentFactory.createEmptyRocket();
|
||||
|
||||
public GeneralRocketLoader(File file) {
|
||||
this.baseFile = file;
|
||||
@ -69,7 +73,7 @@ public class GeneralRocketLoader {
|
||||
try {
|
||||
|
||||
stream = new BufferedInputStream(new FileInputStream(baseFile));
|
||||
OpenRocketDocument doc = load(stream);
|
||||
load(stream);
|
||||
return doc;
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -87,7 +91,7 @@ public class GeneralRocketLoader {
|
||||
|
||||
public final OpenRocketDocument load(InputStream source) throws RocketLoadException {
|
||||
try {
|
||||
OpenRocketDocument doc = loadFromStream(source);
|
||||
loadStep1(source);
|
||||
return doc;
|
||||
} catch (Exception e) {
|
||||
throw new RocketLoadException("Exception loading stream", e);
|
||||
@ -98,8 +102,20 @@ public class GeneralRocketLoader {
|
||||
return warnings;
|
||||
}
|
||||
|
||||
private OpenRocketDocument loadFromStream(InputStream source) throws IOException,
|
||||
RocketLoadException {
|
||||
/**
|
||||
* This method determines the type file contained in the stream then calls the appropriate loading mecahnism.
|
||||
*
|
||||
* If the stream is a gzip file, the argument is wrapped in a GzipInputStream and the rocket loaded.
|
||||
*
|
||||
* If the stream is a zip container, the first zip entry with name ending in .ork or .rkt is loaded as the rocket.
|
||||
*
|
||||
* If the stream is neither, then it is assumed to be an xml file containing either an ork or rkt format rocket.
|
||||
*
|
||||
* @param source
|
||||
* @throws IOException
|
||||
* @throws RocketLoadException
|
||||
*/
|
||||
private void loadStep1(InputStream source) throws IOException, RocketLoadException {
|
||||
|
||||
// Check for mark() support
|
||||
if (!source.markSupported()) {
|
||||
@ -122,19 +138,17 @@ public class GeneralRocketLoader {
|
||||
|
||||
// Check for GZIP
|
||||
if (buffer[0] == GZIP_SIGNATURE[0] && buffer[1] == GZIP_SIGNATURE[1]) {
|
||||
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentForFile(baseFile, false);
|
||||
loadFromStream(doc, new GZIPInputStream(source));
|
||||
return doc;
|
||||
isContainer = false;
|
||||
setAttachmentFactory();
|
||||
loadRocket(new GZIPInputStream(source));
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for ZIP (for future compatibility)
|
||||
if (buffer[0] == ZIP_SIGNATURE[0] && buffer[1] == ZIP_SIGNATURE[1]) {
|
||||
OpenRocketDocument doc;
|
||||
if (baseFile != null) {
|
||||
doc = OpenRocketDocumentFactory.createDocumentForFile(baseFile, true);
|
||||
} else {
|
||||
doc = OpenRocketDocumentFactory.createDocumentForUrl(jarURL, true);
|
||||
}
|
||||
isContainer = true;
|
||||
setAttachmentFactory();
|
||||
// Search for entry with name *.ork
|
||||
ZipInputStream in = new ZipInputStream(source);
|
||||
while (true) {
|
||||
@ -143,27 +157,25 @@ public class GeneralRocketLoader {
|
||||
throw new RocketLoadException("Unsupported or corrupt file.");
|
||||
}
|
||||
if (entry.getName().matches(".*\\.[oO][rR][kK]$")) {
|
||||
loadFromStream(doc, in);
|
||||
return doc;
|
||||
loadRocket(in);
|
||||
return;
|
||||
} else if (entry.getName().matches(".*\\.[rR][kK][tT]$")) {
|
||||
loadFromStream(doc, in);
|
||||
return doc;
|
||||
}
|
||||
loadRocket(in);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
OpenRocketDocument doc = null;
|
||||
if (baseFile != null) {
|
||||
doc = OpenRocketDocumentFactory.createDocumentForFile(baseFile, false);
|
||||
} else {
|
||||
doc = OpenRocketDocumentFactory.createDocumentForUrl(jarURL, false);
|
||||
// FIXME should throw here because the zip file didn't contain either ork or rkt file.
|
||||
}
|
||||
loadFromStream(doc, source);
|
||||
return doc;
|
||||
|
||||
isContainer = false;
|
||||
setAttachmentFactory();
|
||||
loadRocket(source);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
private void loadFromStream(OpenRocketDocument doc, InputStream source) throws IOException, RocketLoadException {
|
||||
private void loadRocket(InputStream source) throws IOException, RocketLoadException {
|
||||
|
||||
// Check for mark() support
|
||||
if (!source.markSupported()) {
|
||||
@ -187,7 +199,7 @@ public class GeneralRocketLoader {
|
||||
if (buffer[i] == OPENROCKET_SIGNATURE[match]) {
|
||||
match++;
|
||||
if (match == OPENROCKET_SIGNATURE.length) {
|
||||
loadUsing(doc, openRocketLoader, source);
|
||||
loadUsing(openRocketLoader, source);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -197,16 +209,36 @@ public class GeneralRocketLoader {
|
||||
|
||||
byte[] typeIdentifier = ArrayUtils.copyOf(buffer, ROCKSIM_SIGNATURE.length);
|
||||
if (Arrays.equals(ROCKSIM_SIGNATURE, typeIdentifier)) {
|
||||
loadUsing(doc, rocksimLoader, source);
|
||||
loadUsing(rocksimLoader, source);
|
||||
return;
|
||||
}
|
||||
throw new RocketLoadException("Unsupported or corrupt file.");
|
||||
|
||||
}
|
||||
|
||||
private void loadUsing(OpenRocketDocument doc, RocketLoader loader, InputStream source) throws RocketLoadException {
|
||||
private void setAttachmentFactory() {
|
||||
attachmentFactory = new FileSystemAttachmentFactory(null);
|
||||
if (jarURL != null && isContainer) {
|
||||
attachmentFactory = new ZipFileAttachmentFactory(jarURL);
|
||||
} else {
|
||||
if (isContainer) {
|
||||
try {
|
||||
attachmentFactory = new ZipFileAttachmentFactory(baseFile.toURI().toURL());
|
||||
} catch (MalformedURLException mex) {
|
||||
}
|
||||
} else if (baseFile != null) {
|
||||
attachmentFactory = new FileSystemAttachmentFactory(baseFile.getParentFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadUsing(RocketLoader loader, InputStream source) throws RocketLoadException {
|
||||
warnings.clear();
|
||||
loader.load(doc, source, motorFinder);
|
||||
DocumentLoadingContext context = new DocumentLoadingContext();
|
||||
context.setOpenRocketDocument(doc);
|
||||
context.setMotorFinder(motorFinder);
|
||||
context.setAttachmentFactory(attachmentFactory);
|
||||
loader.load(context, source);
|
||||
warnings.addAll(loader.getWarnings());
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,10 @@ package net.sf.openrocket.file;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
|
||||
public interface RocketLoader {
|
||||
|
||||
public void load(OpenRocketDocument doc, InputStream source, MotorFinder motorFinder) throws RocketLoadException;
|
||||
public void load(DocumentLoadingContext context, InputStream source) throws RocketLoadException;
|
||||
|
||||
public WarningSet getWarnings();
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
package net.sf.openrocket.document;
|
||||
package net.sf.openrocket.file;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import net.sf.openrocket.document.Attachment;
|
||||
import net.sf.openrocket.document.attachments.ZipFileAttachment;
|
||||
|
||||
public class ZipFileAttachmentFactory implements AttachmentFactory<Attachment> {
|
||||
public class ZipFileAttachmentFactory implements AttachmentFactory {
|
||||
|
||||
private final URL zipFile;
|
||||
|
@ -5,6 +5,8 @@ import java.util.HashMap;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.appearance.AppearanceBuilder;
|
||||
import net.sf.openrocket.appearance.Decal.EdgeMode;
|
||||
import net.sf.openrocket.document.Attachment;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
@ -14,7 +16,6 @@ import net.sf.openrocket.util.Color;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
class AppearanceHandler extends AbstractElementHandler {
|
||||
@SuppressWarnings("unused")
|
||||
private final DocumentLoadingContext context;
|
||||
private final RocketComponent component;
|
||||
|
||||
@ -31,7 +32,8 @@ class AppearanceHandler extends AbstractElementHandler {
|
||||
throws SAXException {
|
||||
if ("decal".equals(element)) {
|
||||
String name = attributes.remove("name");
|
||||
builder.setImage(context.getOpenRocketDocument().getDecalRegistry().getAttachment(name));
|
||||
Attachment a = context.getAttachmentFactory().getAttachment(name);
|
||||
builder.setImage(context.getOpenRocketDocument().getDecalImage(a));
|
||||
double rotation = Double.parseDouble(attributes.remove("rotation"));
|
||||
builder.setRotation(rotation);
|
||||
String edgeModeName = attributes.remove("edgemode");
|
||||
|
@ -3,6 +3,7 @@ package net.sf.openrocket.file.openrocket.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -3,6 +3,7 @@ package net.sf.openrocket.file.openrocket.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.simulation.customexpression.CustomExpression;
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -3,6 +3,7 @@ package net.sf.openrocket.file.openrocket.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -5,6 +5,7 @@ import java.util.Locale;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -5,6 +5,7 @@ import java.util.Locale;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
|
||||
|
@ -7,6 +7,7 @@ import java.util.regex.Pattern;
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
|
||||
|
@ -8,7 +8,7 @@ import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.document.StorageOptions;
|
||||
import net.sf.openrocket.file.AbstractRocketLoader;
|
||||
import net.sf.openrocket.file.MotorFinder;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.RocketLoadException;
|
||||
import net.sf.openrocket.file.simplesax.SimpleSAX;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
@ -35,16 +35,14 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
||||
|
||||
|
||||
@Override
|
||||
public void loadFromStream(OpenRocketDocument doc, InputStream source, MotorFinder motorFinder) throws RocketLoadException,
|
||||
public void loadFromStream(DocumentLoadingContext context, InputStream source) throws RocketLoadException,
|
||||
IOException {
|
||||
log.info("Loading .ork file");
|
||||
DocumentLoadingContext context = new DocumentLoadingContext();
|
||||
context.setMotorFinder(motorFinder);
|
||||
context.setOpenRocketDocument(doc);
|
||||
|
||||
InputSource xmlSource = new InputSource(source);
|
||||
OpenRocketHandler handler = new OpenRocketHandler(context);
|
||||
|
||||
OpenRocketDocument doc = context.getOpenRocketDocument();
|
||||
|
||||
try {
|
||||
SimpleSAX.readXML(xmlSource, handler, warnings);
|
||||
|
@ -3,6 +3,7 @@ package net.sf.openrocket.file.openrocket.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.simulation.customexpression.CustomExpression;
|
||||
|
@ -8,6 +8,7 @@ import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.document.Simulation.Status;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
@ -16,7 +16,7 @@ import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
* A SAX handler for the Rocksim AttachedParts XML type.
|
||||
*/
|
||||
class AttachedPartsHandler extends AbstractElementHandler {
|
||||
private final OpenRocketDocument document;
|
||||
private final DocumentLoadingContext context;
|
||||
|
||||
/** The parent component. */
|
||||
private final RocketComponent component;
|
||||
@ -28,42 +28,42 @@ class AttachedPartsHandler extends AbstractElementHandler {
|
||||
*
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public AttachedPartsHandler(OpenRocketDocument document, RocketComponent c) throws IllegalArgumentException {
|
||||
public AttachedPartsHandler(DocumentLoadingContext context, RocketComponent c) throws IllegalArgumentException {
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The parent component of any attached part may not be null.");
|
||||
}
|
||||
this.document = document;
|
||||
this.context = context;
|
||||
component = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
|
||||
if (RocksimCommonConstants.FIN_SET.equals(element)) {
|
||||
return new FinSetHandler(document, component);
|
||||
return new FinSetHandler(context, component);
|
||||
}
|
||||
if (RocksimCommonConstants.CUSTOM_FIN_SET.equals(element)) {
|
||||
return new FinSetHandler(document, component);
|
||||
return new FinSetHandler(context, component);
|
||||
}
|
||||
if (RocksimCommonConstants.LAUNCH_LUG.equals(element)) {
|
||||
return new LaunchLugHandler(document, component, warnings);
|
||||
return new LaunchLugHandler(context, component, warnings);
|
||||
}
|
||||
if (RocksimCommonConstants.PARACHUTE.equals(element)) {
|
||||
return new ParachuteHandler(document, component, warnings);
|
||||
return new ParachuteHandler(context, component, warnings);
|
||||
}
|
||||
if (RocksimCommonConstants.STREAMER.equals(element)) {
|
||||
return new StreamerHandler(document, component, warnings);
|
||||
return new StreamerHandler(context, component, warnings);
|
||||
}
|
||||
if (RocksimCommonConstants.MASS_OBJECT.equals(element)) {
|
||||
return new MassObjectHandler(document, component, warnings);
|
||||
return new MassObjectHandler(context, component, warnings);
|
||||
}
|
||||
if (RocksimCommonConstants.RING.equals(element)) {
|
||||
return new RingHandler(document, component, warnings);
|
||||
return new RingHandler(context, component, warnings);
|
||||
}
|
||||
if (RocksimCommonConstants.BODY_TUBE.equals(element)) {
|
||||
return new InnerBodyTubeHandler(document, component, warnings);
|
||||
return new InnerBodyTubeHandler(context, component, warnings);
|
||||
}
|
||||
if (RocksimCommonConstants.TRANSITION.equals(element)) {
|
||||
return new TransitionHandler(document, component, warnings);
|
||||
return new TransitionHandler(context, component, warnings);
|
||||
}
|
||||
if (RocksimCommonConstants.TUBE_FIN_SET.equals(element)) {
|
||||
warnings.add("Tube fins are not currently supported. Ignoring.");
|
||||
@ -77,4 +77,3 @@ class AttachedPartsHandler extends AbstractElementHandler {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.database.Databases;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.rocksim.RocksimDensityType;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
@ -53,12 +53,12 @@ public abstract class BaseHandler<C extends RocketComponent> extends AbstractEle
|
||||
*/
|
||||
private String materialName = "";
|
||||
|
||||
protected final OpenRocketDocument document;
|
||||
protected final DocumentLoadingContext context;
|
||||
private final RockSimAppearanceBuilder appearanceBuilder;
|
||||
|
||||
public BaseHandler( OpenRocketDocument document ) {
|
||||
this.document = document;
|
||||
appearanceBuilder = new RockSimAppearanceBuilder( document );
|
||||
public BaseHandler(DocumentLoadingContext context) {
|
||||
this.context = context;
|
||||
appearanceBuilder = new RockSimAppearanceBuilder(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.rocksim.RocksimFinishCode;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
@ -33,8 +33,8 @@ class BodyTubeHandler extends BaseHandler<BodyTube> {
|
||||
* @param warnings the warning set
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public BodyTubeHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(document);
|
||||
public BodyTubeHandler(DocumentLoadingContext context, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(context);
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The parent component of a body tube may not be null.");
|
||||
}
|
||||
@ -47,7 +47,7 @@ class BodyTubeHandler extends BaseHandler<BodyTube> {
|
||||
@Override
|
||||
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
|
||||
if (RocksimCommonConstants.ATTACHED_PARTS.equals(element)) {
|
||||
return new AttachedPartsHandler(document, bodyTube);
|
||||
return new AttachedPartsHandler(context, bodyTube);
|
||||
}
|
||||
return PlainTextHandler.INSTANCE;
|
||||
}
|
||||
@ -80,8 +80,7 @@ class BodyTubeHandler extends BaseHandler<BodyTube> {
|
||||
if (RocksimCommonConstants.MATERIAL.equals(element)) {
|
||||
setMaterialName(content);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||
}
|
||||
}
|
||||
@ -105,4 +104,3 @@ class BodyTubeHandler extends BaseHandler<BodyTube> {
|
||||
return Material.Type.BULK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.rocksim.RocksimFinishCode;
|
||||
import net.sf.openrocket.file.rocksim.RocksimLocationMode;
|
||||
@ -150,11 +150,11 @@ class FinSetHandler extends AbstractElementHandler {
|
||||
*
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public FinSetHandler (OpenRocketDocument document, RocketComponent c) throws IllegalArgumentException {
|
||||
public FinSetHandler(DocumentLoadingContext context, RocketComponent c) throws IllegalArgumentException {
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The parent component of a fin set may not be null.");
|
||||
}
|
||||
appearanceBuilder = new RockSimAppearanceBuilder( document );
|
||||
appearanceBuilder = new RockSimAppearanceBuilder(context);
|
||||
component = c;
|
||||
}
|
||||
|
||||
@ -244,8 +244,7 @@ class FinSetHandler extends AbstractElementHandler {
|
||||
}
|
||||
|
||||
appearanceBuilder.processElement(element, content, warnings);
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||
}
|
||||
}
|
||||
@ -303,8 +302,7 @@ class FinSetHandler extends AbstractElementHandler {
|
||||
result = new FreeformFinSet();
|
||||
try {
|
||||
((FreeformFinSet) result).setPoints(toCoordinates(pointList, warnings));
|
||||
}
|
||||
catch (IllegalFinPointException e) {
|
||||
} catch (IllegalFinPointException e) {
|
||||
warnings.add("Illegal fin point set. " + e.getMessage() + " Ignoring.");
|
||||
}
|
||||
}
|
||||
@ -353,8 +351,7 @@ class FinSetHandler extends AbstractElementHandler {
|
||||
else {
|
||||
warnings.add("Invalid fin point pair.");
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Fin point not in numeric format.");
|
||||
}
|
||||
}
|
||||
@ -403,4 +400,3 @@ class FinSetHandler extends AbstractElementHandler {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
@ -33,8 +33,8 @@ class InnerBodyTubeHandler extends PositionDependentHandler<InnerTube> {
|
||||
* @param warnings the warning set
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public InnerBodyTubeHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(document);
|
||||
public InnerBodyTubeHandler(DocumentLoadingContext context, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(context);
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The parent component of an inner tube may not be null.");
|
||||
}
|
||||
@ -47,7 +47,7 @@ class InnerBodyTubeHandler extends PositionDependentHandler<InnerTube> {
|
||||
@Override
|
||||
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
|
||||
if (RocksimCommonConstants.ATTACHED_PARTS.equals(element)) {
|
||||
return new AttachedPartsHandler(document, bodyTube);
|
||||
return new AttachedPartsHandler(context, bodyTube);
|
||||
}
|
||||
return PlainTextHandler.INSTANCE;
|
||||
}
|
||||
@ -83,8 +83,7 @@ class InnerBodyTubeHandler extends PositionDependentHandler<InnerTube> {
|
||||
if (RocksimCommonConstants.RADIAL_LOC.equals(element)) {
|
||||
bodyTube.setRadialPosition(Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.rocksim.RocksimFinishCode;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
@ -35,8 +35,8 @@ class LaunchLugHandler extends PositionDependentHandler<LaunchLug> {
|
||||
*
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public LaunchLugHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(document);
|
||||
public LaunchLugHandler(DocumentLoadingContext context, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(context);
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The parent component of a launch lug may not be null.");
|
||||
}
|
||||
@ -75,8 +75,7 @@ class LaunchLugHandler extends PositionDependentHandler<LaunchLug> {
|
||||
if (RocksimCommonConstants.FINISH_CODE.equals(element)) {
|
||||
lug.setFinish(RocksimFinishCode.fromCode(Integer.parseInt(content)).asOpenRocket());
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||
}
|
||||
}
|
||||
@ -112,4 +111,3 @@ class LaunchLugHandler extends PositionDependentHandler<LaunchLug> {
|
||||
return Material.Type.BULK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.rocksim.RocksimDensityType;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
@ -62,8 +62,8 @@ class MassObjectHandler extends PositionDependentHandler<MassObject> {
|
||||
*
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public MassObjectHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(document);
|
||||
public MassObjectHandler(DocumentLoadingContext context, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(context);
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The parent component of a mass component may not be null.");
|
||||
}
|
||||
@ -102,8 +102,7 @@ class MassObjectHandler extends PositionDependentHandler<MassObject> {
|
||||
if (RocksimCommonConstants.MATERIAL.equals(element)) {
|
||||
setMaterialName(content);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.rocksim.RocksimFinishCode;
|
||||
import net.sf.openrocket.file.rocksim.RocksimNoseConeCode;
|
||||
@ -42,8 +42,8 @@ class NoseConeHandler extends BaseHandler<NoseCone> {
|
||||
*
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public NoseConeHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(document);
|
||||
public NoseConeHandler(DocumentLoadingContext context, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(context);
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The parent component of a nose cone may not be null.");
|
||||
}
|
||||
@ -57,7 +57,7 @@ class NoseConeHandler extends BaseHandler<NoseCone> {
|
||||
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
|
||||
//Nose cones in Rocksim may have attached parts - namely Mass Objects - as children.
|
||||
if (RocksimCommonConstants.ATTACHED_PARTS.equals(element)) {
|
||||
return new AttachedPartsHandler(document, noseCone);
|
||||
return new AttachedPartsHandler(context, noseCone);
|
||||
}
|
||||
return PlainTextHandler.INSTANCE;
|
||||
}
|
||||
@ -115,8 +115,7 @@ class NoseConeHandler extends BaseHandler<NoseCone> {
|
||||
if (RocksimCommonConstants.MATERIAL.equals(element)) {
|
||||
setMaterialName(content);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
@ -39,8 +39,8 @@ class ParachuteHandler extends RecoveryDeviceHandler<Parachute> {
|
||||
*
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public ParachuteHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(document);
|
||||
public ParachuteHandler(DocumentLoadingContext context, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(context);
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The parent of a parachute may not be null.");
|
||||
}
|
||||
@ -105,8 +105,7 @@ class ParachuteHandler extends RecoveryDeviceHandler<Parachute> {
|
||||
if (RocksimCommonConstants.MATERIAL.equals(element)) {
|
||||
setMaterialName(content);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||
}
|
||||
}
|
||||
@ -121,4 +120,3 @@ class ParachuteHandler extends RecoveryDeviceHandler<Parachute> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.rocksim.RocksimLocationMode;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
@ -27,9 +27,10 @@ public abstract class PositionDependentHandler<C extends RocketComponent> extend
|
||||
/** Temporary position. */
|
||||
private RocketComponent.Position position = RocketComponent.Position.TOP;
|
||||
|
||||
public PositionDependentHandler( OpenRocketDocument document ) {
|
||||
super(document);
|
||||
public PositionDependentHandler(DocumentLoadingContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.rocksim.RocksimDensityType;
|
||||
import net.sf.openrocket.material.Material;
|
||||
@ -33,8 +33,8 @@ public abstract class RecoveryDeviceHandler<C extends RecoveryDevice> extends Po
|
||||
*/
|
||||
private Double calcMass = 0d;
|
||||
|
||||
public RecoveryDeviceHandler( OpenRocketDocument document ) {
|
||||
super(document);
|
||||
public RecoveryDeviceHandler(DocumentLoadingContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,8 +52,7 @@ public abstract class RecoveryDeviceHandler<C extends RecoveryDevice> extends Po
|
||||
if (RocksimCommonConstants.CALC_MASS.equals(element)) {
|
||||
calcMass = Math.max(0d, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
@ -47,8 +47,8 @@ class RingHandler extends PositionDependentHandler<CenteringRing> {
|
||||
* @param warnings the warning set
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public RingHandler(OpenRocketDocument document, RocketComponent theParent, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(document);
|
||||
public RingHandler(DocumentLoadingContext context, RocketComponent theParent, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(context);
|
||||
if (theParent == null) {
|
||||
throw new IllegalArgumentException("The parent of a ring may not be null.");
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ import java.net.MalformedURLException;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.appearance.AppearanceBuilder;
|
||||
import net.sf.openrocket.appearance.Decal.EdgeMode;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Attachment;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.util.Color;
|
||||
|
||||
@ -16,10 +17,10 @@ public class RockSimAppearanceBuilder extends AppearanceBuilder {
|
||||
boolean preventSeam = false;
|
||||
boolean repeat = false;
|
||||
|
||||
private final OpenRocketDocument document;
|
||||
private final DocumentLoadingContext context;
|
||||
|
||||
public RockSimAppearanceBuilder(OpenRocketDocument document) {
|
||||
this.document = document;
|
||||
public RockSimAppearanceBuilder(DocumentLoadingContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void processElement(String element, String content, WarningSet warnings) {
|
||||
@ -68,7 +69,8 @@ public class RockSimAppearanceBuilder extends AppearanceBuilder {
|
||||
//Find out how to get path of current rocksim file
|
||||
//so I can look in it's directory
|
||||
}
|
||||
setImage(document.getDecalRegistry().getAttachment(value));
|
||||
Attachment a = context.getAttachmentFactory().getAttachment(name);
|
||||
setImage(context.getOpenRocketDocument().getDecalImage(a));
|
||||
}
|
||||
} else if ("repeat".equals(name)) {
|
||||
repeat = "1".equals(value);
|
||||
|
@ -9,6 +9,7 @@ import java.util.HashMap;
|
||||
import net.sf.openrocket.aerodynamics.Warning;
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
@ -33,11 +34,11 @@ public class RocksimHandler extends AbstractElementHandler {
|
||||
*/
|
||||
private RocksimContentHandler handler = null;
|
||||
|
||||
private final OpenRocketDocument document;
|
||||
private final DocumentLoadingContext context;
|
||||
|
||||
public RocksimHandler(OpenRocketDocument document) {
|
||||
public RocksimHandler(DocumentLoadingContext context) {
|
||||
super();
|
||||
this.document = document;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +48,7 @@ public class RocksimHandler extends AbstractElementHandler {
|
||||
* @return the document read, or null.
|
||||
*/
|
||||
public OpenRocketDocument getDocument() {
|
||||
return document;
|
||||
return context.getOpenRocketDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,7 +68,7 @@ public class RocksimHandler extends AbstractElementHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
handler = new RocksimContentHandler(document);
|
||||
handler = new RocksimContentHandler(context);
|
||||
return handler;
|
||||
}
|
||||
|
||||
@ -78,9 +79,9 @@ public class RocksimHandler extends AbstractElementHandler {
|
||||
*/
|
||||
class RocksimContentHandler extends AbstractElementHandler {
|
||||
/**
|
||||
* The OpenRocketDocument that is the container for the rocket.
|
||||
* The DocumentLoadingContext
|
||||
*/
|
||||
private final OpenRocketDocument doc;
|
||||
private final DocumentLoadingContext context;
|
||||
|
||||
/**
|
||||
* The top-level component, from which all child components are added.
|
||||
@ -92,10 +93,10 @@ class RocksimContentHandler extends AbstractElementHandler {
|
||||
*/
|
||||
private String version;
|
||||
|
||||
public RocksimContentHandler(OpenRocketDocument doc) {
|
||||
public RocksimContentHandler(DocumentLoadingContext context) {
|
||||
super();
|
||||
this.doc = doc;
|
||||
this.rocket = doc.getRocket();
|
||||
this.context = context;
|
||||
this.rocket = context.getOpenRocketDocument().getRocket();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +105,7 @@ class RocksimContentHandler extends AbstractElementHandler {
|
||||
* @return the instantiated OpenRocketDocument
|
||||
*/
|
||||
public OpenRocketDocument getDocument() {
|
||||
return doc;
|
||||
return context.getOpenRocketDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -119,7 +120,7 @@ class RocksimContentHandler extends AbstractElementHandler {
|
||||
return PlainTextHandler.INSTANCE;
|
||||
}
|
||||
if (RocksimCommonConstants.ROCKET_DESIGN.equals(element)) {
|
||||
return new RocketDesignHandler(doc, rocket);
|
||||
return new RocketDesignHandler(context, rocket);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -153,7 +154,7 @@ class RocksimContentHandler extends AbstractElementHandler {
|
||||
* structures. If that invariant is not true, then behavior will be unpredictable.
|
||||
*/
|
||||
class RocketDesignHandler extends AbstractElementHandler {
|
||||
private final OpenRocketDocument document;
|
||||
private final DocumentLoadingContext context;
|
||||
/**
|
||||
* The parent component.
|
||||
*/
|
||||
@ -192,8 +193,8 @@ class RocketDesignHandler extends AbstractElementHandler {
|
||||
*
|
||||
* @param c the parent component
|
||||
*/
|
||||
public RocketDesignHandler(OpenRocketDocument document, RocketComponent c) {
|
||||
this.document = document;
|
||||
public RocketDesignHandler(DocumentLoadingContext context, RocketComponent c) {
|
||||
this.context = context;
|
||||
component = c;
|
||||
}
|
||||
|
||||
@ -216,7 +217,7 @@ class RocketDesignHandler extends AbstractElementHandler {
|
||||
stage.setOverrideCGX(stage3CG);
|
||||
}
|
||||
component.addChild(stage);
|
||||
return new StageHandler(document, stage);
|
||||
return new StageHandler(context, stage);
|
||||
}
|
||||
if ("Stage2Parts".equals(element)) {
|
||||
if (stageCount >= 2) {
|
||||
@ -232,7 +233,7 @@ class RocketDesignHandler extends AbstractElementHandler {
|
||||
stage.setOverrideCGX(stage2CG);
|
||||
}
|
||||
component.addChild(stage);
|
||||
return new StageHandler(document, stage);
|
||||
return new StageHandler(context, stage);
|
||||
}
|
||||
}
|
||||
if ("Stage1Parts".equals(element)) {
|
||||
@ -249,7 +250,7 @@ class RocketDesignHandler extends AbstractElementHandler {
|
||||
stage.setOverrideCGX(stage1CG);
|
||||
}
|
||||
component.addChild(stage);
|
||||
return new StageHandler(document, stage);
|
||||
return new StageHandler(context, stage);
|
||||
}
|
||||
}
|
||||
if (RocksimCommonConstants.NAME.equals(element)) {
|
||||
@ -318,7 +319,7 @@ class RocketDesignHandler extends AbstractElementHandler {
|
||||
* A SAX handler for a Rocksim stage.
|
||||
*/
|
||||
class StageHandler extends AbstractElementHandler {
|
||||
private final OpenRocketDocument document;
|
||||
private final DocumentLoadingContext context;
|
||||
/**
|
||||
* The parent OpenRocket component.
|
||||
*/
|
||||
@ -330,24 +331,24 @@ class StageHandler extends AbstractElementHandler {
|
||||
* @param c the parent component
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public StageHandler(OpenRocketDocument document, RocketComponent c) throws IllegalArgumentException {
|
||||
public StageHandler(DocumentLoadingContext context, RocketComponent c) throws IllegalArgumentException {
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The stage component may not be null.");
|
||||
}
|
||||
this.document = document;
|
||||
this.context = context;
|
||||
component = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
|
||||
if (RocksimCommonConstants.NOSE_CONE.equals(element)) {
|
||||
return new NoseConeHandler(document, component, warnings);
|
||||
return new NoseConeHandler(context, component, warnings);
|
||||
}
|
||||
if (RocksimCommonConstants.BODY_TUBE.equals(element)) {
|
||||
return new BodyTubeHandler(document, component, warnings);
|
||||
return new BodyTubeHandler(context, component, warnings);
|
||||
}
|
||||
if (RocksimCommonConstants.TRANSITION.equals(element)) {
|
||||
return new TransitionHandler(document, component, warnings);
|
||||
return new TransitionHandler(context, component, warnings);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -6,9 +6,8 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.AbstractRocketLoader;
|
||||
import net.sf.openrocket.file.MotorFinder;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.RocketLoadException;
|
||||
import net.sf.openrocket.file.simplesax.SimpleSAX;
|
||||
|
||||
@ -39,11 +38,11 @@ public class RocksimLoader extends AbstractRocketLoader {
|
||||
* if an error occurs during loading.
|
||||
*/
|
||||
@Override
|
||||
protected void loadFromStream(OpenRocketDocument doc, InputStream source, MotorFinder motorFinder) throws IOException, RocketLoadException {
|
||||
protected void loadFromStream(DocumentLoadingContext context, InputStream source) throws IOException, RocketLoadException {
|
||||
|
||||
InputSource xmlSource = new InputSource(source);
|
||||
|
||||
RocksimHandler handler = new RocksimHandler(doc);
|
||||
RocksimHandler handler = new RocksimHandler(context);
|
||||
|
||||
try {
|
||||
SimpleSAX.readXML(xmlSource, handler, warnings);
|
||||
@ -51,7 +50,7 @@ public class RocksimLoader extends AbstractRocketLoader {
|
||||
throw new RocketLoadException("Malformed XML in input.", e);
|
||||
}
|
||||
|
||||
doc.setFile(null);
|
||||
doc.clearUndo();
|
||||
context.getOpenRocketDocument().setFile(null);
|
||||
context.getOpenRocketDocument().clearUndo();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
@ -33,8 +33,8 @@ class StreamerHandler extends RecoveryDeviceHandler<Streamer> {
|
||||
*
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public StreamerHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(document);
|
||||
public StreamerHandler(DocumentLoadingContext context, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(context);
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The parent of a streamer may not be null.");
|
||||
}
|
||||
@ -73,8 +73,7 @@ class StreamerHandler extends RecoveryDeviceHandler<Streamer> {
|
||||
if (RocksimCommonConstants.MATERIAL.equals(element)) {
|
||||
setMaterialName(content);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package net.sf.openrocket.file.rocksim.importt;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
|
||||
import net.sf.openrocket.file.rocksim.RocksimFinishCode;
|
||||
import net.sf.openrocket.file.rocksim.RocksimNoseConeCode;
|
||||
@ -39,8 +39,8 @@ class TransitionHandler extends BaseHandler<Transition> {
|
||||
* @param warnings the warning set
|
||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||
*/
|
||||
public TransitionHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(document);
|
||||
public TransitionHandler(DocumentLoadingContext context, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
|
||||
super(context);
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("The parent of a transition may not be null.");
|
||||
}
|
||||
@ -52,7 +52,7 @@ class TransitionHandler extends BaseHandler<Transition> {
|
||||
@Override
|
||||
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
|
||||
if (RocksimCommonConstants.ATTACHED_PARTS.equals(element)) {
|
||||
return new AttachedPartsHandler(document, transition);
|
||||
return new AttachedPartsHandler(context, transition);
|
||||
}
|
||||
return PlainTextHandler.INSTANCE;
|
||||
}
|
||||
@ -121,8 +121,7 @@ class TransitionHandler extends BaseHandler<Transition> {
|
||||
if ("Material".equals(element)) {
|
||||
setMaterialName(content);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||
}
|
||||
}
|
||||
@ -160,4 +159,3 @@ class TransitionHandler extends BaseHandler<Transition> {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class ExportDecalDialog extends JDialog {
|
||||
JLabel label = new JLabel(trans.get("ExportDecalDialog.decalList.lbl"));
|
||||
panel.add(label);
|
||||
|
||||
Collection<DecalImage> exportableDecals = document.getDecalRegistry().getDecalList();
|
||||
Collection<DecalImage> exportableDecals = document.getDecalList();
|
||||
|
||||
decalComboBox = new JComboBox(exportableDecals.toArray(new DecalImage[0]));
|
||||
decalComboBox.setEditable(false);
|
||||
|
@ -10,7 +10,9 @@ import javax.swing.SwingUtilities;
|
||||
|
||||
import net.sf.openrocket.appearance.AppearanceBuilder;
|
||||
import net.sf.openrocket.appearance.DecalImage;
|
||||
import net.sf.openrocket.document.Attachment;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.file.FileSystemAttachmentFactory;
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
@ -34,7 +36,7 @@ public class DecalModel extends AbstractListModel implements ComboBoxModel {
|
||||
this.document = document;
|
||||
this.parent = parent;
|
||||
this.ab = ab;
|
||||
decals = document.getDecalRegistry().getDecalList().toArray(new DecalImage[0]);
|
||||
decals = document.getDecalList().toArray(new DecalImage[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,7 +73,8 @@ public class DecalModel extends AbstractListModel implements ComboBoxModel {
|
||||
if (action == JFileChooser.APPROVE_OPTION) {
|
||||
((SwingPreferences) Application.getPreferences()).setDefaultDirectory(fc.getCurrentDirectory());
|
||||
File file = fc.getSelectedFile();
|
||||
setSelectedItem(document.getDecalRegistry().getAttachment(file));
|
||||
Attachment a = (new FileSystemAttachmentFactory().getAttachment(file));
|
||||
setSelectedItem(document.getDecalImage(a));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -11,6 +11,7 @@ import java.io.InputStream;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.OpenRocketDocumentFactory;
|
||||
import net.sf.openrocket.file.DatabaseMotorFinder;
|
||||
import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.RocketLoadException;
|
||||
import net.sf.openrocket.rocketcomponent.BodyTube;
|
||||
import net.sf.openrocket.rocketcomponent.LaunchLug;
|
||||
@ -35,9 +36,11 @@ public class RocksimLoaderTest {
|
||||
InputStream stream = this.getClass().getResourceAsStream("PodFins.rkt");
|
||||
Assert.assertNotNull("Could not open PodFins.rkt", stream);
|
||||
try {
|
||||
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentForFile(null, false);
|
||||
loader.loadFromStream(doc, new BufferedInputStream(stream), new DatabaseMotorFinder());
|
||||
Assert.assertNotNull(doc);
|
||||
OpenRocketDocument doc = OpenRocketDocumentFactory.createEmptyRocket();
|
||||
DocumentLoadingContext context = new DocumentLoadingContext();
|
||||
context.setOpenRocketDocument(doc);
|
||||
context.setMotorFinder(new DatabaseMotorFinder());
|
||||
loader.loadFromStream(context, new BufferedInputStream(stream));
|
||||
Rocket rocket = doc.getRocket();
|
||||
Assert.assertNotNull(rocket);
|
||||
} catch (IllegalStateException ise) {
|
||||
@ -67,8 +70,11 @@ public class RocksimLoaderTest {
|
||||
stream = this.getClass().getResourceAsStream("rocksimTestRocket2.rkt");
|
||||
Assert.assertNotNull("Could not open rocksimTestRocket2.rkt", stream);
|
||||
|
||||
doc = OpenRocketDocumentFactory.createDocumentForFile(null, false);
|
||||
loader.loadFromStream(doc, new BufferedInputStream(stream), new DatabaseMotorFinder());
|
||||
doc = OpenRocketDocumentFactory.createEmptyRocket();
|
||||
DocumentLoadingContext context = new DocumentLoadingContext();
|
||||
context.setOpenRocketDocument(doc);
|
||||
context.setMotorFinder(new DatabaseMotorFinder());
|
||||
loader.loadFromStream(context, new BufferedInputStream(stream));
|
||||
|
||||
Assert.assertNotNull(doc);
|
||||
rocket = doc.getRocket();
|
||||
@ -92,8 +98,11 @@ public class RocksimLoaderTest {
|
||||
stream = this.getClass().getResourceAsStream("rocksimTestRocket3.rkt");
|
||||
Assert.assertNotNull("Could not open rocksimTestRocket3.rkt", stream);
|
||||
|
||||
doc = OpenRocketDocumentFactory.createDocumentForFile(null, false);
|
||||
loader.loadFromStream(doc, new BufferedInputStream(stream), new DatabaseMotorFinder());
|
||||
doc = OpenRocketDocumentFactory.createEmptyRocket();
|
||||
context = new DocumentLoadingContext();
|
||||
context.setOpenRocketDocument(doc);
|
||||
context.setMotorFinder(new DatabaseMotorFinder());
|
||||
loader.loadFromStream(context, new BufferedInputStream(stream));
|
||||
|
||||
Assert.assertNotNull(doc);
|
||||
rocket = doc.getRocket();
|
||||
@ -139,8 +148,11 @@ public class RocksimLoaderTest {
|
||||
InputStream stream = RocksimLoaderTest.class.getResourceAsStream("rocksimTestRocket1.rkt");
|
||||
try {
|
||||
Assert.assertNotNull("Could not open rocksimTestRocket1.rkt", stream);
|
||||
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentForFile(null, false);
|
||||
theLoader.loadFromStream(doc, new BufferedInputStream(stream), new DatabaseMotorFinder());
|
||||
OpenRocketDocument doc = OpenRocketDocumentFactory.createEmptyRocket();
|
||||
DocumentLoadingContext context = new DocumentLoadingContext();
|
||||
context.setOpenRocketDocument(doc);
|
||||
context.setMotorFinder(new DatabaseMotorFinder());
|
||||
theLoader.loadFromStream(context, new BufferedInputStream(stream));
|
||||
return doc;
|
||||
} finally {
|
||||
stream.close();
|
||||
@ -151,8 +163,11 @@ public class RocksimLoaderTest {
|
||||
InputStream stream = RocksimLoaderTest.class.getResourceAsStream("rocksimTestRocket3.rkt");
|
||||
try {
|
||||
Assert.assertNotNull("Could not open rocksimTestRocket3.rkt", stream);
|
||||
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentForFile(null, false);
|
||||
theLoader.loadFromStream(doc, new BufferedInputStream(stream), new DatabaseMotorFinder());
|
||||
OpenRocketDocument doc = OpenRocketDocumentFactory.createEmptyRocket();
|
||||
DocumentLoadingContext context = new DocumentLoadingContext();
|
||||
context.setOpenRocketDocument(doc);
|
||||
context.setMotorFinder(new DatabaseMotorFinder());
|
||||
theLoader.loadFromStream(context, new BufferedInputStream(stream));
|
||||
return doc;
|
||||
} finally {
|
||||
stream.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user