- Timestamp:
- 2016-08-03T14:37:38+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
r10634 r10714 32 32 import org.openstreetmap.josm.tools.GBC; 33 33 import org.openstreetmap.josm.tools.ImageProvider; 34 import org.openstreetmap.josm.tools.ImageResource;35 34 36 35 /** … … 56 55 String icon = info.getIcon(); 57 56 if (icon != null) { 58 new ImageProvider(icon).setOptional(true).get InBackground((ImageResource result)-> {57 new ImageProvider(icon).setOptional(true).getResourceAsync().thenAccept(result -> { 59 58 if (result != null) { 60 59 GuiHelper.runInEDT(() -> result.attachImageIcon(this)); -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java
r10634 r10714 19 19 import org.openstreetmap.josm.gui.util.GuiHelper; 20 20 import org.openstreetmap.josm.tools.ImageProvider; 21 import org.openstreetmap.josm.tools.ImageProvider.ImageCallback;22 21 import org.openstreetmap.josm.tools.Utils; 23 22 … … 99 98 .setHeight(height) 100 99 .setOptional(true) 101 .get InBackground((ImageCallback)result -> {100 .getAsync().thenAccept(result -> { 102 101 synchronized (this) { 103 102 if (result == null) { -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
r10657 r10714 60 60 import org.openstreetmap.josm.tools.GBC; 61 61 import org.openstreetmap.josm.tools.ImageProvider; 62 import org.openstreetmap.josm.tools.ImageProvider.ImageResourceCallback;63 62 import org.openstreetmap.josm.tools.Utils; 64 63 import org.openstreetmap.josm.tools.template_engine.ParseError; … … 204 203 imgProv.setArchive(arch); 205 204 imgProv.setOptional(true); 206 imgProv.get InBackground((ImageResourceCallback)result -> {205 imgProv.getResourceAsync().thenAccept(result -> { 207 206 if (result != null) { 208 207 GuiHelper.runInEDT(() -> result.attachImageIcon(this)); -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r10680 r10714 40 40 import java.util.Map; 41 41 import java.util.TreeSet; 42 import java.util.concurrent.CompletableFuture; 42 43 import java.util.concurrent.ExecutorService; 43 44 import java.util.concurrent.Executors; … … 308 309 309 310 /** 310 * Callback interface for asynchronous image loading.311 * @since 10600 (functional interface)312 */313 @FunctionalInterface314 public interface ImageCallback {315 /**316 * Called when image loading has finished.317 * @param result the loaded image icon318 */319 void finished(ImageIcon result);320 }321 322 /**323 * Callback interface for asynchronous image loading (with delayed scaling possibility).324 * @since 7693325 * @since 10600 (functional interface)326 */327 @FunctionalInterface328 public interface ImageResourceCallback {329 /**330 * Called when image loading has finished.331 * @param result the loaded image resource332 */333 void finished(ImageResource result);334 }335 336 /**337 311 * Constructs a new {@code ImageProvider} from a filename in a given directory. 338 312 * @param subdir subdirectory the image lies in … … 653 627 654 628 /** 629 * Load the image in a background thread. 630 * 631 * This method returns immediately and runs the image request asynchronously. 632 * 633 * @return the future of the requested image 634 * @since 10714 635 */ 636 public CompletableFuture<ImageIcon> getAsync() { 637 return CompletableFuture.supplyAsync(this::get, IMAGE_FETCHER); 638 } 639 640 /** 655 641 * Execute the image request. 656 642 * … … 687 673 * This method returns immediately and runs the image request asynchronously. 688 674 * 689 * @param callback a callback. It is called, when the image is ready. 690 * This can happen before the call to this method returns or it may be 691 * invoked some time (seconds) later. If no image is available, a null 692 * value is returned to callback (just like {@link #get}). 693 */ 694 public void getInBackground(final ImageCallback callback) { 695 if (name.startsWith(HTTP_PROTOCOL) || name.startsWith(WIKI_PROTOCOL)) { 696 IMAGE_FETCHER.submit(() -> callback.finished(get())); 697 } else { 698 callback.finished(get()); 699 } 700 } 701 702 /** 703 * Load the image in a background thread. 704 * 705 * This method returns immediately and runs the image request asynchronously. 706 * 707 * @param callback a callback. It is called, when the image is ready. 708 * This can happen before the call to this method returns or it may be 709 * invoked some time (seconds) later. If no image is available, a null 710 * value is returned to callback (just like {@link #get}). 711 * @since 7693 712 */ 713 public void getInBackground(final ImageResourceCallback callback) { 714 if (name.startsWith(HTTP_PROTOCOL) || name.startsWith(WIKI_PROTOCOL)) { 715 IMAGE_FETCHER.submit(() -> callback.finished(getResource())); 716 } else { 717 callback.finished(getResource()); 718 } 675 * @return the future of the requested image 676 * @since 10714 677 */ 678 public CompletableFuture<ImageResource> getResourceAsync() { 679 return CompletableFuture.supplyAsync(this::getResource, IMAGE_FETCHER); 719 680 } 720 681
Note:
See TracChangeset
for help on using the changeset viewer.