Changeset 7693 in josm for trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
- Timestamp:
- 2014-11-02T01:19:59+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r7689 r7693 163 163 private static final ExecutorService IMAGE_FETCHER = Executors.newSingleThreadExecutor(); 164 164 165 /** 166 * Callback interface for asynchronous image loading. 167 */ 165 168 public interface ImageCallback { 166 169 void finished(ImageIcon result); 170 } 171 172 /** 173 * Callback interface for asynchronous image loading (with delayed scaling possibility). 174 * @since 7693 175 */ 176 public interface ImageResourceCallback { 177 void finished(ImageResource result); 167 178 } 168 179 … … 237 248 * @since 7687 238 249 */ 239 public Dimension getImageSizes(ImageSizes size) {250 static public Dimension getImageSizes(ImageSizes size) { 240 251 int sizeval; 241 252 switch(size) { … … 382 393 383 394 /** 395 * Execute the image request and scale result. 396 * @return the requested image or null if the request failed 397 */ 398 public ImageIcon get() { 399 ImageResource ir = getResource(); 400 if (maxWidth != -1 || maxHeight != -1) 401 return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight)); 402 else 403 return ir.getImageIcon(new Dimension(width, height)); 404 } 405 406 /** 384 407 * Execute the image request. 385 408 * @return the requested image or null if the request failed 386 */ 387 public ImageIcon get() { 409 * @since 7693 410 */ 411 public ImageResource getResource() { 388 412 ImageResource ir = getIfAvailableImpl(additionalClassLoaders); 389 413 if (ir == null) { … … 398 422 } 399 423 } 400 if (maxWidth != -1 || maxHeight != -1) 401 return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight)); 402 else 403 return ir.getImageIcon(new Dimension(width, height)); 424 return ir; 404 425 } 405 426 … … 428 449 ImageIcon result = get(); 429 450 callback.finished(result); 451 } 452 } 453 454 /** 455 * Load the image in a background thread. 456 * 457 * This method returns immediately and runs the image request 458 * asynchronously. 459 * 460 * @param callback a callback. It is called, when the image is ready. 461 * This can happen before the call to this method returns or it may be 462 * invoked some time (seconds) later. If no image is available, a null 463 * value is returned to callback (just like {@link #get}). 464 * @since 7693 465 */ 466 public void getInBackground(final ImageResourceCallback callback) { 467 if (name.startsWith("http://") || name.startsWith("wiki://")) { 468 Runnable fetch = new Runnable() { 469 @Override 470 public void run() { 471 callback.finished(getResource()); 472 } 473 }; 474 IMAGE_FETCHER.submit(fetch); 475 } else { 476 callback.finished(getResource()); 430 477 } 431 478 }
Note:
See TracChangeset
for help on using the changeset viewer.