Changeset 5033 in josm
- Timestamp:
- 2012-03-02T13:58:16+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r5027 r5033 27 27 import java.net.URL; 28 28 import java.net.URLDecoder; 29 import java.util.ArrayList; 29 30 import java.util.Arrays; 30 31 import java.util.Collection; … … 216 217 return get(true); 217 218 } 218 219 219 220 /** 220 221 * Execute the image request. 222 * @param warn If the requested image has been set as optional and is not found, prints an error message on System.err. 221 223 */ 222 224 public ImageIcon get(boolean warn) { 223 ImageResource ir = getIfAvailableImpl(); 225 return get(warn, null); 226 } 227 228 /** 229 * Execute the image request. 230 * @param additionalClassLoaders A collection of additional class loaders to search image for. 231 */ 232 public ImageIcon get(Collection<ClassLoader> additionalClassLoaders) { 233 return get(true, additionalClassLoaders); 234 } 235 236 /** 237 * Execute the image request. 238 * @param warn If the requested image has been set as optional and is not found, prints an error message on System.err. 239 * @param additionalClassLoaders A collection of additional class loaders to search image for. 240 */ 241 public ImageIcon get(boolean warn, Collection<ClassLoader> additionalClassLoaders) { 242 ImageResource ir = getIfAvailableImpl(additionalClassLoaders); 224 243 if (ir == null) { 225 244 if (!optional) { … … 228 247 } else { 229 248 if (warn) { 230 System. out.println(tr("Failed to locate image ''{0}''", name));249 System.err.println(tr("Failed to locate image ''{0}''", name)); 231 250 } 232 251 return null; … … 270 289 "^data:([a-zA-Z]+/[a-zA-Z+]+)?(;base64)?,(.+)$"); 271 290 272 private ImageResource getIfAvailableImpl( ) {291 private ImageResource getIfAvailableImpl(Collection<ClassLoader> additionalClassLoaders) { 273 292 if (name == null) 274 293 return null; … … 371 390 // and don't bother to create a URL unless we're actually 372 391 // creating the image. 373 URL path = getImageUrl(full_name, dirs );392 URL path = getImageUrl(full_name, dirs, additionalClassLoaders); 374 393 if (path == null) { 375 394 continue; … … 510 529 } 511 530 512 private static URL getImageUrl(String path, String name ) {531 private static URL getImageUrl(String path, String name, Collection<ClassLoader> additionalClassLoaders) { 513 532 if (path != null && path.startsWith("resource://")) { 514 533 String p = path.substring("resource://".length()); 515 for (ClassLoader source : PluginHandler.getResourceClassLoaders()) { 534 Collection<ClassLoader> classLoaders = new ArrayList<ClassLoader>(PluginHandler.getResourceClassLoaders()); 535 if (additionalClassLoaders != null) { 536 classLoaders.addAll(additionalClassLoaders); 537 } 538 for (ClassLoader source : classLoaders) { 516 539 URL res; 517 540 if ((res = source.getResource(p + name)) != null) … … 529 552 } 530 553 531 private static URL getImageUrl(String imageName, Collection<String> dirs ) {554 private static URL getImageUrl(String imageName, Collection<String> dirs, Collection<ClassLoader> additionalClassLoaders) { 532 555 URL u = null; 533 556 … … 536 559 for (String name : dirs) { 537 560 try { 538 u = getImageUrl(name, imageName );561 u = getImageUrl(name, imageName, additionalClassLoaders); 539 562 if (u != null) 540 563 return u; … … 550 573 String dir = Main.pref.getPreferencesDir() + "images"; 551 574 try { 552 u = getImageUrl(dir, imageName );575 u = getImageUrl(dir, imageName, additionalClassLoaders); 553 576 if (u != null) 554 577 return u; … … 560 583 561 584 // Absolute path? 562 u = getImageUrl(null, imageName );585 u = getImageUrl(null, imageName, additionalClassLoaders); 563 586 if (u != null) 564 587 return u; 565 588 566 589 // Try plugins and josm classloader 567 u = getImageUrl("resource://images/", imageName );590 u = getImageUrl("resource://images/", imageName, additionalClassLoaders); 568 591 if (u != null) 569 592 return u; … … 571 594 // Try all other resource directories 572 595 for (String location : Main.pref.getAllPossiblePreferenceDirs()) { 573 u = getImageUrl(location + "images", imageName );596 u = getImageUrl(location + "images", imageName, additionalClassLoaders); 574 597 if (u != null) 575 598 return u; 576 u = getImageUrl(location, imageName );599 u = getImageUrl(location, imageName, additionalClassLoaders); 577 600 if (u != null) 578 601 return u;
Note:
See TracChangeset
for help on using the changeset viewer.