[Patchanim-commit] SF.net SVN: patchanim: [66] trunk/patchanim/src/com/mebigfatguy/patchanim
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-01-30 02:04:38
|
Revision: 66
http://patchanim.svn.sourceforge.net/patchanim/?rev=66&view=rev
Author: dbrosius
Date: 2008-01-29 18:04:43 -0800 (Tue, 29 Jan 2008)
Log Message:
-----------
add an export listener so that a gui can show progress
Modified Paths:
--------------
trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java
Added Paths:
-----------
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportEvent.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportListener.java
Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportEvent.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportEvent.java (rev 0)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportEvent.java 2008-01-30 02:04:43 UTC (rev 66)
@@ -0,0 +1,25 @@
+package com.mebigfatguy.patchanim.gui.events;
+
+import java.util.EventObject;
+
+public class ExportEvent extends EventObject {
+ private static final long serialVersionUID = 2626267094073359857L;
+
+ private int index;
+ private int total;
+
+ public ExportEvent(Object src, int curImage, int totalImages) {
+ super(src);
+ index = curImage;
+ total = totalImages;
+ }
+
+ public int getCurrentImage() {
+ return index;
+ }
+
+ public int getTotalImages() {
+ return total;
+ }
+
+}
Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportEvent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportListener.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportListener.java (rev 0)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportListener.java 2008-01-30 02:04:43 UTC (rev 66)
@@ -0,0 +1,5 @@
+package com.mebigfatguy.patchanim.gui.events;
+
+public interface ExportListener {
+ public void imageExported(ExportEvent ee);
+}
Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/events/ExportListener.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java 2008-01-30 01:49:46 UTC (rev 65)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/io/PatchExporter.java 2008-01-30 02:04:43 UTC (rev 66)
@@ -22,7 +22,9 @@
import java.io.File;
import java.io.IOException;
import java.text.NumberFormat;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import javax.imageio.ImageIO;
@@ -31,6 +33,8 @@
import com.mebigfatguy.patchanim.ExportType;
import com.mebigfatguy.patchanim.OutOfBoundsColor;
import com.mebigfatguy.patchanim.PatchAnimDocument;
+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;
@@ -38,6 +42,8 @@
private ExportType type;
private File loc;
private AnimatedGifEncoder agEncoder;
+ private int totalImages;
+ private Set<ExportListener> elisteners = new HashSet<ExportListener>();
public PatchExporter(ExportType exportType, File location) {
type = exportType;
@@ -48,6 +54,10 @@
agEncoder = null;
}
+ public void addExportListener(ExportListener el) {
+ elisteners.add(el);
+ }
+
public void export(PatchAnimDocument document) throws IOException {
try {
String baseName = loc.getName();
@@ -62,8 +72,9 @@
agEncoder.start(new File(loc, baseName).getPath());
}
+ totalImages = calcImageCount(document);
+
BufferedImage image = PatchGenerator.buildImage(null, document.getWidth(), document.getHeight());
-
List<CombinedPatch> patches = document.getPatches();
int lastPatch = patches.size() - 1;
int tweenCount = document.getTweenCount();
@@ -71,6 +82,10 @@
int imageIndex = 1;
AnimationType atype = document.getAnimationType();
+ if (type == ExportType.AnimatedGif) {
+ agEncoder.setRepeat((atype != AnimationType.None) ? 0 : -1);
+ }
+
for(int p = 0; p < lastPatch; p++) {
CombinedPatch startPatch = patches.get(p);
CombinedPatch endPatch = patches.get(p+1);
@@ -120,6 +135,23 @@
}
else
ImageIO.write(image, type.getExtension(), imageFile);
+
+ fireExportEvent(index);
}
-
+
+ private void fireExportEvent(int index) {
+ ExportEvent ee = new ExportEvent(this, index, totalImages);
+ for (ExportListener el : elisteners) {
+ el.imageExported(ee);
+ }
+ }
+
+ private int calcImageCount(PatchAnimDocument document) {
+ int total = (document.getPatches().size() - 1) * document.getTweenCount() + 1;
+
+ if (document.getAnimationType() == AnimationType.Wave)
+ total *= 2;
+
+ return total;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|