Changeset 32979 in osm
- Timestamp:
- 2016-09-11T13:48:02+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r32383 r32979 8 8 import java.util.concurrent.ConcurrentHashMap; 9 9 import java.util.concurrent.CopyOnWriteArrayList; 10 import java.util.stream.Collectors; 10 11 11 12 import org.openstreetmap.josm.Main; … … 143 144 */ 144 145 public void addMultiSelectedImage(Set<MapillaryAbstractImage> images) { 145 for (MapillaryAbstractImage image : images) { 146 if (!this.multiSelectedImages.contains(image)) { 147 if (this.getSelectedImage() == null) { 148 this.setSelectedImage(image); 149 } else { 150 this.multiSelectedImages.add(image); 151 } 152 } 153 } 146 images.stream().filter(image -> !this.multiSelectedImages.contains(image)).forEach(image -> { 147 if (this.getSelectedImage() == null) { 148 this.setSelectedImage(image); 149 } else { 150 this.multiSelectedImages.add(image); 151 } 152 }); 154 153 Main.map.mapView.repaint(); 155 154 } … … 186 185 */ 187 186 public synchronized void remove(Set<MapillaryAbstractImage> images) { 188 for (MapillaryAbstractImage img : images) { 189 remove(img); 190 } 187 images.forEach(this::remove); 191 188 } 192 189 … … 240 237 */ 241 238 public synchronized Set<MapillarySequence> getSequences() { 242 Set<MapillarySequence> result = new HashSet<>(); 243 for (MapillaryAbstractImage img : getImages()) { 244 result.add(img.getSequence()); 245 } 239 Set<MapillarySequence> result = getImages().stream().map(MapillaryAbstractImage::getSequence).collect(Collectors.toSet()); 246 240 return result; 247 241 } … … 259 253 if (this.listeners.isEmpty()) 260 254 return; 261 for (MapillaryDataListener lis : this.listeners) { 262 if (lis != null) 263 lis.imagesAdded(); 264 } 255 this.listeners.stream().filter(lis -> lis != null).forEach(MapillaryDataListener::imagesAdded); 265 256 } 266 257 … … 385 376 if (this.listeners.isEmpty()) 386 377 return; 387 for (MapillaryDataListener lis : this.listeners) { 388 if (lis != null) 389 lis.selectedImageChanged(oldImage, newImage); 390 } 378 this.listeners.stream().filter(lis -> lis != null).forEach(lis -> lis.selectedImageChanged(oldImage, newImage)); 391 379 } 392 380 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java
r32974 r32979 83 83 @Override 84 84 public boolean equals(Object other) { 85 if (other != null && other.getClass() == this.getClass()) 86 return this.file.equals(((MapillaryImportedImage) other).file); 87 return false; 85 return other != null && other.getClass() == this.getClass() && this.file.equals(((MapillaryImportedImage) other).file); 88 86 } 89 87 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r32974 r32979 69 69 * 70 70 * @author nokutu 71 *72 71 */ 73 72 public final class MapillaryLayer extends AbstractModifiableLayer implements 74 73 DataSetListener, ActiveLayerChangeListener { 75 74 76 75 /** Maximum distance for the red/blue lines. */ 77 76 public static final int SEQUENCE_MAX_JUMP_DISTANCE = Main.pref.getInteger( 78 77 "mapillary.sequence-max-jump-distance", 100); 79 78 80 79 /** If the download is in semiautomatic during this object lifetime. */ … … 132 131 if (Main.main != null) { 133 132 MapillaryMainDialog.getInstance() 134 135 133 .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) 134 .put(KeyStroke.getKeyStroke("DELETE"), "MapillaryDel"); 136 135 MapillaryMainDialog.getInstance().getActionMap() 137 136 .put("MapillaryDel", new DeleteImageAction()); 138 137 } 139 138 … … 146 145 * Changes the mode the the given one. 147 146 * 148 * @param mode 149 * The mode that is going to be activated. 147 * @param mode The mode that is going to be activated. 150 148 */ 151 149 public void setMode(AbstractMode mode) { … … 354 352 if (imageAbs instanceof MapillaryImage && !((MapillaryImage) imageAbs).getSigns().isEmpty()) { 355 353 g.drawImage( 356 357 358 359 354 MapillaryPlugin.MAP_SIGN.getImage(), 355 p.x - MapillaryPlugin.MAP_SIGN.getIconWidth() / 2, 356 p.y - MapillaryPlugin.MAP_SIGN.getIconHeight() / 2, 357 Main.map.mapView 360 358 ); 361 359 } … … 370 368 * Draws the highlight of the icon. 371 369 * 372 * @param g 373 * @param p 374 * @param size 370 * @param g the graphics context 371 * @param p the {@link Point} where the image must be set. 372 * @param size the width in pixels of the highlight. 375 373 */ 376 374 private void drawPointHighlight(Graphics2D g, Point p, int size) { … … 378 376 Color highlightColor = PaintColors.HIGHLIGHT.get(); 379 377 Color highlightColorTransparent = new Color(highlightColor.getRed(), 380 378 highlightColor.getGreen(), highlightColor.getBlue(), 100); 381 379 g.setColor(highlightColorTransparent); 382 380 int s = size + this.highlightPointRadius; … … 393 391 * image. 394 392 * 395 * @param g 396 * @param image 397 * @param icon 398 * @param p 393 * @param g the graphics context 394 * @param image The {@link MapillaryAbstractImage} which is being drown. 395 * @param icon The {@link ImageIcon} that represents the image. 396 * @param p The P¡{@link Point} when the image lies. 399 397 */ 400 398 private void draw(Graphics2D g, MapillaryAbstractImage image, ImageIcon icon, Point p) { … … 430 428 public void mergeFrom(Layer from) { 431 429 throw new UnsupportedOperationException( 432 430 "This layer does not support merging yet"); 433 431 } 434 432 … … 447 445 * 448 446 * @return An array of length 2 containing the two closest images belonging to 449 * 447 * different sequences. 450 448 */ 451 449 private MapillaryImage[] getClosestImagesFromDifferentSequences() { … … 455 453 MapillaryImage[] ret = new MapillaryImage[2]; 456 454 double[] distances = { 457 458 455 SEQUENCE_MAX_JUMP_DISTANCE, 456 SEQUENCE_MAX_JUMP_DISTANCE 459 457 }; 460 458 LatLon selectedCoords = this.data.getSelectedImage().getMovingLatLon(); … … 466 464 MapillaryImage image = (MapillaryImage) imagePrev; 467 465 if (image.getMovingLatLon().greatCircleDistance(selectedCoords) < SEQUENCE_MAX_JUMP_DISTANCE 468 466 && selected.getSequence() != image.getSequence()) { 469 467 if ( 470 468 ret[0] == null && ret[1] == null 471 469 || image.getMovingLatLon().greatCircleDistance(selectedCoords) < distances[0] 472 470 && (ret[1] == null || image.getSequence() != ret[1].getSequence()) 473 ) {471 ) { 474 472 ret[0] = image; 475 473 distances[0] = image.getMovingLatLon().greatCircleDistance(selectedCoords); 476 474 } else if ((ret[1] == null || image.getMovingLatLon().greatCircleDistance( 477 478 475 selectedCoords) < distances[1]) 476 && image.getSequence() != ret[0].getSequence()) { 479 477 ret[1] = image; 480 478 distances[1] = image.getMovingLatLon().greatCircleDistance(selectedCoords); … … 492 490 @Override 493 491 public Object getInfoComponent() { 494 return new StringBuilder(35) 495 .append(tr("Mapillary layer")) 496 .append('\n') 497 .append(tr("Total images:")) 498 .append(' ') 499 .append(this.data.size()) 500 .append('\n') 501 .toString(); 492 return tr("Mapillary layer") + 493 '\n' + 494 tr("Total images:") + 495 ' ' + 496 this.data.size() + 497 '\n'; 502 498 } 503 499 … … 574 570 * 575 571 * @author nokutu 576 *577 572 */ 578 573 private static class DelayedDownload extends Thread { … … 593 588 * 594 589 * @author nokutu 595 *596 590 */ 597 591 private class DeleteImageAction extends AbstractAction { … … 603 597 if (instance != null) 604 598 MapillaryRecord.getInstance().addCommand( 605 599 new CommandDelete(getData().getMultiSelectedImages())); 606 600 } 607 601 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLocationChangeset.java
r32593 r32979 21 21 22 22 private void fireListeners() { 23 for (MapillaryChangesetListener listener : listeners) { 24 listener.changesetChanged(); 25 } 23 listeners.forEach(MapillaryChangesetListener::changesetChanged); 26 24 } 27 25 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySign.java
r32977 r32979 1 1 package org.openstreetmap.josm.plugins.mapillary; 2 3 import org.openstreetmap.josm.Main;4 2 5 3 import java.io.BufferedReader; 6 4 import java.io.IOException; 7 5 import java.io.InputStreamReader; 8 import java.nio.charset.Charset;9 6 import java.util.HashMap; 10 7 import java.util.Map; 11 8 import java.util.Optional; 12 9 10 import org.openstreetmap.josm.Main; 11 13 12 /** 14 * Created by nokutu on 30/07/16. 13 * Each {@link MapillarySign} represents a traffic sign detected by the Mapillary's system. 14 * 15 * @author nokutu 15 16 */ 16 17 public class MapillarySign { … … 33 34 BufferedReader br = new BufferedReader(new InputStreamReader( 34 35 MapillarySign.class.getResourceAsStream("/data/signs/" + country + ".cson"), "UTF-8" 35 )) ;36 )) 36 37 ) { 37 38 String line = ""; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java
r32978 r32979 79 79 if (image instanceof MapillaryImage) { 80 80 if (!images.contains(image)) { 81 images.addAll( ((MapillaryImage) image).getSequence().getImages());81 images.addAll(image.getSequence().getImages()); 82 82 } 83 83 } else { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java
r32977 r32979 148 148 this.interrupt(); 149 149 } else { 150 SwingUtilities.invokeLater( () -> stopWalk());150 SwingUtilities.invokeLater(this::stopWalk); 151 151 } 152 152 } … … 161 161 MapillaryMainDialog.getInstance().setMode(MapillaryMainDialog.MODE.NORMAL); 162 162 } else { 163 SwingUtilities.invokeLater( () -> end());163 SwingUtilities.invokeLater(this::end); 164 164 } 165 165 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/CacheUtils.java
r32374 r32979 27 27 FULL_IMAGE, 28 28 /** Both of them */ 29 BOTH ;29 BOTH 30 30 } 31 31 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/MapillaryCache.java
r32974 r32979 44 44 */ 45 45 public MapillaryCache(String key, Type type) { 46 super(MapillaryPlugin.getCache(), 50000, 50000, new HashMap< String, String>());46 super(MapillaryPlugin.getCache(), 50000, 50000, new HashMap<>()); 47 47 String k = null; 48 48 URL u = null; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java
r32653 r32979 112 112 LinkPopUp(final String key) { 113 113 this.copy = new JMenuItem(tr("Copy key")); 114 this.copy.addActionListener(new ActionListener() { 115 @Override 116 public void actionPerformed(ActionEvent paramActionEvent) { 117 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(key), null); 118 } 119 }); 114 this.copy.addActionListener(paramActionEvent -> Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(key), null)); 120 115 add(this.copy); 121 116 122 117 this.copyTag = new JMenuItem(tr("Copy key tag")); 123 this.copyTag.addActionListener(new ActionListener() { 124 @Override 125 public void actionPerformed(ActionEvent paramActionEvent) { 126 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection("mapillary=" + key), null); 127 } 128 }); 118 this.copyTag.addActionListener(paramActionEvent -> Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection("mapillary=" + key), null)); 129 119 add(this.copyTag); 130 120 131 121 this.edit = new JMenuItem(tr("Edit on website")); 132 this.edit.addActionListener(new ActionListener() { 133 @Override 134 public void actionPerformed(ActionEvent paramActionEvent) { 135 try { 136 MapillaryUtils.browse(MapillaryURL.browseEditURL(key)); 137 } catch (IOException e) { 138 Main.error(e); 139 } 122 this.edit.addActionListener(paramActionEvent -> { 123 try { 124 MapillaryUtils.browse(MapillaryURL.browseEditURL(key)); 125 } catch (IOException e) { 126 Main.error(e); 140 127 } 141 128 }); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryChangesetDialog.java
r32974 r32979 10 10 import java.awt.event.ActionEvent; 11 11 import java.awt.event.KeyEvent; 12 import java.util. Arrays;12 import java.util.Collections; 13 13 import java.util.concurrent.ConcurrentHashMap; 14 14 … … 97 97 this.submitButton = new SideButton(new SubmitAction()); 98 98 99 createLayout(treesPanel, true, Arrays.asList(new SideButton[] { this.submitButton }));99 createLayout(treesPanel, true, Collections.singletonList(this.submitButton)); 100 100 buildTree(); 101 101 } … … 124 124 125 125 this.map.clear(); 126 for (MapillaryImage command : changeset) { 127 if (command != null) { 128 DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString()); 129 this.map.put(node, command); 130 changesetRoot.add(node); 131 } 132 } 126 changeset.parallelStream().filter(command -> command != null).forEach(command -> { 127 DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString()); 128 this.map.put(node, command); 129 changesetRoot.add(node); 130 }); 133 131 134 132 this.spacer.setVisible(changeset.isEmpty()); … … 140 138 public void changesetChanged() { 141 139 if (!SwingUtilities.isEventDispatchThread()) { 142 SwingUtilities.invokeLater( () -> buildTree());140 SwingUtilities.invokeLater(this::buildTree); 143 141 } else { 144 142 buildTree(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java
r32373 r32979 83 83 // Some options are disabled depending on the circumstances 84 84 if (!(MapillaryLayer.getInstance().getData().getSelectedImage() instanceof MapillaryImage) 85 || ((MapillaryImage) MapillaryLayer.getInstance().getData().getSelectedImage()).getSequence() == null85 || MapillaryLayer.getInstance().getData().getSelectedImage().getSequence() == null 86 86 ) { 87 87 this.sequence.setEnabled(false); … … 90 90 this.selected.setEnabled(false); 91 91 } 92 this.rewrite.setEnabled(false); 93 for (MapillaryAbstractImage img : MapillaryLayer.getInstance().getData().getImages()) { 94 if (img instanceof MapillaryImportedImage) { 95 this.rewrite.setEnabled(true); 96 } 97 } 92 this.rewrite.setEnabled(MapillaryLayer.getInstance().getData().getImages().parallelStream().anyMatch(img -> img instanceof MapillaryImportedImage)); 98 93 99 94 this.path = new JLabel(tr("Select a folder")); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java
r32974 r32979 51 51 52 52 private static final String[] TIME_LIST = {tr("All"), tr("Years"), tr("Months"), tr("Days")}; 53 54 private final static long[] TIME_FACTOR = new long[]{ 55 31_536_000_000L, // = 365 * 24 * 60 * 60 * 1000 = number of ms in a year 56 2_592_000_000L, // = 30 * 24 * 60 * 60 * 1000 = number of ms in a month 57 86_400_000 // = 24 * 60 * 60 * 1000 = number of ms in a day 58 }; 53 59 54 60 /** … … 136 142 panel.add(signChooserPanel, c); 137 143 138 createLayout(panel, true, Arrays.asList( new SideButton[]{updateButton, resetButton}));144 createLayout(panel, true, Arrays.asList(updateButton, resetButton)); 139 145 } 140 146 … … 197 203 private boolean checkValidTime(MapillaryAbstractImage img) { 198 204 Long currentTime = currentTime(); 199 long[] timeFactor = new long[]{200 31_536_000_000L, // = 365 * 24 * 60 * 60 * 1000 = number of ms in a year201 2_592_000_000L, // = 30 * 24 * 60 * 60 * 1000 = number of ms in a month202 86_400_000 // = 24 * 60 * 60 * 1000 = number of ms in a day203 };204 205 for (int i = 1; i <= 3; i++) { 205 if (TIME_LIST[i].equals(time.getSelectedItem()) 206 && img.getCapturedAt() < currentTime - ((Integer) spinner.getValue()).longValue() * timeFactor[i - 1] 207 ) { 206 if (TIME_LIST[i].equals(time.getSelectedItem()) && 207 img.getCapturedAt() < currentTime - ((Integer) spinner.getValue()).longValue() * TIME_FACTOR[i - 1]) { 208 208 return true; 209 209 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java
r32690 r32979 112 112 this.redoButton = new SideButton(new RedoAction()); 113 113 114 createLayout(treesPanel, true, Arrays.asList( new SideButton[] {this.undoButton, this.redoButton}));114 createLayout(treesPanel, true, Arrays.asList(this.undoButton, this.redoButton)); 115 115 } 116 116 … … 148 148 149 149 this.map.clear(); 150 for (MapillaryCommand command : undoCommands) { 151 if (command != null) { 152 DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString()); 153 this.map.put(node, command); 154 undoRoot.add(node); 155 } 156 } 157 for (MapillaryCommand command : redoCommands) { 158 if (command != null) { 159 DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString()); 160 this.map.put(node, command); 161 redoRoot.add(node); 162 } 163 } 150 undoCommands.stream().filter(command -> command != null).forEach(command -> { 151 DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString()); 152 this.map.put(node, command); 153 undoRoot.add(node); 154 }); 155 redoCommands.stream().filter(command -> command != null).forEach(command -> { 156 DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString()); 157 this.map.put(node, command); 158 redoRoot.add(node); 159 }); 164 160 165 161 this.separator.setVisible(!undoCommands.isEmpty() || !redoCommands.isEmpty()); … … 173 169 public void recordChanged() { 174 170 if (!SwingUtilities.isEventDispatchThread()) { 175 SwingUtilities.invokeLater( () -> recordChanged());171 SwingUtilities.invokeLater(this::recordChanged); 176 172 } else { 177 173 buildTree(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java
r32690 r32979 84 84 * Mode when in walk. 85 85 */ 86 WALK ;86 WALK 87 87 } 88 88 … … 149 149 createLayout( 150 150 this.mapillaryImageDisplay, 151 Arrays.asList( new SideButton[]{playButton, pauseButton, stopButton})151 Arrays.asList(playButton, pauseButton, stopButton) 152 152 ); 153 153 break; … … 156 156 createLayout( 157 157 this.mapillaryImageDisplay, 158 Arrays.asList( new SideButton[]{blueButton, previousButton, nextButton, redButton})158 Arrays.asList(blueButton, previousButton, nextButton, redButton) 159 159 ); 160 160 break; … … 190 190 public synchronized void updateImage(boolean fullQuality) { 191 191 if (!SwingUtilities.isEventDispatchThread()) { 192 SwingUtilities.invokeLater( () -> updateImage());192 SwingUtilities.invokeLater(this::updateImage); 193 193 } else { 194 194 if (!MapillaryLayer.hasInstance()) { … … 293 293 public synchronized void updateTitle() { 294 294 if (!SwingUtilities.isEventDispatchThread()) { 295 SwingUtilities.invokeLater( () -> updateTitle());295 SwingUtilities.invokeLater(this::updateTitle); 296 296 } else if (this.image != null) { 297 297 StringBuilder title = new StringBuilder(tr(BASE_TITLE)); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
r32974 r32979 47 47 */ 48 48 public class MapillaryPreferenceSetting implements SubPreferenceSetting, MapillaryLoginListener { 49 49 50 private final JComboBox<String> downloadModeComboBox = new JComboBox<>(new String[]{ 50 51 DOWNLOAD_MODE.VISIBLE_AREA.getLabel(), … … 154 155 @Override 155 156 public boolean ok() { 156 boolean mod = false;157 158 157 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), false); 159 158 Main.pref.put( … … 171 170 Main.pref.put("mapillary.move-to-picture", this.moveTo.isSelected()); 172 171 Main.pref.put("mapillary.hover-enabled", this.hoverEnabled.isSelected()); 173 return mod; 172 173 //Restart is enver required 174 return false; 174 175 } 175 176 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java
r31987 r32979 122 122 123 123 private void fireRecordChanged() { 124 for (MapillaryRecordListener lis : this.listeners) { 125 if (lis != null) 126 lis.recordChanged(); 127 } 124 this.listeners.stream().filter(lis -> lis != null).forEach(MapillaryRecordListener::recordChanged); 128 125 } 129 126 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java
r32978 r32979 2 2 package org.openstreetmap.josm.plugins.mapillary.io.download; 3 3 4 import java.util.ArrayList;5 import java.util.List;6 4 import java.util.concurrent.ArrayBlockingQueue; 7 5 import java.util.concurrent.ThreadPoolExecutor; 8 6 import java.util.concurrent.TimeUnit; 9 import java.util.stream.IntStream;10 7 11 8 import javax.swing.JOptionPane; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryImageInfoDownloadThread.java
r32973 r32979 48 48 BufferedReader br = new BufferedReader(new InputStreamReader( 49 49 MapillaryURL.searchImageInfoURL(bounds, page, null).openStream(), "UTF-8" 50 )) ;50 )) 51 51 ) { 52 52 try (JsonReader reader = Json.createReader(br)) { … … 59 59 data = jsonArr.getJsonObject(i); 60 60 String key = data.getString("key"); 61 for (MapillaryAbstractImage image : MapillaryLayer.getInstance().getData().getImages()) { 62 if ( 63 image instanceof MapillaryImage 64 && ((MapillaryImage) image).getKey().equals(key) 65 && ((MapillaryImage) image).getUser() == null 66 ) { 67 ((MapillaryImage) image).setUser(data.getString("user")); 68 ((MapillaryImage) image).setCapturedAt(data.getJsonNumber("captured_at").longValue()); 69 if (!data.isNull("location")) { 70 ((MapillaryImage) image).setLocation(data.getString("location")); 71 } 61 MapillaryLayer.getInstance().getData().getImages().stream().filter(image -> image instanceof MapillaryImage 62 && ((MapillaryImage) image).getKey().equals(key) 63 && ((MapillaryImage) image).getUser() == null).forEach(image -> { 64 ((MapillaryImage) image).setUser(data.getString("user")); 65 image.setCapturedAt(data.getJsonNumber("captured_at").longValue()); 66 if (!data.isNull("location")) { 67 ((MapillaryImage) image).setLocation(data.getString("location")); 72 68 } 73 } 69 }); 74 70 } 75 71 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillarySequenceDownloadThread.java
r32383 r32979 9 9 import java.util.concurrent.ConcurrentSkipListSet; 10 10 import java.util.concurrent.ExecutorService; 11 import java.util.stream.Collectors; 11 12 12 13 import javax.json.Json; … … 40 41 * Main constructor. 41 42 * 42 * @param ex 43 * @param ex {@link ExecutorService} executing this thread. 43 44 * @param bounds The bounds inside which the sequences should be downloaded 44 * @param page 45 * @param page the pagenumber of the results that should be retrieved 45 46 */ 46 47 public MapillarySequenceDownloadThread(ExecutorService ex, Bounds bounds, int page) { … … 53 54 public void run() { 54 55 try ( 55 56 57 ));56 BufferedReader br = new BufferedReader(new InputStreamReader( 57 MapillaryURL.searchSequenceURL(bounds, page).openStream(), "UTF-8" 58 )) 58 59 ) { 59 60 JsonObject jsonall = Json.createReader(br).readObject(); … … 72 73 try { 73 74 images.add(new MapillaryImage( 74 75 76 77 78 79 75 keys.getString(j), 76 new LatLon( 77 coords.getJsonArray(j).getJsonNumber(1).doubleValue(), 78 coords.getJsonArray(j).getJsonNumber(0).doubleValue() 79 ), 80 cas.getJsonNumber(j).doubleValue())); 80 81 } catch (IndexOutOfBoundsException e) { 81 82 Main.warn("Mapillary bug at " + MapillaryURL.searchSequenceURL(bounds, page)); … … 86 87 break; 87 88 MapillarySequence sequence = new MapillarySequence( 88 89 89 jsonobj.getString("key"), jsonobj.getJsonNumber("captured_at") 90 .longValue()); 90 91 List<MapillaryImage> finalImages = new ArrayList<>(images); 91 92 // Here it gets only those images which are in the downloaded 92 93 // area. 93 for (MapillaryAbstractImage img : images) { 94 if (!isInside(img)) 95 finalImages.remove(img); 96 } 97 synchronized (this.getClass()) { 94 finalImages = images.parallelStream().filter(MapillarySequenceDownloadThread::isInside).collect(Collectors.toList()); 95 96 synchronized (MapillarySequenceDownloadThread.class) { 98 97 synchronized (MapillaryAbstractImage.class) { 99 98 for (MapillaryImage img : finalImages) { … … 101 100 // The image in finalImages is substituted by the one in the 102 101 // database, as they represent the same picture. 103 for (MapillaryAbstractImage source : MapillaryLayer.getInstance().getData().getImages()) { 104 if (source.equals(img)) {105 img = (MapillaryImage) source;106 }107 } 102 103 final MapillaryImage lambdaImg = img; 104 //noinspection OptionalGetWithoutIsPresent 105 img = (MapillaryImage) MapillaryLayer.getInstance().getData().getImages().parallelStream().filter(source -> source.equals(lambdaImg)).findAny().get(); 106 108 107 sequence.add(img); 109 108 img.setSequence(sequence); … … 117 116 } 118 117 119 MapillaryLayer.getInstance().getData().add(new ConcurrentSkipListSet< MapillaryAbstractImage>(finalImages), false);118 MapillaryLayer.getInstance().getData().add(new ConcurrentSkipListSet<>(finalImages), false); 120 119 } 121 120 } catch (IOException e) { 122 121 Main.error(String.format( 123 124 122 "Error reading the url %s, this might be a Mapillary problem.", 123 MapillaryURL.searchSequenceURL(bounds, page) 125 124 ), e); 126 125 } … … 129 128 130 129 private static boolean isInside(MapillaryAbstractImage image) { 131 for (Bounds b : MapillaryLayer.getInstance().getData().getBounds()) { 132 if (b.contains(image.getMovingLatLon())) { 133 return true; 134 } 135 } 136 return false; 130 return MapillaryLayer.getInstance().getData().getBounds().parallelStream().anyMatch(b -> b.contains(image.getLatLon())); 137 131 } 138 132 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryTrafficSignDownloadThread.java
r32972 r32979 5 5 import java.io.IOException; 6 6 import java.io.InputStreamReader; 7 import java.net.MalformedURLException;8 7 import java.util.concurrent.ExecutorService; 9 8 … … 49 48 BufferedReader br = new BufferedReader(new InputStreamReader( 50 49 MapillaryURL.searchImageInfoURL(bounds, page, IMAGE_SELECTOR.OBJ_REC_ONLY).openStream(), "UTF-8" 51 )) ;50 )) 52 51 ) { 53 52 JsonObject jsonobj = Json.createReader(br).readObject(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/export/MapillaryExportDownloadThread.java
r31811 r32979 63 63 CacheEntryAttributes attributes, LoadResult result) { 64 64 try { 65 synchronized ( this.getClass()) {65 synchronized (MapillaryExportDownloadThread.class) { 66 66 this.queue 67 67 .put(ImageIO.read(new ByteArrayInputStream(data.getContent()))); 68 68 this.queueImages.put(this.image); 69 69 } 70 } catch (InterruptedException e) { 71 Main.error(e); 72 } catch (IOException e) { 70 } catch (InterruptedException | IOException e) { 73 71 Main.error(e); 74 72 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/export/MapillaryExportManager.java
r32373 r32979 109 109 } 110 110 this.ex = new ThreadPoolExecutor(20, 35, 25, TimeUnit.SECONDS, 111 new ArrayBlockingQueue<Runnable>(10));111 new ArrayBlockingQueue<>(10)); 112 112 for (MapillaryAbstractImage image : this.images) { 113 113 if (image instanceof MapillaryImage) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/export/MapillaryExportWriterThread.java
r32383 r32979 129 129 if (mimg instanceof MapillaryImportedImage) { 130 130 exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, 131 ((MapillaryImportedImage) mimg).getDate("yyyy/MM/dd HH:mm:ss"));131 mimg.getDate("yyyy/MM/dd HH:mm:ss")); 132 132 } else if (mimg instanceof MapillaryImage) { 133 133 exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, 134 ((MapillaryImage) mimg).getDate("yyyy/MM/dd HH/mm/ss"));134 mimg.getDate("yyyy/MM/dd HH/mm/ss")); 135 135 } 136 136 outputSet.setGPSInDegrees(mimg.getMovingLatLon().lon(), mimg.getMovingLatLon().lat()); … … 142 142 Main.info("Mapillary export cancelled"); 143 143 return; 144 } catch (IOException e) { 145 Main.error(e); 146 } catch (ImageWriteException e) { 147 Main.error(e); 148 } catch (ImageReadException e) { 144 } catch (IOException | ImageReadException | ImageWriteException e) { 149 145 Main.error(e); 150 146 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java
r32978 r32979 57 57 * Paint the dataset using the engine set. 58 58 * 59 * @param g 59 * @param g {@link Graphics2D} used for painting 60 60 * @param mv 61 61 * The object that can translate GeoPoints to screen coordinates. 62 * @param box 62 * @param box Area where painting is going to be performed 63 63 */ 64 64 public abstract void paint(Graphics2D g, MapView mv, Bounds box); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java
r31976 r32979 43 43 Socket clientSocket = serverSocket.accept(); 44 44 PrintWriter out = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8"), true); 45 Scanner in = new Scanner(new InputStreamReader(clientSocket.getInputStream(), "UTF-8")) ;45 Scanner in = new Scanner(new InputStreamReader(clientSocket.getInputStream(), "UTF-8")) 46 46 ) { 47 47 String s; 48 48 String accessToken = null; 49 while (in.hasNextLine() && accessToken == null) {49 while (in.hasNextLine()) { 50 50 s = in.nextLine(); 51 51 Matcher tokenMatcher = Pattern.compile("^.*&access_token=([^&]+)&.*$").matcher('&'+s+'&'); … … 76 76 } catch (BindException e) { 77 77 Main.warn(e); 78 return;79 78 } catch (IOException e) { 80 79 Main.error(e); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java
r32974 r32979 85 85 this.images = images; 86 86 this.uuid = UUID.randomUUID(); 87 this.ex = new ThreadPoolExecutor(8, 8, 25, TimeUnit.SECONDS, new ArrayBlockingQueue< Runnable>(15));87 this.ex = new ThreadPoolExecutor(8, 8, 25, TimeUnit.SECONDS, new ArrayBlockingQueue<>(15)); 88 88 this.delete = delete; 89 89 } … … 137 137 * tags. 138 138 * 139 * @param image 139 * @param image The image to be uploaded 140 140 * @return A File object containing the picture and an updated version of the 141 141 * EXIF tags. … … 145 145 * @throws ImageWriteException if there are errors writing the image in the file. 146 146 */ 147 p ublicstatic File updateFile(MapillaryImportedImage image)147 private static File updateFile(MapillaryImportedImage image) 148 148 throws ImageReadException, IOException, ImageWriteException { 149 149 TiffOutputSet outputSet = null; … … 153 153 154 154 // If the image is imported, loads the rest of the EXIF data. 155 JpegImageMetadata jpegMetadata = null; 156 try { 157 ImageMetadata metadata = Imaging.getMetadata(image.getFile()); 158 jpegMetadata = (JpegImageMetadata) metadata; 159 } catch (Exception e) { 160 } 155 ImageMetadata metadata = Imaging.getMetadata(image.getFile()); 156 JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; 157 161 158 if (null != jpegMetadata) { 162 159 final TiffImageMetadata exif = jpegMetadata.getExif(); … … 204 201 * Uploads the given MapillaryImportedImage object. 205 202 * 206 * @param image 203 * @param image The image to be uploaded 204 * @throws IllegalStateException If {@link MapillaryUser#getSecrets()} returns null 207 205 */ 208 206 public static void upload(MapillaryImportedImage image) { … … 211 209 212 210 /** 213 * @param image 211 * @param image The image to be uploaded 214 212 * @param uuid The UUID used to create the sequence. 215 213 */ 216 214 public static void upload(MapillaryImportedImage image, UUID uuid) { 217 String key = new StringBuilder(MapillaryUser.getUsername()) 218 .append('/').append(uuid) 219 .append('/').append(image.getMovingLatLon().lat()) // TODO: Make sure, that the double values are not appended as something like "10e-4", "Infinity" or "NaN" (all possible values of Double.toString(double)) 220 .append('_').append(image.getMovingLatLon().lon()) 221 .append('_').append(image.getMovingCa()) 222 .append('_').append(image.getCapturedAt()) 223 .append(".jpg") 224 .toString(); 215 Map<String, String> secretMap = MapillaryUser.getSecrets(); 216 if (secretMap == null) { 217 throw new IllegalStateException("Can't obtain secrents from user"); 218 } 219 220 String key = MapillaryUser.getUsername() + 221 '/' + uuid + 222 '/' + image.getMovingLatLon().lat() + // TODO: Make sure, that the double values are not appended as something like "10e-4", "Infinity" or "NaN" (all possible values of Double.toString(double)) 223 '_' + image.getMovingLatLon().lon() + 224 '_' + image.getMovingCa() + 225 '_' + image.getCapturedAt() + 226 ".jpg"; 225 227 226 228 String policy; 227 229 String signature; 228 policy = MapillaryUser.getSecrets().get("images_policy");229 signature = MapillaryUser.getSecrets().get("images_hash");230 policy = secretMap.get("images_policy"); 231 signature = secretMap.get("images_hash"); 230 232 231 233 Map<String, String> hash = new HashMap<>(); … … 244 246 245 247 /** 246 * @param file 247 * @param hash 248 * @throws IOException 248 * @param file File that is going to be uploaded 249 * @param hash Information attached to the upload 249 250 * @throws IllegalArgumentException if the hash doesn't contain all the needed keys. 250 251 */ 251 p ublicstatic void uploadFile(File file, Map<String, String> hash) throws IOException {252 private static void uploadFile(File file, Map<String, String> hash) throws IOException { 252 253 HttpClientBuilder builder = HttpClientBuilder.create(); 253 254 HttpPost httpPost = new HttpPost(UPLOAD_URL); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoSign.java
r32066 r32979 109 109 // Create Map for country if not already exists 110 110 if (!signs.containsKey(sign.getCountry())) { 111 signs.put(sign.getCountry(), new TreeMap< String, TrafficoSign>());111 signs.put(sign.getCountry(), new TreeMap<>()); 112 112 } 113 113 // Don't overwrite existing sign with same country-name-combination -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryColorScheme.java
r32717 r32979 59 59 } 60 60 ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 61 ((Graphics2D) g).fillRoundRect(0, 0, getWidth(), getHeight(), 3, 3);61 g.fillRoundRect(0, 0, getWidth(), getHeight(), 3, 3); 62 62 super.paintComponent(g); 63 63 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java
r32690 r32979 10 10 import java.text.ParseException; 11 11 import java.text.SimpleDateFormat; 12 import java.util.ArrayList;13 12 import java.util.Calendar; 14 13 import java.util.Locale; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/PluginState.java
r32690 r32979 111 111 dlg.setVisible(true); 112 112 } else { 113 SwingUtilities.invokeLater( () -> finishedUploadDialog());113 SwingUtilities.invokeLater(PluginState::finishedUploadDialog); 114 114 } 115 115 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/ValidationUtil.java
r32403 r32979 56 56 * @param nullAllowed this controls the behaviour when the key is <code>null</code>. If this variable is 57 57 * <code>false</code>, an {@link IllegalArgumentException} is then thrown, otherwise nothing is done. 58 * @see {@link #validateSequenceKey(String)}58 * @see #validateSequenceKey(String) 59 59 */ 60 @SuppressWarnings ("ConstantConditions") 60 61 public static void throwExceptionForInvalidSeqKey(String seqKey, boolean nullAllowed) { 61 62 if (!validateSequenceKey(seqKey)) {
Note:
See TracChangeset
for help on using the changeset viewer.