- Timestamp:
- 2020-03-21T20:25:18+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java
r16153 r16186 12 12 import java.util.concurrent.CompletableFuture; 13 13 import java.util.concurrent.ExecutionException; 14 import java.util.function.Consumer; 14 15 15 16 import javax.swing.ImageIcon; … … 118 119 /** 119 120 * Get the image resource associated with this MapImage object. 120 * This method blocks until the image has been loaded.121 * This method blocks until the image resource has been loaded. 121 122 * @return the image resource 122 123 */ … … 124 125 if (imageResource == null) { 125 126 try { 126 // load and wait for the image 127 loadImage ().get();127 // load and wait for the image resource 128 loadImageResource().get(); 128 129 } catch (ExecutionException | InterruptedException e) { 129 130 Logging.warn(e); … … 165 166 } 166 167 167 private CompletableFuture<Void> load Image() {168 private CompletableFuture<Void> load(Consumer<? super ImageResource> action) { 168 169 return new ImageProvider(name) 169 170 .setDirs(MapPaintStyles.getIconSourceDirs(source)) … … 172 173 .setInArchiveDir(source.getZipEntryDirName()) 173 174 .setOptional(true) 174 .getResourceAsync( result -> {175 synchronized (this) {176 imageResource = result; 177 if (result == null) {178 source.logWarning(tr("Failed to locate image ''{0}''", name));179 ImageIcon noIcon = MapPaintStyles.getNoIconIcon(source);180 img = noIcon == null ? null : noIcon.getImage();181 } else {182 img = rescale(result.getImageIcon(new Dimension(width, height)).getImage());183 }184 if (temporary) {185 disabledImgCache = null;186 MapView mapView = MainApplication.getMap().mapView;187 mapView.preferenceChanged(null); // otherwise repaint is ignored, because layer hasn't changed188 mapView.repaint();189 }190 temporary = false;191 }175 .getResourceAsync(action); 176 } 177 178 /** 179 * Loads image resource and actual rescaled image. 180 * @return the future of the requested image 181 * @see #loadImageResource 182 */ 183 private CompletableFuture<Void> loadImage() { 184 return load(result -> { 185 synchronized (this) { 186 imageResource = result; 187 if (result == null) { 188 source.logWarning(tr("Failed to locate image ''{0}''", name)); 189 ImageIcon noIcon = MapPaintStyles.getNoIconIcon(source); 190 img = noIcon == null ? null : noIcon.getImage(); 191 } else { 192 img = rescale(result.getImageIcon(new Dimension(width, height)).getImage()); 192 193 } 193 ); 194 if (temporary) { 195 disabledImgCache = null; 196 MapView mapView = MainApplication.getMap().mapView; 197 mapView.preferenceChanged(null); // otherwise repaint is ignored, because layer hasn't changed 198 mapView.repaint(); 199 } 200 temporary = false; 201 } 202 }); 203 } 204 205 /** 206 * Loads image resource only. 207 * @return the future of the requested image resource 208 * @see #loadImage 209 */ 210 private CompletableFuture<Void> loadImageResource() { 211 return load(result -> { 212 synchronized (this) { 213 imageResource = result; 214 if (result == null) { 215 source.logWarning(tr("Failed to locate image ''{0}''", name)); 216 } 217 } 218 }); 194 219 } 195 220
Note:
See TracChangeset
for help on using the changeset viewer.