Changeset 31514 in osm for applications


Ignore:
Timestamp:
2015-08-21T20:44:24+02:00 (9 years ago)
Author:
nokutu
Message:

Code improvements and fixed a bug caused by trying to upload a picture without being logged in.

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

Legend:

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

    r31513 r31514  
    44import java.util.Calendar;
    55import java.util.Date;
    6 import java.util.concurrent.locks.Lock;
    7 import java.util.concurrent.locks.ReentrantLock;
    86
    97import org.openstreetmap.josm.Main;
     
    1816 */
    1917public abstract class MapillaryAbstractImage {
    20 
    21   /**
    22    * Lock that locks {@link MapillaryAbstractImage#next()} and
    23    * {@link MapillaryAbstractImage#previous()} methods. Used when downloading
    24    * images to prevent concurrency problems.
    25    */
    26   public static final Lock LOCK = new ReentrantLock();
    2718
    2819  /** The time the image was captured, in Epoch format. */
     
    205196   */
    206197  public MapillaryAbstractImage next() {
    207     LOCK.lock();
    208     try {
    209       if (this.getSequence() == null) {
     198    synchronized (this.getClass()) {
     199      if (this.getSequence() == null)
    210200        return null;
    211       }
    212201      return this.getSequence().next(this);
    213     } finally {
    214       LOCK.unlock();
    215202    }
    216203  }
     
    223210   */
    224211  public MapillaryAbstractImage previous() {
    225     LOCK.lock();
    226     try {
    227       if (this.getSequence() == null) {
     212    synchronized (this.getClass()) {
     213      if (this.getSequence() == null)
    228214        return null;
    229       }
    230215      return this.getSequence().previous(this);
    231     } finally {
    232       LOCK.unlock();
    233     }
    234 
     216    }
    235217  }
    236218
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryUploadAction.java

    r31512 r31514  
    5353
    5454    if (pane.getValue() != null
    55         && (int) pane.getValue() == JOptionPane.OK_OPTION) {
     55        && (int) pane.getValue() == JOptionPane.OK_OPTION
     56        && dialog.delete != null) {
    5657      if (dialog.sequence.isSelected()) {
    5758        UploadUtils.uploadSequence(MapillaryLayer.getInstance().getData()
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java

    r31502 r31514  
    22
    33import java.awt.image.BufferedImage;
    4 import java.util.concurrent.locks.Lock;
    5 import java.util.concurrent.locks.ReentrantLock;
    64
    75import javax.swing.SwingUtilities;
     
    2422  private final int interval;
    2523  private final MapillaryData data;
    26   private final Lock lock;
    2724  private boolean end = false;
    2825  private final boolean waitForFullQuality;
     
    5350    this.data = MapillaryLayer.getInstance().getData();
    5451    this.data.addListener(this);
    55     this.lock = new ReentrantLock();
    5652  }
    5753
     
    110106          this.lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay
    111107              .getImage();
    112           this.lock.lock();
    113           try {
     108          synchronized (this) {
    114109            if (this.goForward)
    115110              this.data.selectNext(this.followSelected);
    116111            else
    117112              this.data.selectPrevious(this.followSelected);
    118           } finally {
    119             this.lock.unlock();
    120113          }
    121114        } catch (InterruptedException e) {
     
    130123
    131124  @Override
    132   public void interrupt() {
    133     this.lock.lock();
    134     try {
    135       super.interrupt();
    136     } catch (Exception e) {
    137     } finally {
    138       this.lock.unlock();
    139     }
     125  public synchronized void interrupt() {
     126    super.interrupt();
    140127  }
    141128
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31513 r31514  
    88import java.util.List;
    99import java.util.concurrent.ExecutorService;
    10 import java.util.concurrent.locks.Lock;
    11 import java.util.concurrent.locks.ReentrantLock;
    1210
    1311import javax.json.Json;
     
    3331  private static final String URL = MapillaryDownloader.BASE_URL + "search/s/";
    3432
    35   /** Lock to prevent multiple downloads to be imported at the same time. */
    36   private static final Lock LOCK = new ReentrantLock();
    37 
    3833  private final String queryString;
    3934  private final ExecutorService ex;
     
    5853    try {
    5954      BufferedReader br;
    60       br = new BufferedReader(new InputStreamReader(
    61           new URL(URL + this.queryString).openStream(), "UTF-8"));
     55      br = new BufferedReader(new InputStreamReader(new URL(URL
     56          + this.queryString).openStream(), "UTF-8"));
    6257      JsonObject jsonall = Json.createReader(br).readObject();
    6358
     
    9590            finalImages.remove(img);
    9691        }
    97 
    98         LOCK.lock();
    99         MapillaryAbstractImage.LOCK.lock();
    100         try {
    101           for (MapillaryImage img : finalImages) {
    102             if (this.layer.getData().getImages().contains(img)) {
    103               // The image in finalImages is substituted by the one in the
    104               // database, as they represent the same picture.
    105               img = (MapillaryImage) this.layer.getData().getImages()
    106                   .get(this.layer.getData().getImages().indexOf(img));
    107               sequence.add(img);
    108               ((MapillaryImage) this.layer.getData().getImages()
    109                   .get(this.layer.getData().getImages().indexOf(img)))
    110                   .setSequence(sequence);
    111               finalImages.set(finalImages.indexOf(img), img);
    112             } else {
    113               img.setSequence(sequence);
    114               sequence.add(img);
     92        synchronized (this.getClass()) {
     93          synchronized (MapillaryAbstractImage.class) {
     94            for (MapillaryImage img : finalImages) {
     95              if (this.layer.getData().getImages().contains(img)) {
     96                // The image in finalImages is substituted by the one in the
     97                // database, as they represent the same picture.
     98                img = (MapillaryImage) this.layer.getData().getImages()
     99                    .get(this.layer.getData().getImages().indexOf(img));
     100                sequence.add(img);
     101                ((MapillaryImage) this.layer.getData().getImages()
     102                    .get(this.layer.getData().getImages().indexOf(img)))
     103                    .setSequence(sequence);
     104                finalImages.set(finalImages.indexOf(img), img);
     105              } else {
     106                img.setSequence(sequence);
     107                sequence.add(img);
     108              }
    115109            }
    116110          }
    117         } finally {
    118           MapillaryAbstractImage.LOCK.unlock();
    119           LOCK.unlock();
    120111        }
    121112
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r31473 r31514  
    8383    panel.add(this.moveTo);
    8484    this.login = new JButton(new LoginAction());
    85     if (Main.pref.get("mapillary.access-token") == null)
     85    if (MapillaryUser.getUsername() == null)
    8686      this.login.setText("Login");
    8787    else
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryUploadDialog.java

    r31511 r31514  
    66import javax.swing.ButtonGroup;
    77import javax.swing.JCheckBox;
     8import javax.swing.JLabel;
    89import javax.swing.JPanel;
    910import javax.swing.JRadioButton;
     
    1213import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    1314import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     15import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryUser;
    1416
    1517/**
     
    3335  public MapillaryUploadDialog() {
    3436    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
     37    if (MapillaryUser.getUsername() != null) {
     38      this.group = new ButtonGroup();
    3539
    36     this.group = new ButtonGroup();
     40      this.sequence = new JRadioButton(tr("Upload selected sequence"));
     41      if (MapillaryLayer.getInstance().getData().getSelectedImage() == null
     42          || !(MapillaryLayer.getInstance().getData().getSelectedImage() instanceof MapillaryImportedImage))
     43        this.sequence.setEnabled(false);
     44      this.group.add(this.sequence);
     45      add(this.sequence);
     46      this.group.setSelected(this.sequence.getModel(), true);
    3747
    38     this.sequence = new JRadioButton(tr("Upload selected sequence"));
    39     if (MapillaryLayer.getInstance().getData().getSelectedImage() == null
    40         || !(MapillaryLayer.getInstance().getData().getSelectedImage() instanceof MapillaryImportedImage))
    41       this.sequence.setEnabled(false);
    42     this.group.add(this.sequence);
    43     add(this.sequence);
    44     this.group.setSelected(this.sequence.getModel(), true);
    45 
    46     this.delete = new JCheckBox(tr("Delete after upload"));
    47     this.delete.setSelected(Main.pref.getBoolean(
    48         "mapillary.delete-after-upload", true));
    49     add(this.delete);
    50 
     48      this.delete = new JCheckBox(tr("Delete after upload"));
     49      this.delete.setSelected(Main.pref.getBoolean(
     50          "mapillary.delete-after-upload", true));
     51      add(this.delete);
     52    } else {
     53      this.add(new JLabel("Go to setting and log in to Mapillary before uploading."));
     54    }
    5155  }
    5256}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java

    r31512 r31514  
    6161        Main.error(e);
    6262        isTokenValid = false;
    63         isTokenValid = false;
    6463      }
    6564    hash.put("images_hash", images_hash);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoSignElement.java

    r31391 r31514  
    2020   */
    2121  public Color getColor() {
    22     return color;
     22    return this.color;
    2323  }
    2424
     
    2727   */
    2828  public char getGlyph() {
    29     return glyph;
     29    return this.glyph;
    3030  }
    3131}
Note: See TracChangeset for help on using the changeset viewer.