Changeset 12870 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2017-09-16T22:08:55+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15229 - see #15182 - remove dependence of ImageProvider on PluginHandler

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r12862 r12870  
    307307        try {
    308308            sources.add(ClassLoader.getSystemClassLoader());
    309             sources.add(org.openstreetmap.josm.gui.MainApplication.class.getClassLoader());
     309            sources.add(PluginHandler.class.getClassLoader());
    310310        } catch (SecurityException ex) {
    311311            Logging.debug(ex);
     
    862862
    863863            extendJoinedPluginResourceCL(toLoad);
     864            ImageProvider.addAdditionalClassLoaders(getResourceClassLoaders());
    864865            monitor.setTicksCount(toLoad.size());
    865866            for (PluginInformation info : toLoad) {
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r12865 r12870  
    3030import java.net.URL;
    3131import java.nio.charset.StandardCharsets;
    32 import java.util.ArrayList;
    3332import java.util.Arrays;
    3433import java.util.Base64;
    3534import java.util.Collection;
    3635import java.util.HashMap;
     36import java.util.HashSet;
    3737import java.util.Hashtable;
    3838import java.util.Iterator;
     
    4040import java.util.List;
    4141import java.util.Map;
     42import java.util.Set;
    4243import java.util.TreeSet;
    4344import java.util.concurrent.CompletableFuture;
     
    7172import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    7273import org.openstreetmap.josm.io.CachedFile;
    73 import org.openstreetmap.josm.plugins.PluginHandler;
    7474import org.openstreetmap.josm.spi.preferences.Config;
    7575import org.w3c.dom.Element;
     
    248248    public static final String PROP_TRANSPARENCY_COLOR = "josm.transparency.color";
    249249
     250    /** set of class loaders to take images from */
     251    protected static final Set<ClassLoader> classLoaders = new HashSet<>(Arrays.asList(
     252            ClassLoader.getSystemClassLoader(), ImageProvider.class.getClassLoader()));
     253
    250254    /** directories in which images are searched */
    251255    protected Collection<String> dirs;
     
    272276    /** <code>true</code> if warnings should be suppressed */
    273277    protected boolean suppressWarnings;
    274     /** list of class loaders to take images from */
    275     protected Collection<ClassLoader> additionalClassLoaders;
    276278    /** ordered list of overlay images */
    277279    protected List<ImageOverlay> overlayInfo;
     
    334336        this.optional = image.optional;
    335337        this.suppressWarnings = image.suppressWarnings;
    336         this.additionalClassLoaders = image.additionalClassLoaders;
    337338        this.overlayInfo = image.overlayInfo;
    338339        this.isDisabled = image.isDisabled;
     
    578579
    579580    /**
     581     * Add an additional class loader to search image for.
     582     * @param additionalClassLoader class loader to add to the internal set
     583     * @return {@code true} if the set changed as a result of the call
     584     * @since 12870
     585     */
     586    public static boolean addAdditionalClassLoader(ClassLoader additionalClassLoader) {
     587        return classLoaders.add(additionalClassLoader);
     588    }
     589
     590    /**
    580591     * Add a collection of additional class loaders to search image for.
    581      * @param additionalClassLoaders class loaders to add to the internal list
    582      * @return the current object, for convenience
    583      */
    584     public ImageProvider setAdditionalClassLoaders(Collection<ClassLoader> additionalClassLoaders) {
    585         this.additionalClassLoaders = additionalClassLoaders;
    586         return this;
     592     * @param additionalClassLoaders class loaders to add to the internal set
     593     * @return {@code true} if the set changed as a result of the call
     594     * @since 12870
     595     */
     596    public static boolean addAdditionalClassLoaders(Collection<ClassLoader> additionalClassLoaders) {
     597        return classLoaders.addAll(additionalClassLoaders);
    587598    }
    588599
     
    658669     */
    659670    public ImageResource getResource() {
    660         ImageResource ir = getIfAvailableImpl(additionalClassLoaders);
     671        ImageResource ir = getIfAvailableImpl();
    661672        if (ir == null) {
    662673            if (!optional) {
     
    803814     * Internal implementation of the image request.
    804815     *
    805      * @param additionalClassLoaders the list of class loaders to use
    806816     * @return the requested image or null if the request failed
    807817     */
    808     private ImageResource getIfAvailableImpl(Collection<ClassLoader> additionalClassLoaders) {
     818    private ImageResource getIfAvailableImpl() {
    809819        synchronized (cache) {
    810820            // This method is called from different thread and modifying HashMap concurrently can result
     
    902912                        // and don't bother to create a URL unless we're actually
    903913                        // creating the image.
    904                         URL path = getImageUrl(fullName, dirs, additionalClassLoaders);
     914                        URL path = getImageUrl(fullName);
    905915                        if (path == null) {
    906916                            continue;
     
    11341144    }
    11351145
    1136     private static URL getImageUrl(String path, String name, Collection<ClassLoader> additionalClassLoaders) {
     1146    private URL getImageUrl(String path, String name) {
    11371147        if (path != null && path.startsWith("resource://")) {
    11381148            String p = path.substring("resource://".length());
    1139             Collection<ClassLoader> classLoaders = new ArrayList<>(PluginHandler.getResourceClassLoaders());
    1140             if (additionalClassLoaders != null) {
    1141                 classLoaders.addAll(additionalClassLoaders);
    1142             }
    11431149            for (ClassLoader source : classLoaders) {
    11441150                URL res;
     
    11541160    }
    11551161
    1156     private static URL getImageUrl(String imageName, Collection<String> dirs, Collection<ClassLoader> additionalClassLoaders) {
     1162    private URL getImageUrl(String imageName) {
    11571163        URL u;
    11581164
     
    11611167            for (String name : dirs) {
    11621168                try {
    1163                     u = getImageUrl(name, imageName, additionalClassLoaders);
     1169                    u = getImageUrl(name, imageName);
    11641170                    if (u != null)
    11651171                        return u;
     
    11761182            String dir = new File(Config.getDirs().getUserDataDirectory(false), "images").getAbsolutePath();
    11771183            try {
    1178                 u = getImageUrl(dir, imageName, additionalClassLoaders);
     1184                u = getImageUrl(dir, imageName);
    11791185                if (u != null)
    11801186                    return u;
     
    11871193
    11881194        // Absolute path?
    1189         u = getImageUrl(null, imageName, additionalClassLoaders);
     1195        u = getImageUrl(null, imageName);
    11901196        if (u != null)
    11911197            return u;
    11921198
    11931199        // Try plugins and josm classloader
    1194         u = getImageUrl("resource://images/", imageName, additionalClassLoaders);
     1200        u = getImageUrl("resource://images/", imageName);
    11951201        if (u != null)
    11961202            return u;
     
    11991205        if (Main.pref != null) {
    12001206            for (String location : Main.pref.getAllPossiblePreferenceDirs()) {
    1201                 u = getImageUrl(location + "images", imageName, additionalClassLoaders);
     1207                u = getImageUrl(location + "images", imageName);
    12021208                if (u != null)
    12031209                    return u;
    1204                 u = getImageUrl(location, imageName, additionalClassLoaders);
     1210                u = getImageUrl(location, imageName);
    12051211                if (u != null)
    12061212                    return u;
Note: See TracChangeset for help on using the changeset viewer.