Changeset 31445 in osm for applications/editors/josm/plugins/mapillary
- Timestamp:
- 2015-08-04T11:35:15+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 3 added
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImage.java
r31415 r31445 88 88 */ 89 89 public LatLon getLatLon() { 90 return movingLatLon;90 return this.movingLatLon; 91 91 } 92 92 … … 97 97 */ 98 98 public boolean isVisible() { 99 return visible;99 return this.visible; 100 100 } 101 101 … … 116 116 */ 117 117 public LatLon getTempLatLon() { 118 return t empLatLon;118 return this.tempLatLon; 119 119 } 120 120 … … 159 159 */ 160 160 public double getCa() { 161 return movingCa;161 return this.movingCa; 162 162 } 163 163 … … 168 168 */ 169 169 public double getTempCa() { 170 return t empCa;170 return this.tempCa; 171 171 } 172 172 … … 195 195 * 196 196 * @param capturedAt 197 * Epoch time when the image was captured. 197 198 */ 198 199 public void setCapturedAt(long capturedAt) { … … 206 207 */ 207 208 public long getCapturedAt() { 208 return capturedAt;209 return this.capturedAt; 209 210 } 210 211 … … 212 213 * Returns the date the picture was taken in the given format. 213 214 * 214 * @param format 215 * @param format Format of the date. See {@link SimpleDateFormat}. 215 216 * @return A String containing the date the picture was taken using the given 216 217 * format. … … 233 234 * @return The date in Epoch format. 234 235 */ 235 public long getEpoch(String date, String format) {236 public static long getEpoch(String date, String format) { 236 237 237 238 SimpleDateFormat formatter = new SimpleDateFormat(format); … … 250 251 * @return The current date in Epoch format. 251 252 */ 252 private long currentTime() {253 private static long currentTime() { 253 254 Calendar cal = Calendar.getInstance(); 254 255 return cal.getTimeInMillis(); … … 271 272 */ 272 273 public MapillarySequence getSequence() { 274 if (this.sequence == null) { 275 this.sequence = new MapillarySequence(); 276 this.sequence.add(this); 277 } 278 273 279 return this.sequence; 274 280 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31418 r31445 20 20 /** Unique instance of the class */ 21 21 public volatile static MapillaryData INSTANCE; 22 /** Enable this if you are using in Unit Tests */23 public static boolean TEST_MODE = false;24 22 25 23 private final List<MapillaryAbstractImage> images; … … 35 33 */ 36 34 private MapillaryData() { 37 images = new CopyOnWriteArrayList<>();38 multiSelectedImages = new ArrayList<>();39 selectedImage = null;35 this.images = new CopyOnWriteArrayList<>(); 36 this.multiSelectedImages = new ArrayList<>(); 37 this.selectedImage = null; 40 38 41 39 addListener(MapillaryPlugin.walkAction); … … 88 86 */ 89 87 public void addListener(MapillaryDataListener lis) { 90 listeners.add(lis);88 this.listeners.add(lis); 91 89 } 92 90 … … 98 96 */ 99 97 public void removeListener(MapillaryDataListener lis) { 100 listeners.remove(lis);98 this.listeners.remove(lis); 101 99 } 102 100 … … 124 122 */ 125 123 public void setHighlightedImage(MapillaryAbstractImage image) { 126 highlightedImage = image;124 this.highlightedImage = image; 127 125 } 128 126 … … 133 131 */ 134 132 public MapillaryAbstractImage getHighlighted() { 135 return highlightedImage;133 return this.highlightedImage; 136 134 } 137 135 … … 146 144 */ 147 145 public synchronized void add(MapillaryAbstractImage image, boolean update) { 148 if (! images.contains(image)) {146 if (!this.images.contains(image)) { 149 147 this.images.add(image); 150 148 } … … 157 155 * Repaints mapView object. 158 156 */ 159 public synchronized void dataUpdated() {160 if ( !TEST_MODE)157 public synchronized static void dataUpdated() { 158 if (Main.main != null) 161 159 Main.map.mapView.repaint(); 162 160 } … … 168 166 */ 169 167 public List<MapillaryAbstractImage> getImages() { 170 return images;168 return this.images; 171 169 } 172 170 … … 177 175 */ 178 176 public MapillaryAbstractImage getSelectedImage() { 179 return selectedImage;177 return this.selectedImage; 180 178 } 181 179 182 180 private void fireImagesAdded() { 183 if (listeners.isEmpty()) 184 return; 185 for (MapillaryDataListener lis : listeners) 186 lis.imagesAdded(); 181 if (this.listeners.isEmpty()) 182 return; 183 for (MapillaryDataListener lis : this.listeners) 184 if (lis != null) 185 lis.imagesAdded(); 187 186 } 188 187 … … 197 196 if (getSelectedImage().getSequence() == null) 198 197 return; 199 MapillaryAbstractImage tempImage = selectedImage;198 MapillaryAbstractImage tempImage = this.selectedImage; 200 199 while (tempImage.next() != null) { 201 200 tempImage = tempImage.next(); … … 221 220 if (getSelectedImage().getSequence() == null) 222 221 return; 223 MapillaryAbstractImage tempImage = selectedImage;222 MapillaryAbstractImage tempImage = this.selectedImage; 224 223 while (tempImage.next() != null) { 225 224 tempImage = tempImage.next(); … … 241 240 if (getSelectedImage().getSequence() == null) 242 241 throw new IllegalStateException(); 243 MapillaryAbstractImage tempImage = selectedImage;242 MapillaryAbstractImage tempImage = this.selectedImage; 244 243 while (tempImage.previous() != null) { 245 244 tempImage = tempImage.previous(); … … 265 264 if (getSelectedImage().getSequence() == null) 266 265 throw new IllegalStateException(); 267 MapillaryAbstractImage tempImage = selectedImage;266 MapillaryAbstractImage tempImage = this.selectedImage; 268 267 while (tempImage.previous() != null) { 269 268 tempImage = tempImage.previous(); … … 295 294 */ 296 295 public void setSelectedImage(MapillaryAbstractImage image, boolean zoom) { 297 MapillaryAbstractImage oldImage = selectedImage;298 selectedImage = image;299 multiSelectedImages.clear();300 multiSelectedImages.add(image);296 MapillaryAbstractImage oldImage = this.selectedImage; 297 this.selectedImage = image; 298 this.multiSelectedImages.clear(); 299 this.multiSelectedImages.add(image); 301 300 if (image != null) { 302 301 if (image instanceof MapillaryImage) { … … 320 319 Main.map.mapView.zoomTo(MapillaryData.getInstance().getSelectedImage() 321 320 .getLatLon()); 322 if (Main.ma p!= null)321 if (Main.main != null) 323 322 Main.map.mapView.repaint(); 324 fireSelectedImageChanged(oldImage, selectedImage);323 fireSelectedImageChanged(oldImage, this.selectedImage); 325 324 } 326 325 327 326 private void fireSelectedImageChanged(MapillaryAbstractImage oldImage, 328 327 MapillaryAbstractImage newImage) { 329 if (listeners.isEmpty()) 330 return; 331 for (MapillaryDataListener lis : listeners) 332 lis.selectedImageChanged(oldImage, newImage); 328 if (this.listeners.isEmpty()) 329 return; 330 for (MapillaryDataListener lis : this.listeners) 331 if (lis != null) 332 lis.selectedImageChanged(oldImage, newImage); 333 333 } 334 334 … … 375 375 */ 376 376 public List<MapillaryAbstractImage> getMultiSelectedImages() { 377 return multiSelectedImages;377 return this.multiSelectedImages; 378 378 } 379 379 … … 384 384 */ 385 385 public int size() { 386 return images.size();386 return this.images.size(); 387 387 } 388 388 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java
r31409 r31445 27 27 */ 28 28 public String getLocation() { 29 return location;29 return this.location; 30 30 } 31 31 … … 34 34 * 35 35 * @param location 36 * A String object containing the place where the image was taken. 36 37 */ 37 38 public void setLocation(String location) { … … 73 74 */ 74 75 public void addSign(String sign) { 75 signs.add(sign);76 this.signs.add(sign); 76 77 } 77 78 … … 82 83 */ 83 84 public List<String> getSigns() { 84 return signs;85 return this.signs; 85 86 } 86 87 … … 102 103 */ 103 104 public String getUser() { 104 return user;105 return this.user; 105 106 } 106 107 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java
r31410 r31445 63 63 * Returns the pictures of the file. 64 64 * 65 * @return A BufferedImage object containing the picture, 66 * or null if the{@link File} given in the constructor was null.65 * @return A BufferedImage object containing the picture, or null if the 66 * {@link File} given in the constructor was null. 67 67 * @throws IOException 68 * If the file parameter of the object isn't an image. 68 69 */ 69 70 public BufferedImage getImage() throws IOException { 70 return file == null ? null : ImageIO.read(file);71 return this.file == null ? null : ImageIO.read(this.file); 71 72 } 72 73 … … 77 78 */ 78 79 public File getFile() { 79 return file;80 return this.file; 80 81 } 81 82 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31422 r31445 98 98 private MapillaryLayer() { 99 99 super(tr("Mapillary Images")); 100 data = MapillaryData.getInstance();101 bounds = new CopyOnWriteArrayList<>();100 this.data = MapillaryData.getInstance(); 101 this.bounds = new CopyOnWriteArrayList<>(); 102 102 init(); 103 103 } … … 109 109 if (INSTANCE == null) 110 110 INSTANCE = this; 111 if (Main.ma p!= null && Main.map.mapView != null) {111 if (Main.main != null && Main.map.mapView != null) { 112 112 setMode(new SelectMode()); 113 113 Main.map.mapView.addLayer(this); … … 119 119 MapillaryDownloader.automaticDownload(); 120 120 if (MapillaryDownloader.getMode() == MapillaryDownloader.SEMIAUTOMATIC) 121 mode.zoomChanged();121 this.mode.zoomChanged(); 122 122 } 123 123 if (MapillaryPlugin.EXPORT_MENU != null) { // Does not execute when in … … 128 128 } 129 129 createHatchTexture(); 130 data.dataUpdated(); 130 if (Main.main != null) 131 MapillaryData.dataUpdated(); 131 132 } 132 133 … … 171 172 */ 172 173 public MapillaryData getMapillaryData() { 173 return data;174 return this.data; 174 175 } 175 176 … … 183 184 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, false); 184 185 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.ZOOM_MENU, false); 185 Main.map.mapView.removeMouseListener( mode);186 Main.map.mapView.removeMouseMotionListener( mode);186 Main.map.mapView.removeMouseListener(this.mode); 187 Main.map.mapView.removeMouseMotionListener(this.mode); 187 188 MapView.removeEditLayerChangeListener(this); 188 189 if (Main.map.mapView.getEditLayer() != null) … … 209 210 double maxLat = -90; 210 211 double maxLon = -180; 211 for (MapillaryAbstractImage img : data.getImages()) {212 for (MapillaryAbstractImage img : this.data.getImages()) { 212 213 if (img.getLatLon().lat() < minLat) 213 214 minLat = img.getLatLon().lat(); … … 225 226 @Override 226 227 public boolean isModified() { 227 for (MapillaryAbstractImage image : data.getImages())228 for (MapillaryAbstractImage image : this.data.getImages()) 228 229 if (image.isModified()) 229 230 return true; … … 234 235 public void setVisible(boolean visible) { 235 236 super.setVisible(visible); 236 for (MapillaryAbstractImage img : data.getImages())237 for (MapillaryAbstractImage img : this.data.getImages()) 237 238 img.setVisible(visible); 238 239 MapillaryFilterDialog.getInstance().refresh(); … … 244 245 * @return background color for downloaded areas. Black by default 245 246 */ 246 private Color getBackgroundColor() {247 private static Color getBackgroundColor() { 247 248 return Main.pref.getColor(marktr("background"), Color.BLACK); 248 249 } … … 253 254 * @return background color for non-downloaded areas. Yellow by default 254 255 */ 255 private Color getOutsideColor() {256 private static Color getOutsideColor() { 256 257 return Main.pref.getColor(marktr("outside downloaded area"), Color.YELLOW); 257 258 } … … 270 271 big.drawLine(0, 15, 15, 0); 271 272 Rectangle r = new Rectangle(0, 0, 15, 15); 272 hatched = new TexturePaint(bi, r);273 this.hatched = new TexturePaint(bi, r); 273 274 } 274 275 … … 291 292 } 292 293 // paint remainder 293 g.setPaint( hatched);294 g.setPaint(this.hatched); 294 295 g.fill(a); 295 296 } … … 302 303 303 304 // Sets blue and red lines and enables/disables the buttons 304 if ( data.getSelectedImage() != null) {305 if (this.data.getSelectedImage() != null) { 305 306 MapillaryImage[] closestImages = getClosestImagesFromDifferentSequences(); 306 Point selected = mv.getPoint( data.getSelectedImage().getLatLon());307 Point selected = mv.getPoint(this.data.getSelectedImage().getLatLon()); 307 308 if (closestImages[0] != null) { 308 309 MapillaryLayer.BLUE = closestImages[0]; … … 321 322 } 322 323 g.setColor(Color.WHITE); 323 for (MapillaryAbstractImage imageAbs : data.getImages()) {324 for (MapillaryAbstractImage imageAbs : this.data.getImages()) { 324 325 if (!imageAbs.isVisible()) 325 326 continue; … … 344 345 MapillaryImage image = (MapillaryImage) imageAbs; 345 346 ImageIcon icon; 346 if (! data.getMultiSelectedImages().contains(image))347 if (!this.data.getMultiSelectedImages().contains(image)) 347 348 icon = MapillaryPlugin.MAP_ICON; 348 349 else … … 357 358 MapillaryImportedImage image = (MapillaryImportedImage) imageAbs; 358 359 ImageIcon icon; 359 if (! data.getMultiSelectedImages().contains(image))360 if (!this.data.getMultiSelectedImages().contains(image)) 360 361 icon = MapillaryPlugin.MAP_ICON_IMPORTED; 361 362 else … … 364 365 } 365 366 } 366 if ( mode instanceof JoinMode) {367 mode.paint(g, mv, box);367 if (this.mode instanceof JoinMode) { 368 this.mode.paint(g, mv, box); 368 369 } 369 370 } … … 382 383 highlightColor.getGreen(), highlightColor.getBlue(), 100); 383 384 g.setColor(highlightColorTransparent); 384 int s = size + highlightPointRadius;385 int s = size + this.highlightPointRadius; 385 386 while (s >= size) { 386 387 int r = (int) Math.floor(s / 2d); 387 388 g.fillRoundRect(p.x - r, p.y - r, s, s, r, r); 388 s -= highlightStep;389 s -= this.highlightStep; 389 390 } 390 391 g.setColor(oldColor); … … 418 419 g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2), 419 420 Main.map.mapView); 420 if ( data.getHighlighted() == image) {421 if (this.data.getHighlighted() == image) { 421 422 drawPointHighlight(g, p, 16); 422 423 } … … 455 456 */ 456 457 private MapillaryImage[] getClosestImagesFromDifferentSequences() { 457 if (!( data.getSelectedImage() instanceof MapillaryImage))458 if (!(this.data.getSelectedImage() instanceof MapillaryImage)) 458 459 return new MapillaryImage[2]; 459 MapillaryImage selected = (MapillaryImage) data.getSelectedImage();460 MapillaryImage selected = (MapillaryImage) this.data.getSelectedImage(); 460 461 MapillaryImage[] ret = new MapillaryImage[2]; 461 462 double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE, 462 463 SEQUENCE_MAX_JUMP_DISTANCE }; 463 LatLon selectedCoords = data.getSelectedImage().getLatLon();464 for (MapillaryAbstractImage imagePrev : data.getImages()) {464 LatLon selectedCoords = this.data.getSelectedImage().getLatLon(); 465 for (MapillaryAbstractImage imagePrev : this.data.getImages()) { 465 466 if (!(imagePrev instanceof MapillaryImage)) 466 467 continue; … … 498 499 sb.append(tr("Total images:")); 499 500 sb.append(" "); 500 sb.append( data.size());501 sb.append(this.data.size()); 501 502 sb.append("\n"); 502 503 return sb.toString(); … … 505 506 @Override 506 507 public String getToolTipText() { 507 return data.size() + " " + tr("images");508 return this.data.size() + " " + tr("images"); 508 509 } 509 510 … … 519 520 } 520 521 521 /**522 * When more data is downloaded, a delayed update is thrown, in order to wait523 * for the data bounds to be set.524 *525 * @param event526 */527 522 @Override 528 523 public void dataChanged(DataChangedEvent event) { 524 // When more data is downloaded, a delayed update is thrown, in order to 525 // wait for the data bounds to be set. 529 526 Main.worker.submit(new delayedDownload()); 530 527 } … … 607 604 public void updateHelpText() { 608 605 String ret = ""; 609 if ( data.size() > 0)610 ret += tr("Total images: {0}", data.size());606 if (this.data.size() > 0) 607 ret += tr("Total images: {0}", this.data.size()); 611 608 else 612 609 ret += tr("No images found"); 613 if ( mode != null)614 ret += " -- " + tr( mode.toString());610 if (this.mode != null) 611 ret += " -- " + tr(this.mode.toString()); 615 612 Main.map.statusLine.setHelpText(ret); 616 613 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
r31425 r31445 59 59 /** Walk action */ 60 60 public static MapillaryWalkAction walkAction; 61 private final MapillaryUploadAction uploadAction; 61 62 62 63 /** Menu button for the {@link MapillaryDownloadAction} action. */ … … 76 77 /** Menu button for the {@link MapillaryWalkAction} action. */ 77 78 public static JMenuItem WALK_MENU; 79 /** Menu button for the {@link MapillaryUploadAction} action. */ 80 public static JMenuItem UPLOAD_MENU; 78 81 79 82 /** … … 81 84 * 82 85 * @param info 86 * Required information of the plugin. Obtained from the jar file. 83 87 */ 84 88 public MapillaryPlugin(PluginInformation info) { … … 92 96 MAP_SIGN = new ImageProvider("sign.png").get(); 93 97 94 downloadAction = new MapillaryDownloadAction();98 this.downloadAction = new MapillaryDownloadAction(); 95 99 walkAction = new MapillaryWalkAction(); 96 exportAction = new MapillaryExportAction();100 this.exportAction = new MapillaryExportAction(); 97 101 importAction = new MapillaryImportAction(); 98 zoomAction = new MapillaryZoomAction(); 99 downloadViewAction = new MapillaryDownloadViewAction(); 100 importIntoSequenceAction = new MapillaryImportIntoSequenceAction(); 101 joinAction = new MapillaryJoinAction(); 102 this.zoomAction = new MapillaryZoomAction(); 103 this.downloadViewAction = new MapillaryDownloadViewAction(); 104 this.importIntoSequenceAction = new MapillaryImportIntoSequenceAction(); 105 this.joinAction = new MapillaryJoinAction(); 106 this.uploadAction = new MapillaryUploadAction(); 102 107 103 108 if (Main.main != null) { // important for headless mode 104 DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu, downloadAction,105 false);106 EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, exportAction, false,107 14);109 DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu, 110 this.downloadAction, false); 111 EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, this.exportAction, 112 false, 14); 108 113 IMPORT_INTO_SEQUENCE_MENU = MainMenu.add(Main.main.menu.fileMenu, 109 importIntoSequenceAction, false, 14);114 this.importIntoSequenceAction, false, 14); 110 115 IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction, false, 111 116 14); 112 ZOOM_MENU = MainMenu.add(Main.main.menu.viewMenu, zoomAction, false, 15); 117 UPLOAD_MENU = MainMenu.add(Main.main.menu.fileMenu, this.uploadAction, 118 false, 14); 119 ZOOM_MENU = MainMenu.add(Main.main.menu.viewMenu, this.zoomAction, false, 120 15); 113 121 DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu, 114 downloadViewAction, false, 14);115 JOIN_MENU = MainMenu.add(Main.main.menu.dataMenu, joinAction, false);122 this.downloadViewAction, false, 14); 123 JOIN_MENU = MainMenu.add(Main.main.menu.dataMenu, this.joinAction, false); 116 124 WALK_MENU = MainMenu.add(Main.main.menu.moreToolsMenu, walkAction, false); 117 125 … … 182 190 * 183 191 * @param s 184 * @return A ImageProvider object for the given string or null if in headless mode. 192 * The name of the file where the picture is. 193 * @return A ImageProvider object for the given string or null if in headless 194 * mode. 185 195 */ 186 196 public static ImageProvider getProvider(String s) { 187 if (Main.ma p== null)197 if (Main.main == null) 188 198 return null; 189 199 else -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java
r31387 r31445 55 55 */ 56 56 public long getCreatedAt() { 57 return created_at;57 return this.created_at; 58 58 } 59 59 60 60 /** 61 * Adds a new MapillaryImage object to this object.61 * Adds a new {@link MapillaryAbstractImage} object to the database. 62 62 * 63 63 * @param image 64 * The {@link MapillaryAbstractImage} object to be added 64 65 */ 65 66 public synchronized void add(MapillaryAbstractImage image) { … … 79 80 80 81 /** 81 * Adds a set of MapillaryImage objects to this object.82 * Adds a set of {@link MapillaryAbstractImage} objects to the database. 82 83 * 83 84 * @param images 85 * The set of {@link MapillaryAbstractImage} objects to be added. 84 86 */ 85 87 public synchronized void add(List<MapillaryAbstractImage> images) { … … 89 91 90 92 /** 91 * Removes a MapillaryImage object from this object.93 * Removes a {@link MapillaryAbstractImage} object from the database. 92 94 * 93 95 * @param image 96 * The {@link MapillaryAbstractImage} object to be removed. 94 97 */ 95 98 public void remove(MapillaryAbstractImage image) { … … 106 109 */ 107 110 public MapillaryAbstractImage next(MapillaryAbstractImage image) { 108 if (! images.contains(image))111 if (!this.images.contains(image)) 109 112 throw new IllegalArgumentException(); 110 int i = images.indexOf(image);111 if (i == images.size() - 1)113 int i = this.images.indexOf(image); 114 if (i == this.images.size() - 1) 112 115 return null; 113 return images.get(i + 1);116 return this.images.get(i + 1); 114 117 } 115 118 … … 123 126 */ 124 127 public MapillaryAbstractImage previous(MapillaryAbstractImage image) { 125 if (! images.contains(image))128 if (!this.images.contains(image)) 126 129 throw new IllegalArgumentException(); 127 int i = images.indexOf(image);130 int i = this.images.indexOf(image); 128 131 if (i == 0) 129 132 return null; 130 return images.get(i - 1);133 return this.images.get(i - 1); 131 134 } 132 135 … … 136 139 * 137 140 * @param image1 141 * The first image. 138 142 * @param image2 143 * The second image. 139 144 * @return The distance between two {@link MapillaryAbstractImage} objects 140 145 * belonging to the same {@link MapillarySequence}. -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java
r31425 r31445 58 58 cancel.addActionListener(new CancelAction(pane)); 59 59 60 dialog = new MapillaryExportDialog(ok);61 pane.setMessage( dialog);60 this.dialog = new MapillaryExportDialog(ok); 61 pane.setMessage(this.dialog); 62 62 pane.setOptions(new JButton[] { ok, cancel }); 63 63 … … 69 69 if (pane.getValue() != null 70 70 && (int) pane.getValue() == JOptionPane.OK_OPTION 71 && dialog.chooser != null) {72 if ( dialog.group.isSelected(dialog.all.getModel())) {71 && this.dialog.chooser != null) { 72 if (this.dialog.group.isSelected(this.dialog.all.getModel())) { 73 73 export(MapillaryData.getInstance().getImages()); 74 } else if ( dialog.group.isSelected(dialog.sequence.getModel())) {74 } else if (this.dialog.group.isSelected(this.dialog.sequence.getModel())) { 75 75 ArrayList<MapillaryAbstractImage> images = new ArrayList<>(); 76 76 for (MapillaryAbstractImage image : MapillaryData.getInstance() … … 82 82 images.add(image); 83 83 export(images); 84 } else if ( dialog.group.isSelected(dialog.selected.getModel())) {84 } else if (this.dialog.group.isSelected(this.dialog.selected.getModel())) { 85 85 export(MapillaryData.getInstance().getMultiSelectedImages()); 86 86 } 87 87 // This option ignores the selected directory. 88 } else if ( dialog.group.isSelected(dialog.rewrite.getModel())) {88 } else if (this.dialog.group.isSelected(this.dialog.rewrite.getModel())) { 89 89 ArrayList<MapillaryImportedImage> images = new ArrayList<>(); 90 90 for (MapillaryAbstractImage image : MapillaryData.getInstance() … … 110 110 public void export(List<MapillaryAbstractImage> images) { 111 111 Main.worker.submit(new Thread(new MapillaryExportManager(images, 112 dialog.chooser.getSelectedFile().toString())));112 this.dialog.chooser.getSelectedFile().toString()))); 113 113 } 114 114 … … 122 122 @Override 123 123 public void actionPerformed(ActionEvent e) { 124 pane.setValue(JOptionPane.OK_OPTION);124 this.pane.setValue(JOptionPane.OK_OPTION); 125 125 } 126 126 } … … 135 135 @Override 136 136 public void actionPerformed(ActionEvent e) { 137 pane.setValue(JOptionPane.CANCEL_OPTION);137 this.pane.setValue(JOptionPane.CANCEL_OPTION); 138 138 } 139 139 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
r31425 r31445 59 59 @Override 60 60 public void actionPerformed(ActionEvent e) { 61 chooser = new JFileChooser();61 this.chooser = new JFileChooser(); 62 62 File startDirectory = new File(Main.pref.get("mapillary.start-directory", 63 63 System.getProperty("user.home"))); 64 chooser.setCurrentDirectory(startDirectory);65 chooser.setDialogTitle(tr("Select pictures"));66 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);67 chooser.setAcceptAllFileFilterUsed(false);68 chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg",69 "jp eg", "png"));70 chooser.setMultiSelectionEnabled(true);71 if ( chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {72 for (int i = 0; i < chooser.getSelectedFiles().length; i++) {73 File file = chooser.getSelectedFiles()[i];64 this.chooser.setCurrentDirectory(startDirectory); 65 this.chooser.setDialogTitle(tr("Select pictures")); 66 this.chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 67 this.chooser.setAcceptAllFileFilterUsed(false); 68 this.chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", 69 "jpg", "jpeg", "png")); 70 this.chooser.setMultiSelectionEnabled(true); 71 if (this.chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { 72 for (int i = 0; i < this.chooser.getSelectedFiles().length; i++) { 73 File file = this.chooser.getSelectedFiles()[i]; 74 74 Main.pref.put("mapillary.start-directory", file.getParent()); 75 75 MapillaryLayer.getInstance(); … … 121 121 * 122 122 * @param file 123 * The file where the picture is located. 123 124 * @return The imported image. 124 125 * @throws ImageReadException 126 * If the file isn't an image. 125 127 * @throws IOException 126 */ 127 public MapillaryImportedImage readJPG(File file) throws ImageReadException, 128 IOException { 128 * If the file doesn't have the valid metadata. 129 */ 130 public MapillaryImportedImage readJPG(File file) throws IOException, 131 ImageReadException { 129 132 final ImageMetadata metadata = Imaging.getMetadata(file); 130 133 if (metadata instanceof JpegImageMetadata) { … … 170 173 * 171 174 * @param file 175 * The file where the image is located. 172 176 * @return The imported image. 173 177 */ … … 184 188 * 185 189 * @param file 190 * The file where the image is located. 186 191 * @param pos 187 192 * A {@link LatLon} object indicating the position in the map where … … 192 197 double HORIZONTAL_DISTANCE = 0.0001; 193 198 double horDev; 194 if ( noTagsPics % 2 == 0)195 horDev = HORIZONTAL_DISTANCE * noTagsPics / 2;199 if (this.noTagsPics % 2 == 0) 200 horDev = HORIZONTAL_DISTANCE * this.noTagsPics / 2; 196 201 else 197 horDev = -HORIZONTAL_DISTANCE * (( noTagsPics + 1) / 2);198 noTagsPics++;202 horDev = -HORIZONTAL_DISTANCE * ((this.noTagsPics + 1) / 2); 203 this.noTagsPics++; 199 204 return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file); 200 205 } … … 204 209 * 205 210 * @param file 211 * The file where the image is located. 206 212 * @return The imported image. 207 213 */ -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java
r31425 r31445 50 50 */ 51 51 public MapillaryImportIntoSequenceAction() { 52 super(tr("Import pictures into sequence"), MapillaryPlugin .getProvider("icon24.png"),53 tr("Import local pictures"), Shortcut.registerShortcut(54 52 super(tr("Import pictures into sequence"), MapillaryPlugin 53 .getProvider("icon24.png"), tr("Import local pictures"), Shortcut 54 .registerShortcut("Import Mapillary Sequence", 55 55 tr("Import pictures into Mapillary layer in a sequence"), 56 56 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, … … 61 61 @Override 62 62 public void actionPerformed(ActionEvent arg0) { 63 images = new LinkedList<>();64 65 chooser = new JFileChooser();63 this.images = new LinkedList<>(); 64 65 this.chooser = new JFileChooser(); 66 66 File startDirectory = new File(Main.pref.get("mapillary.start-directory", 67 67 System.getProperty("user.home"))); 68 chooser.setCurrentDirectory(startDirectory);69 chooser.setDialogTitle(tr("Select pictures"));70 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);71 chooser.setAcceptAllFileFilterUsed(false);72 chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg",73 "jp eg"));74 chooser.setMultiSelectionEnabled(true);75 76 if ( chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {77 for (int i = 0; i < chooser.getSelectedFiles().length; i++) {78 File file = chooser.getSelectedFiles()[i];68 this.chooser.setCurrentDirectory(startDirectory); 69 this.chooser.setDialogTitle(tr("Select pictures")); 70 this.chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 71 this.chooser.setAcceptAllFileFilterUsed(false); 72 this.chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", 73 "jpg", "jpeg")); 74 this.chooser.setMultiSelectionEnabled(true); 75 76 if (this.chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { 77 for (int i = 0; i < this.chooser.getSelectedFiles().length; i++) { 78 File file = this.chooser.getSelectedFiles()[i]; 79 79 if (file == null) 80 80 break; … … 117 117 118 118 /** 119 * Reads a jpgpictures that contains the needed GPS information (position and119 * Reads a JPG pictures that contains the needed GPS information (position and 120 120 * direction) and creates a new icon in that position. 121 121 * 122 122 * @param file 123 * The file where the image is located. 123 124 * @throws ImageReadException 125 * If the file doesn't contain an image. 124 126 * @throws IOException 127 * If the file doesn't contain valid metadata. 125 128 */ 126 129 public void readJPG(File file) throws ImageReadException, IOException { … … 162 165 image.getCapturedAt(); 163 166 164 images.add(image);167 this.images.add(image); 165 168 } 166 169 } … … 170 173 */ 171 174 public void joinImages() { 172 Collections.sort( images, new MapillaryEpochComparator());175 Collections.sort(this.images, new MapillaryEpochComparator()); 173 176 MapillarySequence seq = new MapillarySequence(); 174 for (MapillaryImportedImage img : images) {177 for (MapillaryImportedImage img : this.images) { 175 178 seq.add(img); 176 179 img.setSequence(seq); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryWalkAction.java
r31425 r31445 38 38 */ 39 39 public MapillaryWalkAction() { 40 super(tr("Walk mode"), MapillaryPlugin.getProvider("icon24.png"), tr("Walk mode"),41 Shortcut.registerShortcut("Mapillary walk", tr("Start walk mode"),42 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, "mapillaryWalk",43 false );40 super(tr("Walk mode"), MapillaryPlugin.getProvider("icon24.png"), 41 tr("Walk mode"), Shortcut.registerShortcut("Mapillary walk", 42 tr("Start walk mode"), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), 43 false, "mapillaryWalk", false); 44 44 this.setEnabled(false); 45 45 } … … 55 55 if (pane.getValue() != null 56 56 && (int) pane.getValue() == JOptionPane.OK_OPTION) { 57 th read = new WalkThread((int) dialog.spin.getValue(),57 this.thread = new WalkThread((int) dialog.spin.getValue(), 58 58 dialog.waitForPicture.isSelected(), 59 59 dialog.followSelection.isSelected(), dialog.goForward.isSelected()); 60 60 fireWalkStarted(); 61 th read.start();61 this.thread.start(); 62 62 MapillaryMainDialog.getInstance().setMode(MapillaryMainDialog.Mode.WALK); 63 63 } … … 73 73 * 74 74 * @param lis 75 * The listener to be added. 75 76 */ 76 77 public void addListener(WalkListener lis) { 77 listeners.add(lis);78 this.listeners.add(lis); 78 79 } 79 80 … … 82 83 * 83 84 * @param lis 85 * The listener to be added. 84 86 */ 85 87 public void removeListener(WalkListener lis) { 86 listeners.remove(lis);88 this.listeners.remove(lis); 87 89 } 88 90 89 91 private void fireWalkStarted() { 90 if ( listeners.isEmpty())92 if (this.listeners.isEmpty()) 91 93 return; 92 for (WalkListener lis : listeners)93 lis.walkStarted(th read);94 for (WalkListener lis : this.listeners) 95 lis.walkStarted(this.thread); 94 96 } 95 97 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkListener.java
r31401 r31445 13 13 * Called when a new walk thread is started. 14 14 * 15 * @param thread 15 * @param thread The thread executing the walk. 16 16 */ 17 17 public void walkStarted(WalkThread thread); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java
r31416 r31445 36 36 * 37 37 * @param interval 38 * How often the images switch. 38 39 * @param waitForPicture 40 * If it must wait for the full resolution picture or just the 41 * thumbnail. 39 42 * @param followSelected 43 * Zoom to each image that is selected. 40 44 * @param goForward 45 * true to go forward; false to go backwards. 41 46 */ 42 47 public WalkThread(int interval, boolean waitForPicture, … … 46 51 this.followSelected = followSelected; 47 52 this.goForward = goForward; 48 data = MapillaryLayer.getInstance().getMapillaryData();49 data.addListener(this);53 this.data = MapillaryLayer.getInstance().getMapillaryData(); 54 this.data.addListener(this); 50 55 } 51 56 … … 53 58 public void run() { 54 59 try { 55 while (! end &&data.getSelectedImage().next() != null) {56 MapillaryAbstractImage image = data.getSelectedImage();60 while (!this.end && this.data.getSelectedImage().next() != null) { 61 MapillaryAbstractImage image = this.data.getSelectedImage(); 57 62 if (image instanceof MapillaryImage) { 58 63 // Predownload next 10 thumbnails. … … 64 69 Utils.PICTURE.THUMBNAIL); 65 70 } 66 } 67 if (waitForFullQuality) 68 // Start downloading 3 next full images. 69 for (int i = 0; i < 3; i++) { 70 if (image.next() == null) 71 break; 72 image = image.next(); 73 Utils.downloadPicture((MapillaryImage) image, Utils.PICTURE.FULL_IMAGE); 74 } 71 if (this.waitForFullQuality) 72 // Start downloading 3 next full images. 73 for (int i = 0; i < 3; i++) { 74 if (image.next() == null) 75 break; 76 image = image.next(); 77 Utils.downloadPicture((MapillaryImage) image, 78 Utils.PICTURE.FULL_IMAGE); 79 } 80 } 75 81 try { 76 82 synchronized (this) { 77 if (waitForFullQuality 78 && data.getSelectedImage() instanceof MapillaryImage) { 83 if (this.waitForFullQuality && image instanceof MapillaryImage) { 79 84 while (MapillaryMainDialog.getInstance().mapillaryImageDisplay 80 .getImage() == lastImage85 .getImage() == this.lastImage 81 86 || MapillaryMainDialog.getInstance().mapillaryImageDisplay 82 87 .getImage() == null … … 86 91 } else { 87 92 while (MapillaryMainDialog.getInstance().mapillaryImageDisplay 88 .getImage() == lastImage93 .getImage() == this.lastImage 89 94 || MapillaryMainDialog.getInstance().mapillaryImageDisplay 90 95 .getImage() == null … … 93 98 wait(100); 94 99 } 95 while ( paused)100 while (this.paused) 96 101 wait(100); 97 wait( interval);98 while ( paused)102 wait(this.interval); 103 while (this.paused) 99 104 wait(100); 100 105 } 101 lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay106 this.lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay 102 107 .getImage(); 103 lock.lock(); 104 if (goForward) 105 data.selectNext(followSelected); 106 else 107 data.selectPrevious(followSelected); 108 lock.unlock(); 108 this.lock.lock(); 109 try { 110 if (this.goForward) 111 this.data.selectNext(this.followSelected); 112 else 113 this.data.selectPrevious(this.followSelected); 114 } finally { 115 this.lock.unlock(); 116 } 109 117 } catch (InterruptedException e) { 110 118 return; 111 } finally {112 lock.unlock();113 119 } 114 120 } … … 121 127 @Override 122 128 public void interrupt() { 123 lock.lock();129 this.lock.lock(); 124 130 try { 125 131 super.interrupt(); 126 132 } catch (Exception e) { 127 133 } finally { 128 lock.unlock();134 this.lock.unlock(); 129 135 } 130 136 … … 148 154 */ 149 155 public void play() { 150 paused = false;156 this.paused = false; 151 157 } 152 158 … … 155 161 */ 156 162 public void pause() { 157 paused = true;163 this.paused = true; 158 164 } 159 165 … … 187 193 }); 188 194 } else { 189 end = true;190 data.removeListener(this);195 this.end = true; 196 this.data.removeListener(this); 191 197 MapillaryMainDialog.getInstance() 192 198 .setMode(MapillaryMainDialog.Mode.NORMAL); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/MapillaryCache.java
r31416 r31445 39 39 * 40 40 * @param key 41 * The key of the image. 41 42 * @param type 43 * The type of image that must be downloaded (THUMNAIL or 44 * FULL_IMAGE). 42 45 */ 43 46 public MapillaryCache(String key, Type type) { … … 47 50 switch (type) { 48 51 case FULL_IMAGE: 49 url = new URL("https://d1cuyjsrcm0gby.cloudfront.net/" + key52 this.url = new URL("https://d1cuyjsrcm0gby.cloudfront.net/" + key 50 53 + "/thumb-2048.jpg"); 51 54 this.key += ".FULL_IMAGE"; 52 55 break; 53 56 case THUMBNAIL: 54 url = new URL("https://d1cuyjsrcm0gby.cloudfront.net/" + key57 this.url = new URL("https://d1cuyjsrcm0gby.cloudfront.net/" + key 55 58 + "/thumb-320.jpg"); 56 59 this.key += ".THUMBNAIL"; … … 64 67 @Override 65 68 public String getCacheKey() { 66 return key;69 return this.key; 67 70 } 68 71 69 72 @Override 70 73 public URL getUrl() { 71 return url;74 return this.url; 72 75 } 73 76 … … 79 82 @Override 80 83 protected boolean isObjectLoadable() { 81 if ( cacheData == null)84 if (this.cacheData == null) 82 85 return false; 83 byte[] content = cacheData.getContent();86 byte[] content = this.cacheData.getContent(); 84 87 return content != null && content.length > 0; 85 88 } 86 87 // @Override88 protected boolean handleNotFound() {89 return false;90 }91 89 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/Utils.java
r31416 r31445 41 41 * in cache. 42 42 * 43 * @param img 43 * @param img The image to be downloaded. 44 44 * @param pic 45 45 * The picture type to be downloaded (full quality, thumbnail or -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java
r31401 r31445 21 21 /** 22 22 * Main constructor. 23 * 23 * 24 24 * @param images 25 25 * Set of images that are going to be moved. … … 38 38 @Override 39 39 public void undo() { 40 for (MapillaryAbstractImage image : images) {41 image.move(- x, -y);40 for (MapillaryAbstractImage image : this.images) { 41 image.move(-this.x, -this.y); 42 42 image.stopMoving(); 43 43 } … … 48 48 @Override 49 49 public void redo() { 50 for (MapillaryAbstractImage image : images) {51 image.move( x,y);50 for (MapillaryAbstractImage image : this.images) { 51 image.move(this.x, this.y); 52 52 image.stopMoving(); 53 53 } … … 58 58 @Override 59 59 public String toString() { 60 return trn("Moved {0} image", "Moved {0} images", images.size(),61 images.size());60 return trn("Moved {0} image", "Moved {0} images", this.images.size(), 61 this.images.size()); 62 62 } 63 63 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java
r31401 r31445 20 20 /** 21 21 * Main constructor. 22 * 22 * 23 23 * @param images 24 24 * Set of images that is turned. … … 33 33 @Override 34 34 public void undo() { 35 for (MapillaryAbstractImage image : images) {36 image.turn(- ca);35 for (MapillaryAbstractImage image : this.images) { 36 image.turn(-this.ca); 37 37 image.stopMoving(); 38 38 } … … 43 43 @Override 44 44 public void redo() { 45 for (MapillaryAbstractImage image : images) {46 image.turn( ca);45 for (MapillaryAbstractImage image : this.images) { 46 image.turn(this.ca); 47 47 image.stopMoving(); 48 48 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryCommand.java
r31387 r31445 7 7 /** 8 8 * Abstract class for any Mapillary command. 9 * 9 * 10 10 * @author nokutu 11 11 * … … 27 27 * If two equal commands are applied consecutively to the same set of images, 28 28 * they are summed in order to reduce them to just one command. 29 * 30 * @param command 29 * 30 * @param command The command to be summed to last command. 31 31 */ 32 32 public abstract void sum(MapillaryCommand command); … … 36 36 */ 37 37 public void checkModified() { 38 for (MapillaryAbstractImage image : images)38 for (MapillaryAbstractImage image : this.images) 39 39 image.isModified = (image.tempLatLon == image.latLon || image.tempCa == image.ca); 40 40 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecord.java
r31401 r31445 7 7 /** 8 8 * History record system in order to let the user undo and redo commands 9 * 9 * 10 10 * @author nokutu 11 11 * … … 26 26 */ 27 27 public MapillaryRecord() { 28 commandList = new ArrayList<>();29 position = -1;30 listeners = new ArrayList<>();28 this.commandList = new ArrayList<>(); 29 this.position = -1; 30 this.listeners = new ArrayList<>(); 31 31 } 32 32 33 33 /** 34 34 * Returns the unique instance of the class. 35 * 35 * 36 36 * @return The unique instance of the class. 37 37 */ … … 44 44 /** 45 45 * Adds a listener. 46 * 46 * 47 47 * @param lis 48 * The listener to be added. 48 49 */ 49 50 public void addListener(MapillaryRecordListener lis) { … … 53 54 /** 54 55 * Removes the given listener. 55 * 56 * 56 57 * @param lis 58 * The listener to be removed. 57 59 */ 58 60 public void removeListener(MapillaryRecordListener lis) { … … 62 64 /** 63 65 * Adds a new command to the list. 64 * 66 * 65 67 * @param command 68 * The command to be added. 66 69 */ 67 70 public void addCommand(MapillaryCommand command) { 68 71 // Checks if it is a continuation of last command 69 if ( position != -1) {72 if (this.position != -1) { 70 73 boolean equalSets = true; 71 for (MapillaryAbstractImage img : commandList.get(position).images)74 for (MapillaryAbstractImage img : this.commandList.get(this.position).images) 72 75 if (!command.images.contains(img)) 73 76 equalSets = false; 74 77 if (equalSets 75 && commandList.get(position).getClass() == command.getClass()) { 76 commandList.get(position).sum(command); 78 && this.commandList.get(this.position).getClass() == command 79 .getClass()) { 80 this.commandList.get(this.position).sum(command); 77 81 fireRecordChanged(); 78 82 return; … … 80 84 } 81 85 // Adds the command to the last position of the list. 82 commandList.add(position + 1, command);83 position++;84 while ( commandList.size() >position + 1) {85 commandList.remove(position + 1);86 this.commandList.add(this.position + 1, command); 87 this.position++; 88 while (this.commandList.size() > this.position + 1) { 89 this.commandList.remove(this.position + 1); 86 90 } 87 91 fireRecordChanged(); … … 92 96 */ 93 97 public void undo() { 94 if ( position == -1)98 if (this.position == -1) 95 99 return; 96 commandList.get(position).undo();97 position--;100 this.commandList.get(this.position).undo(); 101 this.position--; 98 102 fireRecordChanged(); 99 103 } … … 103 107 */ 104 108 public void redo() { 105 if ( position + 1 >=commandList.size())109 if (this.position + 1 >= this.commandList.size()) 106 110 return; 107 position++;108 commandList.get(position).redo();111 this.position++; 112 this.commandList.get(this.position).redo(); 109 113 fireRecordChanged(); 110 114 } 111 115 112 116 private void fireRecordChanged() { 113 for (MapillaryRecordListener lis : listeners)117 for (MapillaryRecordListener lis : this.listeners) 114 118 if (lis != null) 115 119 lis.recordChanged(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java
r31422 r31445 14 14 import org.openstreetmap.josm.data.Bounds; 15 15 import org.openstreetmap.josm.data.coor.LatLon; 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 16 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 17 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; … … 121 122 * 122 123 * @param bounds 124 * A {@link Bounds} object containing the area to be downloaded. 123 125 */ 124 126 public static void getImages(Bounds bounds) { … … 156 158 private static boolean isAreaTooBig() { 157 159 double area = 0; 160 System.out.println(Main.map.mapView.getLayersOfType(OsmDataLayer.class)); 158 161 for (Bounds bounds : Main.map.mapView.getEditLayer().data 159 162 .getDataSourceBounds()) { … … 172 175 public static int getMode() { 173 176 if (Main.pref.get("mapillary.download-mode").equals(MODES[0]) 174 && !MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC)177 && (MapillaryLayer.INSTANCE == null || !MapillaryLayer.INSTANCE.TEMP_SEMIAUTOMATIC)) 175 178 return 0; 176 179 else if (Main.pref.get("mapillary.download-mode").equals(MODES[1]) 177 || MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC)180 || (MapillaryLayer.INSTANCE != null && MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC)) 178 181 return 1; 179 182 else if (Main.pref.get("mapillary.download-mode").equals(MODES[2])) 180 183 return 2; 184 else if (Main.pref.get("mapillary.download-mode").equals("")) 185 return 0; 181 186 else 182 187 throw new IllegalStateException(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportDownloadThread.java
r31401 r31445 20 20 * This is the thread that downloads one of the images that are going to be 21 21 * exported and writes them in a {@link ArrayBlockingQueue}. 22 * 22 * 23 23 * @author nokutu 24 24 * @see MapillaryExportManager … … 37 37 /** 38 38 * Main constructor. 39 * 39 * 40 40 * @param image 41 41 * Image to be downloaded. … … 50 50 ArrayBlockingQueue<BufferedImage> queue, 51 51 ArrayBlockingQueue<MapillaryAbstractImage> queueImages) { 52 url = "https://d1cuyjsrcm0gby.cloudfront.net/" + image.getKey()52 this.url = "https://d1cuyjsrcm0gby.cloudfront.net/" + image.getKey() 53 53 + "/thumb-2048.jpg"; 54 54 this.queue = queue; … … 59 59 @Override 60 60 public void run() { 61 new MapillaryCache( image.getKey(), MapillaryCache.Type.FULL_IMAGE).submit(61 new MapillaryCache(this.image.getKey(), MapillaryCache.Type.FULL_IMAGE).submit( 62 62 this, false); 63 63 } … … 67 67 LoadResult result) { 68 68 try { 69 queue.put(ImageIO.read(new ByteArrayInputStream(data.getContent())));70 queueImages.put(image);69 this.queue.put(ImageIO.read(new ByteArrayInputStream(data.getContent()))); 70 this.queueImages.put(this.image); 71 71 } catch (InterruptedException e) { 72 72 Main.error(e); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportManager.java
r31401 r31445 44 44 /** 45 45 * Main constructor. 46 * 46 * 47 47 * @param images 48 48 * Set of {@link MapillaryAbstractImage} objects to be exported. … … 53 53 super(tr("Downloading") + "...", new PleaseWaitProgressMonitor( 54 54 "Exporting Mapillary Images"), true); 55 queue = new ArrayBlockingQueue<>(10);56 queueImages = new ArrayBlockingQueue<>(10);55 this.queue = new ArrayBlockingQueue<>(10); 56 this.queueImages = new ArrayBlockingQueue<>(10); 57 57 58 58 this.images = images; 59 amount = images.size();59 this.amount = images.size(); 60 60 this.path = path; 61 61 } … … 65 65 * 66 66 * @param images 67 * The set of {@link MapillaryImportedImage} object that is going to 68 * be rewritten. 67 69 * @throws IOException 70 * If the file of one of the {@link MapillaryImportedImage} objects 71 * doesn't contain a picture. 68 72 */ 69 73 public MapillaryExportManager(List<MapillaryImportedImage> images) … … 71 75 super(tr("Downloading") + "...", new PleaseWaitProgressMonitor( 72 76 "Exporting Mapillary Images"), true); 73 queue = new ArrayBlockingQueue<>(10);74 queueImages = new ArrayBlockingQueue<>(10);77 this.queue = new ArrayBlockingQueue<>(10); 78 this.queueImages = new ArrayBlockingQueue<>(10); 75 79 for (MapillaryImportedImage image : images) { 76 queue.add(image.getImage());77 queueImages.add(image);80 this.queue.add(image.getImage()); 81 this.queueImages.add(image); 78 82 } 79 amount = images.size();83 this.amount = images.size(); 80 84 } 81 85 82 86 @Override 83 87 protected void cancel() { 84 writer.interrupt();85 ex.shutdown();88 this.writer.interrupt(); 89 this.ex.shutdown(); 86 90 } 87 91 … … 90 94 OsmTransferException { 91 95 // Starts a writer thread in order to write the pictures on the disk. 92 writer = new MapillaryExportWriterThread(path, queue, queueImages, amount,93 this. getProgressMonitor());94 writer.start();95 if ( path == null) {96 this.writer = new MapillaryExportWriterThread(this.path, this.queue, 97 this.queueImages, this.amount, this.getProgressMonitor()); 98 this.writer.start(); 99 if (this.path == null) { 96 100 try { 97 writer.join();101 this.writer.join(); 98 102 } catch (InterruptedException e) { 99 103 Main.error(e); … … 101 105 return; 102 106 } 103 ex = new ThreadPoolExecutor(20, 35, 25, TimeUnit.SECONDS,107 this.ex = new ThreadPoolExecutor(20, 35, 25, TimeUnit.SECONDS, 104 108 new ArrayBlockingQueue<Runnable>(10)); 105 for (MapillaryAbstractImage image : images) {109 for (MapillaryAbstractImage image : this.images) { 106 110 if (image instanceof MapillaryImage) { 107 111 try { 108 ex.execute(new MapillaryExportDownloadThread((MapillaryImage) image,109 queue,queueImages));112 this.ex.execute(new MapillaryExportDownloadThread( 113 (MapillaryImage) image, this.queue, this.queueImages)); 110 114 } catch (Exception e) { 111 115 Main.error(e); … … 113 117 } else if (image instanceof MapillaryImportedImage) { 114 118 try { 115 queue.put(((MapillaryImportedImage) image).getImage());116 queueImages.put(image);119 this.queue.put(((MapillaryImportedImage) image).getImage()); 120 this.queueImages.put(image); 117 121 } catch (InterruptedException e) { 118 122 Main.error(e); … … 122 126 // If the queue is full, waits for it to have more space 123 127 // available before executing anything else. 124 while ( ex.getQueue().remainingCapacity() == 0)128 while (this.ex.getQueue().remainingCapacity() == 0) 125 129 Thread.sleep(100); 126 130 } catch (Exception e) { … … 129 133 } 130 134 try { 131 writer.join();135 this.writer.join(); 132 136 } catch (InterruptedException e) { 133 137 Main.error(e); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportWriterThread.java
r31401 r31445 3 3 import java.awt.image.BufferedImage; 4 4 import java.io.BufferedOutputStream; 5 import java.io. File;5 import java.io.ByteArrayOutputStream; 6 6 import java.io.FileOutputStream; 7 7 import java.io.IOException; … … 32 32 /** 33 33 * Writes the images from the queue in the file system. 34 * 34 * 35 35 * @author nokutu 36 36 * @see MapillaryExportManager … … 46 46 /** 47 47 * Main constructor. 48 * 48 * 49 49 * @param path 50 50 * Path to write the pictures. … … 71 71 @Override 72 72 public void run() { 73 monitor.setCustomText("Downloaded 0/" +amount);74 File tempFile = null;73 this.monitor.setCustomText("Downloaded 0/" + this.amount); 74 //File tempFile = null; 75 75 BufferedImage img; 76 76 MapillaryAbstractImage mimg = null; 77 77 String finalPath = ""; 78 for (int i = 0; i < amount; i++) {78 for (int i = 0; i < this.amount; i++) { 79 79 try { 80 img = queue.take();81 mimg = queueImages.take();80 img = this.queue.take(); 81 mimg = this.queueImages.take(); 82 82 if (img == null || mimg == null) 83 83 throw new IllegalStateException("Null image"); 84 if ( path == null && mimg instanceof MapillaryImportedImage) {84 if (this.path == null && mimg instanceof MapillaryImportedImage) { 85 85 String path = ((MapillaryImportedImage) mimg).getFile().getPath(); 86 86 finalPath = path.substring(0, path.lastIndexOf('.')); 87 87 } else if (mimg instanceof MapillaryImage) 88 finalPath = path + "/" + ((MapillaryImage) mimg).getKey();88 finalPath = this.path + "/" + ((MapillaryImage) mimg).getKey(); 89 89 else if (mimg instanceof MapillaryImportedImage) 90 finalPath = path + "/"90 finalPath = this.path + "/" 91 91 + ((MapillaryImportedImage) mimg).getFile().getName(); 92 92 ; 93 // Creates a temporal file that is going to be deleted after 94 // writing the EXIF tags. 95 tempFile = new File(finalPath + ".tmp"); 96 ImageIO.write(img, "jpg", tempFile); 93 94 // Transforms the image into a byte array. 95 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 96 ImageIO.write(img, "jpg", outputStream); 97 byte[] imageBytes = outputStream.toByteArray(); 97 98 98 99 // Write EXIF tags … … 136 137 OutputStream os = new BufferedOutputStream(new FileOutputStream( 137 138 finalPath + ".jpg")); 138 new ExifRewriter().updateExifMetadataLossless( tempFile, os, outputSet);139 tempFile.delete(); 139 new ExifRewriter().updateExifMetadataLossless(imageBytes, os, outputSet); 140 140 141 os.close(); 141 142 } catch (InterruptedException e) { … … 151 152 152 153 // Increases the progress bar. 153 monitor.worked(PleaseWaitProgressMonitor.PROGRESS_BAR_MAX /amount);154 monitor.setCustomText("Downloaded " + (i + 1) + "/" +amount);154 this.monitor.worked(PleaseWaitProgressMonitor.PROGRESS_BAR_MAX / this.amount); 155 this.monitor.setCustomText("Downloaded " + (i + 1) + "/" + this.amount); 155 156 } 156 157 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryImageInfoDownloaderThread.java
r31401 r31445 31 31 /** 32 32 * Main constructor. 33 * 33 * 34 34 * @param ex 35 35 * {@link ExecutorService} object that is executing this thread. 36 36 * @param queryString 37 * A String containing the parameters for the download. 37 38 * @param layer 39 * The layer to store the data. 38 40 */ 39 41 public MapillaryImageInfoDownloaderThread(ExecutorService ex, … … 48 50 try { 49 51 BufferedReader br = new BufferedReader(new InputStreamReader(new URL(URL 50 + queryString).openStream(), "UTF-8"));52 + this.queryString).openStream(), "UTF-8")); 51 53 JsonObject jsonobj = Json.createReader(br).readObject(); 52 54 if (!jsonobj.getBoolean("more")) 53 ex.shutdown();55 this.ex.shutdown(); 54 56 JsonArray jsonarr = jsonobj.getJsonArray("ims"); 55 57 JsonObject data; … … 57 59 data = jsonarr.getJsonObject(i); 58 60 String key = data.getString("key"); 59 for (MapillaryAbstractImage image : layer.getMapillaryData()61 for (MapillaryAbstractImage image : this.layer.getMapillaryData() 60 62 .getImages()) { 61 63 if (image instanceof MapillaryImage) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31418 r31445 18 18 import org.openstreetmap.josm.Main; 19 19 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 20 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 20 21 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 21 22 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; … … 44 45 * 45 46 * @param ex 47 * {@link ExecutorService} executing this thread. 46 48 * @param queryString 49 * String containing the parameters for the download. 47 50 */ 48 51 public MapillarySequenceDownloadThread(ExecutorService ex, String queryString) { … … 57 60 BufferedReader br; 58 61 br = new BufferedReader(new InputStreamReader( 59 new URL(URL + queryString).openStream(), "UTF-8"));62 new URL(URL + this.queryString).openStream(), "UTF-8")); 60 63 JsonObject jsonall = Json.createReader(br).readObject(); 61 64 62 if (!jsonall.getBoolean("more") && ! ex.isShutdown())63 ex.shutdown();65 if (!jsonall.getBoolean("more") && !this.ex.isShutdown()) 66 this.ex.shutdown(); 64 67 JsonArray jsonseq = jsonall.getJsonArray("ss"); 65 68 boolean isSequenceWrong = false; … … 77 80 .getJsonNumber(j).doubleValue())); 78 81 } catch (IndexOutOfBoundsException e) { 79 Main.warn("Mapillary bug at " + URL + queryString);82 Main.warn("Mapillary bug at " + URL + this.queryString); 80 83 isSequenceWrong = true; 81 84 } … … 95 98 96 99 LOCK.lock(); 97 Mapillary Image.LOCK.lock();100 MapillaryAbstractImage.LOCK.lock(); 98 101 try { 99 102 for (MapillaryImage img : finalImages) { 100 if ( layer.getMapillaryData().getImages().contains(img)) {103 if (this.layer.getMapillaryData().getImages().contains(img)) { 101 104 // The image in finalImages is substituted by the one in the 102 105 // database, as they represent the same picture. 103 img = (MapillaryImage) layer.getMapillaryData().getImages()104 .get( layer.getMapillaryData().getImages().indexOf(img));106 img = (MapillaryImage) this.layer.getMapillaryData().getImages() 107 .get(this.layer.getMapillaryData().getImages().indexOf(img)); 105 108 sequence.add(img); 106 ((MapillaryImage) layer.getMapillaryData().getImages()107 .get( layer.getMapillaryData().getImages().indexOf(img)))109 ((MapillaryImage) this.layer.getMapillaryData().getImages() 110 .get(this.layer.getMapillaryData().getImages().indexOf(img))) 108 111 .setSequence(sequence); 109 112 finalImages.set(finalImages.indexOf(img), img); … … 114 117 } 115 118 } finally { 116 Mapillary Image.LOCK.unlock();119 MapillaryAbstractImage.LOCK.unlock(); 117 120 LOCK.unlock(); 118 121 } 119 122 120 layer.getMapillaryData().add(123 this.layer.getMapillaryData().add( 121 124 new ArrayList<MapillaryAbstractImage>(finalImages), false); 122 125 } 123 126 } catch (IOException e) { 124 Main.error("Error reading the url " + URL + queryString127 Main.error("Error reading the url " + URL + this.queryString 125 128 + " might be a Mapillary problem."); 126 129 } 127 layer.getMapillaryData().dataUpdated();130 MapillaryData.dataUpdated(); 128 131 } 129 132 130 133 private boolean isInside(MapillaryAbstractImage image) { 131 for (int i = 0; i < layer.bounds.size(); i++)132 if ( layer.bounds.get(i).contains(image.getLatLon()))134 for (int i = 0; i < this.layer.bounds.size(); i++) 135 if (this.layer.bounds.get(i).contains(image.getLatLon())) 133 136 return true; 134 137 return false; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31409 r31445 12 12 13 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 14 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 15 16 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog; … … 36 37 * 37 38 * @param queryStringParts 39 * The query data. 38 40 * @param layer 41 * The layer to store the images. 39 42 * 40 43 */ … … 46 49 47 50 // TODO: Move this line to the appropriate place, here's no GET-request 48 Main.info("GET " + sequenceQueryString + " (Mapillary plugin)");51 Main.info("GET " + this.sequenceQueryString + " (Mapillary plugin)"); 49 52 50 53 this.layer = layer; … … 52 55 53 56 // TODO: Maybe move into a separate utility class? 54 private String buildQueryString(ConcurrentHashMap<String, Double> hash) {57 private static String buildQueryString(ConcurrentHashMap<String, Double> hash) { 55 58 StringBuilder ret = new StringBuilder("?client_id=" 56 59 + MapillaryDownloader.CLIENT_ID); … … 81 84 Main.error("Mapillary download interrupted (probably because of closing the layer)."); 82 85 } 83 layer.updateHelpText();84 layer.getMapillaryData().dataUpdated();86 this.layer.updateHelpText(); 87 MapillaryData.dataUpdated(); 85 88 MapillaryFilterDialog.getInstance().refresh(); 86 89 MapillaryMainDialog.getInstance().updateImage(); … … 92 95 int page = 0; 93 96 while (!ex.isShutdown()) { 94 ex.execute(new MapillarySequenceDownloadThread(ex, sequenceQueryString95 + "&page=" + page + "&limit=10"));97 ex.execute(new MapillarySequenceDownloadThread(ex, 98 this.sequenceQueryString + "&page=" + page + "&limit=10")); 96 99 while (ex.getQueue().remainingCapacity() == 0) 97 100 Thread.sleep(500); … … 99 102 } 100 103 ex.awaitTermination(15, TimeUnit.SECONDS); 101 layer.getMapillaryData().dataUpdated();104 MapillaryData.dataUpdated(); 102 105 } 103 106 … … 107 110 int page = 0; 108 111 while (!ex.isShutdown()) { 109 ex.execute(new MapillaryImageInfoDownloaderThread(ex, imageQueryString110 + "&page=" + page + "&limit=20",layer));112 ex.execute(new MapillaryImageInfoDownloaderThread(ex, 113 this.imageQueryString + "&page=" + page + "&limit=20", this.layer)); 111 114 while (ex.getQueue().remainingCapacity() == 0) 112 115 Thread.sleep(100); … … 121 124 int page = 0; 122 125 while (!ex.isShutdown()) { 123 ex.execute(new MapillaryTrafficSignDownloaderThread(ex, signQueryString124 + "&page=" + page + "&limit=20",layer));126 ex.execute(new MapillaryTrafficSignDownloaderThread(ex, 127 this.signQueryString + "&page=" + page + "&limit=20", this.layer)); 125 128 while (ex.getQueue().remainingCapacity() == 0) 126 129 Thread.sleep(100); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryTrafficSignDownloaderThread.java
r31409 r31445 36 36 * {@link ExecutorService} object that is executing this thread. 37 37 * @param queryString 38 * A String containing the parameter for the download. 38 39 * @param layer 40 * The layer to store the data. 39 41 */ 40 42 public MapillaryTrafficSignDownloaderThread(ExecutorService ex, … … 50 52 try { 51 53 br = new BufferedReader(new InputStreamReader( 52 new URL(URL + queryString).openStream(), "UTF-8"));54 new URL(URL + this.queryString).openStream(), "UTF-8")); 53 55 JsonObject jsonobj = Json.createReader(br).readObject(); 54 56 if (!jsonobj.getBoolean("more")) { 55 ex.shutdown();57 this.ex.shutdown(); 56 58 } 57 59 JsonArray jsonarr = jsonobj.getJsonArray("ims"); … … 66 68 for (int k = 0; k < rects.size(); k++) { 67 69 JsonObject data = rects.getJsonObject(k); 68 for (MapillaryAbstractImage image : layer.getMapillaryData()70 for (MapillaryAbstractImage image : this.layer.getMapillaryData() 69 71 .getImages()) 70 72 if (image instanceof MapillaryImage … … 79 81 for (int j = 0; j < rects.size(); j++) { 80 82 JsonObject data = rects.getJsonObject(j); 81 for (MapillaryAbstractImage image : layer.getMapillaryData()83 for (MapillaryAbstractImage image : this.layer.getMapillaryData() 82 84 .getImages()) 83 85 if (image instanceof MapillaryImage -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java
r31399 r31445 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.AWTEvent; 5 6 import java.awt.Cursor; 6 7 import java.awt.event.ActionEvent; … … 13 14 14 15 import javax.swing.JLabel; 15 import javax.swing.Swing Utilities;16 import javax.swing.SwingConstants; 16 17 17 18 import org.openstreetmap.josm.Main; … … 35 36 */ 36 37 public HyperlinkLabel() { 37 super(tr("View in website"), Swing Utilities.RIGHT);38 super(tr("View in website"), SwingConstants.RIGHT); 38 39 this.addActionListener(this); 39 40 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 40 41 41 enableEvents( MouseEvent.MOUSE_EVENT_MASK);42 enableEvents(AWTEvent.MOUSE_EVENT_MASK); 42 43 } 43 44 … … 56 57 * 57 58 * @param key 59 * The key of the image that the hyperlink will point to. 58 60 */ 59 61 public void setURL(String key) { … … 75 77 */ 76 78 public String getNormalText() { 77 return t ext;79 return this.text; 78 80 } 79 81 … … 94 96 * 95 97 * @param listener 98 * The listener to be added. 96 99 */ 97 100 public void addActionListener(ActionListener listener) { 98 listenerList.add(ActionListener.class, listener);101 this.listenerList.add(ActionListener.class, listener); 99 102 } 100 103 … … 104 107 * 105 108 * @param listener 109 * The listener to be added. 106 110 */ 107 111 public void removeActionListener(ActionListener listener) { 108 listenerList.remove(ActionListener.class, listener);112 this.listenerList.remove(ActionListener.class, listener); 109 113 } 110 114 … … 115 119 */ 116 120 protected void fireActionPerformed(ActionEvent evt) { 117 Object[] listeners = listenerList.getListenerList();121 Object[] listeners = this.listenerList.getListenerList(); 118 122 for (int i = 0; i < listeners.length; i += 2) { 119 123 if (listeners[i] == ActionListener.class) { … … 131 135 if (desktop.isSupported(Desktop.Action.BROWSE)) { 132 136 try { 133 desktop.browse( url.toURI());137 desktop.browse(this.url.toURI()); 134 138 } catch (IOException | URISyntaxException e1) { 135 139 Main.error(e1); … … 138 142 Runtime runtime = Runtime.getRuntime(); 139 143 try { 140 runtime.exec("xdg-open " + url);144 runtime.exec("xdg-open " + this.url); 141 145 } catch (IOException exc) { 142 146 exc.printStackTrace(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java
r31401 r31445 56 56 /** 57 57 * Main constructor. 58 * 58 * 59 59 * @param ok 60 * The button for to OK option. 60 61 */ 61 62 public MapillaryExportDialog(JButton ok) { … … 66 67 67 68 RewriteButtonAction action = new RewriteButtonAction(this); 68 group = new ButtonGroup();69 all = new JRadioButton(action);70 all.setText(tr("Export all images"));71 sequence = new JRadioButton(action);72 sequence.setText(tr("Export selected sequence"));73 selected = new JRadioButton(action);74 selected.setText(tr("Export selected images"));75 rewrite = new JRadioButton(action);76 rewrite.setText(tr("Rewrite imported images"));77 group.add(all);78 group.add(sequence);79 group.add(selected);80 group.add(rewrite);69 this.group = new ButtonGroup(); 70 this.all = new JRadioButton(action); 71 this.all.setText(tr("Export all images")); 72 this.sequence = new JRadioButton(action); 73 this.sequence.setText(tr("Export selected sequence")); 74 this.selected = new JRadioButton(action); 75 this.selected.setText(tr("Export selected images")); 76 this.rewrite = new JRadioButton(action); 77 this.rewrite.setText(tr("Rewrite imported images")); 78 this.group.add(this.all); 79 this.group.add(this.sequence); 80 this.group.add(this.selected); 81 this.group.add(this.rewrite); 81 82 // Some options are disabled depending on the circumstances 82 83 if (MapillaryData.getInstance().getSelectedImage() == null 83 84 || !(MapillaryData.getInstance().getSelectedImage() instanceof MapillaryImage && ((MapillaryImage) MapillaryData 84 85 .getInstance().getSelectedImage()).getSequence() != null)) { 85 sequence.setEnabled(false);86 this.sequence.setEnabled(false); 86 87 } 87 88 if (MapillaryData.getInstance().getMultiSelectedImages().isEmpty()) { 88 selected.setEnabled(false);89 this.selected.setEnabled(false); 89 90 } 90 rewrite.setEnabled(false);91 this.rewrite.setEnabled(false); 91 92 for (MapillaryAbstractImage img : MapillaryData.getInstance().getImages()) 92 93 if (img instanceof MapillaryImportedImage) 93 rewrite.setEnabled(true);94 this.rewrite.setEnabled(true); 94 95 95 path = new JLabel(tr("Select a folder"));96 choose = new JButton(tr("Explore"));97 choose.addActionListener(this);96 this.path = new JLabel(tr("Select a folder")); 97 this.choose = new JButton(tr("Explore")); 98 this.choose.addActionListener(this); 98 99 99 100 // All options belong to the same jpanel so the are in line. 100 101 JPanel jpanel = new JPanel(); 101 102 jpanel.setLayout(new BoxLayout(jpanel, BoxLayout.PAGE_AXIS)); 102 jpanel.add( all);103 jpanel.add( sequence);104 jpanel.add( selected);105 jpanel.add( rewrite);103 jpanel.add(this.all); 104 jpanel.add(this.sequence); 105 jpanel.add(this.selected); 106 jpanel.add(this.rewrite); 106 107 jpanel.setAlignmentX(Component.CENTER_ALIGNMENT); 107 path.setAlignmentX(Component.CENTER_ALIGNMENT);108 choose.setAlignmentX(Component.CENTER_ALIGNMENT);108 this.path.setAlignmentX(Component.CENTER_ALIGNMENT); 109 this.choose.setAlignmentX(Component.CENTER_ALIGNMENT); 109 110 110 111 add(jpanel); 111 add( path);112 add( choose);112 add(this.path); 113 add(this.choose); 113 114 } 114 115 … … 118 119 @Override 119 120 public void actionPerformed(ActionEvent e) { 120 chooser = new JFileChooser();121 chooser.setCurrentDirectory(new java.io.File(System121 this.chooser = new JFileChooser(); 122 this.chooser.setCurrentDirectory(new java.io.File(System 122 123 .getProperty("user.home"))); 123 chooser.setDialogTitle(tr("Select a directory"));124 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);125 chooser.setAcceptAllFileFilterUsed(false);124 this.chooser.setDialogTitle(tr("Select a directory")); 125 this.chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 126 this.chooser.setAcceptAllFileFilterUsed(false); 126 127 127 if ( chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {128 path.setText(chooser.getSelectedFile().toString());128 if (this.chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { 129 this.path.setText(this.chooser.getSelectedFile().toString()); 129 130 this.updateUI(); 130 ok.setEnabled(true);131 this.ok.setEnabled(true); 131 132 } 132 133 } … … 157 158 @Override 158 159 public void actionPerformed(ActionEvent arg0) { 159 choose.setEnabled(!rewrite.isSelected());160 if ( rewrite.isSelected()) {161 lastPath =dlg.path.getText();162 dlg.path.setText(" ");163 } else if ( lastPath != null) {164 dlg.path.setText(lastPath);160 MapillaryExportDialog.this.choose.setEnabled(!MapillaryExportDialog.this.rewrite.isSelected()); 161 if (MapillaryExportDialog.this.rewrite.isSelected()) { 162 this.lastPath = this.dlg.path.getText(); 163 this.dlg.path.setText(" "); 164 } else if (this.lastPath != null) { 165 this.dlg.path.setText(this.lastPath); 165 166 } 166 167 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterChooseSigns.java
r31389 r31445 49 49 50 50 private MapillaryFilterChooseSigns() { 51 maxSpeed.setSelected(true);52 stop.setSelected(true);53 giveWay.setSelected(true);54 roundabout.setSelected(true);55 access.setSelected(true);56 intersection.setSelected(true);57 direction.setSelected(true);58 uneven.setSelected(true);59 noParking.setSelected(true);60 noOvertaking.setSelected(true);61 crossing.setSelected(true);62 noTurn.setSelected(true);51 this.maxSpeed.setSelected(true); 52 this.stop.setSelected(true); 53 this.giveWay.setSelected(true); 54 this.roundabout.setSelected(true); 55 this.access.setSelected(true); 56 this.intersection.setSelected(true); 57 this.direction.setSelected(true); 58 this.uneven.setSelected(true); 59 this.noParking.setSelected(true); 60 this.noOvertaking.setSelected(true); 61 this.crossing.setSelected(true); 62 this.noTurn.setSelected(true); 63 63 64 64 // Max speed sign … … 67 67 maxspeedLabel.setIcon(new ImageProvider("signs/speed.png").get()); 68 68 maxspeedPanel.add(maxspeedLabel); 69 maxspeedPanel.add( maxSpeed);69 maxspeedPanel.add(this.maxSpeed); 70 70 this.add(maxspeedPanel); 71 71 … … 75 75 stopLabel.setIcon(new ImageProvider("signs/stop.png").get()); 76 76 stopPanel.add(stopLabel); 77 stopPanel.add( stop);77 stopPanel.add(this.stop); 78 78 this.add(stopPanel); 79 79 … … 83 83 giveWayLabel.setIcon(new ImageProvider("signs/right_of_way.png").get()); 84 84 giveWayPanel.add(giveWayLabel); 85 giveWayPanel.add( giveWay);85 giveWayPanel.add(this.giveWay); 86 86 this.add(giveWayPanel); 87 87 … … 92 92 .get()); 93 93 roundaboutPanel.add(roundaboutLabel); 94 roundaboutPanel.add( roundabout);94 roundaboutPanel.add(this.roundabout); 95 95 this.add(roundaboutPanel); 96 96 … … 100 100 noEntryLabel.setIcon(new ImageProvider("signs/no_entry.png").get()); 101 101 noEntryPanel.add(noEntryLabel); 102 noEntryPanel.add( access);102 noEntryPanel.add(this.access); 103 103 this.add(noEntryPanel); 104 104 … … 109 109 .setIcon(new ImageProvider("signs/intersection_danger.png").get()); 110 110 intersectionPanel.add(intersectionLabel); 111 intersectionPanel.add( intersection);111 intersectionPanel.add(this.intersection); 112 112 this.add(intersectionPanel); 113 113 … … 118 118 .get()); 119 119 directionPanel.add(directionLabel); 120 directionPanel.add( direction);120 directionPanel.add(this.direction); 121 121 this.add(directionPanel); 122 122 … … 126 126 noTurnLabel.setIcon(new ImageProvider("signs/no_turn.png").get()); 127 127 noTurnPanel.add(noTurnLabel); 128 noTurnPanel.add( noTurn);128 noTurnPanel.add(this.noTurn); 129 129 this.add(noTurnPanel); 130 130 … … 134 134 unevenLabel.setIcon(new ImageProvider("signs/uneaven.png").get()); 135 135 unevenPanel.add(unevenLabel); 136 unevenPanel.add( uneven);136 unevenPanel.add(this.uneven); 137 137 this.add(unevenPanel); 138 138 … … 142 142 noParkingLabel.setIcon(new ImageProvider("signs/no_parking.png").get()); 143 143 noParkingPanel.add(noParkingLabel); 144 noParkingPanel.add( noParking);144 noParkingPanel.add(this.noParking); 145 145 this.add(noParkingPanel); 146 146 … … 151 151 .get()); 152 152 noOvertakingPanel.add(noOvertakingLabel); 153 noOvertakingPanel.add( noOvertaking);153 noOvertakingPanel.add(this.noOvertaking); 154 154 this.add(noOvertakingPanel); 155 155 … … 159 159 crossingLabel.setIcon(new ImageProvider("signs/crossing.png").get()); 160 160 crossingPanel.add(crossingLabel); 161 crossingPanel.add( crossing);161 crossingPanel.add(this.crossing); 162 162 this.add(crossingPanel); 163 163 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java
r31415 r31445 78 78 "prohibitory_noturn" }; 79 79 /** The the {@link JCheckBox} where the respective tag should be searched */ 80 private final JCheckBox[] SIGN_CHECKBOXES = { signFilter.maxSpeed,81 signFilter.stop, signFilter.giveWay,signFilter.roundabout,82 signFilter.access, signFilter.access,signFilter.intersection,83 signFilter.direction, signFilter.direction,signFilter.intersection,84 signFilter.uneven, signFilter.noParking,signFilter.noOvertaking,85 signFilter.crossing, signFilter.noTurn,signFilter.noTurn };80 private final JCheckBox[] SIGN_CHECKBOXES = { this.signFilter.maxSpeed, 81 this.signFilter.stop, this.signFilter.giveWay, this.signFilter.roundabout, 82 this.signFilter.access, this.signFilter.access, this.signFilter.intersection, 83 this.signFilter.direction, this.signFilter.direction, this.signFilter.intersection, 84 this.signFilter.uneven, this.signFilter.noParking, this.signFilter.noOvertaking, 85 this.signFilter.crossing, this.signFilter.noTurn, this.signFilter.noTurn }; 86 86 87 87 private MapillaryFilterDialog() { … … 91 91 KeyEvent.VK_M, Shortcut.NONE), 200); 92 92 93 signChooser.setEnabled(false);93 this.signChooser.setEnabled(false); 94 94 JPanel signChooserPanel = new JPanel(); 95 95 signChooserPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); 96 signChooserPanel.add( signChooser);96 signChooserPanel.add(this.signChooser); 97 97 98 98 JPanel fromPanel = new JPanel(); 99 99 fromPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); 100 100 fromPanel.add(new JLabel("Not older than: ")); 101 spinner = new SpinnerNumberModel(1, 0, 10000, 1);102 fromPanel.add(new JSpinner( spinner));103 t ime = new JComboBox<>(TIME_LIST);104 fromPanel.add(t ime);101 this.spinner = new SpinnerNumberModel(1, 0, 10000, 1); 102 fromPanel.add(new JSpinner(this.spinner)); 103 this.time = new JComboBox<>(TIME_LIST); 104 fromPanel.add(this.time); 105 105 106 106 JPanel userSearchPanel = new JPanel(); 107 107 userSearchPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); 108 user = new JTextField(10);109 user.addActionListener(new UpdateAction());108 this.user = new JTextField(10); 109 this.user.addActionListener(new UpdateAction()); 110 110 userSearchPanel.add(new JLabel("User")); 111 userSearchPanel.add( user);112 113 imported.setSelected(true);114 downloaded.setSelected(true);111 userSearchPanel.add(this.user); 112 113 this.imported.setSelected(true); 114 this.downloaded.setSelected(true); 115 115 116 116 JPanel col1 = new JPanel(new GridLayout(2, 1)); 117 col1.add( downloaded);117 col1.add(this.downloaded); 118 118 col1.add(fromPanel); 119 panel.add(col1);119 this.panel.add(col1); 120 120 JPanel col2 = new JPanel(new GridLayout(2, 1)); 121 col2.add( imported);121 col2.add(this.imported); 122 122 col2.add(userSearchPanel); 123 panel.add(col2);123 this.panel.add(col2); 124 124 JPanel col3 = new JPanel(new GridLayout(2, 1)); 125 col3.add( onlySigns);125 col3.add(this.onlySigns); 126 126 col3.add(signChooserPanel); 127 panel.add(col3);128 129 createLayout( panel, true,130 Arrays.asList(new SideButton[] { updateButton,resetButton }));127 this.panel.add(col3); 128 129 createLayout(this.panel, true, 130 Arrays.asList(new SideButton[] { this.updateButton, this.resetButton })); 131 131 } 132 132 … … 156 156 */ 157 157 public void reset() { 158 imported.setSelected(true);159 downloaded.setSelected(true);160 onlySigns.setEnabled(true);161 onlySigns.setSelected(false);162 user.setText("");163 t ime.setSelectedItem(TIME_LIST[0]);164 spinner.setValue(1);158 this.imported.setSelected(true); 159 this.downloaded.setSelected(true); 160 this.onlySigns.setEnabled(true); 161 this.onlySigns.setSelected(false); 162 this.user.setText(""); 163 this.time.setSelectedItem(TIME_LIST[0]); 164 this.spinner.setValue(1); 165 165 refresh(); 166 166 } … … 195 195 } 196 196 } 197 if (! user.getText().equals("")198 && ! user.getText().equals(((MapillaryImage) img).getUser())) {197 if (!this.user.getText().equals("") 198 && !this.user.getText().equals(((MapillaryImage) img).getUser())) { 199 199 img.setVisible(false); 200 200 continue; … … 203 203 // Calculates the amount of days since the image was taken 204 204 Long currentTime = currentTime(); 205 if (t ime.getSelectedItem().equals(TIME_LIST[1])) {205 if (this.time.getSelectedItem().equals(TIME_LIST[1])) { 206 206 if (img.getCapturedAt() < currentTime 207 - ((Integer) spinner.getValue()).longValue() * 365 * 24 * 60 * 60207 - ((Integer) this.spinner.getValue()).longValue() * 365 * 24 * 60 * 60 208 208 * 1000) { 209 209 img.setVisible(false); … … 211 211 } 212 212 } 213 if (t ime.getSelectedItem().equals(TIME_LIST[2])) {213 if (this.time.getSelectedItem().equals(TIME_LIST[2])) { 214 214 if (img.getCapturedAt() < currentTime 215 - ((Integer) spinner.getValue()).longValue() * 30 * 24 * 60 * 60215 - ((Integer) this.spinner.getValue()).longValue() * 30 * 24 * 60 * 60 216 216 * 1000) { 217 217 img.setVisible(false); … … 219 219 } 220 220 } 221 if (t ime.getSelectedItem().equals(TIME_LIST[3])) {221 if (this.time.getSelectedItem().equals(TIME_LIST[3])) { 222 222 if (img.getCapturedAt() < currentTime 223 - ((Integer) spinner.getValue()).longValue() * 60 * 60 * 1000) {223 - ((Integer) this.spinner.getValue()).longValue() * 60 * 60 * 1000) { 224 224 img.setVisible(false); 225 225 continue; … … 240 240 */ 241 241 private boolean checkSigns(MapillaryImage img) { 242 for (int i = 0; i < SIGN_TAGS.length; i++) {243 if (checkSign(img, SIGN_CHECKBOXES[i],SIGN_TAGS[i]))242 for (int i = 0; i < this.SIGN_TAGS.length; i++) { 243 if (checkSign(img, this.SIGN_CHECKBOXES[i], this.SIGN_TAGS[i])) 244 244 return true; 245 245 } … … 247 247 } 248 248 249 private boolean checkSign(MapillaryImage img, JCheckBox signCheckBox,249 private static boolean checkSign(MapillaryImage img, JCheckBox signCheckBox, 250 250 String singString) { 251 251 boolean contains = false; … … 259 259 } 260 260 261 private long currentTime() {261 private static long currentTime() { 262 262 Calendar cal = Calendar.getInstance(); 263 263 return cal.getTimeInMillis(); … … 274 274 @Override 275 275 public void actionPerformed(ActionEvent arg0) { 276 onlySigns.setEnabled(downloaded.isSelected());276 MapillaryFilterDialog.this.onlySigns.setEnabled(MapillaryFilterDialog.this.downloaded.isSelected()); 277 277 } 278 278 } … … 318 318 @Override 319 319 public void actionPerformed(ActionEvent arg0) { 320 signChooser.setEnabled(onlySigns.isSelected());320 MapillaryFilterDialog.this.signChooser.setEnabled(MapillaryFilterDialog.this.onlySigns.isSelected()); 321 321 } 322 322 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java
r31389 r31445 5 5 import java.awt.Component; 6 6 import java.awt.Dimension; 7 import java.awt.GridBagConstraints; 7 8 import java.awt.GridBagLayout; 8 9 import java.awt.event.ActionEvent; … … 50 51 private final DefaultTreeModel redoTreeModel = new DefaultTreeModel( 51 52 new DefaultMutableTreeNode()); 52 private final JTree undoTree = new JTree( undoTreeModel);53 private final JTree redoTree = new JTree( redoTreeModel);53 private final JTree undoTree = new JTree(this.undoTreeModel); 54 private final JTree redoTree = new JTree(this.redoTreeModel); 54 55 55 56 private JSeparator separator = new JSeparator(); … … 67 68 MapillaryRecord.getInstance().addListener(this); 68 69 69 undoTree.expandRow(0);70 undoTree.setShowsRootHandles(true);71 undoTree.setRootVisible(false);72 undoTree.setCellRenderer(new MapillaryCellRenderer());73 redoTree.expandRow(0);74 redoTree.setCellRenderer(new MapillaryCellRenderer());75 redoTree.setShowsRootHandles(true);76 redoTree.setRootVisible(false);70 this.undoTree.expandRow(0); 71 this.undoTree.setShowsRootHandles(true); 72 this.undoTree.setRootVisible(false); 73 this.undoTree.setCellRenderer(new MapillaryCellRenderer()); 74 this.redoTree.expandRow(0); 75 this.redoTree.setCellRenderer(new MapillaryCellRenderer()); 76 this.redoTree.setShowsRootHandles(true); 77 this.redoTree.setRootVisible(false); 77 78 78 79 JPanel treesPanel = new JPanel(new GridBagLayout()); 79 treesPanel.add( spacer, GBC.eol());80 spacer.setVisible(false);81 treesPanel.add( undoTree, GBC.eol().fill(GBC.HORIZONTAL));82 separator.setVisible(false);83 treesPanel.add( separator, GBC.eol().fill(GBC.HORIZONTAL));84 treesPanel.add( redoTree, GBC.eol().fill(GBC.HORIZONTAL));80 treesPanel.add(this.spacer, GBC.eol()); 81 this.spacer.setVisible(false); 82 treesPanel.add(this.undoTree, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 83 this.separator.setVisible(false); 84 treesPanel.add(this.separator, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 85 treesPanel.add(this.redoTree, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 85 86 treesPanel.add(Box.createRigidArea(new Dimension(0, 0)), 86 87 GBC.std().weight(0, 1)); 87 treesPanel.setBackground( redoTree.getBackground());88 89 undoButton = new SideButton(new UndoAction());90 redoButton = new SideButton(new RedoAction());88 treesPanel.setBackground(this.redoTree.getBackground()); 89 90 this.undoButton = new SideButton(new UndoAction()); 91 this.redoButton = new SideButton(new RedoAction()); 91 92 92 93 createLayout(treesPanel, true, 93 Arrays.asList(new SideButton[] { undoButton,redoButton }));94 Arrays.asList(new SideButton[] { this.undoButton, this.redoButton })); 94 95 } 95 96 … … 106 107 107 108 private void buildTree() { 108 redoButton.setEnabled(true);109 undoButton.setEnabled(true);109 this.redoButton.setEnabled(true); 110 this.undoButton.setEnabled(true); 110 111 ArrayList<MapillaryCommand> commands = MapillaryRecord.getInstance().commandList; 111 112 int position = MapillaryRecord.getInstance().position; … … 114 115 undoCommands = new ArrayList<>(commands.subList(0, position + 1)); 115 116 else 116 undoButton.setEnabled(false);117 this.undoButton.setEnabled(false); 117 118 ArrayList<MapillaryCommand> redoCommands = new ArrayList<>(); 118 119 if (commands.size() > 0 && position + 1 < commands.size()) … … 120 121 commands.size())); 121 122 else 122 redoButton.setEnabled(false);123 this.redoButton.setEnabled(false); 123 124 124 125 DefaultMutableTreeNode redoRoot = new DefaultMutableTreeNode(); … … 134 135 } 135 136 136 separator.setVisible(!undoCommands.isEmpty() || !redoCommands.isEmpty());137 spacer.setVisible(undoCommands.isEmpty() && !redoCommands.isEmpty());138 139 undoTreeModel.setRoot(undoRoot);140 redoTreeModel.setRoot(redoRoot);137 this.separator.setVisible(!undoCommands.isEmpty() || !redoCommands.isEmpty()); 138 this.spacer.setVisible(undoCommands.isEmpty() && !redoCommands.isEmpty()); 139 140 this.undoTreeModel.setRoot(undoRoot); 141 this.redoTreeModel.setRoot(redoRoot); 141 142 } 142 143 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java
r31389 r31445 77 77 visibleRect = MapillaryImageDisplay.this.visibleRect; 78 78 } 79 mouseIsDragging = false;80 selectedRect = null;79 this.mouseIsDragging = false; 80 MapillaryImageDisplay.this.selectedRect = null; 81 81 if (image == null) 82 82 return; … … 87 87 // borders, this point is not calculated 88 88 // again if there was less than 1.5seconds since the last event. 89 if (e.getWhen() - lastTimeForMousePoint > 1500 ||mousePointInImg == null) {90 lastTimeForMousePoint = e.getWhen();91 mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());89 if (e.getWhen() - this.lastTimeForMousePoint > 1500 || this.mousePointInImg == null) { 90 this.lastTimeForMousePoint = e.getWhen(); 91 this.mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY()); 92 92 } 93 93 // Applicate the zoom to the visible rectangle in image coordinates … … 119 119 // cursor doesn't move on the image. 120 120 Rectangle drawRect = calculateDrawImageRectangle(visibleRect); 121 visibleRect.x = mousePointInImg.x121 visibleRect.x = this.mousePointInImg.x 122 122 + ((drawRect.x - e.getX()) * visibleRect.width) / drawRect.width; 123 visibleRect.y = mousePointInImg.y123 visibleRect.y = this.mousePointInImg.y 124 124 + ((drawRect.y - e.getY()) * visibleRect.height) / drawRect.height; 125 125 // The position is also limited by the image size … … 178 178 @Override 179 179 public void mousePressed(MouseEvent e) { 180 if ( image == null) {181 mouseIsDragging = false;182 selectedRect = null;180 if (MapillaryImageDisplay.this.image == null) { 181 this.mouseIsDragging = false; 182 MapillaryImageDisplay.this.selectedRect = null; 183 183 return; 184 184 } … … 192 192 return; 193 193 if (e.getButton() == DRAG_BUTTON) { 194 mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());195 mouseIsDragging = true;196 selectedRect = null;194 this.mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY()); 195 this.mouseIsDragging = true; 196 MapillaryImageDisplay.this.selectedRect = null; 197 197 } else if (e.getButton() == ZOOM_BUTTON) { 198 mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());199 checkPointInVisibleRect( mousePointInImg, visibleRect);200 mouseIsDragging = false;201 selectedRect = new Rectangle(mousePointInImg.x,mousePointInImg.y, 0, 0);198 this.mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY()); 199 checkPointInVisibleRect(this.mousePointInImg, visibleRect); 200 this.mouseIsDragging = false; 201 MapillaryImageDisplay.this.selectedRect = new Rectangle(this.mousePointInImg.x, this.mousePointInImg.y, 0, 0); 202 202 MapillaryImageDisplay.this.repaint(); 203 203 } else { 204 mouseIsDragging = false;205 selectedRect = null;204 this.mouseIsDragging = false; 205 MapillaryImageDisplay.this.selectedRect = null; 206 206 } 207 207 } … … 209 209 @Override 210 210 public void mouseDragged(MouseEvent e) { 211 if (! mouseIsDragging &&selectedRect == null)211 if (!this.mouseIsDragging && MapillaryImageDisplay.this.selectedRect == null) 212 212 return; 213 213 Image image; … … 218 218 } 219 219 if (image == null) { 220 mouseIsDragging = false;221 selectedRect = null;222 return; 223 } 224 if ( mouseIsDragging) {220 this.mouseIsDragging = false; 221 MapillaryImageDisplay.this.selectedRect = null; 222 return; 223 } 224 if (this.mouseIsDragging) { 225 225 Point p = comp2imgCoord(visibleRect, e.getX(), e.getY()); 226 visibleRect.x += mousePointInImg.x - p.x;227 visibleRect.y += mousePointInImg.y - p.y;226 visibleRect.x += this.mousePointInImg.x - p.x; 227 visibleRect.y += this.mousePointInImg.y - p.y; 228 228 checkVisibleRectPos(image, visibleRect); 229 229 synchronized (MapillaryImageDisplay.this) { … … 231 231 } 232 232 MapillaryImageDisplay.this.repaint(); 233 } else if ( selectedRect != null) {233 } else if (MapillaryImageDisplay.this.selectedRect != null) { 234 234 Point p = comp2imgCoord(visibleRect, e.getX(), e.getY()); 235 235 checkPointInVisibleRect(p, visibleRect); 236 Rectangle rect = new Rectangle(p.x < mousePointInImg.x ? p.x237 : mousePointInImg.x, p.y <mousePointInImg.y ? p.y238 : mousePointInImg.y, p.x < mousePointInImg.x ?mousePointInImg.x239 - p.x : p.x - mousePointInImg.x,240 p.y < mousePointInImg.y ?mousePointInImg.y - p.y : p.y241 - mousePointInImg.y);236 Rectangle rect = new Rectangle(p.x < this.mousePointInImg.x ? p.x 237 : this.mousePointInImg.x, p.y < this.mousePointInImg.y ? p.y 238 : this.mousePointInImg.y, p.x < this.mousePointInImg.x ? this.mousePointInImg.x 239 - p.x : p.x - this.mousePointInImg.x, 240 p.y < this.mousePointInImg.y ? this.mousePointInImg.y - p.y : p.y 241 - this.mousePointInImg.y); 242 242 checkVisibleRectSize(image, rect); 243 243 checkVisibleRectPos(image, rect); … … 249 249 @Override 250 250 public void mouseReleased(MouseEvent e) { 251 if (! mouseIsDragging &&selectedRect == null)251 if (!this.mouseIsDragging && MapillaryImageDisplay.this.selectedRect == null) 252 252 return; 253 253 Image image; … … 256 256 } 257 257 if (image == null) { 258 mouseIsDragging = false;259 selectedRect = null;260 return; 261 } 262 if ( mouseIsDragging) {263 mouseIsDragging = false;264 } else if ( selectedRect != null) {265 int oldWidth = selectedRect.width;266 int oldHeight = selectedRect.height;258 this.mouseIsDragging = false; 259 MapillaryImageDisplay.this.selectedRect = null; 260 return; 261 } 262 if (this.mouseIsDragging) { 263 this.mouseIsDragging = false; 264 } else if (MapillaryImageDisplay.this.selectedRect != null) { 265 int oldWidth = MapillaryImageDisplay.this.selectedRect.width; 266 int oldHeight = MapillaryImageDisplay.this.selectedRect.height; 267 267 // Check that the zoom doesn't exceed 2:1 268 if ( selectedRect.width < getSize().width / 2) {269 selectedRect.width = getSize().width / 2;270 } 271 if ( selectedRect.height < getSize().height / 2) {272 selectedRect.height = getSize().height / 2;268 if (MapillaryImageDisplay.this.selectedRect.width < getSize().width / 2) { 269 MapillaryImageDisplay.this.selectedRect.width = getSize().width / 2; 270 } 271 if (MapillaryImageDisplay.this.selectedRect.height < getSize().height / 2) { 272 MapillaryImageDisplay.this.selectedRect.height = getSize().height / 2; 273 273 } 274 274 // Set the same ratio for the visible rectangle and the display 275 275 // area 276 int hFact = selectedRect.height * getSize().width;277 int wFact = selectedRect.width * getSize().height;276 int hFact = MapillaryImageDisplay.this.selectedRect.height * getSize().width; 277 int wFact = MapillaryImageDisplay.this.selectedRect.width * getSize().height; 278 278 if (hFact > wFact) { 279 selectedRect.width = hFact / getSize().height;279 MapillaryImageDisplay.this.selectedRect.width = hFact / getSize().height; 280 280 } else { 281 selectedRect.height = wFact / getSize().width;281 MapillaryImageDisplay.this.selectedRect.height = wFact / getSize().width; 282 282 } 283 283 // Keep the center of the selection 284 if ( selectedRect.width != oldWidth) {285 selectedRect.x -= (selectedRect.width - oldWidth) / 2;286 } 287 if ( selectedRect.height != oldHeight) {288 selectedRect.y -= (selectedRect.height - oldHeight) / 2;289 } 290 checkVisibleRectSize(image, selectedRect);291 checkVisibleRectPos(image, selectedRect);284 if (MapillaryImageDisplay.this.selectedRect.width != oldWidth) { 285 MapillaryImageDisplay.this.selectedRect.x -= (MapillaryImageDisplay.this.selectedRect.width - oldWidth) / 2; 286 } 287 if (MapillaryImageDisplay.this.selectedRect.height != oldHeight) { 288 MapillaryImageDisplay.this.selectedRect.y -= (MapillaryImageDisplay.this.selectedRect.height - oldHeight) / 2; 289 } 290 checkVisibleRectSize(image, MapillaryImageDisplay.this.selectedRect); 291 checkVisibleRectPos(image, MapillaryImageDisplay.this.selectedRect); 292 292 synchronized (MapillaryImageDisplay.this) { 293 MapillaryImageDisplay.this.visibleRect = selectedRect;294 } 295 selectedRect = null;293 MapillaryImageDisplay.this.visibleRect = MapillaryImageDisplay.this.selectedRect; 294 } 295 MapillaryImageDisplay.this.selectedRect = null; 296 296 MapillaryImageDisplay.this.repaint(); 297 297 } … … 337 337 JPanel southPanel = new JPanel(); 338 338 southPanel.setLayout(new BorderLayout()); 339 hyperlink = new HyperlinkLabel();340 southPanel.add( hyperlink, BorderLayout.EAST);339 this.hyperlink = new HyperlinkLabel(); 340 southPanel.add(this.hyperlink, BorderLayout.EAST); 341 341 southPanel.setOpaque(false); 342 342 … … 347 347 * Sets a new picture to be displayed. 348 348 * 349 * @param image 349 * @param image The picture to be displayed. 350 350 */ 351 351 public void setImage(BufferedImage image) { 352 352 synchronized (this) { 353 353 this.image = image; 354 selectedRect = null;354 this.selectedRect = null; 355 355 if (image != null) 356 356 this.visibleRect = new Rectangle(0, 0, image.getWidth(null), … … 394 394 + target.height, visibleRect.x, visibleRect.y, visibleRect.x 395 395 + visibleRect.width, visibleRect.y + visibleRect.height, null); 396 if ( selectedRect != null) {397 Point topLeft = img2compCoord(visibleRect, selectedRect.x,398 selectedRect.y);399 Point bottomRight = img2compCoord(visibleRect, selectedRect.x400 + selectedRect.width, selectedRect.y +selectedRect.height);396 if (this.selectedRect != null) { 397 Point topLeft = img2compCoord(visibleRect, this.selectedRect.x, 398 this.selectedRect.y); 399 Point bottomRight = img2compCoord(visibleRect, this.selectedRect.x 400 + this.selectedRect.width, this.selectedRect.y + this.selectedRect.height); 401 401 g.setColor(new Color(128, 128, 128, 180)); 402 402 g.fillRect(target.x, target.y, target.width, topLeft.y - target.y); … … 427 427 } 428 428 429 private final Point getCenterImgCoord(Rectangle visibleRect) {429 private final static Point getCenterImgCoord(Rectangle visibleRect) { 430 430 return new Point(visibleRect.x + visibleRect.width / 2, visibleRect.y 431 431 + visibleRect.height / 2); … … 498 498 } 499 499 500 private final void checkVisibleRectPos(Image image, Rectangle visibleRect) {500 private final static void checkVisibleRectPos(Image image, Rectangle visibleRect) { 501 501 if (visibleRect.x < 0) { 502 502 visibleRect.x = 0; … … 513 513 } 514 514 515 private void checkVisibleRectSize(Image image, Rectangle visibleRect) {515 private static void checkVisibleRectSize(Image image, Rectangle visibleRect) { 516 516 if (visibleRect.width > image.getWidth(null)) { 517 517 visibleRect.width = image.getWidth(null); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java
r31409 r31445 99 99 MapillaryData.getInstance().addListener(this); 100 100 addShortcuts(); 101 mapillaryImageDisplay = new MapillaryImageDisplay();102 103 blueButton.setForeground(Color.BLUE);104 redButton.setForeground(Color.RED);101 this.mapillaryImageDisplay = new MapillaryImageDisplay(); 102 103 this.blueButton.setForeground(Color.BLUE); 104 this.redButton.setForeground(Color.RED); 105 105 106 106 createLayout( 107 mapillaryImageDisplay,108 Arrays.asList(new SideButton[] { blueButton,previousButton,109 nextButton,redButton }),107 this.mapillaryImageDisplay, 108 Arrays.asList(new SideButton[] { this.blueButton, this.previousButton, 109 this.nextButton, this.redButton }), 110 110 Main.pref.getBoolean("mapillary.reverse-buttons")); 111 111 disableAllButtons(); … … 117 117 */ 118 118 private void addShortcuts() { 119 nextButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(119 this.nextButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 120 120 KeyStroke.getKeyStroke("PAGE_DOWN"), "next"); 121 nextButton.getActionMap().put("next", new nextPictureAction());122 previousButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(121 this.nextButton.getActionMap().put("next", new nextPictureAction()); 122 this.previousButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 123 123 KeyStroke.getKeyStroke("PAGE_UP"), "previous"); 124 previousButton.getActionMap().put("previous", new previousPictureAction()); 125 blueButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 124 this.previousButton.getActionMap().put("previous", 125 new previousPictureAction()); 126 this.blueButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 126 127 KeyStroke.getKeyStroke("control PAGE_UP"), "blue"); 127 blueButton.getActionMap().put("blue", new blueAction());128 redButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(128 this.blueButton.getActionMap().put("blue", new blueAction()); 129 this.redButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 129 130 KeyStroke.getKeyStroke("control PAGE_DOWN"), "red"); 130 redButton.getActionMap().put("red", new redAction());131 this.redButton.getActionMap().put("red", new redAction()); 131 132 } 132 133 … … 143 144 144 145 /** 146 * Sets a new mode for the dialog. 147 * 145 148 * @param mode 149 * The mode to be set. 146 150 */ 147 151 public void setMode(Mode mode) { … … 149 153 case NORMAL: 150 154 createLayout( 151 mapillaryImageDisplay,152 Arrays.asList(new SideButton[] { blueButton, previousButton,153 nextButton,redButton }),155 this.mapillaryImageDisplay, 156 Arrays.asList(new SideButton[] { this.blueButton, 157 this.previousButton, this.nextButton, this.redButton }), 154 158 Main.pref.getBoolean("mapillary.reverse-buttons")); 155 159 break; 156 160 case WALK: 157 161 createLayout( 158 mapillaryImageDisplay,159 Arrays.asList(new SideButton[] { playButton,pauseButton,160 stopButton }),162 this.mapillaryImageDisplay, 163 Arrays.asList(new SideButton[] { this.playButton, this.pauseButton, 164 this.stopButton }), 161 165 Main.pref.getBoolean("mapillary.reverse-buttons")); 162 166 break; … … 202 206 } 203 207 if (this.image == null) { 204 mapillaryImageDisplay.setImage(null);208 this.mapillaryImageDisplay.setImage(null); 205 209 setTitle(tr(BASE_TITLE)); 206 210 disableAllButtons(); … … 210 214 this.nextButton.setEnabled(false); 211 215 this.previousButton.setEnabled(false); 212 if ( image.getSequence() != null) {213 MapillaryAbstractImage tempImage = image;216 if (this.image.getSequence() != null) { 217 MapillaryAbstractImage tempImage = this.image; 214 218 while (tempImage.next() != null) { 215 219 tempImage = tempImage.next(); … … 220 224 } 221 225 } 222 if ( image.getSequence() != null) {223 MapillaryAbstractImage tempImage = image;226 if (this.image.getSequence() != null) { 227 MapillaryAbstractImage tempImage = this.image; 224 228 while (tempImage.previous() != null) { 225 229 tempImage = tempImage.previous(); … … 230 234 } 231 235 } 232 if ( image instanceof MapillaryImage) {233 mapillaryImageDisplay.hyperlink.setVisible(true);236 if (this.image instanceof MapillaryImage) { 237 this.mapillaryImageDisplay.hyperlink.setVisible(true); 234 238 MapillaryImage mapillaryImage = (MapillaryImage) this.image; 235 mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey());239 this.mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey()); 236 240 // Downloads the thumbnail. 237 241 this.mapillaryImageDisplay.setImage(null); 238 if (th umbnailCache != null)239 th umbnailCache.cancelOutstandingTasks();240 th umbnailCache = new MapillaryCache(mapillaryImage.getKey(),242 if (this.thumbnailCache != null) 243 this.thumbnailCache.cancelOutstandingTasks(); 244 this.thumbnailCache = new MapillaryCache(mapillaryImage.getKey(), 241 245 MapillaryCache.Type.THUMBNAIL); 242 th umbnailCache.submit(this, false);246 this.thumbnailCache.submit(this, false); 243 247 244 248 // Downloads the full resolution image. 245 249 if (fullQuality) { 246 if ( imageCache != null)247 imageCache.cancelOutstandingTasks();248 imageCache = new MapillaryCache(mapillaryImage.getKey(),250 if (this.imageCache != null) 251 this.imageCache.cancelOutstandingTasks(); 252 this.imageCache = new MapillaryCache(mapillaryImage.getKey(), 249 253 MapillaryCache.Type.FULL_IMAGE); 250 imageCache.submit(this, false);251 } 252 } else if ( image instanceof MapillaryImportedImage) {253 mapillaryImageDisplay.hyperlink.setVisible(false);254 mapillaryImageDisplay.hyperlink.setURL(null);254 this.imageCache.submit(this, false); 255 } 256 } else if (this.image instanceof MapillaryImportedImage) { 257 this.mapillaryImageDisplay.hyperlink.setVisible(false); 258 this.mapillaryImageDisplay.hyperlink.setURL(null); 255 259 MapillaryImportedImage mapillaryImage = (MapillaryImportedImage) this.image; 256 260 try { 257 mapillaryImageDisplay.setImage(mapillaryImage.getImage());261 this.mapillaryImageDisplay.setImage(mapillaryImage.getImage()); 258 262 } catch (IOException e) { 259 263 Main.error(e); … … 266 270 267 271 private void disableAllButtons() { 268 nextButton.setEnabled(false);269 previousButton.setEnabled(false);270 blueButton.setEnabled(false);271 redButton.setEnabled(false);272 mapillaryImageDisplay.hyperlink.setVisible(false);272 this.nextButton.setEnabled(false); 273 this.previousButton.setEnabled(false); 274 this.blueButton.setEnabled(false); 275 this.redButton.setEnabled(false); 276 this.mapillaryImageDisplay.hyperlink.setVisible(false); 273 277 } 274 278 … … 277 281 * 278 282 * @param image 283 * The image to be shown. 279 284 */ 280 285 public synchronized void setImage(MapillaryAbstractImage image) { … … 429 434 @Override 430 435 public void actionPerformed(ActionEvent e) { 431 if (th read != null)432 th read.stopWalk();436 if (this.thread != null) 437 this.thread.stopWalk(); 433 438 } 434 439 … … 453 458 @Override 454 459 public void actionPerformed(ActionEvent e) { 455 if (th read != null)456 th read.play();460 if (this.thread != null) 461 this.thread.play(); 457 462 } 458 463 … … 479 484 @Override 480 485 public void actionPerformed(ActionEvent e) { 481 th read.pause();486 this.thread.pause(); 482 487 } 483 488 … … 510 515 return; 511 516 if (this.mapillaryImageDisplay.getImage() == null) 512 mapillaryImageDisplay.setImage(img);517 this.mapillaryImageDisplay.setImage(img); 513 518 else if (img.getHeight() > this.mapillaryImageDisplay.getImage() 514 519 .getHeight()) { 515 mapillaryImageDisplay.setImage(img);520 this.mapillaryImageDisplay.setImage(img); 516 521 } 517 522 } catch (IOException e) { … … 539 544 panel.add(data, BorderLayout.CENTER); 540 545 if (reverse) { 541 buttonsPanel = new JPanel(new GridLayout(1, 1));546 this.buttonsPanel = new JPanel(new GridLayout(1, 1)); 542 547 if (!buttons.isEmpty() && buttons.get(0) != null) { 543 548 final JPanel buttonRowPanel = new JPanel(Main.pref.getBoolean( 544 549 "dialog.align.left", false) ? new FlowLayout(FlowLayout.LEFT) 545 550 : new GridLayout(1, buttons.size())); 546 buttonsPanel.add(buttonRowPanel);551 this.buttonsPanel.add(buttonRowPanel); 547 552 for (SideButton button : buttons) 548 553 buttonRowPanel.add(button); 549 554 } 550 panel.add( buttonsPanel, BorderLayout.NORTH);555 panel.add(this.buttonsPanel, BorderLayout.NORTH); 551 556 createLayout(panel, true, null); 552 557 } else 553 558 createLayout(panel, true, buttons); 554 this.add(t itleBar, BorderLayout.NORTH);559 this.add(this.titleBar, BorderLayout.NORTH); 555 560 } 556 561 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
r31418 r31445 7 7 import java.awt.event.ActionEvent; 8 8 import java.io.IOException; 9 import java.net.MalformedURLException; 9 10 import java.net.URI; 10 11 import java.net.URISyntaxException; … … 23 24 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 24 25 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader; 26 import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryUser; 25 27 import org.openstreetmap.josm.plugins.mapillary.oauth.OAuthPortListener; 26 28 … … 52 54 JPanel panel = new JPanel(); 53 55 54 reverseButtons.setSelected(Main.pref56 this.reverseButtons.setSelected(Main.pref 55 57 .getBoolean("mapillary.reverse-buttons")); 56 displayHour.setSelected(Main.pref58 this.displayHour.setSelected(Main.pref 57 59 .getBoolean("mapillary.display-hour", true)); 58 format24.setSelected(Main.pref.getBoolean("mapillary.format-24"));59 moveTo.setSelected(Main.pref.getBoolean("mapillary.move-to-picture", true));60 this.format24.setSelected(Main.pref.getBoolean("mapillary.format-24")); 61 this.moveTo.setSelected(Main.pref.getBoolean("mapillary.move-to-picture", true)); 60 62 61 63 panel.setLayout(new FlowLayout(FlowLayout.LEFT)); 62 panel.add( reverseButtons);64 panel.add(this.reverseButtons); 63 65 64 66 // Sets the value of the ComboBox. 65 67 if (Main.pref.get("mapillary.download-mode").equals( 66 68 MapillaryDownloader.MODES[0])) 67 downloadMode.setSelectedItem(MapillaryDownloader.MODES[0]);69 this.downloadMode.setSelectedItem(MapillaryDownloader.MODES[0]); 68 70 if (Main.pref.get("mapillary.download-mode").equals( 69 71 MapillaryDownloader.MODES[1])) 70 downloadMode.setSelectedItem(MapillaryDownloader.MODES[1]);72 this.downloadMode.setSelectedItem(MapillaryDownloader.MODES[1]); 71 73 if (Main.pref.get("mapillary.download-mode").equals( 72 74 MapillaryDownloader.MODES[2])) 73 downloadMode.setSelectedItem(MapillaryDownloader.MODES[2]);75 this.downloadMode.setSelectedItem(MapillaryDownloader.MODES[2]); 74 76 JPanel downloadModePanel = new JPanel(); 75 77 downloadModePanel.add(new JLabel(tr("Download mode: "))); 76 downloadModePanel.add( downloadMode);78 downloadModePanel.add(this.downloadMode); 77 79 panel.add(downloadModePanel); 78 80 79 panel.add( displayHour);80 panel.add( format24);81 panel.add( moveTo);81 panel.add(this.displayHour); 82 panel.add(this.format24); 83 panel.add(this.moveTo); 82 84 JButton oauth = new JButton(new OAuthAction()); 83 85 if (Main.pref.get("mapillary.access-token") == null) 84 86 oauth.setText("Login"); 85 87 else 86 oauth.setText("Logged as: " + Main.pref.get("mapillary.username") + ". Click to relogin."); 88 try { 89 oauth.setText("Logged as: " + MapillaryUser.getUsername() + ". Click to relogin."); 90 } catch (MalformedURLException e) { 91 // TODO Auto-generated catch block 92 e.printStackTrace(); 93 } catch (IOException e) { 94 // TODO Auto-generated catch block 95 e.printStackTrace(); 96 } 87 97 panel.add(oauth); 88 98 gui.getDisplayPreference().addSubTab(this, "Mapillary", panel); … … 92 102 public boolean ok() { 93 103 boolean mod = false; 94 Main.pref.put("mapillary.reverse-buttons", reverseButtons.isSelected());104 Main.pref.put("mapillary.reverse-buttons", this.reverseButtons.isSelected()); 95 105 96 106 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, false); 97 if ( downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[0]))107 if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[0])) 98 108 Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[0]); 99 if ( downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[1]))109 if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[1])) 100 110 Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[1]); 101 if ( downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[2])) {111 if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[2])) { 102 112 Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[2]); 103 113 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true); 104 114 } 105 115 106 Main.pref.put("mapillary.display-hour", displayHour.isSelected());107 Main.pref.put("mapillary.format-24", format24.isSelected());108 Main.pref.put("mapillary.move-to-picture", moveTo.isSelected());116 Main.pref.put("mapillary.display-hour", this.displayHour.isSelected()); 117 Main.pref.put("mapillary.format-24", this.format24.isSelected()); 118 Main.pref.put("mapillary.move-to-picture", this.moveTo.isSelected()); 109 119 return mod; 110 120 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryWalkDialog.java
r31416 r31445 32 32 public MapillaryWalkDialog() { 33 33 JPanel interval = new JPanel(); 34 spin = new SpinnerNumberModel(2000, 500, 10000, 500);34 this.spin = new SpinnerNumberModel(2000, 500, 10000, 500); 35 35 interval.add(new JLabel("Interval (miliseconds): ")); 36 interval.add(new JSpinner( spin));36 interval.add(new JSpinner(this.spin)); 37 37 add(interval); 38 38 39 waitForPicture = new JCheckBox("Wait for full quality pictures");40 waitForPicture.setSelected(true);41 add( waitForPicture);39 this.waitForPicture = new JCheckBox("Wait for full quality pictures"); 40 this.waitForPicture.setSelected(true); 41 add(this.waitForPicture); 42 42 43 followSelection = new JCheckBox("Follow selected image");44 followSelection.setSelected(true);45 add( followSelection);43 this.followSelection = new JCheckBox("Follow selected image"); 44 this.followSelection.setSelected(true); 45 add(this.followSelection); 46 46 47 goForward = new JCheckBox("Go forward");48 goForward.setSelected(true);49 add( goForward);47 this.goForward = new JCheckBox("Go forward"); 48 this.goForward.setSelected(true); 49 add(this.goForward); 50 50 } 51 51 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java
r31422 r31445 40 40 double minDistance = Double.MAX_VALUE; 41 41 MapillaryAbstractImage closest = null; 42 for (MapillaryAbstractImage image : data.getImages()) {42 for (MapillaryAbstractImage image : this.data.getImages()) { 43 43 Point imagePoint = Main.map.mapView.getPoint(image.getLatLon()); 44 44 imagePoint.setLocation(imagePoint.getX(), imagePoint.getY()); … … 54 54 55 55 /** 56 * Paints whatever the mode needs. 57 * 56 * Paint the dataset using the engine set. 58 57 * @param g 59 * @param mv 58 * @param mv The object that can translate GeoPoints to screen coordinates. 60 59 * @param box 61 60 */ … … 89 88 public void run() { 90 89 while (true) { 91 if ( moved92 && Calendar.getInstance().getTimeInMillis() - lastDownload >= DOWNLOAD_COOLDOWN) {93 lastDownload = Calendar.getInstance().getTimeInMillis();90 if (this.moved 91 && Calendar.getInstance().getTimeInMillis() - this.lastDownload >= DOWNLOAD_COOLDOWN) { 92 this.lastDownload = Calendar.getInstance().getTimeInMillis(); 94 93 MapillaryDownloader.completeView(); 95 moved = false;96 MapillaryData. getInstance().dataUpdated();94 this.moved = false; 95 MapillaryData.dataUpdated(); 97 96 } 98 97 synchronized (this) { … … 106 105 107 106 public void moved() { 108 moved = true;107 this.moved = true; 109 108 } 110 109 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/JoinMode.java
r31389 r31445 12 12 import org.openstreetmap.josm.gui.MapView; 13 13 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 14 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 14 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 15 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; … … 31 32 */ 32 33 public JoinMode() { 33 cursor = Cursor.CROSSHAIR_CURSOR;34 this.cursor = Cursor.CROSSHAIR_CURSOR; 34 35 } 35 36 36 37 @Override 37 38 public void mousePressed(MouseEvent e) { 38 if ( data.getHighlighted() == null)39 if (this.data.getHighlighted() == null) 39 40 return; 40 if ( lastClick == null41 && data.getHighlighted() instanceof MapillaryImportedImage) {42 lastClick = (MapillaryImportedImage)data.getHighlighted();43 } else if ( lastClick != null44 && data.getHighlighted() instanceof MapillaryImportedImage) {45 if ((( data.getHighlighted().previous() == null && lastClick.next() == null) || (data46 .getHighlighted().next() == null && lastClick.previous() == null))47 && ( data.getHighlighted().getSequence() != lastClick.getSequence() ||lastClick41 if (this.lastClick == null 42 && this.data.getHighlighted() instanceof MapillaryImportedImage) { 43 this.lastClick = (MapillaryImportedImage) this.data.getHighlighted(); 44 } else if (this.lastClick != null 45 && this.data.getHighlighted() instanceof MapillaryImportedImage) { 46 if (((this.data.getHighlighted().previous() == null && this.lastClick.next() == null) || (this.data 47 .getHighlighted().next() == null && this.lastClick.previous() == null)) 48 && (this.data.getHighlighted().getSequence() != this.lastClick.getSequence() || this.lastClick 48 49 .getSequence() == null)) { 49 join( lastClick, (MapillaryImportedImage)data.getHighlighted());50 } else if ( lastClick.next() ==data.getHighlighted()51 || lastClick.previous() ==data.getHighlighted())52 unjoin( lastClick, (MapillaryImportedImage)data.getHighlighted());53 lastClick = null;50 join(this.lastClick, (MapillaryImportedImage) this.data.getHighlighted()); 51 } else if (this.lastClick.next() == this.data.getHighlighted() 52 || this.lastClick.previous() == this.data.getHighlighted()) 53 unjoin(this.lastClick, (MapillaryImportedImage) this.data.getHighlighted()); 54 this.lastClick = null; 54 55 } 55 data.dataUpdated();56 MapillaryData.dataUpdated(); 56 57 } 57 58 58 59 @Override 59 60 public void mouseMoved(MouseEvent e) { 60 lastPos = e;61 this.lastPos = e; 61 62 if (!(Main.map.mapView.getActiveLayer() instanceof MapillaryLayer)) 62 63 return; 63 64 MapillaryAbstractImage closestTemp = getClosest(e.getPoint()); 64 data.setHighlightedImage(closestTemp);65 data.dataUpdated();65 this.data.setHighlightedImage(closestTemp); 66 MapillaryData.dataUpdated(); 66 67 } 67 68 68 69 @Override 69 70 public void paint(Graphics2D g, MapView mv, Bounds box) { 70 if ( lastClick != null) {71 if (this.lastClick != null) { 71 72 g.setColor(Color.WHITE); 72 Point p0 = mv.getPoint( lastClick.getLatLon());73 Point p1 = lastPos.getPoint();73 Point p0 = mv.getPoint(this.lastClick.getLatLon()); 74 Point p1 = this.lastPos.getPoint(); 74 75 g.drawLine(p0.x, p0.y, p1.x, p1.y); 75 76 } 76 77 } 77 78 78 private void join(MapillaryImportedImage img1, MapillaryImportedImage img2) { 79 private static void join(MapillaryImportedImage img1, MapillaryImportedImage img2) { 80 MapillaryImportedImage firstImage = img1; 81 MapillaryImportedImage secondImage = img2; 82 79 83 if (img1.next() != null) { 80 MapillaryImportedImage temp = img1; 81 img1 = img2; 82 img2 = temp; 84 firstImage = img2; 85 secondImage = img1; 83 86 } 84 if ( img1.getSequence() == null) {87 if (firstImage.getSequence() == null) { 85 88 MapillarySequence seq = new MapillarySequence(); 86 seq.add( img1);87 img1.setSequence(seq);89 seq.add(firstImage); 90 firstImage.setSequence(seq); 88 91 } 89 if ( img2.getSequence() == null) {92 if (secondImage.getSequence() == null) { 90 93 MapillarySequence seq = new MapillarySequence(); 91 seq.add( img2);94 seq.add(secondImage); 92 95 img2.setSequence(seq); 93 96 } 94 97 95 for (MapillaryAbstractImage img : img2.getSequence().getImages()) {96 img1.getSequence().add(img);97 img.setSequence( img1.getSequence());98 for (MapillaryAbstractImage img : secondImage.getSequence().getImages()) { 99 firstImage.getSequence().add(img); 100 img.setSequence(firstImage.getSequence()); 98 101 } 99 102 } 100 103 101 private void unjoin(MapillaryImportedImage img1, MapillaryImportedImage img2) { 104 private static void unjoin(MapillaryImportedImage img1, MapillaryImportedImage img2) { 105 MapillaryImportedImage firstImage = img1; 106 MapillaryImportedImage secondImage = img2; 107 102 108 if (img1.next() != img2) { 103 MapillaryImportedImage temp = img1; 104 img1 = img2; 105 img2 = temp; 109 firstImage = img2; 110 secondImage = img1; 106 111 } 107 112 108 ArrayList<MapillaryAbstractImage> firstHalf = new ArrayList<>( img1113 ArrayList<MapillaryAbstractImage> firstHalf = new ArrayList<>(firstImage 109 114 .getSequence().getImages() 110 .subList(0, img1.getSequence().getImages().indexOf(img2)));111 ArrayList<MapillaryAbstractImage> secondHalf = new ArrayList<>( img1115 .subList(0, firstImage.getSequence().getImages().indexOf(secondImage))); 116 ArrayList<MapillaryAbstractImage> secondHalf = new ArrayList<>(firstImage 112 117 .getSequence() 113 118 .getImages() 114 .subList( img1.getSequence().getImages().indexOf(img2),115 img1.getSequence().getImages().size()));119 .subList(firstImage.getSequence().getImages().indexOf(secondImage), 120 firstImage.getSequence().getImages().size())); 116 121 117 122 MapillarySequence seq1 = new MapillarySequence(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java
r31422 r31445 3 3 import java.awt.Graphics2D; 4 4 import java.awt.Point; 5 import java.awt.event.InputEvent; 5 6 import java.awt.event.MouseEvent; 6 7 import java.util.ArrayList; … … 13 14 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 15 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 16 18 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; … … 40 42 */ 41 43 public SelectMode() { 42 record = MapillaryRecord.getInstance();44 this.record = MapillaryRecord.getInstance(); 43 45 } 44 46 45 47 @Override 46 48 public void mousePressed(MouseEvent e) { 47 lastButton = e.getButton();49 this.lastButton = e.getButton(); 48 50 if (e.getButton() != MouseEvent.BUTTON1) 49 51 return; … … 52 54 && closest != null && Main.map.mapMode == Main.map.mapModeSelect) { 53 55 this.lastClicked = this.closest; 54 data.setSelectedImage(closest);56 this.data.setSelectedImage(closest); 55 57 return; 56 58 } else if (Main.map.mapView.getActiveLayer() != MapillaryLayer … … 58 60 return; 59 61 // Double click 60 if (e.getClickCount() == 2 && data.getSelectedImage() != null62 if (e.getClickCount() == 2 && this.data.getSelectedImage() != null 61 63 && closest != null) { 62 64 for (MapillaryAbstractImage img : closest.getSequence().getImages()) { 63 data.addMultiSelectedImage(img);65 this.data.addMultiSelectedImage(img); 64 66 } 65 67 } … … 67 69 this.lastClicked = this.closest; 68 70 this.closest = closest; 69 if ( data.getMultiSelectedImages().contains(closest))71 if (this.data.getMultiSelectedImages().contains(closest)) 70 72 return; 71 73 // ctrl+click 72 if (e.getModifiers() == ( MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK)74 if (e.getModifiers() == (InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK) 73 75 && closest != null) 74 data.addMultiSelectedImage(closest);76 this.data.addMultiSelectedImage(closest); 75 77 // shift + click 76 else if (e.getModifiers() == ( MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK)78 else if (e.getModifiers() == (InputEvent.BUTTON1_MASK | InputEvent.SHIFT_MASK) 77 79 && this.lastClicked instanceof MapillaryImage) { 78 80 if (this.closest != null && this.lastClicked != null … … 82 84 .indexOf(this.lastClicked); 83 85 if (i < j) 84 data.addMultiSelectedImage(new ArrayList<>(this.closest.getSequence()86 this.data.addMultiSelectedImage(new ArrayList<>(this.closest.getSequence() 85 87 .getImages().subList(i, j + 1))); 86 88 else 87 data.addMultiSelectedImage(new ArrayList<>(this.closest.getSequence()89 this.data.addMultiSelectedImage(new ArrayList<>(this.closest.getSequence() 88 90 .getImages().subList(j, i + 1))); 89 91 } 90 92 // click 91 93 } else 92 data.setSelectedImage(closest);94 this.data.setSelectedImage(closest); 93 95 } 94 96 … … 99 101 100 102 if (!Main.pref.getBoolean("mapillary.developer")) 101 for (MapillaryAbstractImage img : data.getMultiSelectedImages()) {103 for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) { 102 104 if (img instanceof MapillaryImage) 103 105 return; 104 106 } 105 if ( data.getSelectedImage() != null) {106 if ( lastButton == MouseEvent.BUTTON1 && !e.isShiftDown()) {107 if (this.data.getSelectedImage() != null) { 108 if (this.lastButton == MouseEvent.BUTTON1 && !e.isShiftDown()) { 107 109 LatLon to = Main.map.mapView.getLatLon(e.getX(), e.getY()); 108 LatLon from = Main.map.mapView.getLatLon( start.getX(),start.getY());109 for (MapillaryAbstractImage img : data.getMultiSelectedImages()) {110 LatLon from = Main.map.mapView.getLatLon(this.start.getX(), this.start.getY()); 111 for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) { 110 112 111 113 img.move(to.getX() - from.getX(), to.getY() - from.getY()); 112 114 } 113 115 Main.map.repaint(); 114 } else if ( lastButton == MouseEvent.BUTTON1 && e.isShiftDown()) {115 this.closest.turn(Math.toDegrees(Math.atan2((e.getX() - start.x),116 -(e.getY() - start.y)))117 - closest.getTempCa());118 for (MapillaryAbstractImage img : data.getMultiSelectedImages()) {119 img.turn(Math.toDegrees(Math.atan2((e.getX() - start.x),120 -(e.getY() - start.y))) -closest.getTempCa());116 } else if (this.lastButton == MouseEvent.BUTTON1 && e.isShiftDown()) { 117 this.closest.turn(Math.toDegrees(Math.atan2((e.getX() - this.start.x), 118 -(e.getY() - this.start.y))) 119 - this.closest.getTempCa()); 120 for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) { 121 img.turn(Math.toDegrees(Math.atan2((e.getX() - this.start.x), 122 -(e.getY() - this.start.y))) - this.closest.getTempCa()); 121 123 } 122 124 Main.map.repaint(); … … 127 129 @Override 128 130 public void mouseReleased(MouseEvent e) { 129 if ( data.getSelectedImage() == null)130 return; 131 if ( data.getSelectedImage().getTempCa() !=data.getSelectedImage().getCa()) {132 double from = data.getSelectedImage().getTempCa();133 double to = data.getSelectedImage().getCa();134 record.addCommand(new CommandTurnImage(data.getMultiSelectedImages(), to131 if (this.data.getSelectedImage() == null) 132 return; 133 if (this.data.getSelectedImage().getTempCa() != this.data.getSelectedImage().getCa()) { 134 double from = this.data.getSelectedImage().getTempCa(); 135 double to = this.data.getSelectedImage().getCa(); 136 this.record.addCommand(new CommandTurnImage(this.data.getMultiSelectedImages(), to 135 137 - from)); 136 } else if ( data.getSelectedImage().getTempLatLon() !=data138 } else if (this.data.getSelectedImage().getTempLatLon() != this.data 137 139 .getSelectedImage().getLatLon()) { 138 LatLon from = data.getSelectedImage().getTempLatLon();139 LatLon to = data.getSelectedImage().getLatLon();140 record.addCommand(new CommandMoveImage(data.getMultiSelectedImages(), to140 LatLon from = this.data.getSelectedImage().getTempLatLon(); 141 LatLon to = this.data.getSelectedImage().getLatLon(); 142 this.record.addCommand(new CommandMoveImage(this.data.getMultiSelectedImages(), to 141 143 .getX() - from.getX(), to.getY() - from.getY())); 142 144 } 143 for (MapillaryAbstractImage img : data.getMultiSelectedImages()) {145 for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) { 144 146 if (img != null) 145 147 img.stopMoving(); … … 158 160 if (closestTemp != null 159 161 && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 160 && ! imageHighlighted) {162 && !this.imageHighlighted) { 161 163 Main.map.mapMode.putValue("active", Boolean.FALSE); 162 imageHighlighted = true;164 this.imageHighlighted = true; 163 165 164 166 } else if (closestTemp == null 165 167 && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 166 && imageHighlighted &¬hingHighlighted) {167 nothingHighlighted = false;168 && this.imageHighlighted && this.nothingHighlighted) { 169 this.nothingHighlighted = false; 168 170 Main.map.mapMode.putValue("active", Boolean.TRUE); 169 171 170 } else if ( imageHighlighted && !nothingHighlighted172 } else if (this.imageHighlighted && !this.nothingHighlighted 171 173 && Main.map.mapView.getEditLayer().data != null 172 174 && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer) { … … 176 178 primivitive.setHighlighted(false); 177 179 } 178 imageHighlighted = false;179 nothingHighlighted = true;180 } 181 182 if ( data.getHighlighted() != closestTemp && closestTemp != null) {183 data.setHighlightedImage(closestTemp);180 this.imageHighlighted = false; 181 this.nothingHighlighted = true; 182 } 183 184 if (this.data.getHighlighted() != closestTemp && closestTemp != null) { 185 this.data.setHighlightedImage(closestTemp); 184 186 MapillaryMainDialog.getInstance().setImage(closestTemp); 185 187 MapillaryMainDialog.getInstance().updateImage(false); 186 } else if ( data.getHighlighted() != closestTemp && closestTemp == null) {187 data.setHighlightedImage(null);188 MapillaryMainDialog.getInstance().setImage( data.getSelectedImage());188 } else if (this.data.getHighlighted() != closestTemp && closestTemp == null) { 189 this.data.setHighlightedImage(null); 190 MapillaryMainDialog.getInstance().setImage(this.data.getSelectedImage()); 189 191 MapillaryMainDialog.getInstance().updateImage(); 190 192 } 191 data.dataUpdated();193 MapillaryData.dataUpdated(); 192 194 } 193 195 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java
r31418 r31445 8 8 import java.net.ServerSocket; 9 9 import java.net.Socket; 10 import java.net.URL;11 10 import java.util.Scanner; 12 11 … … 54 53 serverSocket.close(); 55 54 55 MapillaryUser.reset(); 56 56 57 Main.info("Successful login with Mapillary, the access token is: " 57 58 + accessToken); 58 59 // Saves the access token in preferences. 59 60 Main.pref.put("mapillary.access-token", accessToken); 60 // Sets the logged username in preferences.61 Main.pref62 .put(63 "mapillary.username",64 OAuthUtils65 .getWithHeader(66 new URL(67 "https://a.mapillary.com/v2/me?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz"))68 .getString("username"));69 61 70 Main.info("The username is: " + Ma in.pref.get("mapillary.username"));62 Main.info("The username is: " + MapillaryUser.getUsername()); 71 63 72 64 } catch (BindException e) { … … 77 69 } 78 70 79 private void writeContent(PrintWriter out) {71 private static void writeContent(PrintWriter out) { 80 72 String response = "<html><head><title>Mapillary login</title></head><body>Login successful, return to JOSM.</body></html>"; 81 73 out.println("HTTP/1.1 200 OK"); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java
r31418 r31445 1 1 package org.openstreetmap.josm.plugins.mapillary.oauth; 2 2 3 import java.io.BufferedOutputStream; 3 4 import java.io.BufferedReader; 5 import java.io.ByteArrayOutputStream; 6 import java.io.File; 7 import java.io.FileOutputStream; 4 8 import java.io.IOException; 5 9 import java.io.InputStreamReader; 10 import java.io.OutputStream; 11 import java.io.UnsupportedEncodingException; 6 12 import java.net.HttpURLConnection; 7 13 import java.net.URL; 8 14 import java.security.InvalidKeyException; 15 import java.security.NoSuchAlgorithmException; 16 import java.util.HashMap; 17 import java.util.UUID; 18 19 import javax.imageio.ImageIO; 9 20 import javax.json.Json; 10 21 import javax.json.JsonObject; 11 22 23 import org.apache.commons.imaging.ImageReadException; 24 import org.apache.commons.imaging.ImageWriteException; 25 import org.apache.commons.imaging.Imaging; 26 import org.apache.commons.imaging.common.ImageMetadata; 27 import org.apache.commons.imaging.common.RationalNumber; 28 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; 29 import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; 30 import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; 31 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; 32 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants; 33 import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; 34 import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; 35 import org.apache.http.HttpEntity; 36 import org.apache.http.HttpResponse; 37 import org.apache.http.client.HttpClient; 38 import org.apache.http.client.methods.HttpPost; 39 import org.apache.http.entity.ContentType; 40 import org.apache.http.entity.mime.MultipartEntityBuilder; 41 import org.apache.http.entity.mime.content.FileBody; 42 import org.apache.http.entity.mime.content.StringBody; 43 import org.apache.http.impl.client.HttpClientBuilder; 12 44 import org.openstreetmap.josm.Main; 45 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 46 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 47 import org.openstreetmap.josm.plugins.mapillary.MapillarySequence; 13 48 14 49 /** … … 20 55 public class OAuthUtils { 21 56 22 /** URL where to upload the images. */ 23 public static final String MAPILLARY_UPLOAD_URL = "https://s3-eu-west-1.amazonaws.com/mapillary.uploads.manual.images"; 57 private static final String[] keys = { "key", "AWSAccessKeyId", "acl", 58 "policy", "signature", "Content-Type" }; 59 private static final String UPLOAD_URL = "https://s3-eu-west-1.amazonaws.com/mapillary.uploads.manual.images"; 60 61 // Count to name temporal files. 62 private static int c = 0; 24 63 25 64 /** … … 28 67 * 29 68 * @param url 69 * The {@link URL} where the request must be made. 30 70 * @return A JsonObject containing the result of the GET request. 31 71 * @throws IOException 72 * Errors relating to the connection. 32 73 */ 33 74 public static JsonObject getWithHeader(URL url) throws IOException { … … 41 82 return Json.createReader(in).readObject(); 42 83 } 84 85 /** 86 * Uploads the given MapillaryImportedImage object. 87 * 88 * @param image 89 * 90 * @throws NoSuchAlgorithmException 91 * @throws UnsupportedEncodingException 92 * @throws InvalidKeyException 93 * 94 */ 95 public static void upload(MapillaryImportedImage image) 96 throws InvalidKeyException, UnsupportedEncodingException, 97 NoSuchAlgorithmException { 98 try { 99 upload(image, UUID.randomUUID()); 100 } catch (IOException e) { 101 Main.error(e); 102 } 103 } 104 105 /** 106 * @param image 107 * @param uuid 108 * The UUID used to create the sequence. 109 * @param username 110 * The username who is going to upload the picture. 111 * @throws NoSuchAlgorithmException 112 * @throws InvalidKeyException 113 * @throws IOException 114 */ 115 public static void upload(MapillaryImportedImage image, UUID uuid) 116 throws NoSuchAlgorithmException, InvalidKeyException, IOException { 117 String key = MapillaryUser.getUsername() + "/" + uuid.toString() + "/" 118 + image.getLatLon().lat() + "_" + image.getLatLon().lon() + "_" 119 + image.getCa() + "_" + image.datetimeOriginal + ".jpg"; 120 121 String policy = null; 122 String signature = null; 123 policy = MapillaryUser.getSecrets().get("images_policy"); 124 signature = MapillaryUser.getSecrets().get("images_hash"); 125 126 HashMap<String, String> hash = new HashMap<>(); 127 hash.put("key", key); 128 hash.put("AWSAccessKeyId", "AKIAI2X3BJAT2W75HILA"); 129 hash.put("acl", "private"); 130 hash.put("policy", policy); 131 hash.put("signature", signature); 132 hash.put("Content-Type", "image/jpeg"); 133 134 try { 135 uploadFile(updateFile(image), hash); 136 } catch (ImageReadException | ImageWriteException e) { 137 Main.error(e); 138 } 139 140 } 141 142 /** 143 * @param file 144 * @param hash 145 * @throws IOException 146 */ 147 public static void uploadFile(File file, HashMap<String, String> hash) 148 throws IOException { 149 HttpClientBuilder builder = HttpClientBuilder.create(); 150 HttpClient httpClient = builder.build(); 151 HttpPost httpPost = new HttpPost(UPLOAD_URL); 152 153 MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); 154 for (String key : keys) { 155 entityBuilder.addPart(key, new StringBody(hash.get(key), 156 ContentType.TEXT_PLAIN)); 157 System.out.println(key + " => " + hash.get(key)); 158 } 159 entityBuilder.addPart("file", new FileBody(file)); 160 161 HttpEntity entity = entityBuilder.build(); 162 httpPost.setEntity(entity); 163 164 System.out.println(httpPost); 165 HttpResponse response = httpClient.execute(httpPost); 166 System.out.println(response.toString()); 167 } 168 169 /** 170 * Uploads the given {@link MapillarySequence}. 171 * 172 * @param sequence 173 * The sequence to upload. It must contain only 174 * {@link MapillaryImportedImage} objects. 175 * @throws NoSuchAlgorithmException 176 * @throws UnsupportedEncodingException 177 * @throws InvalidKeyException 178 */ 179 public static void uploadSequence(MapillarySequence sequence) 180 throws InvalidKeyException, UnsupportedEncodingException, 181 NoSuchAlgorithmException { 182 UUID uuid = UUID.randomUUID(); 183 184 for (MapillaryAbstractImage img : sequence.getImages()) { 185 if (!(img instanceof MapillaryImportedImage)) 186 throw new IllegalArgumentException( 187 "The sequence contains downloaded images."); 188 try { 189 upload((MapillaryImportedImage) img, uuid); 190 } catch (IOException e) { 191 Main.error(e); 192 } 193 } 194 } 195 196 private static File updateFile(MapillaryImportedImage image) 197 throws ImageReadException, IOException, ImageWriteException { 198 TiffOutputSet outputSet = null; 199 TiffOutputDirectory exifDirectory = null; 200 // If the image is imported, loads the rest of the EXIF data. 201 ImageMetadata metadata = Imaging.getMetadata(image.getFile()); 202 final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; 203 if (null != jpegMetadata) { 204 final TiffImageMetadata exif = jpegMetadata.getExif(); 205 if (null != exif) { 206 outputSet = exif.getOutputSet(); 207 } 208 } 209 if (null == outputSet) { 210 outputSet = new TiffOutputSet(); 211 } 212 exifDirectory = outputSet.getOrCreateExifDirectory(); 213 214 exifDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF); 215 exifDirectory.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF, 216 GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF_VALUE_TRUE_NORTH); 217 218 exifDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); 219 exifDirectory.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION, 220 RationalNumber.valueOf(image.getCa())); 221 222 exifDirectory.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); 223 exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, 224 ((MapillaryImportedImage) image).getDate("yyyy/MM/dd hh:mm:ss")); 225 226 outputSet.setGPSInDegrees(image.getLatLon().lon(), image.getLatLon().lat()); 227 File tempFile = new File(c + ".tmp"); 228 OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile)); 229 230 // Transforms the image into a byte array. 231 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 232 ImageIO.write(image.getImage(), "jpg", outputStream); 233 byte[] imageBytes = outputStream.toByteArray(); 234 235 new ExifRewriter().updateExifMetadataLossless(imageBytes, os, outputSet); 236 237 return tempFile; 238 } 43 239 } -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImageTest.java
r31411 r31445 8 8 import java.util.TimeZone; 9 9 10 import org.junit.Before;11 10 import org.junit.Test; 12 11 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.plugins.mapillary.util.TestUtil;14 12 15 13 /** 16 14 * 17 15 */ 18 public class MapillaryAbstractImageTest { 19 20 @Before 21 public void init() { 22 TestUtil.initPlugin(); 23 } 16 public class MapillaryAbstractImageTest extends AbstractTest{ 24 17 25 18 /** -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/MapillarySequenceDownloadThreadTest.java
r31409 r31445 28 28 @Before 29 29 public void setUp() { 30 MapillaryData.TEST_MODE = true;31 30 TestUtil.initPlugin(); 32 31 }
Note:
See TracChangeset
for help on using the changeset viewer.