Changeset 8714 in josm


Ignore:
Timestamp:
2015-09-01T22:57:30+02:00 (9 years ago)
Author:
wiktorn
Message:

Do not block in EDT thread, when waiting for attribution download. Closes: #11821

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/CachedAttributionBingAerialTileSource.java

    r8624 r8714  
    1010
    1111import org.openstreetmap.gui.jmapviewer.tilesources.BingAerialTileSource;
     12import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
    1213import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.gui.util.GuiHelper;
    1315import org.openstreetmap.josm.io.CacheCustomContent;
    1416import org.openstreetmap.josm.io.UTFInputStreamReader;
     
    2325 */
    2426public class CachedAttributionBingAerialTileSource extends BingAerialTileSource {
     27    private Runnable attributionDownloadedTask;
     28
    2529    /**
    2630     * Creates tile source
     
    3034        super(info);
    3135    }
     36
     37    /**
     38     * Creates tile source
     39     * @param info ImageryInfo description of this tile source
     40     * @param attributionDownloadedTask runnable to be executed once attribution is loaded
     41     */
     42
     43    public CachedAttributionBingAerialTileSource(TileSourceInfo info, Runnable attributionDownloadedTask) {
     44        super(info);
     45        this.attributionDownloadedTask = attributionDownloadedTask;
     46    }
     47
    3248
    3349    class BingAttributionData extends CacheCustomContent<IOException> {
     
    5975                    try {
    6076                        String xml = attributionLoader.updateIfRequiredString();
    61                         return parseAttributionText(new InputSource(new StringReader((xml))));
     77                        List<Attribution> ret = parseAttributionText(new InputSource(new StringReader((xml))));
     78                        if (attributionDownloadedTask != null) {
     79                            GuiHelper.runInEDT(attributionDownloadedTask);
     80                            attributionDownloadedTask = null;
     81                        }
     82                        return ret;
    6283                    } catch (IOException ex) {
    6384                        Main.warn("Could not connect to Bing API. Will retry in " + waitTimeSec + " seconds.");
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r8673 r8714  
    879879    }
    880880
    881     private void loadAllTiles(boolean force) {
     881    protected void loadAllTiles(boolean force) {
    882882        TileSet ts = getVisibleTileSet();
    883883
     
    890890    }
    891891
    892     private void loadAllErrorTiles(boolean force) {
     892    protected void loadAllErrorTiles(boolean force) {
    893893        TileSet ts = getVisibleTileSet();
    894894        ts.loadAllErrorTiles(force);
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r8602 r8714  
    1010import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource;
    1111import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource;
     12import org.openstreetmap.josm.Main;
    1213import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
    1314import org.openstreetmap.josm.data.imagery.CachedAttributionBingAerialTileSource;
     
    6768    @Override
    6869    protected AbstractTMSTileSource getTileSource(ImageryInfo info) throws IllegalArgumentException {
    69         return getTileSourceStatic(info);
     70        return getTileSourceStatic(info, new Runnable() {
     71            @Override
     72            public void run() {
     73                Main.debug("Attribution loaded, running loadAllErrorTiles");
     74                TMSLayer.this.loadAllErrorTiles(true);
     75            }
     76        });
    7077    }
    7178
     
    97104     */
    98105    public static AbstractTMSTileSource getTileSourceStatic(ImageryInfo info) throws IllegalArgumentException {
     106        return getTileSourceStatic(info, null);
     107    }
     108
     109    /**
     110     * Creates and returns a new TileSource instance depending on the {@link ImageryType}
     111     * of the passed ImageryInfo object.
     112     *
     113     * If no appropriate TileSource is found, null is returned.
     114     * Currently supported ImageryType are {@link ImageryType#TMS},
     115     * {@link ImageryType#BING}, {@link ImageryType#SCANEX}.
     116     *
     117     * @param info imagery info
     118     * @param attributionLoadedTask task to be run once attribution is loaded, might be null, if nothing special shall happen
     119     * @return a new TileSource instance or null if no TileSource for the ImageryInfo/ImageryType could be found.
     120     * @throws IllegalArgumentException if url from imagery info is null or invalid
     121     */
     122    public static AbstractTMSTileSource getTileSourceStatic(ImageryInfo info, Runnable attributionLoadedTask) throws IllegalArgumentException {
    99123        if (info.getImageryType() == ImageryType.TMS) {
    100124            TemplatedTMSTileSource.checkUrl(info.getUrl());
     
    103127            return t;
    104128        } else if (info.getImageryType() == ImageryType.BING)
    105             return new CachedAttributionBingAerialTileSource(info);
     129            return new CachedAttributionBingAerialTileSource(info, attributionLoadedTask);
    106130        else if (info.getImageryType() == ImageryType.SCANEX) {
    107131            return new ScanexTileSource(info);
Note: See TracChangeset for help on using the changeset viewer.