Changeset 9719 in josm


Ignore:
Timestamp:
2016-02-03T00:27:12+01:00 (8 years ago)
Author:
Don-vip
Message:

DownloadWmsAlongTrackAction: add new unit test, error logs, fix infinite loop when tile loading errors occur (for example, with a bad TMS URL)

Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r9576 r9719  
    16901690                        TMSCachedTileLoader.getNewThreadPoolExecutor("Precache downloader"));
    16911691            }
    1692 
    16931692        }
    16941693
     
    17181717        @Override
    17191718        public void tileLoadingFinished(Tile tile, boolean success) {
     1719            int processed = this.processedCount.incrementAndGet();
    17201720            if (success) {
    1721                 int processed = this.processedCount.incrementAndGet();
    17221721                this.progressMonitor.worked(1);
    17231722                this.progressMonitor.setCustomText(tr("Downloaded {0}/{1} tiles", processed, totalCount));
     1723            } else {
     1724                Main.warn("Tile loading failure: " + tile + " - " + tile.getErrorMessage());
    17241725            }
    17251726        }
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackAction.java

    r9576 r9719  
    3636
    3737/**
    38  * Class downloading WMS and TMS along the GPX track
    39  *
     38 * Class downloading WMS and TMS along the GPX track.
     39 * @since 5715
    4040 */
    4141public class DownloadWmsAlongTrackAction extends AbstractAction {
     
    5151    }
    5252
    53     @Override
    54     public void actionPerformed(ActionEvent e) {
    55         final List<LatLon> points = new ArrayList<>();
     53    static class PrecacheWmsTask extends PleaseWaitRunnable {
     54
     55        private final AbstractTileSourceLayer layer;
     56        private final List<LatLon> points;
     57        private PrecacheTask precacheTask;
     58
     59        protected PrecacheWmsTask(AbstractTileSourceLayer layer, List<LatLon> points) {
     60            super(tr("Precaching WMS"));
     61            this.layer = layer;
     62            this.points = points;
     63        }
     64
     65        @Override
     66        protected void realRun() throws SAXException, IOException, OsmTransferException {
     67            precacheTask = layer.new PrecacheTask(progressMonitor);
     68            layer.downloadAreaToCache(precacheTask, points, 0, 0);
     69            while (!precacheTask.isFinished() && !progressMonitor.isCanceled()) {
     70                synchronized (this) {
     71                    try {
     72                        wait(200);
     73                    } catch (InterruptedException ex) {
     74                        Main.warn("InterruptedException in "+getClass().getSimpleName()+" while precaching WMS");
     75                    }
     76                }
     77            }
     78        }
     79
     80        @Override
     81        protected void finish() {
     82            // Do nothing
     83        }
     84
     85        @Override
     86        protected void cancel() {
     87            precacheTask.cancel();
     88        }
     89
     90        @Override
     91        public ProgressTaskId canRunInBackground() {
     92            return ProgressTaskIds.PRECACHE_WMS;
     93        }
     94    }
     95
     96    PrecacheWmsTask createTask() {
     97        List<LatLon> points = new ArrayList<>();
    5698        for (GpxTrack trk : data.tracks) {
    5799            for (GpxTrackSegment segment : trk.getSegments()) {
     
    64106            points.add(p.getCoor());
    65107        }
    66         final AbstractTileSourceLayer layer = askedLayer();
    67         if (layer != null) {
    68             PleaseWaitRunnable task = new PleaseWaitRunnable(tr("Precaching WMS")) {
    69                 private PrecacheTask precacheTask;
     108        AbstractTileSourceLayer layer = askedLayer();
     109        return layer != null ? new PrecacheWmsTask(layer, points) : null;
     110    }
    70111
    71                 @Override
    72                 protected void realRun() throws SAXException, IOException, OsmTransferException {
    73                     precacheTask = layer.new PrecacheTask(progressMonitor);
    74                     layer.downloadAreaToCache(precacheTask, points, 0, 0);
    75                     while (!precacheTask.isFinished() && !progressMonitor.isCanceled()) {
    76                         synchronized (this) {
    77                             try {
    78                                 wait(200);
    79                             } catch (InterruptedException ex) {
    80                                 Main.warn("InterruptedException in "+getClass().getSimpleName()+" while precaching WMS");
    81                             }
    82                         }
    83                     }
    84                 }
    85 
    86                 @Override
    87                 protected void finish() {
    88                 }
    89 
    90                 @Override
    91                 protected void cancel() {
    92                     precacheTask.cancel();
    93                 }
    94 
    95                 @Override
    96                 public ProgressTaskId canRunInBackground() {
    97                     return ProgressTaskIds.PRECACHE_WMS;
    98                 }
    99             };
     112    @Override
     113    public void actionPerformed(ActionEvent e) {
     114        PrecacheWmsTask task = createTask();
     115        if (task != null) {
    100116            Main.worker.execute(task);
    101117        }
     
    103119
    104120    protected AbstractTileSourceLayer askedLayer() {
     121        if (!Main.isDisplayingMapView()) {
     122            return null;
     123        }
    105124        List<AbstractTileSourceLayer> targetLayers = Main.map.mapView.getLayersOfType(AbstractTileSourceLayer.class);
    106125        if (targetLayers.isEmpty()) {
Note: See TracChangeset for help on using the changeset viewer.