Skip to content

Commit

Permalink
Replaces SwingWorker with Task (fixes #59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Håkansson committed Feb 26, 2018
1 parent 7345912 commit 773bf33
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/com/googlecode/e2u/preview/stax/BookReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;

import javax.swing.SwingWorker;

import org.daisy.braille.utils.pef.PEFBook;
import org.daisy.streamline.api.validity.ValidationReport;
import org.daisy.streamline.api.validity.ValidatorFactoryMaker;
import org.daisy.streamline.api.validity.ValidatorFactoryMakerService;

import javafx.concurrent.Task;

public class BookReader {
private static final Logger logger = Logger.getLogger(BookReader.class.getCanonicalName());
private final File source;
private SwingWorker<BookReaderResult, Void> bookReader;
private Task<BookReaderResult> bookReader;
private BookReaderResult book = null;
private org.daisy.streamline.api.validity.Validator pv = null;
private long lastUpdated;
Expand All @@ -31,31 +31,28 @@ public BookReader(final File f) {

private void readBook(File f) {
lastUpdated = System.currentTimeMillis();
bookReader = new SwingWorker<BookReaderResult, Void>() {
Date d;
bookReader = new Task<BookReaderResult>() {
@Override
protected BookReaderResult doInBackground() throws Exception {
d = new Date();
ValidationReport report = null;
if (pv != null) {
report = pv.validate(f.toURI().toURL());
protected BookReaderResult call() throws Exception {
Date d = new Date();
try {
ValidationReport report = null;
if (pv != null) {
report = pv.validate(f.toURI().toURL());
}
URI uri = f.toURI();
PEFBook p = PEFBook.load(uri);
return new BookReaderResult(p, f, uri, report);
} finally {
logger.info("Book Reader (file): " + (new Date().getTime() - d.getTime()));
}
URI uri = f.toURI();
PEFBook p = PEFBook.load(uri);
return new BookReaderResult(p, f, uri, report);
}

@Override
protected void done() {
logger.info("Book Reader (file): " + (new Date().getTime() - d.getTime()));
}

};
new NewThreadExecutor().execute(bookReader);
}

public boolean cancel() {
return bookReader.cancel(true);
return bookReader.cancel();
}

private synchronized void reload() {
Expand Down

0 comments on commit 773bf33

Please sign in to comment.