* cancel/interrupt obsolete background formatters in EpisodeFormatDialog
This commit is contained in:
parent
0b30c631ed
commit
24025d9cb6
|
@ -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) }
|
||||
|
||||
|
||||
/**
|
||||
* Use empty string as default replacement.
|
||||
*/
|
||||
String.metaClass.replaceAll = { String pattern -> replaceAll(pattern, "") }
|
||||
|
||||
|
||||
/**
|
||||
* Replace space characters with a given characters.
|
||||
*
|
||||
|
|
|
@ -21,7 +21,9 @@ import java.util.List;
|
|||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
@ -350,6 +352,9 @@ class EpisodeFormatDialog extends JDialog {
|
|||
}
|
||||
});
|
||||
|
||||
// cancel old worker later
|
||||
Future<String> obsoletePreviewFuture = currentPreviewFuture;
|
||||
|
||||
// create new worker
|
||||
currentPreviewFuture = new SwingWorker<String, Void>() {
|
||||
|
||||
|
@ -376,6 +381,8 @@ class EpisodeFormatDialog extends JDialog {
|
|||
|
||||
// no warning or error
|
||||
status.setVisible(false);
|
||||
} catch (CancellationException e) {
|
||||
// ignore, cancelled tasks are obsolete anyway
|
||||
} catch (Exception e) {
|
||||
status.setText(ExceptionUtilities.getMessage(e));
|
||||
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
|
||||
executor.execute(currentPreviewFuture);
|
||||
} catch (ScriptException e) {
|
||||
|
|
Loading…
Reference in New Issue