Changeset 32652 in osm


Ignore:
Timestamp:
2016-07-14T15:18:07+02:00 (8 years ago)
Author:
floscher
Message:

Rename download modes

The labels facing the user (combobox in the settings) are now internationalized, the preference setting is not.
This change is backwards-compatible, because on each start of JOSM the plugin converts the old names of the download modes with the corresponding new one. This feature will sooner or later be removed again, but as long as every user starts JOSM at least once until then, the setting won't be affected by this change.

In some places the old names are still mentioned (e.g. comments and names of variables or methods), but the relevant occurences are now updated.

Location:
applications/editors/josm/plugins/mapillary
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/build.gradle

    r32631 r32652  
    176176
    177177task debugJosm(type: JavaExec) {
    178     classpath = sourceSets.main.runtimeClasspath
    179     main = 'JOSM'
    180     args '--offline=josm_website'
    181     jvmArgs "-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006", "-Djosm.home=$buildDir/.josm"
    182 
     178  classpath = sourceSets.main.runtimeClasspath
     179  main = 'JOSM'
     180  args '--offline=josm_website'
     181  jvmArgs "-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006", "-Djosm.home=$buildDir/.josm"
    183182}
    184183debugJosm.dependsOn installPlugin
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r32574 r32652  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.mapillary;
     3
     4import static org.openstreetmap.josm.tools.I18n.marktr;
     5import static org.openstreetmap.josm.tools.I18n.tr;
    36
    47import java.awt.AlphaComposite;
     
    5356import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandDelete;
    5457import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader;
     58import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader.DOWNLOAD_MODE;
    5559import org.openstreetmap.josm.plugins.mapillary.mode.AbstractMode;
    5660import org.openstreetmap.josm.plugins.mapillary.mode.JoinMode;
     
    5862import org.openstreetmap.josm.plugins.mapillary.utils.MapViewGeometryUtil;
    5963import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    60 
    61 import static org.openstreetmap.josm.tools.I18n.marktr;
    62 import static org.openstreetmap.josm.tools.I18n.tr;
    6364
    6465/**
     
    110111      Main.getLayerManager().addLayer(this);
    111112      Main.getLayerManager().addActiveLayerChangeListener(this);
    112       if (Main.getLayerManager().getEditLayer() != null)
     113      if (Main.getLayerManager().getEditLayer() != null) {
    113114        Main.getLayerManager().getEditLayer().data.addDataSetListener(this);
    114       if (MapillaryDownloader.getMode() == MapillaryDownloader.MODES.Automatic)
     115      }
     116      if (MapillaryDownloader.getMode() == DOWNLOAD_MODE.OSM_AREA) {
    115117        MapillaryDownloader.automaticDownload();
    116       if (MapillaryDownloader.getMode() == MapillaryDownloader.MODES.Semiautomatic)
     118      }
     119      if (MapillaryDownloader.getMode() == DOWNLOAD_MODE.VISIBLE_AREA) {
    117120        this.mode.zoomChanged();
     121      }
    118122    }
    119123    // Does not execute when in headless mode
    120124    if (MapillaryPlugin.getExportMenu() != null) {
    121125      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getExportMenu(), true);
    122       if (!MapillaryMainDialog.getInstance().isShowing())
     126      if (!MapillaryMainDialog.getInstance().isShowing()) {
    123127        MapillaryMainDialog.getInstance().getButton().doClick();
     128      }
    124129    }
    125130    createHatchTexture();
     
    132137    }
    133138
    134     if (Main.main != null)
     139    if (Main.main != null) {
    135140      MapillaryData.dataUpdated();
     141    }
    136142  }
    137143
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r32593 r32652  
    3232import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
    3333import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryPreferenceSetting;
    34 import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader;
     34import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader.DOWNLOAD_MODE;
    3535import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryUser;
    3636import org.openstreetmap.josm.tools.ImageProvider;
     37import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader;
    3738
    3839/**
     
    145146    }
    146147
    147     if (Main.pref.get("mapillary.access-token") == null)
     148    if (Main.pref.get("mapillary.access-token") == null) {
    148149      MapillaryUser.setTokenValid(false);
     150    }
     151    // Normalize download mode preference setting
     152    Main.pref.put(
     153      "mapillary.download-mode",
     154      DOWNLOAD_MODE.fromPrefId(Main.pref.get("mapillary.download-mode")).getPrefId()
     155    );
    149156  }
    150157
     
    225232      Main.map.addToggleDialog(MapillaryFilterDialog.getInstance(), false);
    226233      setMenuEnabled(downloadMenu, true);
    227       if (MapillaryDownloader.getMode() == MapillaryDownloader.MODES.Manual)
     234      if (MapillaryDownloader.getMode() == DOWNLOAD_MODE.MANUAL_ONLY)
    228235        setMenuEnabled(downloadViewMenu, true);
    229236      setMenuEnabled(importMenu, true);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r32591 r32652  
    2929import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
    3030import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    31 import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader;
     31import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader.DOWNLOAD_MODE;
    3232import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryLoginListener;
    3333import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryUser;
     
    4848public class MapillaryPreferenceSetting implements SubPreferenceSetting, MapillaryLoginListener {
    4949  private final JComboBox<String> downloadModeComboBox = new JComboBox<>(new String[]{
    50       MapillaryDownloader.MODES.Automatic.toString(),
    51       MapillaryDownloader.MODES.Semiautomatic.toString(),
    52       MapillaryDownloader.MODES.Manual.toString()
     50      DOWNLOAD_MODE.VISIBLE_AREA.getLabel(),
     51      DOWNLOAD_MODE.OSM_AREA.getLabel(),
     52      DOWNLOAD_MODE.MANUAL_ONLY.getLabel()
    5353  });
    5454  private final JCheckBox displayHour = new JCheckBox(I18n.tr("Display hour when the picture was taken"));
     
    102102    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    103103
    104     // Sets the value of the ComboBox.
    105     String downloadMode = Main.pref.get("mapillary.download-mode");
    106     if (MapillaryDownloader.MODES.Automatic.toString().equals(downloadMode)
    107         || MapillaryDownloader.MODES.Semiautomatic.toString().equals(downloadMode)
    108         || MapillaryDownloader.MODES.Manual.toString().equals(downloadMode)) {
    109       downloadModeComboBox.setSelectedItem(Main.pref.get("mapillary.download-mode"));
    110     }
     104    downloadModeComboBox.setSelectedItem(DOWNLOAD_MODE.fromPrefId(Main.pref.get("mapillary.download-mode")).getLabel());
     105
    111106    JPanel downloadModePanel = new JPanel();
    112107    downloadModePanel.add(new JLabel(I18n.tr("Download mode")));
     
    170165
    171166    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), false);
    172     if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Automatic.toString())) {
    173       Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Automatic.toString());
    174     }
    175     if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Semiautomatic.toString())) {
    176       Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Semiautomatic.toString());
    177     }
    178     if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Manual.toString())) {
    179       Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Manual.toString());
    180       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), true);
    181     }
     167    Main.pref.put(
     168      "mapillary.download-mode",
     169      DOWNLOAD_MODE.fromLabel(downloadModeComboBox.getSelectedItem().toString()).getPrefId()
     170    );
     171    MapillaryPlugin.setMenuEnabled(
     172      MapillaryPlugin.getDownloadViewMenu(),
     173      DOWNLOAD_MODE.MANUAL_ONLY.getPrefId().equals(
     174        Main.pref.get("mapillary.download-mode", DOWNLOAD_MODE.getDefault().getPrefId())
     175      )
     176    );
    182177    Main.pref.put("mapillary.display-hour", this.displayHour.isSelected());
    183178    Main.pref.put("mapillary.format-24", this.format24.isSelected());
     
    198193   *
    199194   */
    200   public class LoginAction extends AbstractAction {
     195  private class LoginAction extends AbstractAction {
    201196    private static final long serialVersionUID = -3908477563072057344L;
    202197    private final transient MapillaryLoginListener callback;
     
    224219   *
    225220   */
    226   public class LogoutAction extends AbstractAction {
     221  private class LogoutAction extends AbstractAction {
    227222
    228223    private static final long serialVersionUID = 3434780936404707219L;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java

    r32378 r32652  
    1818import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    1919import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
     20import org.openstreetmap.josm.tools.I18n;
    2021
    2122/**
     
    2930
    3031  /** Possible download modes. */
    31   public enum MODES {Automatic, Semiautomatic, Manual}
     32  public enum DOWNLOAD_MODE {
     33    VISIBLE_AREA("visibleArea", I18n.tr("everything in the visible area")),
     34    OSM_AREA("osmArea", I18n.tr("areas with downloaded OSM-data")),
     35    MANUAL_ONLY("manualOnly", I18n.tr("only when manually requested"));
     36
     37    private String prefId;
     38    private String label;
     39
     40    private DOWNLOAD_MODE(String prefId, String label) {
     41      this.prefId = prefId;
     42      this.label = label;
     43    }
     44
     45    public String getPrefId() {
     46      return prefId;
     47    }
     48
     49    public String getLabel() {
     50      return label;
     51    }
     52
     53    public static DOWNLOAD_MODE fromPrefId(String prefId) {
     54      if (MANUAL_ONLY.getPrefId().equals(prefId) || "Manual".equals(prefId)) {
     55        return MANUAL_ONLY;
     56      }
     57      if (OSM_AREA.getPrefId().equals(prefId) || "Automatic".equals(prefId)) {
     58        return OSM_AREA;
     59      }
     60      if (VISIBLE_AREA.getPrefId().equals(prefId) || "Semiautomatic".equals(prefId)) {
     61        return VISIBLE_AREA;
     62      }
     63      return getDefault();
     64    }
     65    public static DOWNLOAD_MODE fromLabel(String label) {
     66      if (MANUAL_ONLY.getLabel().equals(label)) {
     67        return MANUAL_ONLY;
     68      }
     69      if (OSM_AREA.getLabel().equals(label)) {
     70        return OSM_AREA;
     71      }
     72      if (VISIBLE_AREA.getLabel().equals(label)) {
     73        return VISIBLE_AREA;
     74      }
     75      return getDefault();
     76    }
     77
     78    public static DOWNLOAD_MODE getDefault() {
     79      return OSM_AREA;
     80    }
     81  }
    3282
    3383  /** All the Threads that have been run. Used to interrupt them properly. */
     
    73123   * Returns the current download mode.
    74124   *
    75    * @return the currently enabled of the available {@link MODES}
    76    */
    77   public static MapillaryDownloader.MODES getMode() {
    78     String downloadMode = Main.pref.get("mapillary.download-mode", MODES.Automatic.toString());
    79     boolean isTempSemiautomatic = MapillaryLayer.hasInstance() && MapillaryLayer.getInstance().tempSemiautomatic;
    80     if (MODES.Semiautomatic.toString().equals(downloadMode) || isTempSemiautomatic) {
    81       return MODES.Semiautomatic;
    82     } else if (MODES.Manual.toString().equals(downloadMode)) {
    83       return MODES.Manual;
    84     } else if (MODES.Automatic.toString().equals(downloadMode)) {
    85       return MODES.Automatic;
    86     } else {
    87       throw new IllegalStateException();
    88     }
     125   * @return the currently enabled {@link DOWNLOAD_MODE}
     126   */
     127  public static MapillaryDownloader.DOWNLOAD_MODE getMode() {
     128   return MapillaryLayer.hasInstance() && MapillaryLayer.getInstance().tempSemiautomatic
     129     ? DOWNLOAD_MODE.VISIBLE_AREA
     130     : DOWNLOAD_MODE.fromPrefId(Main.pref.get("mapillary.download-mode"));
    89131  }
    90132
     
    98140   */
    99141  public static void completeView() {
    100     if (getMode() != MODES.Semiautomatic && getMode() != MODES.Manual)
    101       throw new IllegalStateException("Must be in semiautomatic or manual mode");
     142    if (getMode() != DOWNLOAD_MODE.VISIBLE_AREA && getMode() != DOWNLOAD_MODE.MANUAL_ONLY) {
     143      throw new IllegalStateException("Download mode must be 'visible area' or 'manual only'");
     144    }
    102145    Bounds view = Main.map.mapView.getRealBounds();
    103     if (view.getArea() > MAX_AREA)
    104       return;
    105     if (isViewDownloaded(view))
    106       return;
     146    if (view.getArea() > MAX_AREA) {
     147      return;
     148    }
     149    if (isViewDownloaded(view)) {
     150      return;
     151    }
    107152    MapillaryLayer.getInstance().getData().getBounds().add(view);
    108153    getImages(view);
     
    159204      return;
    160205    }
    161     if (getMode() != MODES.Automatic)
     206    if (getMode() != DOWNLOAD_MODE.OSM_AREA)
    162207      throw new IllegalStateException("Must be in automatic mode.");
    163208    for (Bounds bounds : Main.getLayerManager().getEditLayer().data
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java

    r32383 r32652  
    6666  @Override
    6767  public void zoomChanged() {
    68     if (MapillaryDownloader.getMode() == MapillaryDownloader.MODES.Semiautomatic) {
     68    if (MapillaryDownloader.getMode() == MapillaryDownloader.DOWNLOAD_MODE.VISIBLE_AREA) {
    6969      if (!semiautomaticThread.isAlive())
    7070        semiautomaticThread.start();
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSettingTest.java

    r32591 r32652  
    77import java.awt.GraphicsEnvironment;
    88import java.lang.reflect.Field;
    9 import java.util.HashMap;
    10 import java.util.Map;
    119
    1210import javax.swing.JButton;
     
    2018import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
    2119import org.openstreetmap.josm.plugins.mapillary.AbstractTest;
     20import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader.DOWNLOAD_MODE;
    2221import org.openstreetmap.josm.tools.I18n;
    2322
     
    118117      ((JComboBox<String>) getPrivateField(settings, "downloadModeComboBox")).setSelectedIndex(i);
    119118      settings.ok();
    120       assertEquals(Main.pref.get("mapillary.download-mode"),
    121           ((JComboBox<String>) getPrivateField(settings, "downloadModeComboBox")).getSelectedItem());
     119      assertEquals(
     120        Main.pref.get("mapillary.download-mode"),
     121        DOWNLOAD_MODE.fromLabel(
     122          ((JComboBox<String>) getPrivateField(settings, "downloadModeComboBox")).getSelectedItem().toString()
     123        ).getPrefId()
     124      );
    122125    }
    123126  }
Note: See TracChangeset for help on using the changeset viewer.