1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48:51 -05:00

* cancel/interrupt obsolete background formatters in EpisodeFormatDialog

This commit is contained in:
Reinhard Pointner 2009-09-24 16:44:56 +00:00
parent 0b30c631ed
commit 24025d9cb6
2 changed files with 18 additions and 0 deletions

View File

@ -24,6 +24,12 @@ Number.metaClass.compareTo = { String other -> delegate.toString().compareTo(oth
String.metaClass.pad = Number.metaClass.pad = { length = 2, padding = "0" -> delegate.toString().padLeft(length, padding) } String.metaClass.pad = Number.metaClass.pad = { length = 2, padding = "0" -> delegate.toString().padLeft(length, padding) }
/**
* Use empty string as default replacement.
*/
String.metaClass.replaceAll = { String pattern -> replaceAll(pattern, "") }
/** /**
* Replace space characters with a given characters. * Replace space characters with a given characters.
* *

View File

@ -21,7 +21,9 @@ import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RunnableFuture; import java.util.concurrent.RunnableFuture;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -350,6 +352,9 @@ class EpisodeFormatDialog extends JDialog {
} }
}); });
// cancel old worker later
Future<String> obsoletePreviewFuture = currentPreviewFuture;
// create new worker // create new worker
currentPreviewFuture = new SwingWorker<String, Void>() { currentPreviewFuture = new SwingWorker<String, Void>() {
@ -376,6 +381,8 @@ class EpisodeFormatDialog extends JDialog {
// no warning or error // no warning or error
status.setVisible(false); status.setVisible(false);
} catch (CancellationException e) {
// ignore, cancelled tasks are obsolete anyway
} catch (Exception e) { } catch (Exception e) {
status.setText(ExceptionUtilities.getMessage(e)); status.setText(ExceptionUtilities.getMessage(e));
status.setIcon(ResourceManager.getIcon("status.warning")); status.setIcon(ResourceManager.getIcon("status.warning"));
@ -395,6 +402,11 @@ class EpisodeFormatDialog extends JDialog {
} }
}; };
// cancel old worker, after new worker has been created, because done() might be called from within cancel()
if (obsoletePreviewFuture != null) {
obsoletePreviewFuture.cancel(true);
}
// submit new worker // submit new worker
executor.execute(currentPreviewFuture); executor.execute(currentPreviewFuture);
} catch (ScriptException e) { } catch (ScriptException e) {