[Patchanim-commit] SF.net SVN: patchanim:[274] trunk/patchanim/src/com/mebigfatguy/patchanim
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-12-28 07:46:04
|
Revision: 274
http://patchanim.svn.sourceforge.net/patchanim/?rev=274&view=rev
Author: dbrosius
Date: 2008-12-28 07:46:02 +0000 (Sun, 28 Dec 2008)
Log Message:
-----------
fix problem where user deletes patch while test animating.
Modified Paths:
--------------
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java
trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchAnimator.java
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-12-28 07:01:27 UTC (rev 273)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-12-28 07:46:02 UTC (rev 274)
@@ -61,14 +61,19 @@
animThread = new Thread(new Runnable() {
public void run() {
- try {
- PatchAnimator animator = new PatchAnimator(document);
- animator.addPatchCompletionListener(JTestFrame.this);
- AnimationType type = document.getAnimationType();
- while (type != AnimationType.None)
+ AnimationType type = document.getAnimationType();
+ do {
+ try {
+ PatchAnimator animator = new PatchAnimator(document);
+ animator.addPatchCompletionListener(JTestFrame.this);
animator.animatePatches();
- } catch (InterruptedException ie) {
- }
+ animator.removePatchCompletionListener(JTestFrame.this);
+ } catch (InterruptedException ie) {
+ break;
+ } catch (Exception e) {
+ //Could get OutOfBoundsException if user deletes patches mid animation
+ }
+ } while (type != AnimationType.None);
}
});
animThread.start();
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchAnimator.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchAnimator.java 2008-12-28 07:01:27 UTC (rev 273)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchAnimator.java 2008-12-28 07:46:02 UTC (rev 274)
@@ -40,9 +40,17 @@
}
public void addPatchCompletionListener(PatchCompletionListener listener) {
- pcListeners.add(listener);
+ synchronized(pcListeners) {
+ pcListeners.add(listener);
+ }
}
+ public void removePatchCompletionListener(PatchCompletionListener listener) {
+ synchronized(pcListeners) {
+ pcListeners.remove(listener);
+ }
+ }
+
public void animatePatches() throws InterruptedException {
BufferedImage image = PatchGenerator.buildImage(null, document.useAlpha(), document.getWidth(), document.getHeight());
List<CombinedPatch> patches = document.getPatches();
@@ -105,7 +113,12 @@
private void firePatchCompleted(BufferedImage image) throws InterruptedException {
PatchCompletionEvent pce = new PatchCompletionEvent(this, image);
- for (PatchCompletionListener listener : pcListeners) {
+ Set<PatchCompletionListener> listeners;
+ synchronized(pcListeners) {
+ listeners = new HashSet<PatchCompletionListener>(pcListeners);
+ }
+
+ for (PatchCompletionListener listener : listeners) {
listener.patchCompleted(pce);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|