Changeset 31252 in osm for applications/editors
- Timestamp:
- 2015-06-08T21:52:34+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 4 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31249 r31252 23 23 public volatile static MapillaryData INSTANCE; 24 24 25 private final List<Mapillary Image> images;26 private Mapillary Image selectedImage;27 private final List<Mapillary Image> multiSelectedImages;25 private final List<MapillaryAbstractImage> images; 26 private MapillaryAbstractImage selectedImage; 27 private final List<MapillaryAbstractImage> multiSelectedImages; 28 28 29 29 public MapillaryData() { … … 46 46 * The set of images to be added. 47 47 */ 48 public synchronized void add(List<Mapillary Image> images) {49 for (Mapillary Image image : images) {48 public synchronized void add(List<MapillaryAbstractImage> images) { 49 for (MapillaryAbstractImage image : images) { 50 50 add(image); 51 51 } … … 58 58 * The image to be added. 59 59 */ 60 public synchronized void add(Mapillary Image image) {60 public synchronized void add(MapillaryAbstractImage image) { 61 61 if (!images.contains(image)) { 62 62 this.images.add(image); … … 72 72 * The set of images to be added. 73 73 */ 74 public synchronized void addWithoutUpdate(List<MapillaryImage> images) { 75 for (MapillaryImage image : images) { 74 public synchronized void addWithoutUpdate( 75 List<MapillaryAbstractImage> images) { 76 for (MapillaryAbstractImage image : images) { 76 77 addWithoutUpdate(image); 77 78 } … … 85 86 * The image to be added. 86 87 */ 87 public synchronized void addWithoutUpdate(Mapillary Image image) {88 public synchronized void addWithoutUpdate(MapillaryAbstractImage image) { 88 89 if (!images.contains(image)) { 89 90 this.images.add(image); … … 103 104 * @return A List object containing all images. 104 105 */ 105 public List<Mapillary Image> getImages() {106 public List<MapillaryAbstractImage> getImages() { 106 107 return images; 107 108 } … … 112 113 * @return The selected MapillaryImage object. 113 114 */ 114 public Mapillary Image getSelectedImage() {115 public MapillaryAbstractImage getSelectedImage() { 115 116 return selectedImage; 116 117 } … … 122 123 */ 123 124 public void selectNext() { 124 if (getSelectedImage() == null) 125 return; 126 if (getSelectedImage().getSequence() == null) 127 return; 128 setSelectedImage(getSelectedImage().next()); 125 if (getSelectedImage() instanceof MapillaryImage) { 126 if (getSelectedImage() == null) 127 return; 128 if (((MapillaryImage) getSelectedImage()).getSequence() == null) 129 return; 130 setSelectedImage(((MapillaryImage) getSelectedImage()).next()); 131 } 129 132 } 130 133 … … 134 137 */ 135 138 public void selectPrevious() { 136 if (getSelectedImage() == null) 137 return; 138 if (getSelectedImage().getSequence() == null) 139 throw new IllegalStateException(); 140 setSelectedImage(getSelectedImage().previous()); 139 if (getSelectedImage() instanceof MapillaryImage) { 140 if (getSelectedImage() == null) 141 return; 142 if (((MapillaryImage) getSelectedImage()).getSequence() == null) 143 throw new IllegalStateException(); 144 setSelectedImage(((MapillaryImage) getSelectedImage()).previous()); 145 } 141 146 } 142 147 … … 149 154 * The MapillaryImage which is going to be selected 150 155 */ 151 public void setSelectedImage(Mapillary Image image) {156 public void setSelectedImage(MapillaryAbstractImage image) { 152 157 selectedImage = image; 153 158 multiSelectedImages.clear(); … … 156 161 MapillaryToggleDialog.getInstance().setImage(selectedImage); 157 162 MapillaryToggleDialog.getInstance().updateImage(); 158 if (image.next() != null) { 159 new MapillaryCache(image.next().getKey(), 160 MapillaryCache.Type.THUMBNAIL).submit(this, false); 161 if (image.next().next() != null) 162 new MapillaryCache(image.next().next().getKey(), 163 if (image instanceof MapillaryImage) { 164 MapillaryImage mapillaryImage = (MapillaryImage) image; 165 if (mapillaryImage.next() != null) { 166 new MapillaryCache(mapillaryImage.next().getKey(), 163 167 MapillaryCache.Type.THUMBNAIL).submit(this, false); 164 } 165 if (image.previous() != null) { 166 new MapillaryCache(image.previous().getKey(), 167 MapillaryCache.Type.THUMBNAIL).submit(this, false); 168 if (image.previous().previous() != null) 169 new MapillaryCache(image.previous().previous().getKey(), 168 if (mapillaryImage.next().next() != null) 169 new MapillaryCache(mapillaryImage.next().next() 170 .getKey(), MapillaryCache.Type.THUMBNAIL) 171 .submit(this, false); 172 } 173 if (mapillaryImage.previous() != null) { 174 new MapillaryCache(mapillaryImage.previous().getKey(), 170 175 MapillaryCache.Type.THUMBNAIL).submit(this, false); 176 if (mapillaryImage.previous().previous() != null) 177 new MapillaryCache(mapillaryImage.previous().previous() 178 .getKey(), MapillaryCache.Type.THUMBNAIL) 179 .submit(this, false); 180 } 171 181 } 172 182 } … … 183 193 * The MapillaryImage object to be added. 184 194 */ 185 public void addMultiSelectedImage(Mapillary Image image) {195 public void addMultiSelectedImage(MapillaryAbstractImage image) { 186 196 if (!this.multiSelectedImages.contains(image)) { 187 197 if (this.getSelectedImage() != null) … … 198 208 * @param images 199 209 */ 200 public void addMultiSelectedImage(List<Mapillary Image> images) {201 for (Mapillary Image image : images)210 public void addMultiSelectedImage(List<MapillaryAbstractImage> images) { 211 for (MapillaryAbstractImage image : images) 202 212 if (!this.multiSelectedImages.contains(image)) { 203 213 if (this.getSelectedImage() != null) … … 215 225 * @return 216 226 */ 217 public List<Mapillary Image> getMultiSelectedImages() {227 public List<MapillaryAbstractImage> getMultiSelectedImages() { 218 228 return multiSelectedImages; 219 229 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java
r31222 r31252 1 1 package org.openstreetmap.josm.plugins.mapillary; 2 2 3 import org.openstreetmap.josm.data.coor.LatLon;4 3 5 4 /** … … 10 9 * @see MapillaryData 11 10 */ 12 public class MapillaryImage {11 public class MapillaryImage extends MapillaryAbstractImage { 13 12 /** Unique identifier of the object */ 14 13 private final String key; 15 /** Postion of the picture */16 public final LatLon latLon;17 /** Direction of the picture */18 private final double ca;19 14 /** Sequence of pictures containing this */ 20 15 private MapillarySequence sequence; 21 22 private boolean isModified = false;23 /** Temporal position of the picture until it is uplaoded */24 public LatLon tempLatLon;25 /**26 * When the object is being dragged in the map, the temporal position is27 * stored here28 */29 public LatLon movingLatLon;30 /** Temporal direction of the picture until it is uplaoded */31 private double tempCa;32 /**33 * When the object direction is being moved in the map, the temporal34 * direction is stored here35 */36 private double movingCa;37 16 38 17 /** … … 49 28 */ 50 29 public MapillaryImage(String key, double lat, double lon, double ca) { 30 super(lat, lon, ca); 51 31 this.key = key; 52 this.latLon = new LatLon(lat, lon);53 this.tempLatLon = this.latLon;54 this.movingLatLon = this.latLon;55 this.ca = ca;56 this.tempCa = ca;57 this.movingCa = ca;58 }59 60 /**61 * Returns whether the object has been modified or not.62 *63 * @return true if the object has been modified; false otherwise.64 */65 public boolean isModified() {66 return this.isModified;67 }68 69 /**70 * Returns a LatLon object containing the coordintes of the object.71 *72 * @return The LatLon object with the position of the object.73 */74 public LatLon getLatLon() {75 return movingLatLon;76 }77 78 public LatLon getTempLatLon() {79 return tempLatLon;80 }81 82 /**83 * Moves the image temporally to another position84 *85 * @param pos86 */87 public void move(double x, double y) {88 this.movingLatLon = new LatLon(this.tempLatLon.getY() + y,89 this.tempLatLon.getX() + x);90 this.isModified = true;91 }92 93 /**94 * Turns the image direction.95 *96 * @param ca97 */98 public void turn(double ca) {99 this.movingCa = this.tempCa + ca;100 this.isModified = true;101 }102 103 /**104 * Called when the mouse button is released, meaning that the picture has105 * stopped being dragged.106 */107 public void stopMoving() {108 this.tempLatLon = this.movingLatLon;109 this.tempCa = this.movingCa;110 }111 112 /**113 * Returns the direction towards the image has been taken.114 *115 * @return The direction of the image (0 means north and goes clockwise).116 */117 public double getCa() {118 return movingCa;119 }120 121 /**122 * Returns the last fixed direction of the object.123 * @return124 */125 public double getTempCa() {126 return tempCa;127 32 } 128 33 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31249 r31252 107 107 download(); 108 108 Main.map.mapView.setActiveLayer(this); 109 Main.map.repaint(); 109 110 } 110 111 … … 125 126 .getInstance()) 126 127 return; 127 MapillaryImage closest = getClosest(e.getPoint()); 128 if (e.getClickCount() == 2 129 && mapillaryData.getSelectedImage() != null 130 && closest != null) { 131 for (MapillaryImage img : closest.getSequence().getImages()) { 132 mapillaryData.addMultiSelectedImage(img); 128 MapillaryAbstractImage closestTemp = getClosest(e.getPoint()); 129 if (closestTemp instanceof MapillaryImage || closestTemp == null) { 130 MapillaryImage closest = (MapillaryImage) closestTemp; 131 if (e.getClickCount() == 2 132 && mapillaryData.getSelectedImage() != null 133 && closest != null) { 134 for (MapillaryAbstractImage img : closest.getSequence() 135 .getImages()) { 136 mapillaryData.addMultiSelectedImage(img); 137 } 133 138 } 134 } 135 this.start = e.getPoint(); 136 this.lastClicked = this.closest; 137 this.closest = closest; 138 if (mapillaryData.getMultiSelectedImages().contains(closest)) 139 return; 140 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) 141 && closest != null) 142 mapillaryData.addMultiSelectedImage(closest); 143 else if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK)) { 144 if (this.closest != null 145 && this.lastClicked != null 146 && this.closest.getSequence() == this.lastClicked 147 .getSequence()) { 148 int i = this.closest.getSequence().getImages() 149 .indexOf(this.closest); 150 int j = this.lastClicked.getSequence().getImages() 151 .indexOf(this.lastClicked); 152 if (i < j) 153 mapillaryData.addMultiSelectedImage(this.closest 154 .getSequence().getImages() 155 .subList(i, j + 1)); 156 else 157 mapillaryData.addMultiSelectedImage(this.closest 158 .getSequence().getImages() 159 .subList(j, i + 1)); 160 } 161 } else 162 mapillaryData.setSelectedImage(closest); 163 } 164 165 private MapillaryImage getClosest(Point clickPoint) { 139 this.start = e.getPoint(); 140 this.lastClicked = this.closest; 141 this.closest = closest; 142 if (mapillaryData.getMultiSelectedImages() 143 .contains(closest)) 144 return; 145 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) 146 && closest != null) 147 mapillaryData.addMultiSelectedImage(closest); 148 else if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK)) { 149 if (this.closest != null 150 && this.lastClicked != null 151 && this.closest.getSequence() == this.lastClicked 152 .getSequence()) { 153 int i = this.closest.getSequence().getImages() 154 .indexOf(this.closest); 155 int j = this.lastClicked.getSequence().getImages() 156 .indexOf(this.lastClicked); 157 if (i < j) 158 mapillaryData 159 .addMultiSelectedImage(new ArrayList<MapillaryAbstractImage>( 160 this.closest.getSequence() 161 .getImages() 162 .subList(i, j + 1))); 163 else 164 mapillaryData 165 .addMultiSelectedImage(new ArrayList<MapillaryAbstractImage>( 166 this.closest.getSequence() 167 .getImages() 168 .subList(j, i + 1))); 169 } 170 } else 171 mapillaryData.setSelectedImage(closest); 172 } 173 } 174 175 private MapillaryAbstractImage getClosest(Point clickPoint) { 166 176 double snapDistance = 10; 167 177 double minDistance = Double.MAX_VALUE; 168 Mapillary Image closest = null;169 for (Mapillary Image image : mapillaryData.getImages()) {178 MapillaryAbstractImage closest = null; 179 for (MapillaryAbstractImage image : mapillaryData.getImages()) { 170 180 Point imagePoint = Main.map.mapView.getPoint(image 171 181 .getLatLon()); … … 193 203 LatLon from = Main.map.mapView.getLatLon(start.getX(), 194 204 start.getY()); 195 for (Mapillary Image img : MapillaryData.getInstance()196 .get MultiSelectedImages()) {205 for (MapillaryAbstractImage img : MapillaryData 206 .getInstance().getMultiSelectedImages()) { 197 207 img.move(to.getX() - from.getX(), 198 208 to.getY() - from.getY()); … … 204 214 (e.getX() - start.x), -(e.getY() - start.y))) 205 215 - closest.getTempCa()); 206 for (Mapillary Image img : MapillaryData.getInstance()207 .get MultiSelectedImages()) {216 for (MapillaryAbstractImage img : MapillaryData 217 .getInstance().getMultiSelectedImages()) { 208 218 img.turn(Math.toDegrees(Math.atan2( 209 219 (e.getX() - start.x), -(e.getY() - start.y))) … … 234 244 to.getY() - from.getY())); 235 245 } 236 for (Mapillary Image img : mapillaryData246 for (MapillaryAbstractImage img : mapillaryData 237 247 .getMultiSelectedImages()) { 238 248 if (img != null) … … 285 295 MapillaryData.INSTANCE = null; 286 296 Main.map.mapView.removeMouseListener(mouseAdapter); 297 Main.map.mapView.removeMouseMotionListener(mouseAdapter); 287 298 MapView.removeEditLayerChangeListener(this); 288 299 if (Main.map.mapView.getEditLayer() != null) … … 296 307 @Override 297 308 public boolean isModified() { 298 for (Mapillary Image image : mapillaryData.getImages())309 for (MapillaryAbstractImage image : mapillaryData.getImages()) 299 310 if (image.isModified()) 300 311 return true; … … 337 348 } 338 349 g.setColor(Color.WHITE); 339 for (MapillaryImage image : mapillaryData.getImages()) { 340 Point p = mv.getPoint(image.getLatLon()); 341 Point nextp; 342 if (image.getSequence() != null 343 && image.getSequence().next(image) != null) { 344 nextp = mv.getPoint(image.getSequence().next(image) 345 .getLatLon()); 346 g.drawLine(p.x, p.y, nextp.x, nextp.y); 347 } 348 ImageIcon icon; 349 if (!mapillaryData.getMultiSelectedImages().contains(image)) 350 icon = MapillaryPlugin.MAP_ICON; 351 else 352 icon = MapillaryPlugin.MAP_ICON_SELECTED; 353 Image imagetemp = icon.getImage(); 354 BufferedImage bi = (BufferedImage) imagetemp; 355 int width = icon.getIconWidth(); 356 int height = icon.getIconHeight(); 357 358 // Rotate the image 359 double rotationRequired = Math.toRadians(image.getCa()); 360 double locationX = width / 2; 361 double locationY = height / 2; 362 AffineTransform tx = AffineTransform.getRotateInstance( 363 rotationRequired, locationX, locationY); 364 AffineTransformOp op = new AffineTransformOp(tx, 365 AffineTransformOp.TYPE_BILINEAR); 366 367 g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y 368 - (height / 2), Main.map.mapView); 350 for (MapillaryAbstractImage imageAbs : mapillaryData.getImages()) { 351 Point p = mv.getPoint(imageAbs.getLatLon()); 352 if (imageAbs instanceof MapillaryImage) { 353 MapillaryImage image = (MapillaryImage) imageAbs; 354 Point nextp; 355 if (image.getSequence() != null 356 && image.getSequence().next(image) != null) { 357 nextp = mv.getPoint(image.getSequence().next(image) 358 .getLatLon()); 359 g.drawLine(p.x, p.y, nextp.x, nextp.y); 360 } 361 ImageIcon icon; 362 if (!mapillaryData.getMultiSelectedImages().contains(image)) 363 icon = MapillaryPlugin.MAP_ICON; 364 else 365 icon = MapillaryPlugin.MAP_ICON_SELECTED; 366 Image imagetemp = icon.getImage(); 367 BufferedImage bi = (BufferedImage) imagetemp; 368 int width = icon.getIconWidth(); 369 int height = icon.getIconHeight(); 370 371 // Rotate the image 372 double rotationRequired = Math.toRadians(image.getCa()); 373 double locationX = width / 2; 374 double locationY = height / 2; 375 AffineTransform tx = AffineTransform.getRotateInstance( 376 rotationRequired, locationX, locationY); 377 AffineTransformOp op = new AffineTransformOp(tx, 378 AffineTransformOp.TYPE_BILINEAR); 379 380 g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y 381 - (height / 2), Main.map.mapView); 382 } else if (imageAbs instanceof MapillaryImportedImage) { 383 MapillaryImportedImage image = (MapillaryImportedImage) imageAbs; 384 ImageIcon icon; 385 if (!mapillaryData.getMultiSelectedImages().contains(image)) 386 icon = MapillaryPlugin.MAP_ICON_IMPORTED; 387 else 388 icon = MapillaryPlugin.MAP_ICON_SELECTED; 389 Image imagetemp = icon.getImage(); 390 BufferedImage bi = (BufferedImage) imagetemp; 391 int width = icon.getIconWidth(); 392 int height = icon.getIconHeight(); 393 394 // Rotate the image 395 double rotationRequired = Math.toRadians(image.getCa()); 396 double locationX = width / 2; 397 double locationY = height / 2; 398 AffineTransform tx = AffineTransform.getRotateInstance( 399 rotationRequired, locationX, locationY); 400 AffineTransformOp op = new AffineTransformOp(tx, 401 AffineTransformOp.TYPE_BILINEAR); 402 403 g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y 404 - (height / 2), Main.map.mapView); 405 } 369 406 } 370 407 } … … 397 434 398 435 private MapillaryImage[] getClosestImagesFromDifferentSequences() { 436 if (!(mapillaryData.getSelectedImage() instanceof MapillaryImage)) 437 return new MapillaryImage[2]; 438 MapillaryImage selected = (MapillaryImage) mapillaryData 439 .getSelectedImage(); 399 440 MapillaryImage[] ret = new MapillaryImage[2]; 400 441 double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE, 401 442 SEQUENCE_MAX_JUMP_DISTANCE }; 402 443 LatLon selectedCoords = mapillaryData.getSelectedImage().getLatLon(); 403 for (MapillaryImage image : mapillaryData.getImages()) { 444 for (MapillaryAbstractImage imagePrev : mapillaryData.getImages()) { 445 if (!(imagePrev instanceof MapillaryImage)) 446 continue; 447 MapillaryImage image = (MapillaryImage) imagePrev; 404 448 if (image.getLatLon().greatCircleDistance(selectedCoords) < SEQUENCE_MAX_JUMP_DISTANCE 405 && mapillaryData.getSelectedImage().getSequence() != image 406 .getSequence()) { 449 && selected.getSequence() != image.getSequence()) { 407 450 if ((ret[0] == null && ret[1] == null) 408 451 || (image.getLatLon().greatCircleDistance( … … 516 559 @Override 517 560 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 518 if (newLayer == this) 519 Main.map.statusLine.setHelpText("Total images: " 520 + MapillaryData.getInstance().getImages().size()); 561 if (newLayer == this) { 562 if (MapillaryData.getInstance().getImages().size() > 0) 563 Main.map.statusLine.setHelpText(tr("Total images: ") 564 + MapillaryData.getInstance().getImages().size()); 565 else 566 Main.map.statusLine.setHelpText(tr("No images found")); 567 } 568 521 569 } 522 570 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
r31251 r31252 29 29 * 30 30 */ 31 public class MapillaryPlugin extends Plugin implements EditLayerChangeListener {31 public class MapillaryPlugin extends Plugin implements EditLayerChangeListener { 32 32 33 33 public static final ImageIcon ICON24 = new ImageProvider("icon24.png") … … 39 39 public static final ImageIcon MAP_ICON_SELECTED = new ImageProvider( 40 40 "mapiconselected.png").get(); 41 public static final ImageIcon MAP_ICON_IMPORTED = new ImageProvider( 42 "mapiconimported.png").get(); 41 43 public static final int ICON_SIZE = 24; 42 44 … … 45 47 private final MapillaryDownloadAction downloadAction; 46 48 private final MapillaryExportAction exportAction; 49 private final MapillaryImportAction importAction; 47 50 48 51 public static JMenuItem DOWNLOAD_MENU; 49 52 public static JMenuItem EXPORT_MENU; 53 public static JMenuItem IMPORT_MENU; 50 54 51 55 public MapillaryPlugin(PluginInformation info) { … … 53 57 downloadAction = new MapillaryDownloadAction(); 54 58 exportAction = new MapillaryExportAction(); 59 importAction = new MapillaryImportAction(); 55 60 56 61 DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu, … … 58 63 EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, exportAction, 59 64 false, 14); 65 IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction, 66 false, 14); 67 60 68 EXPORT_MENU.setEnabled(false); 61 69 DOWNLOAD_MENU.setEnabled(false); 62 70 IMPORT_MENU.setEnabled(false); 71 63 72 MapView.addEditLayerChangeListener(this); 64 73 try { … … 85 94 menu.setEnabled(value); 86 95 } 87 96 88 97 @Override 89 98 public PreferenceSetting getPreferenceSetting() { … … 93 102 @Override 94 103 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 95 if (oldLayer == null && newLayer != null) 96 DOWNLOAD_MENU.setEnabled(true); 97 else if (oldLayer != null && newLayer == null) 104 if (oldLayer == null && newLayer != null) { 105 DOWNLOAD_MENU.setEnabled(true); 106 IMPORT_MENU.setEnabled(true); 107 } else if (oldLayer != null && newLayer == null) { 98 108 DOWNLOAD_MENU.setEnabled(false); 109 IMPORT_MENU.setEnabled(false); 110 } 99 111 } 100 112 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadAction.java
r31251 r31252 27 27 public MapillaryDownloadAction() { 28 28 super(tr("Mapillary"), new ImageProvider("icon24.png"), 29 tr("Create Mapillary layer ."), Shortcut.registerShortcut(30 " menu:Mapillary", tr("Menu: {0}", tr("Mapillary")),29 tr("Create Mapillary layer"), Shortcut.registerShortcut( 30 "Mapillary", tr("Start Mapillary layer"), 31 31 KeyEvent.VK_M, Shortcut.ALT_CTRL_SHIFT), false, 32 32 "mapillaryDownload", false); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java
r31251 r31252 5 5 import java.awt.Dimension; 6 6 import java.awt.event.ActionEvent; 7 import java.awt.event.KeyEvent; 7 8 import java.util.ArrayList; 8 9 import java.util.List; … … 13 14 import org.openstreetmap.josm.Main; 14 15 import org.openstreetmap.josm.actions.JosmAction; 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 15 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 16 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; … … 18 20 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryExportDialog; 19 21 import org.openstreetmap.josm.tools.ImageProvider; 22 import org.openstreetmap.josm.tools.Shortcut; 20 23 21 24 /** … … 30 33 31 34 public MapillaryExportAction() { 32 super(tr("Export images"), new ImageProvider("icon24.png"), 33 tr("Export images."), null, false, "mapillaryExport", false); 35 super(tr("Export pictures"), new ImageProvider("icon24.png"), 36 tr("Export pictures"), Shortcut.registerShortcut( 37 "Export Mapillary", tr("Export Mapillary pictures"), 38 KeyEvent.VK_M, Shortcut.NONE), false, "mapillaryExport", false); 34 39 } 35 40 … … 50 55 export(MapillaryData.getInstance().getImages()); 51 56 } else if (dialog.group.isSelected(dialog.sequence.getModel())) { 52 ArrayList<MapillaryImage> images = new ArrayList<>(); 53 for (MapillaryImage image : MapillaryData.getInstance().getMultiSelectedImages()) 54 if (!images.contains(image)) 55 images.addAll(image.getSequence().getImages()); 57 ArrayList<MapillaryAbstractImage> images = new ArrayList<>(); 58 for (MapillaryAbstractImage image : MapillaryData.getInstance().getMultiSelectedImages()) 59 if (image instanceof MapillaryImage) { 60 if (!images.contains(image)) 61 images.addAll(((MapillaryImage) image).getSequence().getImages()); 62 } 63 else 64 images.add(image); 56 65 export(images); 57 66 } else if (dialog.group.isSelected(dialog.selected.getModel())) { … … 65 74 * Exports the given images from the database. 66 75 */ 67 public void export(List<Mapillary Image> images) {76 public void export(List<MapillaryAbstractImage> images) { 68 77 Main.worker.submit(new Thread(new MapillaryExportManager(images, 69 78 dialog.chooser.getSelectedFile().toString()))); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java
r31245 r31252 5 5 6 6 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.plugins.mapillary.Mapillary Image;7 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 8 8 9 9 /** … … 14 14 */ 15 15 public class CommandMoveImage extends MapillaryCommand { 16 private List<Mapillary Image> images;16 private List<MapillaryAbstractImage> images; 17 17 private double x; 18 18 private double y; 19 19 20 public CommandMoveImage(List<Mapillary Image> images, double x, double y) {20 public CommandMoveImage(List<MapillaryAbstractImage> images, double x, double y) { 21 21 this.images = new ArrayList<>(images); 22 22 this.x = x; … … 26 26 @Override 27 27 public void undo() { 28 for (Mapillary Image image : images) {28 for (MapillaryAbstractImage image : images) { 29 29 image.move(-x, -y); 30 30 image.stopMoving(); … … 35 35 @Override 36 36 public void redo() { 37 for (Mapillary Image image : images) {37 for (MapillaryAbstractImage image : images) { 38 38 image.move(x, y); 39 39 image.stopMoving(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java
r31245 r31252 5 5 6 6 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.plugins.mapillary.Mapillary Image;7 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 8 8 9 9 /** … … 14 14 */ 15 15 public class CommandTurnImage extends MapillaryCommand { 16 private List<Mapillary Image> images;16 private List<MapillaryAbstractImage> images; 17 17 private double ca; 18 18 19 public CommandTurnImage(List<Mapillary Image> images, double ca) {19 public CommandTurnImage(List<MapillaryAbstractImage> images, double ca) { 20 20 this.images = new ArrayList<>(images); 21 21 this.ca = ca; … … 24 24 @Override 25 25 public void undo() { 26 for (Mapillary Image image : images) {26 for (MapillaryAbstractImage image : images) { 27 27 image.turn(-ca); 28 28 image.stopMoving(); … … 33 33 @Override 34 34 public void redo() { 35 for (Mapillary Image image : images) {35 for (MapillaryAbstractImage image : images) { 36 36 image.turn(ca); 37 37 image.stopMoving(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportDownloadThread.java
r31185 r31252 13 13 import org.openstreetmap.josm.data.cache.ICachedLoaderListener; 14 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 15 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 16 17 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; … … 28 29 String url; 29 30 ArrayBlockingQueue<BufferedImage> queue; 30 ArrayBlockingQueue<Mapillary Image> queueImages;31 ArrayBlockingQueue<MapillaryAbstractImage> queueImages; 31 32 32 33 ProgressMonitor monitor; … … 35 36 public MapillaryExportDownloadThread(MapillaryImage image, 36 37 ArrayBlockingQueue<BufferedImage> queue, 37 ArrayBlockingQueue<Mapillary Image> queueImages) {38 ArrayBlockingQueue<MapillaryAbstractImage> queueImages) { 38 39 url = "https://d1cuyjsrcm0gby.cloudfront.net/" + image.getKey() 39 40 + "/thumb-2048.jpg"; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportManager.java
r31177 r31252 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.image.BufferedImage; 5 6 import java.io.IOException; … … 13 14 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 14 15 import org.openstreetmap.josm.io.OsmTransferException; 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 15 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 16 18 import org.xml.sax.SAXException; … … 30 32 31 33 ArrayBlockingQueue<BufferedImage> queue; 32 ArrayBlockingQueue<Mapillary Image> queueImages;34 ArrayBlockingQueue<MapillaryAbstractImage> queueImages; 33 35 34 List<Mapillary Image> images;36 List<MapillaryAbstractImage> images; 35 37 String path; 36 38 37 public MapillaryExportManager(List<Mapillary Image> images, String path) {39 public MapillaryExportManager(List<MapillaryAbstractImage> images, String path) { 38 40 super(tr("Downloading") + "...", new PleaseWaitProgressMonitor( 39 41 "Exporting Mapillary Images"), true); … … 59 61 ThreadPoolExecutor ex = new ThreadPoolExecutor(20, 35, 25, 60 62 TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); 61 for (MapillaryImage image : images) { 62 try { 63 ex.execute(new MapillaryExportDownloadThread(image, queue, 64 queueImages)); 65 } catch (Exception e) { 66 Main.error(e); 63 for (MapillaryAbstractImage image : images) { 64 if (image instanceof MapillaryImage) { 65 try { 66 ex.execute(new MapillaryExportDownloadThread((MapillaryImage) image, queue, 67 queueImages)); 68 } catch (Exception e) { 69 Main.error(e); 70 } 71 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) { 77 Main.error(e); 78 } 67 79 } 68 try { 69 // If the queue is full, waits for it to have more space 70 // available before executing anything else. 71 while (ex.getQueue().remainingCapacity() == 0) 72 Thread.sleep(100); 73 } catch (Exception e) { 74 Main.error(e); 80 else { 81 //TODO 75 82 } 76 83 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportWriterThread.java
r31183 r31252 18 18 import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; 19 19 import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; 20 21 20 import org.openstreetmap.josm.Main; 22 21 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 23 22 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 23 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 24 24 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 25 25 … … 34 34 private final String path; 35 35 private final ArrayBlockingQueue<BufferedImage> queue; 36 private final ArrayBlockingQueue<Mapillary Image> queueImages;36 private final ArrayBlockingQueue<MapillaryAbstractImage> queueImages; 37 37 private final int amount; 38 38 private final ProgressMonitor monitor; … … 40 40 public MapillaryExportWriterThread(String path, 41 41 ArrayBlockingQueue<BufferedImage> queue, 42 ArrayBlockingQueue<Mapillary Image> queueImages, int amount,42 ArrayBlockingQueue<MapillaryAbstractImage> queueImages, int amount, 43 43 ProgressMonitor monitor) { 44 44 this.path = path; … … 54 54 File tempFile = null; 55 55 BufferedImage img; 56 Mapillary Image mimg = null;56 MapillaryAbstractImage mimg = null; 57 57 String finalPath = ""; 58 58 for (int i = 0; i < amount; i++) { … … 60 60 img = queue.take(); 61 61 mimg = queueImages.take(); 62 finalPath = path + "/" + mimg.getKey(); 62 if (mimg instanceof MapillaryImage) 63 finalPath = path + "/" + ((MapillaryImage) mimg).getKey(); 64 else 65 finalPath = path + "/" + i; 63 66 // Creates a temporal file that is going to be deleted after 64 67 // writing the EXIF tags. -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31245 r31252 16 16 import org.openstreetmap.josm.Main; 17 17 import org.openstreetmap.josm.data.Bounds; 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 18 19 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 19 20 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; … … 78 79 break; 79 80 MapillarySequence sequence = new MapillarySequence(jsonobj.getString("key"), jsonobj.getJsonNumber("captured_at").intValue()); 80 for (MapillaryImage mimage : MapillaryData.getInstance().getImages()) 81 if (mimage.getSequence().getKey().equals(sequence.getKey())) 81 for (MapillaryAbstractImage mimage : MapillaryData.getInstance().getImages()) 82 if (mimage instanceof MapillaryImage 83 && ((MapillaryImage) mimage).getSequence().getKey().equals(sequence.getKey())) 82 84 break; 83 85 int first = -1; … … 87 89 // Here it gets only those images which are in the downloaded 88 90 // area. 89 for (Mapillary Image img : images) {91 for (MapillaryAbstractImage img : images) { 90 92 if (first == -1 && bounds.contains(img.getLatLon())) 91 93 first = pos; … … 106 108 img.setSequence(sequence); 107 109 } 108 MapillaryData.getInstance().addWithoutUpdate( finalImages);110 MapillaryData.getInstance().addWithoutUpdate(new ArrayList<MapillaryAbstractImage>(finalImages)); 109 111 sequence.add(finalImages); 110 112 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31248 r31252 1 1 package org.openstreetmap.josm.plugins.mapillary.downloads; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 2 4 3 5 import java.util.concurrent.ThreadPoolExecutor; … … 34 36 Main.map.statusLine.setHelpText("Downloading images from Mapillary"); 35 37 downloadSequences(); 36 Main.map.statusLine.setHelpText("Total images: " + MapillaryData.getInstance().getImages().size()); 38 if (MapillaryData.getInstance().getImages().size() > 0) 39 Main.map.statusLine.setHelpText(tr("Total images: ") 40 + MapillaryData.getInstance().getImages().size()); 41 else 42 Main.map.statusLine.setHelpText(tr("No images found")); 37 43 } 38 44 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadThread.java
r31176 r31252 13 13 14 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 15 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 16 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; … … 42 43 } 43 44 JsonArray jsonarr = jsonobj.getJsonArray("ims"); 44 ArrayList<Mapillary Image> images = new ArrayList<>();45 ArrayList<MapillaryAbstractImage> images = new ArrayList<>(); 45 46 JsonObject image; 46 47 for (int i = 0; i < jsonarr.size(); i++) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java
r31251 r31252 17 17 18 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 19 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 19 20 20 21 /** … … 53 54 // Some options are disabled depending on the circumstances 54 55 if (MapillaryData.getInstance().getSelectedImage() == null 55 || MapillaryData.getInstance().getSelectedImage().getSequence() == null) { 56 || (MapillaryData.getInstance().getSelectedImage() instanceof MapillaryImage && ((MapillaryImage) MapillaryData 57 .getInstance().getSelectedImage()).getSequence() == null)) { 56 58 sequence.setEnabled(false); 57 59 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryToggleDialog.java
r31251 r31252 21 21 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 22 22 import org.openstreetmap.josm.gui.SideButton; 23 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 23 24 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 24 25 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; … … 42 43 public static MapillaryToggleDialog INSTANCE; 43 44 44 public volatile Mapillary Image image;45 public volatile MapillaryAbstractImage image; 45 46 46 47 final SideButton nextButton = new SideButton(new nextPictureAction()); … … 108 109 if (this.image == null) 109 110 return; 110 this.nextButton.setEnabled(true); 111 this.previousButton.setEnabled(true); 112 if (this.image.next() == null) 113 this.nextButton.setEnabled(false); 114 if (this.image.previous() == null) 115 this.previousButton.setEnabled(false); 116 117 mapillaryImageDisplay.hyperlink.setURL(image.getKey()); 118 this.mapillaryImageDisplay.setImage(null); 119 if (thumbnailCache != null) 120 thumbnailCache.cancelOutstandingTasks(); 121 thumbnailCache = new MapillaryCache(image.getKey(), 122 MapillaryCache.Type.THUMBNAIL); 123 thumbnailCache.submit(this, false); 124 125 if (imageCache != null) 126 imageCache.cancelOutstandingTasks(); 127 imageCache = new MapillaryCache(image.getKey(), 128 MapillaryCache.Type.FULL_IMAGE); 129 imageCache.submit(this, false); 130 111 if (image instanceof MapillaryImage) { 112 this.nextButton.setEnabled(true); 113 this.previousButton.setEnabled(true); 114 MapillaryImage mapillaryImage = (MapillaryImage) this.image; 115 if (mapillaryImage.next() == null) 116 this.nextButton.setEnabled(false); 117 if (mapillaryImage.previous() == null) 118 this.previousButton.setEnabled(false); 119 120 mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey()); 121 this.mapillaryImageDisplay.setImage(null); 122 if (thumbnailCache != null) 123 thumbnailCache.cancelOutstandingTasks(); 124 thumbnailCache = new MapillaryCache(mapillaryImage.getKey(), 125 MapillaryCache.Type.THUMBNAIL); 126 thumbnailCache.submit(this, false); 127 128 if (imageCache != null) 129 imageCache.cancelOutstandingTasks(); 130 imageCache = new MapillaryCache(mapillaryImage.getKey(), 131 MapillaryCache.Type.FULL_IMAGE); 132 imageCache.submit(this, false); 133 } 131 134 } 132 135 } … … 137 140 * @param image 138 141 */ 139 public synchronized void setImage(Mapillary Image image) {142 public synchronized void setImage(MapillaryAbstractImage image) { 140 143 this.image = image; 141 144 } … … 146 149 * @return 147 150 */ 148 public synchronized Mapillary Image getImage() {151 public synchronized MapillaryAbstractImage getImage() { 149 152 return this.image; 150 153 } … … 201 204 public redAction() { 202 205 putValue(NAME, tr("Jump to red")); 203 putValue(SHORT_DESCRIPTION, 206 putValue( 207 SHORT_DESCRIPTION, 204 208 tr("Jumps to the picture at the other side of the red line")); 205 209 } … … 222 226 public blueAction() { 223 227 putValue(NAME, tr("Jump to blue")); 224 putValue(SHORT_DESCRIPTION, 228 putValue( 229 SHORT_DESCRIPTION, 225 230 tr("Jumps to the picture at the other side of the blue line")); 226 231 }
Note:
See TracChangeset
for help on using the changeset viewer.