diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPlugin.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPlugin.java index 3d00eb3..957b93b 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPlugin.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPlugin.java @@ -3,8 +3,6 @@ package org.openstreetmap.josm.plugins.mapwithai; import static org.openstreetmap.josm.tools.I18n.tr; -import javax.swing.JMenuItem; - import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; @@ -12,6 +10,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import javax.swing.JMenuItem; + import org.openstreetmap.josm.actions.JosmAction; import org.openstreetmap.josm.actions.PreferencesAction; import org.openstreetmap.josm.data.validation.OsmValidator; @@ -29,6 +29,7 @@ import org.openstreetmap.josm.plugins.Plugin; import org.openstreetmap.josm.plugins.PluginInformation; import org.openstreetmap.josm.plugins.mapwithai.backend.DownloadListener; import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIAction; +import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils; import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAILayer; import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIMoveAction; import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIObject; @@ -135,7 +136,8 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable { MainApplication.worker.execute(() -> UpdateProd.doProd(info.mainversion)); // Preload the MapWithAILayerInfo for the JOSM download window // This reduces the amount of time taken for first button click by 100ms. - MainApplication.worker.execute(MapWithAILayerInfo::getInstance); + // Don't use the worker thread to avoid blocking user downloads + MapWithAIDataUtils.getForkJoinPool().execute(MapWithAILayerInfo::getInstance); destroyables.add(new MapWithAICopyProhibit()); } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java index 165237d..96a1edb 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java @@ -275,7 +275,7 @@ public class GetDataRunnable extends RecursiveTask { } (boundsToUse.isCollapsed() || boundsToUse.isOutOfTheWorld() ? dataSet.getWays() : dataSet.searchWays(boundsToUse.toBBox())).stream().filter(way -> !way.isDeleted()) - .forEach(GetDataRunnable::cleanupArtifacts); + .forEach(GetDataRunnable::cleanupArtifacts); } /** diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAILayer.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAILayer.java index 324801e..f6c83a7 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAILayer.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAILayer.java @@ -320,21 +320,21 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis private record OsmComparator( Collection previousSelection) implements Comparator, Serializable { - @Override - public int compare(OsmPrimitive o1, OsmPrimitive o2) { - if (previousSelection.contains(o1) == previousSelection.contains(o2)) { - if (o1.isTagged() == o2.isTagged()) { - return o1.compareTo(o2); - } else if (o1.isTagged()) { - return -1; - } - return 1; - } - if (previousSelection.contains(o1)) { + @Override + public int compare(OsmPrimitive o1, OsmPrimitive o2) { + if (previousSelection.contains(o1) == previousSelection.contains(o2)) { + if (o1.isTagged() == o2.isTagged()) { + return o1.compareTo(o2); + } else if (o1.isTagged()) { return -1; } return 1; } + if (previousSelection.contains(o1)) { + return -1; + } + return 1; + } } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWays.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWays.java index e70f184..019067e 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWays.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWays.java @@ -165,8 +165,8 @@ public class MergeDuplicateWays extends Command { .collect(Collectors.toCollection(ArrayList::new)); for (var i = 0; i < ways.size(); i++) { final var way1 = ways.get(i); - final var nearbyWays = dataSet.searchWays(way1.getBBox()).stream() - .filter(MergeDuplicateWays::nonDeletedWay).filter(w -> !Objects.equals(w, way1)).toList(); + final var nearbyWays = dataSet.searchWays(way1.getBBox()).stream().filter(MergeDuplicateWays::nonDeletedWay) + .filter(w -> !Objects.equals(w, way1)).toList(); for (final Way way2 : nearbyWays) { final var command = checkForDuplicateWays(way1, way2); final var deletedWays = new ArrayList(); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAICategory.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAICategory.java index 737d024..d051b8a 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAICategory.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAICategory.java @@ -28,12 +28,12 @@ import jakarta.annotation.Nonnull; */ public enum MapWithAICategory implements ISourceCategory { - BUILDING("data/closedway", "buildings", marktr("Buildings")), - HIGHWAY("presets/transport/way/way_road", "highways", marktr("Roads")), - ADDRESS("presets/misc/housenumber_small", "addresses", marktr("Addresses")), - POWER("presets/power/pole", "pole", marktr("Power")), PRESET("dialogs/search", "presets", marktr("Presets")), - FEATURED("presets/service/network-wireless", "featured", marktr("Featured")), - PREVIEW("presets/misc/fixme", "preview", marktr("Preview")), OTHER(null, "other", marktr("Other")); + BUILDING("data/closedway", "buildings", marktr("Buildings")), HIGHWAY("presets/transport/way/way_road", "highways", + marktr("Roads")), ADDRESS("presets/misc/housenumber_small", "addresses", + marktr("Addresses")), POWER("presets/power/pole", "pole", marktr("Power")), PRESET("dialogs/search", + "presets", marktr("Presets")), FEATURED("presets/service/network-wireless", "featured", + marktr("Featured")), PREVIEW("presets/misc/fixme", "preview", + marktr("Preview")), OTHER(null, "other", marktr("Other")); private static final Map> iconCache = Collections .synchronizedMap(new EnumMap<>(ImageSizes.class)); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java index 491a219..713ea30 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java @@ -283,7 +283,7 @@ public class MapWithAILayerInfo { } // 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; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIType.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIType.java index 74f440d..08f5ec5 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIType.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIType.java @@ -11,8 +11,8 @@ import jakarta.annotation.Nonnull; * @author Taylor Smock */ public enum MapWithAIType implements ISourceType { - FACEBOOK("facebook"), THIRD_PARTY("thirdParty"), ESRI("esri"), ESRI_FEATURE_SERVER("esriFeatureServer"), - MAPBOX_VECTOR_TILE("mvt"), PMTILES("pmtiles"); + FACEBOOK("facebook"), THIRD_PARTY("thirdParty"), ESRI("esri"), ESRI_FEATURE_SERVER( + "esriFeatureServer"), MAPBOX_VECTOR_TILE("mvt"), PMTILES("pmtiles"); private final String typeString; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/RoutingIslandsTest.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/RoutingIslandsTest.java index 5911731..d5f428c 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/RoutingIslandsTest.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/RoutingIslandsTest.java @@ -179,9 +179,11 @@ public class RoutingIslandsTest extends Test { .filter(way -> !incomingWays.contains(way) || !outgoingWays.contains(way)) .filter(way -> Access.getPositiveAccessValues().contains( getDefaultAccessTags(way).getOrDefault(currentTransportMode, Access.AccessTags.NO.getKey()))) - .collect(Collectors.toSet())).stream() - .map(way -> new Pair<>((incomingWays.containsAll(way) ? marktr("outgoing") : marktr("incoming")), way)) - .toList(); + .collect(Collectors.toSet())) + .stream() + .map(way -> new Pair<>( + (incomingWays.containsAll(way) ? marktr("outgoing") : marktr("incoming")), way)) + .toList(); createErrors(problematic, currentTransportMode); } @@ -328,8 +330,7 @@ public class RoutingIslandsTest extends Test { var isAccessible = true; List relations = from.getReferrers().stream().distinct().filter(Relation.class::isInstance) - .map(Relation.class::cast).filter(relation -> "restriction".equals(relation.get("type"))) - .toList(); + .map(Relation.class::cast).filter(relation -> "restriction".equals(relation.get("type"))).toList(); for (Relation relation : relations) { if (((relation.hasKey("except") && relation.get("except").contains(currentTransportMode)) || (currentTransportMode == null || currentTransportMode.trim().isEmpty())) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java index 0b550bf..7eef587 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java @@ -503,7 +503,7 @@ public class MapWithAIProvidersPanel extends JPanel { * @param e The MouseEvent (used to get the appropriate JTable) */ private static void clickListener(MouseEvent e) { - if (e.getSource() instanceof JTable table && table.getSelectedRow() >= 0 && table.getSelectedColumn() >= 0) { + if (e.getSource()instanceof JTable table && table.getSelectedRow() >= 0 && table.getSelectedColumn() >= 0) { final int realCol = table.convertColumnIndexToModel(table.getSelectedColumn()); final int realRow = table.convertRowIndexToModel(table.getSelectedRow()); final var tableName = table.getModel().getColumnName(realCol); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/ESRISourceReader.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/ESRISourceReader.java index 2268923..787e359 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/ESRISourceReader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/ESRISourceReader.java @@ -119,10 +119,10 @@ public class ESRISourceReader { /* Do nothing */ if (parser.hasNext() && parser.next() == JsonParser.Event.START_OBJECT) { parser.getObjectStream().forEach(entry -> { - if ("nextStart".equals(entry.getKey()) && entry.getValue() instanceof JsonNumber number) { + if ("nextStart".equals(entry.getKey()) && entry.getValue()instanceof JsonNumber number) { next.set(number.intValue()); searchUrl.set(startReplace.matcher(search).replaceAll(Integer.toString(next.get()))); - } else if ("results".equals(entry.getKey()) && entry.getValue() instanceof JsonArray features) { + } else if ("results".equals(entry.getKey()) && entry.getValue()instanceof JsonArray features) { for (var feature : features.getValuesAs(JsonObject.class)) { information.add(parse(feature)); } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/tools/MapPaintUtils.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/tools/MapPaintUtils.java index 0c67374..2a80e5c 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/tools/MapPaintUtils.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/tools/MapPaintUtils.java @@ -60,12 +60,13 @@ public final class MapPaintUtils { * Safe colors */ public enum SafeColors { - RED(Color.RED), ORANGE(Color.ORANGE), GOLD(Objects.requireNonNull(ColorHelper.html2color("#ffd700"))), - LIME(Objects.requireNonNull(ColorHelper.html2color("#00ff00"))), CYAN(Color.CYAN), - DODGER_BLUE(Objects.requireNonNull(ColorHelper.html2color("#1e90ff"))), - AI_MAGENTA(Objects.requireNonNull(ColorHelper.html2color("#ff26d4"))), PINK(Color.PINK), - LIGHT_GREY(Objects.requireNonNull(ColorHelper.html2color("#d3d3d3"))), - LINEN(Objects.requireNonNull(ColorHelper.html2color("#faf0e6"))); + RED(Color.RED), ORANGE(Color.ORANGE), GOLD(Objects.requireNonNull(ColorHelper.html2color("#ffd700"))), LIME( + Objects.requireNonNull(ColorHelper.html2color("#00ff00"))), CYAN(Color.CYAN), DODGER_BLUE( + Objects.requireNonNull(ColorHelper.html2color("#1e90ff"))), AI_MAGENTA( + Objects.requireNonNull(ColorHelper.html2color("#ff26d4"))), PINK( + Color.PINK), LIGHT_GREY( + Objects.requireNonNull(ColorHelper.html2color("#d3d3d3"))), LINEN( + Objects.requireNonNull(ColorHelper.html2color("#faf0e6"))); private final Color color;