Ignore:
Timestamp:
2011-07-20T21:01:06+02:00 (13 years ago)
Author:
bastiK
Message:

fixed #6615 - Error with licensechange plugin - missing error.gif?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r4256 r4261  
    5858
    5959    public static enum ImageType {
    60         PNG, SVG
     60        SVG,    // scalable vector graphics
     61        OTHER   // everything else, e.g. png, gif
     62                // must be supported by Java
    6163    }
    6264
     
    8991        ImageIcon icon = getIfAvailable(subdir, name);
    9092        if (icon == null) {
    91             String ext = name.indexOf('.') != -1 ? "" : ".png";
     93            String ext = name.indexOf('.') != -1 ? "" : ".???";
    9294            throw new NullPointerException(tr(
    9395            "Fatal: failed to locate image ''{0}''. This is a serious configuration problem. JOSM will stop working.",
     
    152154        if (name == null)
    153155            return null;
    154         ImageType type = name.toLowerCase().endsWith("svg") ? ImageType.SVG : ImageType.PNG;
     156        ImageType type = name.toLowerCase().endsWith(".svg") ? ImageType.SVG : ImageType.OTHER;
    155157
    156158        if (name.startsWith("http://")) {
     
    171173        }
    172174        String[] extensions;
    173         if (name.toLowerCase().endsWith(".png") | name.toLowerCase().endsWith(".svg")) {
     175        if (name.indexOf('.') != -1) {
    174176            extensions = new String[] { "" };
    175177        } else {
    176178            extensions = new String[] { ".png", ".svg"};
    177179        }
    178         for (String ext : extensions) {
    179             if (".svg".equals(ext)) {
    180                 type = ImageType.SVG;
    181             } else if (".png".equals(ext)) {
    182                 type = ImageType.PNG;
    183             }
    184            
    185             String full_name = subdir + name + ext;
    186             String cache_name = full_name;
    187             /* cache separately */
    188             if (dirs != null && dirs.size() > 0) {
    189                 cache_name = "id:" + id + ":" + full_name;
    190                 if(archive != null) {
    191                     cache_name += ":" + archive.getName();
     180        final int ARCHIVE = 0, LOCAL = 1;
     181        for (int place : new Integer[] { ARCHIVE, LOCAL }) {
     182            for (String ext : extensions) {
     183
     184                if (".svg".equals(ext)) {
     185                    type = ImageType.SVG;
     186                } else if (".png".equals(ext)) {
     187                    type = ImageType.OTHER;
    192188                }
    193             }
    194 
    195             ImageWrapper iw = cache.get(cache_name);
    196             if (iw != null) return iw;
    197 
    198             if (archive != null) {
    199                 iw = getIfAvailableZip(full_name, archive, type);
    200                 if (iw != null) {
    201                     cache.put(cache_name, iw);
    202                     return iw;
     189
     190                String full_name = subdir + name + ext;
     191                String cache_name = full_name;
     192                /* cache separately */
     193                if (dirs != null && dirs.size() > 0) {
     194                    cache_name = "id:" + id + ":" + full_name;
     195                    if(archive != null) {
     196                        cache_name += ":" + archive.getName();
     197                    }
    203198                }
    204             }
    205 
    206             // getImageUrl() does a ton of "stat()" calls and gets expensive
    207             // and redundant when you have a whole ton of objects. So,
    208             // index the cache by the name of the icon we're looking for
    209             // and don't bother to create a URL unless we're actually
    210             // creating the image.
    211             URL path = getImageUrl(full_name, dirs);
    212             if (path == null)
    213                 continue;
    214             iw = getIfAvailableLocalURL(path, type);
    215             if (iw != null) {
    216                 cache.put(cache_name, iw);
    217                 return iw;
     199
     200                ImageWrapper iw = cache.get(cache_name);
     201                if (iw != null) return iw;
     202
     203                switch (place) {
     204                    case ARCHIVE:
     205                        if (archive != null) {
     206                            iw = getIfAvailableZip(full_name, archive, type);
     207                            if (iw != null) {
     208                                cache.put(cache_name, iw);
     209                                return iw;
     210                            }
     211                        }
     212                        break;
     213                    case LOCAL:
     214                        // getImageUrl() does a ton of "stat()" calls and gets expensive
     215                        // and redundant when you have a whole ton of objects. So,
     216                        // index the cache by the name of the icon we're looking for
     217                        // and don't bother to create a URL unless we're actually
     218                        // creating the image.
     219                        URL path = getImageUrl(full_name, dirs);
     220                        if (path == null)
     221                            continue;
     222                        iw = getIfAvailableLocalURL(path, type);
     223                        if (iw != null) {
     224                            cache.put(cache_name, iw);
     225                            return iw;
     226                        }
     227                        break;
     228                }
    218229            }
    219230        }
     
    227238                    new File(Main.pref.getPreferencesDir(), "images").toString());
    228239            switch (type) {
    229                 case PNG:
    230                     img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL());
    231                     break;
    232240                case SVG:
    233241                    URI uri = getSvgUniverse().loadSVG(is, is.getFile().toURI().toURL().toString());
    234242                    img = createImageFromSvgUri(uri);
     243                    break;
     244                case OTHER:
     245                    img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL());
    235246                    break;
    236247            }
     
    256267                    is = zipFile.getInputStream(entry);
    257268                    switch (type) {
    258                         case PNG:
     269                        case SVG:
     270                            URI uri = getSvgUniverse().loadSVG(is, full_name);
     271                            img = createImageFromSvgUri(uri);
     272                            break;
     273                        case OTHER:
    259274                            while(size > 0)
    260275                            {
     
    265280                            img = Toolkit.getDefaultToolkit().createImage(buf);
    266281                            break;
    267                         case SVG:
    268                             URI uri = getSvgUniverse().loadSVG(is, full_name);
    269                             img = createImageFromSvgUri(uri);
    270                             break;
    271282                    }
    272283                } finally {
     
    292303        Image img = null;
    293304        switch (type) {
    294             case PNG:
    295                 img = Toolkit.getDefaultToolkit().createImage(path);
    296                 break;
    297305            case SVG:
    298306                URI uri = getSvgUniverse().loadSVG(path);
    299307                img = createImageFromSvgUri(uri);
     308                break;
     309            case OTHER:
     310                img = Toolkit.getDefaultToolkit().createImage(path);
    300311                break;
    301312        }
Note: See TracChangeset for help on using the changeset viewer.