001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.plugins.streetside.io.download;
003
004import org.openstreetmap.josm.data.Bounds;
005import org.openstreetmap.josm.plugins.streetside.StreetsideLayer;
006import org.openstreetmap.josm.plugins.streetside.gui.StreetsideMainDialog;
007import org.openstreetmap.josm.plugins.streetside.utils.PluginState;
008import org.openstreetmap.josm.plugins.streetside.utils.StreetsideUtils;
009import org.openstreetmap.josm.tools.Logging;
010
011public class StreetsideSquareDownloadRunnable implements Runnable {
012
013  private final Bounds bounds;
014
015  /**
016   * Main constructor.
017   *
018   * @param bounds the bounds of the area that should be downloaded
019   *
020   */
021  public StreetsideSquareDownloadRunnable(Bounds bounds) {
022    this.bounds = bounds;
023  }
024
025  @Override
026  public void run() {
027    PluginState.startDownload();
028    StreetsideUtils.updateHelpText();
029
030    // Download basic sequence data synchronously
031    new SequenceDownloadRunnable(StreetsideLayer.getInstance().getData(), bounds).run();
032
033    if (Thread.interrupted()) {
034      return;
035    }
036
037    // TODO: Revamp image details for Streetside RRH
038    // Asynchronously load the rest of the image details
039    Thread imgDetailsThread = new Thread(new ImageDetailsDownloadRunnable(StreetsideLayer.getInstance().getData(), bounds));
040    imgDetailsThread.start();
041
042    // TODO: Do we support detections? RRH
043    /*Thread detectionsThread = new Thread(new DetectionsDownloadRunnable(StreetsideLayer.getInstance().getData(), bounds));
044    detectionsThread.start();*/
045
046    try {
047      imgDetailsThread.join();
048      //detectionsThread.join();
049    } catch (InterruptedException e) {
050      Logging.log(Logging.LEVEL_WARN, "Streetside download interrupted (probably because of closing the layer).", e);
051      Thread.currentThread().interrupt();
052    } finally {
053      PluginState.finishDownload();
054    }
055
056    StreetsideUtils.updateHelpText();
057    StreetsideLayer.invalidateInstance();
058    //StreetsideFilterDialog.getInstance().refresh();
059    StreetsideMainDialog.getInstance().updateImage();
060  }
061}