[Patchanim-commit] SF.net SVN: patchanim: [198] trunk/patchanim/src/com/mebigfatguy/patchanim/ io/P
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-02-18 03:16:14
|
Revision: 198
http://patchanim.svn.sourceforge.net/patchanim/?rev=198&view=rev
Author: dbrosius
Date: 2008-02-17 19:16:18 -0800 (Sun, 17 Feb 2008)
Log Message:
-----------
rework exported to use the new PatchAnimator as well.
Modified Paths:
--------------
trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java 2008-02-18 03:04:31 UTC (rev 197)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java 2008-02-18 03:16:18 UTC (rev 198)
@@ -23,30 +23,34 @@
import java.io.IOException;
import java.text.NumberFormat;
import java.util.HashSet;
-import java.util.List;
+import java.util.ResourceBundle;
import java.util.Set;
import javax.imageio.ImageIO;
+import javax.swing.JOptionPane;
import com.fmsware.gif.AnimatedGifEncoder;
-import com.mebigfatguy.patchanim.encoders.APngEncoder;
-import com.mebigfatguy.patchanim.encoders.MngEncoder;
import com.mebigfatguy.patchanim.AnimationType;
import com.mebigfatguy.patchanim.ExportType;
-import com.mebigfatguy.patchanim.OutOfBoundsColor;
import com.mebigfatguy.patchanim.PatchAnimDocument;
+import com.mebigfatguy.patchanim.encoders.APngEncoder;
+import com.mebigfatguy.patchanim.encoders.MngEncoder;
import com.mebigfatguy.patchanim.gui.events.ExportEvent;
import com.mebigfatguy.patchanim.gui.events.ExportListener;
-import com.mebigfatguy.patchanim.surface.CombinedPatch;
-import com.mebigfatguy.patchanim.surface.PatchGenerator;
+import com.mebigfatguy.patchanim.gui.events.PatchCompletionEvent;
+import com.mebigfatguy.patchanim.gui.events.PatchCompletionListener;
+import com.mebigfatguy.patchanim.main.PatchAnimBundle;
+import com.mebigfatguy.patchanim.surface.PatchAnimator;
-public class PatchExporter {
+public class PatchExporter implements PatchCompletionListener {
private ExportType type;
private File loc;
private AnimatedGifEncoder agEncoder;
private APngEncoder apngEncoder;
private MngEncoder mngEncoder;
private int totalImages;
+ private int imageIndex;
+ private String baseName;
private Set<ExportListener> elisteners = new HashSet<ExportListener>();
public PatchExporter(ExportType exportType, File location) {
@@ -66,7 +70,7 @@
public void export(PatchAnimDocument document) throws IOException {
try {
- String baseName = loc.getName();
+ baseName = loc.getName();
if (type.isMultipleFiles()) {
loc.mkdir();
} else {
@@ -83,74 +87,33 @@
}
totalImages = calcImageCount(document);
+ imageIndex = 1;
- BufferedImage image = PatchGenerator.buildImage(null, document.getWidth(), document.getHeight());
- List<CombinedPatch> patches = document.getPatches();
- int lastPatch = patches.size() - 1;
- int tweenCount = document.getTweenCount();
- OutOfBoundsColor oob = document.getOutOfBoundsColor();
- int imageIndex = 1;
AnimationType atype = document.getAnimationType();
-
- if (type == ExportType.AnimatedGif) {
- agEncoder.setRepeat((atype != AnimationType.None) ? 0 : -1);
- } else if (type == ExportType.AnimatedPng) {
- apngEncoder.setRepeat(atype != AnimationType.None);
- apngEncoder.setNumFrames(totalImages);
- } else if (type == ExportType.AnimatedMng) {
- mngEncoder.setRepeat(atype != AnimationType.None);
- mngEncoder.setNumFrames(totalImages);
- mngEncoder.setDelay(100);
+ switch (type) {
+ case AnimatedGif:
+ agEncoder.setRepeat((atype != AnimationType.None) ? 0 : -1);
+ break;
+
+ case AnimatedPng:
+ apngEncoder.setRepeat(atype != AnimationType.None);
+ apngEncoder.setNumFrames(totalImages);
+ break;
+
+ case AnimatedMng:
+ mngEncoder.setRepeat(atype != AnimationType.None);
+ mngEncoder.setNumFrames(totalImages);
+ mngEncoder.setDelay(100);
}
+
- if (lastPatch == 0) {
- PatchGenerator.recalcCombinedImage(patches.get(0), image, oob);
- writeSingleFile(image, imageIndex++, loc, baseName, type);
- } else {
- for(int p = 0; p < lastPatch; p++) {
- CombinedPatch startPatch = patches.get(p);
- CombinedPatch endPatch = patches.get(p+1);
- for (int t = 0; t < tweenCount + 1; t++) {
- CombinedPatch tweenPatch = CombinedPatch.tween(startPatch, endPatch, (double)t / (double)(tweenCount + 1));
- PatchGenerator.recalcCombinedImage(tweenPatch, image, oob);
- writeSingleFile(image, imageIndex++, loc, baseName, type);
- }
- }
-
- switch (atype) {
- case None: {
- CombinedPatch patch = patches.get(lastPatch);
- PatchGenerator.recalcCombinedImage(patch, image, oob);
- writeSingleFile(image, imageIndex++, loc, baseName, type);
- if (atype == AnimationType.None)
- return;
- }
- break;
-
- case Cycle: {
- CombinedPatch startPatch = patches.get(lastPatch);
- CombinedPatch endPatch = patches.get(0);
- for (int t = 0; t < tweenCount + 1; t++) {
- CombinedPatch tweenPatch = CombinedPatch.tween(startPatch, endPatch, (double)t / (double)(tweenCount + 1));
- PatchGenerator.recalcCombinedImage(tweenPatch, image, oob);
- writeSingleFile(image, imageIndex++, loc, baseName, type);
- }
- }
- break;
-
- case Wave: {
- for (int p = lastPatch; p > 0; p--) {
- CombinedPatch startPatch = patches.get(p-1);
- CombinedPatch endPatch = patches.get(p);
- for (int t = tweenCount + 1; t > 0; t--) {
- CombinedPatch tweenPatch = CombinedPatch.tween(startPatch, endPatch, (double)t / (double)(tweenCount + 1));
- PatchGenerator.recalcCombinedImage(tweenPatch, image, oob);
- writeSingleFile(image, imageIndex++, loc, baseName, type);
- }
- }
- }
- break;
- }
+ PatchAnimator animator = new PatchAnimator(document);
+ animator.addPatchCompletionListener(this);
+ try {
+ animator.animatePatches();
+ } catch (InterruptedException ie) {
+ ResourceBundle rb = PatchAnimBundle.getBundle();
+ JOptionPane.showMessageDialog(null, rb.getString(PatchAnimBundle.EXPORTFAILED));
}
} finally {
if (type == ExportType.AnimatedGif) {
@@ -163,6 +126,16 @@
}
}
+ public void patchCompleted(PatchCompletionEvent pce) throws InterruptedException {
+ try {
+ writeSingleFile(pce.getImage(), imageIndex++, loc, baseName, type);
+ } catch (IOException ioe) {
+ InterruptedException ie = new InterruptedException("Failed saving animation");
+ ie.initCause(ioe);
+ throw ie;
+ }
+ }
+
private void writeSingleFile(BufferedImage image, int index, File dir, String baseName, ExportType type) throws IOException {
NumberFormat nf = NumberFormat.getIntegerInstance();
nf.setMinimumIntegerDigits(5);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|