Ignore:
Timestamp:
2015-07-30T13:17:32+02:00 (9 years ago)
Author:
nokutu
Message:

Fixed several findbugs problems

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

Legend:

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

    r31409 r31415  
    281281   */
    282282  public MapillaryAbstractImage next() {
    283     synchronized (LOCK) {
    284       if (this.getSequence() == null)
     283    LOCK.lock();
     284    try {
     285      if (this.getSequence() == null) {
    285286        return null;
     287      }
    286288      return this.getSequence().next(this);
     289    } finally {
     290      LOCK.unlock();
    287291    }
    288292  }
     
    295299   */
    296300  public MapillaryAbstractImage previous() {
    297     synchronized (LOCK) {
    298       if (this.getSequence() == null)
     301    LOCK.lock();
     302    try {
     303      if (this.getSequence() == null) {
    299304        return null;
     305      }
    300306      return this.getSequence().previous(this);
     307    } finally {
     308      LOCK.unlock();
    301309    }
     310
    302311  }
    303312}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31409 r31415  
    5757   * Destroys the unique instance.
    5858   */
    59   public void destroy() {
     59  public static void clearInstance() {
    6060    INSTANCE = null;
    6161  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31409 r31415  
    182182    if (Main.map.mapView.getEditLayer() != null)
    183183      Main.map.mapView.getEditLayer().data.removeDataSetListener(this);
    184     MapillaryData.INSTANCE = null;
    185     MapillaryLayer.INSTANCE = null;
     184    MapillaryData.clearInstance();
     185    clearInstance();
    186186    super.destroy();
     187  }
     188
     189  /**
     190   * Clears the unique instance of this class.
     191   */
     192  public static void clearInstance() {
     193    INSTANCE = null;
    187194  }
    188195
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31412 r31415  
    7575        MapillaryLayer.getInstance();
    7676        if (file.isDirectory()) {
     77          if (file.listFiles() == null)
     78            continue;
    7779          for (int j = 0; j < file.listFiles().length; j++) {
    7880            int k = file.listFiles()[j].getName().lastIndexOf('.');
     
    8789              else if (extension.equals("png"))
    8890                readPNG(file.listFiles()[j]);
    89             } catch (ImageReadException | IOException e1) {
     91            } catch (ImageReadException | IOException | NullPointerException e1) {
    9092              Main.error(e1);
    9193            }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java

    r31401 r31415  
    7777      for (int i = 0; i < chooser.getSelectedFiles().length; i++) {
    7878        File file = chooser.getSelectedFiles()[i];
     79        if (file == null)
     80          break;
    7981        Main.pref.put("mapillary.start-directory", file.getParent());
    8082        MapillaryLayer.getInstance();
     
    8991              if (extension.equals("jpg") || extension.equals("jpeg"))
    9092                readJPG(file.listFiles()[j]);
    91             } catch (ImageReadException e) {
    92               Main.error(e);
    93             } catch (IOException e) {
     93            } catch (ImageReadException | NullPointerException | IOException e) {
    9494              Main.error(e);
    9595            }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryWalkAction.java

    r31409 r31415  
    5151    JOptionPane pane = new JOptionPane(dialog, JOptionPane.PLAIN_MESSAGE,
    5252        JOptionPane.OK_CANCEL_OPTION);
    53     JDialog dlg = pane.createDialog(Main.parent, tr("Export images"));
     53    JDialog dlg = pane.createDialog(Main.parent, tr("Walk mode"));
    5454    dlg.setMinimumSize(new Dimension(400, 150));
    5555    dlg.setVisible(true);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java

    r31409 r31415  
    5757              break;
    5858            image = image.next();
    59             Utils.downloadPicture((MapillaryImage) image, Utils.PICTURE.THUMBNAIL);
     59            Utils.downloadPicture((MapillaryImage) image,
     60                Utils.PICTURE.THUMBNAIL);
    6061          }
    6162        }
     
    9697          lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay
    9798              .getImage();
    98           synchronized (lock) {
    99             data.selectNext(followSelected);
    100           }
     99          lock.lock();
     100          data.selectNext(followSelected);
     101          lock.unlock();
    101102        } catch (InterruptedException e) {
    102103          return;
     104        } finally {
     105          lock.unlock();
    103106        }
    104107      }
     
    111114  @Override
    112115  public void interrupt() {
    113     super.interrupt();
     116    lock.lock();
     117    try {
     118      super.interrupt();
     119    } catch (Exception e) {
     120    } finally {
     121      lock.unlock();
     122    }
     123
    114124  }
    115125
     
    123133      MapillaryAbstractImage newImage) {
    124134    if (newImage != oldImage.next()) {
    125       synchronized (lock) {
    126         interrupt();
    127       }
     135      interrupt();
    128136    }
    129137  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31412 r31415  
    4646   * @param queryString
    4747   */
    48   public MapillarySequenceDownloadThread(ExecutorService ex,
    49       String queryString) {
     48  public MapillarySequenceDownloadThread(ExecutorService ex, String queryString) {
    5049    this.queryString = queryString;
    5150    this.ex = ex;
     
    9594        }
    9695
     96        LOCK.lock();
    9797        MapillaryImage.LOCK.lock();
    98         synchronized (LOCK) {
    99           for (MapillaryImage img : finalImages) {
    100             if (layer.getMapillaryData().getImages().contains(img)) {
    101               // The image in finalImages is substituted by the one in the
    102               // database, as they represent the same picture.
    103               img = (MapillaryImage) layer.getMapillaryData().getImages()
    104                   .get(layer.getMapillaryData().getImages().indexOf(img));
    105               sequence.add(img);
    106               ((MapillaryImage) layer.getMapillaryData().getImages()
    107                   .get(layer.getMapillaryData().getImages().indexOf(img)))
    108                   .setSequence(sequence);
    109               finalImages.set(finalImages.indexOf(img), img);
    110             } else {
    111               img.setSequence(sequence);
    112               sequence.add(img);
    113             }
     98        for (MapillaryImage img : finalImages) {
     99          if (layer.getMapillaryData().getImages().contains(img)) {
     100            // The image in finalImages is substituted by the one in the
     101            // database, as they represent the same picture.
     102            img = (MapillaryImage) layer.getMapillaryData().getImages()
     103                .get(layer.getMapillaryData().getImages().indexOf(img));
     104            sequence.add(img);
     105            ((MapillaryImage) layer.getMapillaryData().getImages()
     106                .get(layer.getMapillaryData().getImages().indexOf(img)))
     107                .setSequence(sequence);
     108            finalImages.set(finalImages.indexOf(img), img);
     109          } else {
     110            img.setSequence(sequence);
     111            sequence.add(img);
    114112          }
    115113        }
    116114        MapillaryImage.LOCK.unlock();
     115        LOCK.unlock();
    117116
    118117        layer.getMapillaryData().addWithoutUpdate(
     
    122121      Main.error("Error reading the url " + URL + queryString
    123122          + " might be a Mapillary problem.");
     123    } finally {
     124      LOCK.unlock();
     125      MapillaryImage.LOCK.unlock();
    124126    }
    125127  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java

    r31401 r31415  
    203203      // Calculates the amount of days since the image was taken
    204204      Long currentTime = currentTime();
    205       if (time.getSelectedItem() == TIME_LIST[1]) {
     205      if (time.getSelectedItem().equals(TIME_LIST[1])) {
    206206        if (img.getCapturedAt() < currentTime
    207207            - ((Integer) spinner.getValue()).longValue() * 365 * 24 * 60 * 60
     
    211211        }
    212212      }
    213       if (time.getSelectedItem() == TIME_LIST[2]) {
     213      if (time.getSelectedItem().equals(TIME_LIST[2])) {
    214214        if (img.getCapturedAt() < currentTime
    215215            - ((Integer) spinner.getValue()).longValue() * 30 * 24 * 60 * 60
     
    219219        }
    220220      }
    221       if (time.getSelectedItem() == TIME_LIST[3]) {
     221      if (time.getSelectedItem().equals(TIME_LIST[3])) {
    222222        if (img.getCapturedAt() < currentTime
    223223            - ((Integer) spinner.getValue()).longValue() * 60 * 60 * 1000) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryWalkDialog.java

    r31409 r31415  
    3030  public MapillaryWalkDialog() {
    3131    JPanel interval = new JPanel();
    32     spin = new SpinnerNumberModel(3000, 100, 15000, 100);
     32    spin = new SpinnerNumberModel(2000, 500, 10000, 500);
    3333    interval.add(new JLabel("Interval (miliseconds): "));
    3434    interval.add(new JSpinner(spin));
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java

    r31404 r31415  
    173173
    174174    } else if (imageHighlighted && !nothingHighlighted
    175         && Main.map.mapView != null
    176175        && Main.map.mapView.getEditLayer().data != null
    177176        && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer) {
Note: See TracChangeset for help on using the changeset viewer.