Changeset 5054 in josm for trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
- Timestamp:
- 2012-03-08T12:11:38+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r5033 r5054 32 32 import java.util.HashMap; 33 33 import java.util.Map; 34 import java.util.concurrent.Executors; 35 import java.util.concurrent.ExecutorService; 34 36 import java.util.regex.Matcher; 35 37 import java.util.regex.Pattern; … … 104 106 private static Map<String, ImageResource> cache = new HashMap<String, ImageResource>(); 105 107 108 private final static ExecutorService imageFetcher = Executors.newSingleThreadExecutor(); 109 110 public interface ImageCallback { 111 void finished(ImageIcon result); 112 } 113 106 114 /** 107 115 * @param subdir Subdirectory the image lies in. … … 256 264 else 257 265 return ir.getImageIcon(new Dimension(width, height)); 266 } 267 268 /** 269 * Load the image in a background thread. 270 * 271 * This method returns immediately and runs the image request 272 * asynchronously. 273 * 274 * @param callback is called, when the image is ready. This can happen 275 * before the call to getInBackground returns or it may be invoked some 276 * time (seconds) later. 277 * If no image is available, a null value is returned to callback (just 278 * like ImageProvider.get). 279 */ 280 public void getInBackground(final ImageCallback callback) { 281 if (name.startsWith("http://") || name.startsWith("wiki://")) { 282 Runnable fetch = new Runnable() { 283 @Override 284 public void run() { 285 ImageIcon result = get(); 286 callback.finished(result); 287 } 288 }; 289 imageFetcher.submit(fetch); 290 } else { 291 ImageIcon result = get(); 292 callback.finished(result); 293 } 258 294 } 259 295
Note:
See TracChangeset
for help on using the changeset viewer.
