Changeset 31256 in osm for applications/editors
- Timestamp:
- 2015-06-09T18:27:24+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 2 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImage.java
r31255 r31256 103 103 return tempCa; 104 104 } 105 106 @Override107 public boolean equals(Object object) {108 if (object instanceof MapillaryAbstractImage)109 return this.getLatLon().equalsEpsilon(((MapillaryAbstractImage) object).getLatLon());110 return false;111 }112 113 @Override114 public int hashCode() {115 return this.getLatLon().hashCode();116 }117 105 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java
r31255 r31256 1 1 package org.openstreetmap.josm.plugins.mapillary; 2 3 2 4 3 /** … … 88 87 return this.getSequence().previous(this); 89 88 } 89 90 @Override 91 public boolean equals(Object object) { 92 if (object instanceof MapillaryImage) 93 return this.key.equals(((MapillaryImage) object).getKey()); 94 return false; 95 } 96 97 @Override 98 public int hashCode() { 99 return this.key.hashCode(); 100 } 90 101 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java
r31254 r31256 9 9 public class MapillaryImportedImage extends MapillaryAbstractImage { 10 10 11 pr ivateFile file;12 11 protected File file; 12 13 13 public MapillaryImportedImage(double lat, double lon, double ca, File file) { 14 14 super(lat, lon, ca); 15 15 this.file = file; 16 16 } 17 17 18 18 public BufferedImage getImage() throws IOException { 19 19 return ImageIO.read(file); 20 20 } 21 22 @Override 23 public boolean equals(Object object) { 24 if (object instanceof MapillaryImportedImage) 25 return this.file.equals(((MapillaryImportedImage) object).file); 26 return false; 27 } 28 29 @Override 30 public int hashCode() { 31 return this.file.hashCode(); 32 } 21 33 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31255 r31256 300 300 LatLon selectedCoords = mapillaryData.getSelectedImage().getLatLon(); 301 301 for (MapillaryAbstractImage imagePrev : mapillaryData.getImages()) { 302 if (!(imagePrev instanceof MapillaryIm portedImage))302 if (!(imagePrev instanceof MapillaryImage)) 303 303 continue; 304 304 MapillaryImage image = (MapillaryImage) imagePrev; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java
r31219 r31256 22 22 } 23 23 24 25 24 /** 26 25 * Returns all MapillaryImages objects contained by this object. … … 31 30 return this.images; 32 31 } 33 34 32 35 33 public int getCreatedAt() { … … 45 43 this.images.add(image); 46 44 } 47 45 48 46 public String getKey() { 49 47 return this.key; … … 56 54 */ 57 55 public synchronized void add(List<MapillaryImage> images) { 58 for (MapillaryImage image : images) {56 for (MapillaryImage image : images) 59 57 add(image); 60 }61 58 } 62 59 … … 80 77 throw new IllegalArgumentException(); 81 78 int i = images.indexOf(image); 82 if (i == images.size() - 1) {79 if (i == images.size() - 1) 83 80 return null; 84 }else81 else 85 82 return images.get(i + 1); 86 83 } … … 96 93 throw new IllegalArgumentException(); 97 94 int i = images.indexOf(image); 98 if (i == 0) {95 if (i == 0) 99 96 return null; 100 }else97 else 101 98 return images.get(i - 1); 102 99 } … … 116 113 - this.images.indexOf(image2)); 117 114 } 118 115 119 116 @Override 120 117 public boolean equals(Object obj) { … … 123 120 return false; 124 121 } 125 122 126 123 @Override 127 124 public int hashCode() { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
r31255 r31256 30 30 31 31 public JFileChooser chooser; 32 33 private int noTagsPics = 0; 32 34 33 35 public MapillaryImportAction() { … … 69 71 Main.error(ex); 70 72 } 71 } 72 else if (file.getPath().substring(file.getPath().length() - 4)73 } else if (file.getPath() 74 .substring(file.getPath().length() - 4) 73 75 .equals(".png")) { 74 76 readPNG(file); … … 97 99 double lonValue = 0; 98 100 double caValue = 0; 99 if (lat.getValue() instanceof RationalNumber[]) 101 if (lat != null && lat.getValue() instanceof RationalNumber[]) 100 102 latValue = DegMinSecToDouble((RationalNumber[]) lat.getValue(), 101 103 lat_ref.getValue().toString()); 102 if (lon.getValue() instanceof RationalNumber[]) 104 if (lon != null && lon.getValue() instanceof RationalNumber[]) 103 105 lonValue = DegMinSecToDouble((RationalNumber[]) lon.getValue(), 104 106 lon_ref.getValue().toString()); 105 if (ca.getValue() instanceof RationalNumber) 107 if (ca != null && ca.getValue() instanceof RationalNumber) 106 108 caValue = ((RationalNumber) ca.getValue()).doubleValue(); 107 109 if (lat_ref.getValue().toString().equals("S")) … … 114 116 file)); 115 117 } else { 116 LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon( 117 Main.map.mapView.getCenter()); 118 MapillaryData.getInstance().add( 119 new MapillaryImportedImage(pos.lat(), pos.lon(), 0, 120 file)); 118 readNoTags(file); 121 119 } 122 120 } 123 121 } 124 125 private void readPNG(File file) { 122 123 private void readNoTags(File file) { 124 double HORIZONTAL_DISTANCE = 0.0001; 125 double horDev; 126 if (noTagsPics % 2 == 0) 127 horDev = HORIZONTAL_DISTANCE * noTagsPics / 2; 128 else 129 horDev = -HORIZONTAL_DISTANCE * (noTagsPics + 1) / 2; 126 130 LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon( 127 131 Main.map.mapView.getCenter()); 128 132 MapillaryData.getInstance().add( 129 new MapillaryImportedImage(pos.lat(), pos.lon(), 0, 130 file)); 133 new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file)); 134 noTagsPics++; 135 } 136 137 private void readPNG(File file) { 138 readNoTags(file); 131 139 } 132 140 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java
r31252 r31256 1 1 package org.openstreetmap.josm.plugins.mapillary.commands; 2 2 3 import static org.openstreetmap.josm.tools.I18n.trn; 3 4 import java.util.ArrayList; 4 5 import java.util.List; … … 41 42 Main.map.repaint(); 42 43 } 44 45 public String toString() { 46 return trn("Moved {0} node", "Moved {0} nodes", images.size(), images.size()); 47 } 43 48 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java
r31252 r31256 1 1 package org.openstreetmap.josm.plugins.mapillary.commands; 2 3 import static org.openstreetmap.josm.tools.I18n.trn; 2 4 3 5 import java.util.ArrayList; … … 40 42 } 41 43 44 public String toString() { 45 return trn("Turned {0} node", "Moved {0} nodes", images.size(), images.size()); 46 } 42 47 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportManager.java
r31252 r31256 16 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 17 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 18 19 import org.xml.sax.SAXException; 19 20 … … 37 38 String path; 38 39 39 public MapillaryExportManager(List<MapillaryAbstractImage> images, String path) { 40 public MapillaryExportManager(List<MapillaryAbstractImage> images, 41 String path) { 40 42 super(tr("Downloading") + "...", new PleaseWaitProgressMonitor( 41 43 "Exporting Mapillary Images"), true); … … 64 66 if (image instanceof MapillaryImage) { 65 67 try { 66 ex.execute(new MapillaryExportDownloadThread( (MapillaryImage) image, queue,67 queueImages)); 68 ex.execute(new MapillaryExportDownloadThread( 69 (MapillaryImage) image, queue, queueImages)); 68 70 } catch (Exception e) { 69 71 Main.error(e); 70 72 } 73 } else if (image instanceof MapillaryImportedImage) { 71 74 try { 72 // If the queue is full, waits for it to have more space 73 // available before executing anything else. 74 while (ex.getQueue().remainingCapacity() == 0) 75 Thread.sleep(100); 76 } catch (Exception e) { 75 queue.put(((MapillaryImportedImage) image).getImage()); 76 queueImages.put((MapillaryImportedImage) image); 77 } catch (InterruptedException e) { 77 78 Main.error(e); 78 79 } 79 80 } 80 else { 81 //TODO 81 try { 82 // If the queue is full, waits for it to have more space 83 // available before executing anything else. 84 while (ex.getQueue().remainingCapacity() == 0) 85 Thread.sleep(100); 86 } catch (Exception e) { 87 Main.error(e); 82 88 } 83 89 } 84 90 try { 85 91 writer.join(); 86 } catch (Exception e) { 92 } catch (InterruptedException e) { 87 93 Main.error(e); 88 94 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportWriterThread.java
r31252 r31256 91 91 Main.error(e); 92 92 } catch (ImageWriteException e) { 93 // TODO Auto-generated catch block 94 e.printStackTrace(); 93 Main.error(e); 95 94 } catch (ImageReadException e) { 96 // TODO Auto-generated catch block 97 e.printStackTrace(); 95 Main.error(e); 98 96 } 99 97 … … 103 101 } 104 102 } 105 106 103 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31252 r31256 49 49 JsonObject jsonall = Json.createReader(br).readObject(); 50 50 51 if (!jsonall.getBoolean("more") && !ex.isShutdown()) {51 if (!jsonall.getBoolean("more") && !ex.isShutdown()) 52 52 ex.shutdown(); 53 }54 53 JsonArray jsonseq = jsonall.getJsonArray("ss"); 55 54 // At the moment there is a bug with some sequences at Mapillay API, … … 72 71 Main.warn("Mapillary bug at " + url); 73 72 isSequenceWrong = true; 74 } catch (Exception e) {75 Main.error(e);76 73 } 77 74 } 78 75 if (isSequenceWrong) 79 76 break; 80 MapillarySequence sequence = new MapillarySequence(jsonobj.getString("key"), jsonobj.getJsonNumber("captured_at").intValue()); 81 for (MapillaryAbstractImage mimage : MapillaryData.getInstance().getImages()) 77 MapillarySequence sequence = new MapillarySequence( 78 jsonobj.getString("key"), jsonobj.getJsonNumber( 79 "captured_at").intValue()); 80 for (MapillaryAbstractImage mimage : MapillaryData 81 .getInstance().getImages()) 82 82 if (mimage instanceof MapillaryImage 83 && ((MapillaryImage) mimage).getSequence().getKey().equals(sequence.getKey())) 83 && ((MapillaryImage) mimage).getSequence().getKey() 84 .equals(sequence.getKey())) 84 85 break; 85 86 int first = -1; … … 108 109 img.setSequence(sequence); 109 110 } 110 MapillaryData.getInstance().addWithoutUpdate(new ArrayList<MapillaryAbstractImage>(finalImages)); 111 MapillaryData.getInstance().addWithoutUpdate( 112 new ArrayList<MapillaryAbstractImage>(finalImages)); 111 113 sequence.add(finalImages); 112 114 } 113 115 } catch (IOException e) { 114 Main.error("Error reading the url " + url + " might be a Mapillary problem."); 116 Main.error("Error reading the url " + url 117 + " might be a Mapillary problem."); 115 118 } 116 119 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31252 r31256 27 27 private final Bounds bounds; 28 28 29 public MapillarySquareDownloadManagerThread(String urlImages, String urlSequences, Bounds bounds) { 29 public MapillarySquareDownloadManagerThread(String urlImages, 30 String urlSequences, Bounds bounds) { 30 31 this.urlImages = urlImages; 31 32 this.urlSequences = urlSequences; … … 35 36 public void run() { 36 37 Main.map.statusLine.setHelpText("Downloading images from Mapillary"); 37 downloadSequences(); 38 try { 39 downloadSequences(); 40 } catch (InterruptedException e) { 41 Main.error(e); 42 } 38 43 if (MapillaryData.getInstance().getImages().size() > 0) 39 44 Main.map.statusLine.setHelpText(tr("Total images: ") … … 43 48 } 44 49 45 public void downloadSequences() { 50 public void downloadSequences() throws InterruptedException { 46 51 ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, 47 52 TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5)); 48 53 int page = 0; 49 54 while (!ex.isShutdown()) { 50 ex.execute(new MapillarySequenceDownloadThread(ex, 51 urlSequences + "&page=" + page + "&limit=1", bounds)); 52 try { 53 while (ex.getQueue().remainingCapacity() == 0) 54 Thread.sleep(100); 55 } catch (Exception e) { 56 Main.error(e); 57 } 55 ex.execute(new MapillarySequenceDownloadThread(ex, urlSequences 56 + "&page=" + page + "&limit=1", bounds)); 57 while (ex.getQueue().remainingCapacity() == 0) 58 Thread.sleep(100); 58 59 page++; 59 60 } 60 try { 61 while (!ex.awaitTermination(15, TimeUnit.SECONDS)) { 62 } 63 } catch (Exception e) { 64 Main.error(e); 65 } 61 ex.awaitTermination(15, TimeUnit.SECONDS); 66 62 MapillaryData.getInstance().dataUpdated(); 67 63 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadThread.java
r31252 r31256 2 2 3 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.net.MalformedURLException; 4 6 import java.net.URL; 5 7 import java.io.InputStreamReader; … … 35 37 public void run() { 36 38 try { 37 BufferedReader br; 38 br = new BufferedReader(new InputStreamReader( 39 BufferedReader br = new BufferedReader(new InputStreamReader( 39 40 new URL(url).openStream())); 40 41 JsonObject jsonobj = Json.createReader(br).readObject(); 41 if (!jsonobj.getBoolean("more")) {42 if (!jsonobj.getBoolean("more")) 42 43 ex.shutdownNow(); 43 }44 44 JsonArray jsonarr = jsonobj.getJsonArray("ims"); 45 45 ArrayList<MapillaryAbstractImage> images = new ArrayList<>(); … … 57 57 } 58 58 MapillaryData.getInstance().add(images); 59 } catch (Exception e) { 59 } catch (MalformedURLException e) { 60 Main.error(e); 61 } catch (IOException e) { 60 62 Main.error(e); 61 63 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java
r31251 r31256 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Cursor; 5 6 import java.awt.event.ActionEvent; … … 14 15 import javax.swing.SwingUtilities; 15 16 17 import org.openstreetmap.josm.Main; 18 16 19 import java.awt.Desktop; 17 20 18 21 public class HyperlinkLabel extends JLabel implements ActionListener { 19 22 20 /**21 * The normal text set by the user.22 */23 23 private String text; 24 25 24 private URL url; 26 25 … … 44 43 } 45 44 45 /** 46 * Sets a new URL, just pass the key of the image or null if there is none. 47 * 48 * @param key 49 */ 46 50 public void setURL(String key) { 51 if (key == null) { 52 this.url = null; 53 return; 54 } 47 55 try { 48 56 this.url = new URL("http://www.mapillary.com/map/im/" + key); 49 57 } catch (MalformedURLException e) { 50 // TODO Auto-generated catch block 51 e.printStackTrace(); 58 Main.error(e); 52 59 } 53 60 } … … 56 63 * Returns the text set by the user. 57 64 */ 58 59 65 public String getNormalText() { 60 66 return text; … … 64 70 * Processes mouse events and responds to clicks. 65 71 */ 66 67 72 protected void processMouseEvent(MouseEvent evt) { 68 73 super.processMouseEvent(evt); … … 76 81 * when the label is clicked. 77 82 */ 78 79 83 public void addActionListener(ActionListener listener) { 80 84 listenerList.add(ActionListener.class, listener); … … 85 89 * notifications when the label is clicked. 86 90 */ 87 88 91 public void removeActionListener(ActionListener listener) { 89 92 listenerList.remove(ActionListener.class, listener); … … 93 96 * Fires an ActionEvent to all interested listeners. 94 97 */ 95 96 98 protected void fireActionPerformed(ActionEvent evt) { 97 99 Object[] listeners = listenerList.getListenerList(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java
r31252 r31256 28 28 29 29 protected JOptionPane optionPane; 30 / /Button to export all downloaded images.30 /** Button to export all downloaded images. */ 31 31 public JRadioButton all; 32 // Button to export all images in the sequence of the selected 33 // MapillaryImage. 32 /** 33 * Button to export all images in the sequence of the selected 34 * MapillaryImage. 35 */ 34 36 public JRadioButton sequence; 35 // Button to export all images belonging to the selected MapillaryImage 36 // objects. 37 /** 38 * Button to export all images belonging to the selected MapillaryImage 39 * objects. 40 */ 37 41 public JRadioButton selected; 38 42 public ButtonGroup group; … … 78 82 add(path); 79 83 add(choose); 80 81 84 } 82 85 … … 98 101 } 99 102 } 100 101 103 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java
r31249 r31256 42 42 */ 43 43 private Rectangle visibleRect = null; 44 44 45 /** 45 46 * When a selection is done, the rectangle of the selection (in image -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
r31251 r31256 23 23 @Override 24 24 public void addGui(PreferenceTabbedPane gui) { 25 // TODO Auto-generated method stub26 25 JPanel panel = new JPanel(); 27 26 … … 42 41 @Override 43 42 public boolean isExpert() { 44 // TODO Auto-generated method stub45 43 return false; 46 44 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryToggleDialog.java
r31255 r31256 65 65 mapillaryImageDisplay = new MapillaryImageDisplay(); 66 66 67 // this.add(mapillaryImageDisplay);68 67 blueButton.setForeground(Color.BLUE); 69 68 redButton.setForeground(Color.RED); … … 82 81 83 82 public static MapillaryToggleDialog getInstance() { 84 if (INSTANCE == null) {83 if (INSTANCE == null) 85 84 INSTANCE = new MapillaryToggleDialog(); 86 }87 85 return INSTANCE; 88 86 } … … 142 140 Main.error(e); 143 141 } 142 mapillaryImageDisplay.hyperlink.setURL(null); 144 143 } 145 144 } … … 281 280 } 282 281 } catch (IOException e) { 283 e.printStackTrace();282 Main.error(e); 284 283 } 285 284 } … … 306 305 FlowLayout.LEFT) : new GridLayout(1, buttons.size())); 307 306 buttonsPanel.add(buttonRowPanel); 308 for (SideButton button : buttons) {307 for (SideButton button : buttons) 309 308 buttonRowPanel.add(button); 310 }311 309 if (reverse) 312 310 top.add(buttonsPanel, BorderLayout.SOUTH);
Note:
See TracChangeset
for help on using the changeset viewer.