- Timestamp:
- 2026-03-25T09:07:06+01:00 (4 days ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
-
gui/tagging/presets/TaggingPreset.java (modified) (3 diffs)
-
tools/ImageProvider.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
r19548 r19553 22 22 import java.util.Set; 23 23 import java.util.concurrent.CompletableFuture; 24 import java.util.concurrent.Executor; 24 25 import java.util.function.Predicate; 25 26 import java.util.stream.Collectors; … … 278 279 final Collection<String> s = TaggingPresets.ICON_SOURCES.get(); 279 280 this.iconFuture = new CompletableFuture<>(); 280 new ImageProvider(iconName) 281 final ImageProvider provider = new ImageProvider(iconName) 281 282 .setDirs(s) 282 283 .setId("presets") 283 284 .setArchive(arch) 284 .setOptional(true) 285 .getResourceAsync(result -> { 285 .setOptional(true); 286 final Executor fetcher = ImageProvider.getImageFetchExecutor(); 287 // Explicitly dispatch to the image fetch executor so that even local JAR-bundled icons 288 // are loaded asynchronously, keeping expensive SVG pre-rendering off the startup thread. 289 CompletableFuture.supplyAsync(provider::getResource, fetcher) 290 .thenAcceptAsync(result -> { 286 291 if (result != null) { 287 292 // Pre-render off EDT to avoid flooding the event queue with expensive SVG rendering … … 304 309 iconFuture.complete(null); 305 310 } 306 }); 311 }, fetcher); 307 312 } 308 313 -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r19548 r19553 45 45 import java.util.concurrent.CompletableFuture; 46 46 import java.util.concurrent.ConcurrentHashMap; 47 import java.util.concurrent.Executor; 47 48 import java.util.concurrent.ExecutorService; 48 49 import java.util.concurrent.Executors; … … 718 719 * Load the image in a background thread. 719 720 * <p> 720 * This method returns immediately and runs the image request asynchronously. 721 * This method returns immediately and runs the image request asynchronously for remote resources. 722 * For local resources, the request is executed synchronously in the current thread. 721 723 * @param action the action that will deal with the image 722 724 * … … 725 727 */ 726 728 public CompletableFuture<Void> getResourceAsync(Consumer<? super ImageResource> action) { 727 return CompletableFuture.supplyAsync(this::getResource, IMAGE_FETCHER).thenAcceptAsync(action, IMAGE_FETCHER); 729 return isRemote() 730 ? CompletableFuture.supplyAsync(this::getResource, IMAGE_FETCHER).thenAcceptAsync(action, IMAGE_FETCHER) 731 : CompletableFuture.completedFuture(getResource()).thenAccept(action); 732 } 733 734 /** 735 * Returns the executor used for background image fetching. 736 * Callers that need to force asynchronous loading even for local resources 737 * (e.g. to off-load expensive SVG pre-rendering) may use this executor directly. 738 * @return the image fetch executor 739 * @since 19553 740 */ 741 public static Executor getImageFetchExecutor() { 742 return IMAGE_FETCHER; 728 743 } 729 744
Note:
See TracChangeset
for help on using the changeset viewer.
