Changeset 31391 in osm for applications/editors/josm/plugins/mapillary/src
- Timestamp:
- 2015-07-16T13:56:29+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryImageInfoDownloaderThread.java
r31387 r31391 33 33 * 34 34 * @param ex {@link ExecutorService} object that is executing this thread. 35 * @param url 35 * @param queryString 36 * @param layer 36 37 */ 37 38 public MapillaryImageInfoDownloaderThread(ExecutorService ex, String queryString, MapillaryLayer layer) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31381 r31391 38 38 private final MapillarySquareDownloadManagerThread manager; 39 39 40 public MapillarySequenceDownloadThread(ExecutorService ex, String queryString, 41 MapillaryLayer layer, MapillarySquareDownloadManagerThread manager) { 40 /** 41 * Main constructor. 42 * 43 * @param ex 44 * @param queryString 45 * @param layer 46 * @param manager 47 */ 48 public MapillarySequenceDownloadThread(ExecutorService ex, 49 String queryString, MapillaryLayer layer, 50 MapillarySquareDownloadManagerThread manager) { 42 51 this.queryString = queryString; 43 52 this.ex = ex; … … 51 60 try { 52 61 BufferedReader br; 53 br = new BufferedReader(new InputStreamReader(new URL(URL + queryString).openStream(), "UTF-8")); 62 br = new BufferedReader(new InputStreamReader( 63 new URL(URL + queryString).openStream(), "UTF-8")); 54 64 JsonObject jsonall = Json.createReader(br).readObject(); 55 65 … … 94 104 if (layer.getMapillaryData().getImages().contains(img)) { 95 105 sequence.add(img); 96 ((MapillaryImage) layer.getMapillaryData().getImages().get( 97 layer.getMapillaryData().getImages().indexOf(img))).setSequence(sequence); 106 ((MapillaryImage) layer.getMapillaryData().getImages() 107 .get(layer.getMapillaryData().getImages().indexOf(img))) 108 .setSequence(sequence); 98 109 finalImages.set( 99 110 finalImages.indexOf(img), 100 (MapillaryImage) layer.getMapillaryData().getImages() .get(101 layer.getMapillaryData().getImages().indexOf(img)));111 (MapillaryImage) layer.getMapillaryData().getImages() 112 .get(layer.getMapillaryData().getImages().indexOf(img))); 102 113 } else { 103 114 img.setSequence(sequence); … … 110 121 manager.imagesAdded = imagesAdded; 111 122 } 112 layer.getMapillaryData().addWithoutUpdate( new ArrayList<MapillaryAbstractImage>(113 finalImages));123 layer.getMapillaryData().addWithoutUpdate( 124 new ArrayList<MapillaryAbstractImage>(finalImages)); 114 125 } 115 126 } catch (IOException e) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySignDownloaderThread.java
r31387 r31391 17 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 18 18 19 /** 20 * Downloads the signs information in a given area. 21 * 22 * @author nokutu 23 * 24 */ 19 25 public class MapillarySignDownloaderThread extends Thread { 20 private static final String URL = MapillaryDownloader.BASE_URL + "search/im/or/"; 26 private static final String URL = MapillaryDownloader.BASE_URL 27 + "search/im/or/"; 21 28 private final String queryString; 22 29 private final ExecutorService ex; … … 26 33 * Main constructor. 27 34 * 28 * @param ex {@link ExecutorService} object that is executing this thread. 29 * @param url 35 * @param ex 36 * {@link ExecutorService} object that is executing this thread. 37 * @param queryString 38 * @param layer 30 39 */ 31 public MapillarySignDownloaderThread(ExecutorService ex, String queryString, MapillaryLayer layer) { 40 public MapillarySignDownloaderThread(ExecutorService ex, String queryString, 41 MapillaryLayer layer) { 32 42 this.ex = ex; 33 43 this.queryString = queryString; … … 39 49 BufferedReader br; 40 50 try { 41 br = new BufferedReader(new InputStreamReader(new URL(URL + queryString).openStream(), "UTF-8")); 51 br = new BufferedReader(new InputStreamReader( 52 new URL(URL + queryString).openStream(), "UTF-8")); 42 53 JsonObject jsonobj = Json.createReader(br).readObject(); 43 54 if (!jsonobj.getBoolean("more")) { … … 55 66 for (int k = 0; k < rects.size(); k++) { 56 67 JsonObject data = rects.getJsonObject(k); 57 for (MapillaryAbstractImage image : layer.getMapillaryData().getImages()) 68 for (MapillaryAbstractImage image : layer.getMapillaryData() 69 .getImages()) 58 70 if (image instanceof MapillaryImage 59 71 && ((MapillaryImage) image).getKey().equals(key)) … … 67 79 for (int j = 0; j < rects.size(); j++) { 68 80 JsonObject data = rects.getJsonObject(j); 69 for (MapillaryAbstractImage image : layer.getMapillaryData().getImages()) 81 for (MapillaryAbstractImage image : layer.getMapillaryData() 82 .getImages()) 70 83 if (image instanceof MapillaryImage 71 84 && ((MapillaryImage) image).getKey().equals(key)) -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31387 r31391 31 31 private final String signQueryString; 32 32 private final MapillaryLayer layer; 33 /** Whether if new images have been added in the download or not. */ 33 34 public boolean imagesAdded = false; 34 35 … … 36 37 * Main constructor. 37 38 * 38 * @param urlImages URL used to download the images.39 * @param urlSequences URL used to download the sequences.40 * @param urlSigns URL used to download the signs.39 * @param queryStringParts 40 * @param layer 41 * 41 42 */ 42 public MapillarySquareDownloadManagerThread(ConcurrentHashMap<String, Double> queryStringParts, MapillaryLayer layer) { 43 public MapillarySquareDownloadManagerThread( 44 ConcurrentHashMap<String, Double> queryStringParts, MapillaryLayer layer) { 43 45 this.imageQueryString = buildQueryString(queryStringParts); 44 46 this.sequenceQueryString = buildQueryString(queryStringParts); 45 47 this.signQueryString = buildQueryString(queryStringParts); 46 48 47 Main.info("GET " + sequenceQueryString + " (Mapillary plugin)"); // TODO: Move this line to the appropriate place, here's no GET-request 49 // TODO: Move this line to the appropriate place, here's no GET-request 50 Main.info("GET " + sequenceQueryString + " (Mapillary plugin)"); 48 51 49 52 this.layer = layer; 50 53 } 51 54 52 // TODO: Maybe move into a separate utility class?55 // TODO: Maybe move into a separate utility class? 53 56 private String buildQueryString(ConcurrentHashMap<String, Double> hash) { 54 StringBuilder ret = new StringBuilder("?client_id=" + MapillaryDownloader.CLIENT_ID); 57 StringBuilder ret = new StringBuilder("?client_id=" 58 + MapillaryDownloader.CLIENT_ID); 55 59 for (String key : hash.keySet()) 56 60 if (key != null) 57 61 try { 58 ret.append("&" + URLEncoder.encode(key, "UTF-8")) 59 .append("=" + URLEncoder.encode(String.format(Locale.UK, "%f", hash.get(key)), "UTF-8")); 62 ret.append("&" + URLEncoder.encode(key, "UTF-8")).append( 63 "=" 64 + URLEncoder.encode( 65 String.format(Locale.UK, "%f", hash.get(key)), "UTF-8")); 60 66 } catch (UnsupportedEncodingException e) { 61 67 // This should not happen, as the encoding is hard-coded … … 90 96 int page = 0; 91 97 while (!ex.isShutdown()) { 92 ex.execute( 93 new MapillarySequenceDownloadThread( 94 ex, 95 sequenceQueryString + "&page=" + page + "&limit=10", 96 layer, 97 this 98 ) 99 ); 98 ex.execute(new MapillarySequenceDownloadThread(ex, sequenceQueryString 99 + "&page=" + page + "&limit=10", layer, this)); 100 100 while (ex.getQueue().remainingCapacity() == 0) 101 101 Thread.sleep(500); … … 125 125 int page = 0; 126 126 while (!ex.isShutdown()) { 127 ex.execute(new MapillarySignDownloaderThread(ex, signQueryString + "&page="128 + page + "&limit=20", layer));127 ex.execute(new MapillarySignDownloaderThread(ex, signQueryString 128 + "&page=" + page + "&limit=20", layer)); 129 129 while (ex.getQueue().remainingCapacity() == 0) 130 130 Thread.sleep(100); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java
r31389 r31391 51 51 /** 52 52 * Main constructor. 53 * @param ok 53 54 */ 54 55 public MapillaryExportDialog(JButton ok) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
r31390 r31391 64 64 panel.add(moveTo); 65 65 JButton oauth = new JButton(new OAuthAction()); 66 oauth.setText("Login"); 66 if (Main.pref.get("mapillary.access-token") == null) 67 oauth.setText("Login"); 68 else 69 oauth.setText("Already loged in, click to relogin"); 67 70 panel.add(oauth); 68 71 gui.getDisplayPreference().addSubTab(this, "Mapillary", panel); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java
r31389 r31391 13 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 14 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryData;16 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 17 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;18 16 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 19 17 import org.openstreetmap.josm.plugins.mapillary.commands.CommandMoveImage; … … 51 49 return; 52 50 MapillaryAbstractImage closest = getClosest(e.getPoint()); 53 if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer && closest Temp!= null51 if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer && closest != null 54 52 && Main.map.mapMode == Main.map.mapModeSelect) { 55 53 this.lastClicked = this.closest; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/PortListener.java
r31390 r31391 4 4 import java.io.InputStreamReader; 5 5 import java.io.PrintWriter; 6 import java.net.BindException; 6 7 import java.net.ServerSocket; 7 8 import java.net.Socket; … … 47 48 in.close(); 48 49 serverSocket.close(); 50 } catch (BindException e) { 51 return; 49 52 } catch (IOException e) { 50 53 Main.error(e); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoGlyph.java
r31383 r31391 11 11 public class TrafficoGlyph { 12 12 private static Map<String, Character> glyphs; 13 13 14 private static Map<String, Character> readGlyphsFromResources() { 14 JsonReader reader = Json.createReader(TrafficoSignElement.class.getResourceAsStream("/data/fonts/traffico/glyphs.json")); 15 JsonReader reader = Json.createReader(TrafficoSignElement.class 16 .getResourceAsStream("/data/fonts/traffico/glyphs.json")); 15 17 JsonObject glyphObject = reader.readObject().getJsonObject("glyphs"); 16 18 Set<String> glyphNames = glyphObject.keySet(); … … 21 23 return glyphs; 22 24 } 25 23 26 public static Character getGlyph(String key) { 24 27 if (glyphs == null) { … … 27 30 return glyphs.get(key); 28 31 } 32 29 33 public static void main(String[] args) { 30 34 System.out.println(TrafficoGlyph.getGlyph("h")); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoSign.java
r31383 r31391 30 30 System.out.println("Read signs for " + country); 31 31 InputStream countryStream = TrafficoSign.class 32 .getResourceAsStream("/data/fonts/traffico/signs/" + country + ".json"); 33 if (countryStream == null) { return null; } 32 .getResourceAsStream("/data/fonts/traffico/signs/" + country 33 + ".json"); 34 if (countryStream == null) { 35 return null; 36 } 34 37 JsonObject countrySigns = Json.createReader(countryStream).readObject(); 35 38 Set<String> countrySignNames = countrySigns.keySet(); … … 38 41 for (String name : countrySignNames) { 39 42 System.out.println(" * sign " + name); 40 JsonArray elements = countrySigns.getJsonObject(name).getJsonArray("elements"); 41 List<TrafficoSignElement> layers = new ArrayList<>(); // TODO: Replace by an array when all types of sign 42 // elements (text!) are supported 43 JsonArray elements = countrySigns.getJsonObject(name).getJsonArray( 44 "elements"); 45 46 // TODO: Replace by an array when all types of sign elements (text!) are 47 // supported 48 List<TrafficoSignElement> layers = new ArrayList<>(); 49 43 50 for (int i = 0; i < elements.size(); i++) { 44 System.out.println(" - " + elements.getJsonObject(i).getString("color") + " layer " 51 System.out.println(" - " 52 + elements.getJsonObject(i).getString("color") + " layer " 45 53 + elements.getJsonObject(i).getString("type")); 46 Character glyph = TrafficoGlyph.getGlyph(elements.getJsonObject(i).getString("type")); 54 Character glyph = TrafficoGlyph.getGlyph(elements.getJsonObject(i) 55 .getString("type")); 47 56 if (glyph != null) { 48 57 Color c; … … 76 85 signs.put(country, countryMap); 77 86 } 78 if (signs.get(country).get(signName) != null) { return signs.get(country).get(signName); } 79 if (isIn.containsKey(country)) { return TrafficoSign.getSign(isIn.get(country), signName); } 87 if (signs.get(country).get(signName) != null) { 88 return signs.get(country).get(signName); 89 } 90 if (isIn.containsKey(country)) { 91 return TrafficoSign.getSign(isIn.get(country), signName); 92 } 80 93 return null; 81 94 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoSignElement.java
r31383 r31391 9 9 10 10 public TrafficoSignElement(char glyph, Color c) { 11 12 13 14 15 11 if (c == null) { 12 throw new IllegalArgumentException(); 13 } 14 this.color = c; 15 this.glyph = glyph; 16 16 } 17 17
Note:
See TracChangeset
for help on using the changeset viewer.