Changeset 19553 in josm for trunk/src


Ignore:
Timestamp:
2026-03-25T09:07:06+01:00 (4 days ago)
Author:
stoecker
Message:

fix #24677 - applied modified patch by dnet

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r19548 r19553  
    2222import java.util.Set;
    2323import java.util.concurrent.CompletableFuture;
     24import java.util.concurrent.Executor;
    2425import java.util.function.Predicate;
    2526import java.util.stream.Collectors;
     
    278279        final Collection<String> s = TaggingPresets.ICON_SOURCES.get();
    279280        this.iconFuture = new CompletableFuture<>();
    280         new ImageProvider(iconName)
     281        final ImageProvider provider = new ImageProvider(iconName)
    281282            .setDirs(s)
    282283            .setId("presets")
    283284            .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 -> {
    286291                if (result != null) {
    287292                    // Pre-render off EDT to avoid flooding the event queue with expensive SVG rendering
     
    304309                    iconFuture.complete(null);
    305310                }
    306             });
     311            }, fetcher);
    307312    }
    308313
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r19548 r19553  
    4545import java.util.concurrent.CompletableFuture;
    4646import java.util.concurrent.ConcurrentHashMap;
     47import java.util.concurrent.Executor;
    4748import java.util.concurrent.ExecutorService;
    4849import java.util.concurrent.Executors;
     
    718719     * Load the image in a background thread.
    719720     * <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.
    721723     * @param action the action that will deal with the image
    722724     *
     
    725727     */
    726728    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;
    728743    }
    729744
Note: See TracChangeset for help on using the changeset viewer.