Changeset 4261 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-07-20T21:01:06+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r4256 r4261 58 58 59 59 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 61 63 } 62 64 … … 89 91 ImageIcon icon = getIfAvailable(subdir, name); 90 92 if (icon == null) { 91 String ext = name.indexOf('.') != -1 ? "" : ". png";93 String ext = name.indexOf('.') != -1 ? "" : ".???"; 92 94 throw new NullPointerException(tr( 93 95 "Fatal: failed to locate image ''{0}''. This is a serious configuration problem. JOSM will stop working.", … … 152 154 if (name == null) 153 155 return null; 154 ImageType type = name.toLowerCase().endsWith(" svg") ? ImageType.SVG : ImageType.PNG;156 ImageType type = name.toLowerCase().endsWith(".svg") ? ImageType.SVG : ImageType.OTHER; 155 157 156 158 if (name.startsWith("http://")) { … … 171 173 } 172 174 String[] extensions; 173 if (name. toLowerCase().endsWith(".png") | name.toLowerCase().endsWith(".svg")) {175 if (name.indexOf('.') != -1) { 174 176 extensions = new String[] { "" }; 175 177 } else { 176 178 extensions = new String[] { ".png", ".svg"}; 177 179 } 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; 192 188 } 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 } 203 198 } 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 } 218 229 } 219 230 } … … 227 238 new File(Main.pref.getPreferencesDir(), "images").toString()); 228 239 switch (type) { 229 case PNG:230 img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL());231 break;232 240 case SVG: 233 241 URI uri = getSvgUniverse().loadSVG(is, is.getFile().toURI().toURL().toString()); 234 242 img = createImageFromSvgUri(uri); 243 break; 244 case OTHER: 245 img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL()); 235 246 break; 236 247 } … … 256 267 is = zipFile.getInputStream(entry); 257 268 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: 259 274 while(size > 0) 260 275 { … … 265 280 img = Toolkit.getDefaultToolkit().createImage(buf); 266 281 break; 267 case SVG:268 URI uri = getSvgUniverse().loadSVG(is, full_name);269 img = createImageFromSvgUri(uri);270 break;271 282 } 272 283 } finally { … … 292 303 Image img = null; 293 304 switch (type) { 294 case PNG:295 img = Toolkit.getDefaultToolkit().createImage(path);296 break;297 305 case SVG: 298 306 URI uri = getSvgUniverse().loadSVG(path); 299 307 img = createImageFromSvgUri(uri); 308 break; 309 case OTHER: 310 img = Toolkit.getDefaultToolkit().createImage(path); 300 311 break; 301 312 }
Note:
See TracChangeset
for help on using the changeset viewer.