Move external processing to worker threads

This commit is contained in:
2020-02-03 10:22:20 +00:00
parent f95ae10d03
commit 4d435b4fc1
3 changed files with 21 additions and 6 deletions

View File

@@ -1429,7 +1429,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
Debug.trace();
JMenuObject o = (JMenuObject)e.getSource();
Sentence s = (Sentence)o.getObject();
s.runExternalProcessor(Utils.s2i(o.getActionCommand()));
queueJob(new SentenceExternalJob(s, Utils.s2i(o.getActionCommand())));
}
});
ob.setActionCommand(Integer.toString(i));
@@ -1725,7 +1725,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
for (Enumeration s = c.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement();
if (!snt.isLocked()) {
snt.runExternalProcessor(Utils.s2i(o.getActionCommand()));
queueJob(new SentenceExternalJob(snt, Utils.s2i(o.getActionCommand())));
}
}
}

View File

@@ -956,8 +956,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
public void openInExternalEditor() {
Debug.trace();
ExternalEditor ed = new ExternalEditor(this);
Thread t = new Thread(ed);
t.start();
ed.run();
}
public void backup() throws IOException {
@@ -1051,8 +1050,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
Debug.trace();
if (isLocked()) return;
ExternalProcessor ed = new ExternalProcessor(this, num);
Thread t = new Thread(ed);
t.start();
ed.run();
}
public void undo() {

View File

@@ -0,0 +1,17 @@
package uk.co.majenko.audiobookrecorder;
import java.lang.Runnable;
public class SentenceExternalJob extends SentenceJob {
protected int command;
public SentenceExternalJob(Sentence s, int c) {
super(s);
command = c;
}
@Override
public void run() {
sentence.runExternalProcessor(command);
}
}