Changeset 31514 in osm for applications
- Timestamp:
- 2015-08-21T20:44:24+02:00 (9 years ago)
- 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 4 4 import java.util.Calendar; 5 5 import java.util.Date; 6 import java.util.concurrent.locks.Lock;7 import java.util.concurrent.locks.ReentrantLock;8 6 9 7 import org.openstreetmap.josm.Main; … … 18 16 */ 19 17 public abstract class MapillaryAbstractImage { 20 21 /**22 * Lock that locks {@link MapillaryAbstractImage#next()} and23 * {@link MapillaryAbstractImage#previous()} methods. Used when downloading24 * images to prevent concurrency problems.25 */26 public static final Lock LOCK = new ReentrantLock();27 18 28 19 /** The time the image was captured, in Epoch format. */ … … 205 196 */ 206 197 public MapillaryAbstractImage next() { 207 LOCK.lock(); 208 try { 209 if (this.getSequence() == null) { 198 synchronized (this.getClass()) { 199 if (this.getSequence() == null) 210 200 return null; 211 }212 201 return this.getSequence().next(this); 213 } finally {214 LOCK.unlock();215 202 } 216 203 } … … 223 210 */ 224 211 public MapillaryAbstractImage previous() { 225 LOCK.lock(); 226 try { 227 if (this.getSequence() == null) { 212 synchronized (this.getClass()) { 213 if (this.getSequence() == null) 228 214 return null; 229 }230 215 return this.getSequence().previous(this); 231 } finally { 232 LOCK.unlock(); 233 } 234 216 } 235 217 } 236 218 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryUploadAction.java
r31512 r31514 53 53 54 54 if (pane.getValue() != null 55 && (int) pane.getValue() == JOptionPane.OK_OPTION) { 55 && (int) pane.getValue() == JOptionPane.OK_OPTION 56 && dialog.delete != null) { 56 57 if (dialog.sequence.isSelected()) { 57 58 UploadUtils.uploadSequence(MapillaryLayer.getInstance().getData() -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java
r31502 r31514 2 2 3 3 import java.awt.image.BufferedImage; 4 import java.util.concurrent.locks.Lock;5 import java.util.concurrent.locks.ReentrantLock;6 4 7 5 import javax.swing.SwingUtilities; … … 24 22 private final int interval; 25 23 private final MapillaryData data; 26 private final Lock lock;27 24 private boolean end = false; 28 25 private final boolean waitForFullQuality; … … 53 50 this.data = MapillaryLayer.getInstance().getData(); 54 51 this.data.addListener(this); 55 this.lock = new ReentrantLock();56 52 } 57 53 … … 110 106 this.lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay 111 107 .getImage(); 112 this.lock.lock(); 113 try { 108 synchronized (this) { 114 109 if (this.goForward) 115 110 this.data.selectNext(this.followSelected); 116 111 else 117 112 this.data.selectPrevious(this.followSelected); 118 } finally {119 this.lock.unlock();120 113 } 121 114 } catch (InterruptedException e) { … … 130 123 131 124 @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(); 140 127 } 141 128 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31513 r31514 8 8 import java.util.List; 9 9 import java.util.concurrent.ExecutorService; 10 import java.util.concurrent.locks.Lock;11 import java.util.concurrent.locks.ReentrantLock;12 10 13 11 import javax.json.Json; … … 33 31 private static final String URL = MapillaryDownloader.BASE_URL + "search/s/"; 34 32 35 /** Lock to prevent multiple downloads to be imported at the same time. */36 private static final Lock LOCK = new ReentrantLock();37 38 33 private final String queryString; 39 34 private final ExecutorService ex; … … 58 53 try { 59 54 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")); 62 57 JsonObject jsonall = Json.createReader(br).readObject(); 63 58 … … 95 90 finalImages.remove(img); 96 91 } 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 } 115 109 } 116 110 } 117 } finally {118 MapillaryAbstractImage.LOCK.unlock();119 LOCK.unlock();120 111 } 121 112 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
r31473 r31514 83 83 panel.add(this.moveTo); 84 84 this.login = new JButton(new LoginAction()); 85 if (Ma in.pref.get("mapillary.access-token") == null)85 if (MapillaryUser.getUsername() == null) 86 86 this.login.setText("Login"); 87 87 else -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryUploadDialog.java
r31511 r31514 6 6 import javax.swing.ButtonGroup; 7 7 import javax.swing.JCheckBox; 8 import javax.swing.JLabel; 8 9 import javax.swing.JPanel; 9 10 import javax.swing.JRadioButton; … … 12 13 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 13 14 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 15 import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryUser; 14 16 15 17 /** … … 33 35 public MapillaryUploadDialog() { 34 36 setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); 37 if (MapillaryUser.getUsername() != null) { 38 this.group = new ButtonGroup(); 35 39 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); 37 47 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 } 51 55 } 52 56 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java
r31512 r31514 61 61 Main.error(e); 62 62 isTokenValid = false; 63 isTokenValid = false;64 63 } 65 64 hash.put("images_hash", images_hash); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoSignElement.java
r31391 r31514 20 20 */ 21 21 public Color getColor() { 22 return color;22 return this.color; 23 23 } 24 24 … … 27 27 */ 28 28 public char getGlyph() { 29 return glyph;29 return this.glyph; 30 30 } 31 31 }
Note:
See TracChangeset
for help on using the changeset viewer.