preferences.put(READ_PATH_PREFERENCE, path);
startWaitCursor(r.getFrame().getRootPane());
new Thread(new Runnable() {
public void run() {
NavigationFormatParser parser = new NavigationFormatParser();
NavigationFormatParserListener listener = new NavigationFormatParserListener() {
public void reading(final NavigationFormat<BaseRoute> format) {
invokeLater(new Runnable() {
public void run() {
formatAndRoutesModel.setFormat(format);
}
});
}
};
parser.addNavigationFileParserListener(listener);
try {
invokeAndWait(new Runnable() {
public void run() {
Gpx11Format gpxFormat = new Gpx11Format();
formatAndRoutesModel.setRoutes(new FormatAndRoutes(gpxFormat, new GpxRoute(gpxFormat)));
urlModel.clear();
}
});
final ParserResult result = parser.read(url, formats);
if (result.isSuccessful()) {
log.info("Opened: " + path);
final NavigationFormat format = result.getFormat();
countRead(format);
if (!checkReadFormat(format))
return;
invokeLater(new Runnable() {
public void run() {
formatAndRoutesModel.setRoutes(new FormatAndRoutes(format, result.getAllRoutes()));
comboBoxChoosePositionList.setModel(formatAndRoutesModel);
urlModel.setString(path);
recentUrlsModel.addUrl(url);
if (urls.size() > 1) {
List<URL> append = new ArrayList<>(urls);
append.remove(0);
// this way the route is always marked as modified :-(
appendPositionList(-1, append);
}
}
});
} else {
invokeLater(new Runnable() {
public void run() {
Gpx11Format gpxFormat = new Gpx11Format();
formatAndRoutesModel.setRoutes(new FormatAndRoutes(gpxFormat, new GpxRoute(gpxFormat)));
}
});
r.handleUnsupportedFormat(path);
}
} catch (BabelException e) {
r.handleBabelError(e);
} catch (OutOfMemoryError e) {
r.handleOutOfMemoryError();
} catch (FileNotFoundException e) {
r.handleFileNotFound(path);
} catch (Throwable t) {
r.handleOpenError(t, path);
} finally {
parser.removeNavigationFileParserListener(listener);
invokeLater(new Runnable() {
public void run() {
stopWaitCursor(r.getFrame().getRootPane());
}
});