Only use invokeAndWait if there is a gui

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2019-10-21 16:54:01 -06:00
rodzic 2d62cbb199
commit 9d6f8156c9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
1 zmienionych plików z 19 dodań i 11 usunięć

Wyświetl plik

@ -19,6 +19,8 @@ import java.util.concurrent.RecursiveTask;
import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;
import javax.swing.SwingUtilities;
import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.UndoRedoHandler;
import org.openstreetmap.josm.data.coor.LatLon;
@ -214,23 +216,29 @@ public final class MapWithAIDataUtils {
final DataSet dataSet = new DataSet();
final List<BBox> realBBoxes = bbox.stream().filter(BBox::isValid).collect(Collectors.toList());
final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor();
try {
EventQueue.invokeAndWait(() -> {
monitor.setCancelable(Boolean.FALSE);
monitor.beginTask(tr("Downloading {0} data", MapWithAIPlugin.NAME));
monitor.indeterminateSubTask(null);
});
} catch (InvocationTargetException e) {
Logging.debug(e);
} catch (InterruptedException e) {
Logging.debug(e);
Thread.currentThread().interrupt();
if (SwingUtilities.isEventDispatchThread()) {
try {
EventQueue.invokeAndWait(() -> startMonitor(monitor));
} catch (InvocationTargetException e) {
Logging.debug(e);
} catch (InterruptedException e) {
Logging.debug(e);
Thread.currentThread().interrupt();
}
} else {
startMonitor(monitor);
}
getForkJoinPool().invoke(new GetDataRunnable(realBBoxes, dataSet, monitor));
return dataSet;
}
private static void startMonitor(PleaseWaitProgressMonitor monitor) {
monitor.setCancelable(Boolean.FALSE);
monitor.beginTask(tr("Downloading {0} data", MapWithAIPlugin.NAME));
monitor.indeterminateSubTask(null);
}
/**
* @return The {@link ForkJoinPool} for MapWithAI use.
*/