Skip to content

Commit

Permalink
Fix UI freeze during download of Esri layers
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Apr 15, 2024
1 parent 7f725f7 commit cecb9f4
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import static org.openstreetmap.josm.tools.I18n.tr;

import javax.swing.SwingUtilities;

import java.io.IOException;
import java.io.Serial;
import java.time.Instant;
Expand All @@ -24,6 +22,8 @@
import java.util.concurrent.RecursiveTask;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.swing.SwingUtilities;

import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
import org.openstreetmap.josm.actions.ExpertToggleAction;
import org.openstreetmap.josm.data.Preferences;
Expand Down Expand Up @@ -287,7 +287,7 @@ public List<MapWithAIInfo> compute() {
}
// This is literally to avoid allocations on startup
final Preferences preferences;
if (Config.getPref() instanceof Preferences pref) {
if (Config.getPref()instanceof Preferences pref) {
preferences = pref;
} else {
preferences = null;
Expand Down Expand Up @@ -346,11 +346,12 @@ protected void loadSource(String source) {
* @param layers The layers to update
*/
private void updateEsriLayers(@Nonnull final Collection<MapWithAIInfo> layers) {
final var esriInfo = new ArrayList<MapWithAIInfo>(300);
for (var layer : layers) {
if (MapWithAIType.ESRI == layer.getSourceType()) {
for (var future : parseEsri(layer)) {
try {
allDefaultLayers.add(future.get());
esriInfo.add(future.get());
} catch (InterruptedException e) {
Logging.error(e);
Thread.currentThread().interrupt();
Expand All @@ -359,17 +360,18 @@ private void updateEsriLayers(@Nonnull final Collection<MapWithAIInfo> layers) {
}
}
} else {
allDefaultLayers.add(layer);
esriInfo.add(layer);
}
}
layers.addAll(esriInfo);
}

protected void finish() {
defaultLayers.clear();
synchronized (allDefaultLayers) {
allDefaultLayers.clear();
defaultLayers.addAll(newLayers);
this.updateEsriLayers(newLayers);
allDefaultLayers.addAll(newLayers);
allDefaultLayers.sort(new MapWithAIInfo.MapWithAIInfoCategoryComparator());
allDefaultLayers.sort(Comparator.comparing(TileSourceInfo::getName));
allDefaultLayers.sort(Comparator.comparing(info -> info.getCategory().getDescription()));
Expand Down Expand Up @@ -505,7 +507,7 @@ public void updateEntriesFromDefaults(boolean dropold) {
}

if (changed) {
save();
MainApplication.worker.execute(this::save);
}
}

Expand Down

0 comments on commit cecb9f4

Please sign in to comment.