Make DecalImage no longer inherit from Attachment. It seems less
confusing since a DecalImage cannot be used in place of Attachments in general. Made Attachment a concrete class.
This commit is contained in:
parent
405f0db1b7
commit
4cdf03075b
@ -1,11 +1,17 @@
|
|||||||
package net.sf.openrocket.appearance;
|
package net.sf.openrocket.appearance;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import net.sf.openrocket.document.Attachment;
|
import net.sf.openrocket.util.ChangeSource;
|
||||||
|
|
||||||
public interface DecalImage extends Attachment {
|
public interface DecalImage extends ChangeSource {
|
||||||
|
|
||||||
|
public String getName();
|
||||||
|
|
||||||
|
public InputStream getBytes() throws FileNotFoundException, IOException;
|
||||||
|
|
||||||
public void exportImage(File file, boolean watchForChanges) throws IOException;
|
public void exportImage(File file, boolean watchForChanges) throws IOException;
|
||||||
|
|
||||||
|
@ -4,12 +4,38 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import net.sf.openrocket.util.AbstractChangeSource;
|
||||||
import net.sf.openrocket.util.ChangeSource;
|
import net.sf.openrocket.util.ChangeSource;
|
||||||
|
|
||||||
public interface Attachment extends Comparable<Attachment>, ChangeSource {
|
public abstract class Attachment extends AbstractChangeSource implements Comparable<Attachment>, ChangeSource {
|
||||||
|
|
||||||
public abstract String getName();
|
private final String name;
|
||||||
|
|
||||||
|
public Attachment(String name) {
|
||||||
|
super();
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract InputStream getBytes() throws FileNotFoundException, IOException;
|
public abstract InputStream getBytes() throws FileNotFoundException, IOException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Attachment o) {
|
||||||
|
return this.name.compareTo(o.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fireChangeEvent() {
|
||||||
|
super.fireChangeEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -20,7 +20,6 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import net.sf.openrocket.appearance.DecalImage;
|
import net.sf.openrocket.appearance.DecalImage;
|
||||||
import net.sf.openrocket.document.attachments.BaseAttachment;
|
|
||||||
import net.sf.openrocket.document.attachments.FileSystemAttachment;
|
import net.sf.openrocket.document.attachments.FileSystemAttachment;
|
||||||
import net.sf.openrocket.gui.watcher.FileWatcher;
|
import net.sf.openrocket.gui.watcher.FileWatcher;
|
||||||
import net.sf.openrocket.gui.watcher.WatchEvent;
|
import net.sf.openrocket.gui.watcher.WatchEvent;
|
||||||
@ -28,6 +27,7 @@ import net.sf.openrocket.gui.watcher.WatchService;
|
|||||||
import net.sf.openrocket.logging.LogHelper;
|
import net.sf.openrocket.logging.LogHelper;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.util.BugException;
|
import net.sf.openrocket.util.BugException;
|
||||||
|
import net.sf.openrocket.util.ChangeSource;
|
||||||
import net.sf.openrocket.util.FileUtils;
|
import net.sf.openrocket.util.FileUtils;
|
||||||
|
|
||||||
public class DecalRegistry {
|
public class DecalRegistry {
|
||||||
@ -99,7 +99,7 @@ public class DecalRegistry {
|
|||||||
return decals;
|
return decals;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DecalImageImpl implements DecalImage, Cloneable {
|
public class DecalImageImpl implements DecalImage, Cloneable, Comparable<DecalImage>, ChangeSource {
|
||||||
|
|
||||||
private final Attachment delegate;
|
private final Attachment delegate;
|
||||||
|
|
||||||
@ -115,7 +115,6 @@ public class DecalRegistry {
|
|||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name != null ? name : delegate.getName();
|
return name != null ? name : delegate.getName();
|
||||||
}
|
}
|
||||||
@ -128,7 +127,6 @@ public class DecalRegistry {
|
|||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public InputStream getBytes() throws FileNotFoundException, IOException {
|
public InputStream getBytes() throws FileNotFoundException, IOException {
|
||||||
// First check if the decal is located on the file system
|
// First check if the decal is located on the file system
|
||||||
File exportedFile = getFileSystemLocation();
|
File exportedFile = getFileSystemLocation();
|
||||||
@ -164,7 +162,7 @@ public class DecalRegistry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(WatchEvent evt) {
|
public void handleEvent(WatchEvent evt) {
|
||||||
((BaseAttachment) DecalImageImpl.this.delegate).fireChangeEvent();
|
DecalImageImpl.this.delegate.fireChangeEvent();
|
||||||
System.out.println(this.getFile() + " has changed");
|
System.out.println(this.getFile() + " has changed");
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -191,10 +189,7 @@ public class DecalRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Attachment o) {
|
public int compareTo(DecalImage o) {
|
||||||
if (!(o instanceof DecalImageImpl)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return getName().compareTo(o.getName());
|
return getName().compareTo(o.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
package net.sf.openrocket.document.attachments;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import net.sf.openrocket.document.Attachment;
|
|
||||||
import net.sf.openrocket.util.AbstractChangeSource;
|
|
||||||
|
|
||||||
public abstract class BaseAttachment extends AbstractChangeSource implements Attachment {
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
public BaseAttachment(String name) {
|
|
||||||
super();
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract InputStream getBytes() throws FileNotFoundException, IOException;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Attachment o) {
|
|
||||||
if (!(o instanceof BaseAttachment)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return this.name.compareTo(((BaseAttachment) o).name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fireChangeEvent() {
|
|
||||||
super.fireChangeEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -8,7 +8,7 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
import net.sf.openrocket.document.Attachment;
|
import net.sf.openrocket.document.Attachment;
|
||||||
|
|
||||||
public class FileSystemAttachment extends BaseAttachment implements Attachment {
|
public class FileSystemAttachment extends Attachment {
|
||||||
|
|
||||||
private final File location;
|
private final File location;
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import java.util.zip.ZipInputStream;
|
|||||||
import net.sf.openrocket.document.Attachment;
|
import net.sf.openrocket.document.Attachment;
|
||||||
import net.sf.openrocket.util.FileUtils;
|
import net.sf.openrocket.util.FileUtils;
|
||||||
|
|
||||||
public class ZipFileAttachment extends BaseAttachment implements Attachment {
|
public class ZipFileAttachment extends Attachment {
|
||||||
|
|
||||||
private final URL zipFileLocation;
|
private final URL zipFileLocation;
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import javax.swing.JPanel;
|
|||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.appearance.DecalImage;
|
import net.sf.openrocket.appearance.DecalImage;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.file.AttachmentUtils;
|
|
||||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
@ -79,7 +78,7 @@ public class ExportDecalDialog extends JDialog {
|
|||||||
private void export(DecalImage decal, File selectedFile) {
|
private void export(DecalImage decal, File selectedFile) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AttachmentUtils.exportAttachment(decal, selectedFile);
|
decal.exportImage(selectedFile, false);
|
||||||
} catch (IOException iex) {
|
} catch (IOException iex) {
|
||||||
// FIXME - probably want a simple user dialog here since FileIO is not really a bug.
|
// FIXME - probably want a simple user dialog here since FileIO is not really a bug.
|
||||||
throw new BugException(iex);
|
throw new BugException(iex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user