Changeset 31422 in osm for applications/editors/josm


Ignore:
Timestamp:
2015-07-31T11:36:18+02:00 (9 years ago)
Author:
nokutu
Message:

Fixed EDT when the "Area is too big" dialog appears.

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31416 r31422  
    107107   */
    108108  private void init() {
     109    if (INSTANCE == null)
     110      INSTANCE = this;
    109111    if (Main.map != null && Main.map.mapView != null) {
    110112      setMode(new SelectMode());
     
    114116      if (Main.map.mapView.getEditLayer() != null)
    115117        Main.map.mapView.getEditLayer().data.addDataSetListener(this);
     118      if (MapillaryDownloader.getMode() == MapillaryDownloader.AUTOMATIC)
     119        MapillaryDownloader.automaticDownload();
     120      if (MapillaryDownloader.getMode() == MapillaryDownloader.SEMIAUTOMATIC)
     121        mode.zoomChanged();
    116122    }
    117123    if (MapillaryPlugin.EXPORT_MENU != null) { // Does not execute when in
     
    154160  public synchronized static MapillaryLayer getInstance() {
    155161    if (INSTANCE == null)
    156       INSTANCE = new MapillaryLayer();
     162      return new MapillaryLayer();
    157163    return MapillaryLayer.INSTANCE;
    158164  }
     
    445451   * Returns the 2 closest images belonging to a different sequence.
    446452   *
    447    * @return An array of length 2 containing the two closest images belonging
    448    *         to different sequences.
     453   * @return An array of length 2 containing the two closest images belonging to
     454   *         different sequences.
    449455   */
    450456  private MapillaryImage[] getClosestImagesFromDifferentSequences() {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31418 r31422  
    148148      Main.map.addToggleDialog(MapillaryFilterDialog.getInstance(), false);
    149149      setMenuEnabled(DOWNLOAD_MENU, true);
    150       if (Main.pref.get("mapillary.download-mode").equals(
    151           MapillaryDownloader.MODES[2]))
     150      if (MapillaryDownloader.getMode() == MapillaryDownloader.MANUAL)
    152151        setMenuEnabled(DOWNLOAD_VIEW_MENU, true);
    153152      setMenuEnabled(IMPORT_MENU, true);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadViewAction.java

    r31417 r31422  
    66import java.awt.event.KeyEvent;
    77
    8 import javax.swing.JOptionPane;
    9 
    10 import org.openstreetmap.josm.Main;
    118import org.openstreetmap.josm.actions.JosmAction;
    12 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    139import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    1410import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
     
    2622  private static final long serialVersionUID = -6837073336175123503L;
    2723
    28   /** Max area to be downloaded */
    29   public static final double MAX_AREA = Main.pref.getDouble(
    30       "mapillary.max-download-area", 0.015);
    31 
    3224  /**
    3325   * Main constructor.
     
    4436  @Override
    4537  public void actionPerformed(ActionEvent arg0) {
    46     MapillaryLayer.getInstance().bounds.add(Main.map.mapView.getRealBounds());
    47     if (Main.map.mapView.getRealBounds().getArea() <= MAX_AREA) {
    48       MapillaryDownloader.getImages(Main.map.mapView.getRealBounds());
    49     } else {
    50       JOptionPane.showMessageDialog(Main.parent,
    51           tr("This area is too big to be downloaded"));
    52     }
     38    MapillaryDownloader.completeView();
    5339  }
    5440}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java

    r31418 r31422  
    99
    1010import javax.swing.JOptionPane;
     11import javax.swing.SwingUtilities;
    1112
    1213import org.openstreetmap.josm.Main;
     
    1516import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    1617import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    17 import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryDownloadViewAction;
    1818
    1919/**
     
    2929  public static final String[] MODES = new String[] { "Automatic",
    3030      "Semiautomatic", "Manual" };
     31  /** Automatic mode. */
     32  public static final int AUTOMATIC = 0;
     33  /** Semiautomatic mode. */
     34  public static final int SEMIAUTOMATIC = 1;
     35  /** Manual mode. */
     36  public static final int MANUAL = 2;
     37
     38  /** Max area to be downloaded */
     39  public static final double MAX_AREA = Main.pref.getDouble(
     40      "mapillary.max-download-area", 0.015);
    3141
    3242  /** Base URL of the Mapillary API. */
     
    6676   */
    6777  public static void completeView() {
     78    if (getMode() != SEMIAUTOMATIC && getMode() != MANUAL)
     79      throw new IllegalStateException("Must be in semiautomatic or manual mode");
    6880    Bounds view = Main.map.mapView.getRealBounds();
    69     if (view.getArea() > MapillaryDownloadViewAction.MAX_AREA)
     81    if (view.getArea() > MAX_AREA)
    7082      return;
    7183    if (isViewDownloaded(view))
     
    8193      for (int j = 0; j < n; j++) {
    8294        if (isInBounds(new LatLon(view.getMinLat()
    83             + (view.getMaxLat() - view.getMinLat()) * ((double) i / n), view.getMinLon()
    84  + (view.getMaxLon() - view.getMinLon())
     95            + (view.getMaxLat() - view.getMinLat()) * ((double) i / n),
     96            view.getMinLon() + (view.getMaxLon() - view.getMinLon())
    8597                * ((double) j / n)))) {
    8698          inside[i][j] = true;
     
    120132  public static void automaticDownload() {
    121133    MapillaryLayer layer = MapillaryLayer.getInstance();
    122     checkAreaTooBig();
    123     if (!Main.pref.get("mapillary.download-mode").equals(
    124         MapillaryDownloader.MODES[0])
    125         || layer.TEMP_SEMIAUTOMATIC)
     134    if (isAreaTooBig()) {
     135      tooBigErrorDialog();
    126136      return;
     137    }
     138
     139    if (getMode() != AUTOMATIC)
     140      throw new IllegalStateException("Must be in automatic mode.");
    127141    for (Bounds bounds : Main.map.mapView.getEditLayer().data
    128142        .getDataSourceBounds()) {
     
    140154   * and you will have to download areas manually.
    141155   */
    142   private static void checkAreaTooBig() {
     156  private static boolean isAreaTooBig() {
    143157    double area = 0;
    144158    for (Bounds bounds : Main.map.mapView.getEditLayer().data
     
    146160      area += bounds.getArea();
    147161    }
    148     if (area > MapillaryDownloadViewAction.MAX_AREA) {
     162    if (area > MAX_AREA)
     163      return true;
     164    return false;
     165  }
     166
     167  /**
     168   * Returns the current download mode.
     169   *
     170   * @return 0 - automatic; 1 - semiautomatic; 2 - manual.
     171   */
     172  public static int getMode() {
     173    if (Main.pref.get("mapillary.download-mode").equals(MODES[0])
     174        && !MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC)
     175      return 0;
     176    else if (Main.pref.get("mapillary.download-mode").equals(MODES[1])
     177        || MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC)
     178      return 1;
     179    else if (Main.pref.get("mapillary.download-mode").equals(MODES[2]))
     180      return 2;
     181    else
     182      throw new IllegalStateException();
     183  }
     184
     185  private static void tooBigErrorDialog() {
     186    if (!SwingUtilities.isEventDispatchThread()) {
     187      SwingUtilities.invokeLater(new Runnable() {
     188        @Override
     189        public void run() {
     190          tooBigErrorDialog();
     191        }
     192      });
     193    } else {
    149194      MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC = true;
    150195      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true);
     
    152197          .showMessageDialog(
    153198              Main.parent,
    154               tr("The downloaded OSM area is too big. Download mode has been changed to manual until the layer is restarted."));
     199              tr("The downloaded OSM area is too big. Download mode has been changed to semiautomatic until the layer is restarted."));
    155200    }
    156201  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java

    r31409 r31422  
    6464  @Override
    6565  public void zoomChanged() {
    66     if (Main.pref.get("mapillary.download-mode").equals(
    67         MapillaryDownloader.MODES[1])
    68         || MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC) {
     66    if (MapillaryDownloader.getMode() == MapillaryDownloader.SEMIAUTOMATIC) {
    6967      if (!semiautomaticThread.isAlive())
    7068        semiautomaticThread.start();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java

    r31415 r31422  
    1818import org.openstreetmap.josm.plugins.mapillary.commands.CommandTurnImage;
    1919import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecord;
    20 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    2120import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
    2221
     
    4241  public SelectMode() {
    4342    record = MapillaryRecord.getInstance();
    44     if (Main.pref.get("mapillary.download-mode").equals(
    45         MapillaryDownloader.MODES[1]))
    46       zoomChanged();
    4743  }
    4844
Note: See TracChangeset for help on using the changeset viewer.