Changeset 31796 in osm for applications/editors/josm


Ignore:
Timestamp:
2015-12-03T22:27:51+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Fix more Sonar and FindBugs issues

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

Legend:

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

    r31787 r31796  
    8787   */
    8888  public String getDate() {
    89     String format = "";
     89    StringBuilder format = new StringBuilder("");
    9090    if (Main.pref.getBoolean("iso.dates"))
    91       format += "yyyy-MM-dd";
     91      format.append("yyyy-MM-dd");
    9292    else
    93       format += "dd/MM/yyyy";
     93      format.append("dd/MM/yyyy");
    9494    if (Main.pref.getBoolean("mapillary.display-hour", true)) {
    9595      if (Main.pref.getBoolean("mapillary.format-24"))
    96         format += " - HH:mm:ss (z)";
     96        format.append(" - HH:mm:ss (z)");
    9797      else
    98         format += " - h:mm:ss a (z)";
    99     }
    100     return getDate(format);
     98        format.append(" - h:mm:ss a (z)");
     99    }
     100    return getDate(format.toString());
    101101  }
    102102
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31787 r31796  
    2929  private final List<MapillaryAbstractImage> multiSelectedImages;
    3030  /** Listeners of the class. */
    31   private CopyOnWriteArrayList<MapillaryDataListener> listeners = new CopyOnWriteArrayList<>();
     31  private final CopyOnWriteArrayList<MapillaryDataListener> listeners = new CopyOnWriteArrayList<>();
    3232  /** The bounds of the areas for which the pictures have been downloaded. */
    3333  public CopyOnWriteArrayList<Bounds> bounds;
     
    177177   * Repaints mapView object.
    178178   */
    179   public synchronized static void dataUpdated() {
     179  public static synchronized void dataUpdated() {
    180180    if (Main.main != null)
    181181      Main.map.mapView.repaint();
     
    312312    this.multiSelectedImages.clear();
    313313    this.multiSelectedImages.add(image);
    314     if (image != null && Main.main != null) {
    315       if (image instanceof MapillaryImage) {
    316         MapillaryImage mapillaryImage = (MapillaryImage) image;
    317         // Downloading thumbnails of surrounding pictures.
    318         if (mapillaryImage.next() != null) {
    319           CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.next());
    320           if (mapillaryImage.next().next() != null)
    321             CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.next()
    322                 .next());
    323         }
    324         if (mapillaryImage.previous() != null) {
    325           CacheUtils
    326               .downloadPicture((MapillaryImage) mapillaryImage.previous());
    327           if (mapillaryImage.previous().previous() != null)
    328             CacheUtils.downloadPicture((MapillaryImage) mapillaryImage
    329                 .previous().previous());
    330         }
     314    if (image != null && Main.main != null && image instanceof MapillaryImage) {
     315      MapillaryImage mapillaryImage = (MapillaryImage) image;
     316      // Downloading thumbnails of surrounding pictures.
     317      if (mapillaryImage.next() != null) {
     318        CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.next());
     319        if (mapillaryImage.next().next() != null)
     320          CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.next().next());
     321      }
     322      if (mapillaryImage.previous() != null) {
     323        CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.previous());
     324        if (mapillaryImage.previous().previous() != null)
     325          CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.previous().previous());
    331326      }
    332327    }
     
    396391   * Sets a new ArrayList object as the used set of images.
    397392   *
    398    * @param images
     393   * @param images the new image list (previously set images are completely replaced)
    399394   */
    400395  public synchronized void setImages(List<MapillaryAbstractImage> images) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java

    r31787 r31796  
    2323
    2424  /**
     25   * Main constructor of the class MapillaryImage
     26   *
     27   * @param key
     28   *          The unique identifier of the image.
     29   * @param lat
     30   *          The latitude where it is positioned.
     31   * @param lon
     32   *          The longitude where it is positioned.
     33   * @param ca
     34   *          The direction of the images in degrees, meaning 0 north.
     35   */
     36  public MapillaryImage(String key, double lat, double lon, double ca) {
     37    super(lat, lon, ca);
     38    this.key = key;
     39    this.signs = new ArrayList<>();
     40  }
     41
     42  /**
    2543   * Returns the location where the image was taken.
    2644   *
     
    3957  public void setLocation(String location) {
    4058    this.location = location;
    41   }
    42 
    43   /**
    44    * Main constructor of the class MapillaryImage
    45    *
    46    * @param key
    47    *          The unique identifier of the image.
    48    * @param lat
    49    *          The latitude where it is positioned.
    50    * @param lon
    51    *          The longitude where it is positioned.
    52    * @param ca
    53    *          The direction of the images in degrees, meaning 0 north.
    54    */
    55   public MapillaryImage(String key, double lat, double lon, double ca) {
    56     super(lat, lon, ca);
    57     this.key = key;
    58     this.signs = new ArrayList<>();
    5959  }
    6060
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31787 r31796  
    119119      if (Main.map.mapView.getEditLayer() != null)
    120120        Main.map.mapView.getEditLayer().data.addDataSetListener(this);
    121       if (MapillaryDownloader.getMode() == MapillaryDownloader.AUTOMATIC)
     121      if (MapillaryDownloader.getMode() == MapillaryDownloader.MODES.Automatic)
    122122        MapillaryDownloader.automaticDownload();
    123       if (MapillaryDownloader.getMode() == MapillaryDownloader.SEMIAUTOMATIC)
     123      if (MapillaryDownloader.getMode() == MapillaryDownloader.MODES.Semiautomatic)
    124124        this.mode.zoomChanged();
    125125    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31787 r31796  
    4545  public static final String SEPARATOR = System.getProperty("file.separator");
    4646  /** 24x24 icon. */
    47   public static ImageIcon ICON24;
     47  public static final ImageIcon ICON24 = new ImageProvider("icon24.png").get();
    4848  /** 16x16 icon. */
    49   public static ImageIcon ICON16;
     49  public static final ImageIcon ICON16 = new ImageProvider("icon16.png").get();
    5050  /** Icon representing an image in the map. */
    51   public static ImageIcon MAP_ICON;
     51  public static final ImageIcon MAP_ICON = new ImageProvider("mapicon.png").get();
    5252  /** Icon representing a selected image in the map. */
    53   public static ImageIcon MAP_ICON_SELECTED;
     53  public static final ImageIcon MAP_ICON_SELECTED = new ImageProvider("mapiconselected.png").get();
    5454  /** Icon representing an imported image in the map. */
    55   public static ImageIcon MAP_ICON_IMPORTED;
     55  public static final ImageIcon MAP_ICON_IMPORTED = new ImageProvider("mapiconimported.png").get();
    5656  /** Icon used to identify which images have signs on them */
    57   public static ImageIcon MAP_SIGN;
     57  public static final ImageIcon MAP_SIGN = new ImageProvider("sign.png").get();
    5858
    5959  /** Cache that stores the pictures the downloaded pictures. */
     
    102102    super(info);
    103103
    104     ICON24 = new ImageProvider("icon24.png").get();
    105     ICON16 = new ImageProvider("icon16.png").get();
    106     MAP_ICON = new ImageProvider("mapicon.png").get();
    107     MAP_ICON_SELECTED = new ImageProvider("mapiconselected.png").get();
    108     MAP_ICON_IMPORTED = new ImageProvider("mapiconimported.png").get();
    109     MAP_SIGN = new ImageProvider("sign.png").get();
    110 
    111104    this.downloadAction = new MapillaryDownloadAction();
    112105    walkAction = new MapillaryWalkAction();
     
    167160      Main.map.addToggleDialog(MapillaryFilterDialog.getInstance(), false);
    168161      setMenuEnabled(DOWNLOAD_MENU, true);
    169       if (MapillaryDownloader.getMode() == MapillaryDownloader.MANUAL)
     162      if (MapillaryDownloader.getMode() == MapillaryDownloader.MODES.Manual)
    170163        setMenuEnabled(DOWNLOAD_VIEW_MENU, true);
    171164      setMenuEnabled(IMPORT_MENU, true);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r31787 r31796  
    3636  private JCheckBox reverseButtons = new JCheckBox(
    3737      tr("Reverse buttons position when displaying images."));
    38   private JComboBox<String> downloadMode = new JComboBox<>(
    39       MapillaryDownloader.MODES);
     38  private JComboBox<String> downloadMode = new JComboBox<>(new String[]{
     39      MapillaryDownloader.MODES.Automatic.toString(),
     40      MapillaryDownloader.MODES.Semiautomatic.toString(),
     41      MapillaryDownloader.MODES.Manual.toString()
     42  });
    4043  private JCheckBox displayHour = new JCheckBox(
    4144      tr("Display hour when the picture was taken"));
     
    6366    panel.add(this.reverseButtons);
    6467    // Sets the value of the ComboBox.
    65     if (Main.pref.get("mapillary.download-mode").equals(
    66         MapillaryDownloader.MODES[0]))
    67       this.downloadMode.setSelectedItem(MapillaryDownloader.MODES[0]);
    68     if (Main.pref.get("mapillary.download-mode").equals(
    69         MapillaryDownloader.MODES[1]))
    70       this.downloadMode.setSelectedItem(MapillaryDownloader.MODES[1]);
    71     if (Main.pref.get("mapillary.download-mode").equals(
    72         MapillaryDownloader.MODES[2]))
    73       this.downloadMode.setSelectedItem(MapillaryDownloader.MODES[2]);
     68    if (Main.pref.get("mapillary.download-mode").equals(MapillaryDownloader.MODES.Automatic.toString())
     69        || Main.pref.get("mapillary.download-mode").equals(MapillaryDownloader.MODES.Semiautomatic.toString())
     70        || Main.pref.get("mapillary.download-mode").equals(MapillaryDownloader.MODES.Manual.toString())) {
     71      this.downloadMode.setSelectedItem(Main.pref.get("mapillary.download-mode"));
     72    }
    7473    JPanel downloadModePanel = new JPanel();
    7574    downloadModePanel.add(new JLabel(tr("Download mode: ")));
     
    101100
    102101    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, false);
    103     if (this.downloadMode.getSelectedItem()
    104         .equals(MapillaryDownloader.MODES[0]))
    105       Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[0]);
    106     if (this.downloadMode.getSelectedItem()
    107         .equals(MapillaryDownloader.MODES[1]))
    108       Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[1]);
    109     if (this.downloadMode.getSelectedItem()
    110         .equals(MapillaryDownloader.MODES[2])) {
    111       Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[2]);
     102    if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES.Automatic.toString()))
     103      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Automatic.toString());
     104    if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES.Semiautomatic.toString()))
     105      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Semiautomatic.toString());
     106    if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES.Manual.toString())) {
     107      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Manual.toString());
    112108      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true);
    113109    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java

    r31787 r31796  
    2929
    3030  /** Possible download modes. */
    31   public static final String[] MODES = new String[] { "Automatic",
    32       "Semiautomatic", "Manual" };
    33   /** Automatic mode. */
    34   public static final int AUTOMATIC = 0;
    35   /** Semiautomatic mode. */
    36   public static final int SEMIAUTOMATIC = 1;
    37   /** Manual mode. */
    38   public static final int MANUAL = 2;
     31  public enum MODES {Automatic, Semiautomatic, Manual};
    3932
    4033  /** All the Threads that have been run. Used to interrupt them properly. */
     
    8073   */
    8174  public static void completeView() {
    82     if (getMode() != SEMIAUTOMATIC && getMode() != MANUAL)
     75    if (getMode() != MODES.Semiautomatic && getMode() != MODES.Manual)
    8376      throw new IllegalStateException("Must be in semiautomatic or manual mode");
    8477    Bounds view = Main.map.mapView.getRealBounds();
     
    151144      return;
    152145    }
    153     if (getMode() != AUTOMATIC)
     146    if (getMode() != MODES.Automatic)
    154147      throw new IllegalStateException("Must be in automatic mode.");
    155148    for (Bounds bounds : Main.map.mapView.getEditLayer().data
     
    184177   * @return 0 - automatic; 1 - semiautomatic; 2 - manual.
    185178   */
    186   public static int getMode() {
    187     if (Main.pref.get("mapillary.download-mode").equals(MODES[0])
     179  public static MapillaryDownloader.MODES getMode() {
     180    if (Main.pref.get("mapillary.download-mode").equals(MODES.Automatic.toString())
    188181        && (MapillaryLayer.INSTANCE == null || !MapillaryLayer.INSTANCE.TEMP_SEMIAUTOMATIC))
    189       return 0;
    190     else if (Main.pref.get("mapillary.download-mode").equals(MODES[1])
     182      return MODES.Automatic;
     183    else if (Main.pref.get("mapillary.download-mode").equals(MODES.Semiautomatic.toString())
    191184        || (MapillaryLayer.INSTANCE != null && MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC))
    192       return 1;
    193     else if (Main.pref.get("mapillary.download-mode").equals(MODES[2]))
    194       return 2;
     185      return MODES.Semiautomatic;
     186    else if (Main.pref.get("mapillary.download-mode").equals(MODES.Manual.toString()))
     187      return MODES.Manual;
    195188    else if (Main.pref.get("mapillary.download-mode").equals(""))
    196       return 0;
     189      return MODES.Automatic;
    197190    else
    198191      throw new IllegalStateException();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java

    r31787 r31796  
    6666  @Override
    6767  public void zoomChanged() {
    68     if (MapillaryDownloader.getMode() == MapillaryDownloader.SEMIAUTOMATIC) {
     68    if (MapillaryDownloader.getMode() == MapillaryDownloader.MODES.Semiautomatic) {
    6969      if (!semiautomaticThread.isAlive())
    7070        semiautomaticThread.start();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java

    r31787 r31796  
    2424public class OAuthPortListener extends Thread {
    2525
    26   protected static String RESPONSE = tr("<html><head><title>Mapillary login</title></head><body>Login successful, return to JOSM.</body></html>");
     26  protected static final String RESPONSE = tr("<html><head><title>Mapillary login</title></head><body>Login successful, return to JOSM.</body></html>");
    2727
    2828  @Override
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java

    r31795 r31796  
    3838
    3939    try (
    40       BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))
     40      BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"))
    4141    ) {
    4242      return Json.createReader(in).readObject();
Note: See TracChangeset for help on using the changeset viewer.