Changeset 31457 in osm for applications
- Timestamp:
- 2015-08-05T16:28:33+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 11 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31453 r31457 2 2 3 3 import org.openstreetmap.josm.Main; 4 import org.openstreetmap.josm.plugins.mapillary.cache. Utils;4 import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils; 5 5 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog; 6 6 … … 173 173 * following visible MapillaryImage is selected. In case there is none, does 174 174 * nothing. 175 * 176 * @throws IllegalStateException 177 * if the selected image is null or the selected image doesn't 178 * belong to a sequence. 175 179 */ 176 180 public void selectNext() { 177 if (getSelectedImage() == null) 178 return; 179 if (getSelectedImage().getSequence() == null) 180 return; 181 MapillaryAbstractImage tempImage = this.selectedImage; 182 while (tempImage.next() != null) { 183 tempImage = tempImage.next(); 184 if (tempImage.isVisible()) { 185 setSelectedImage(tempImage, 186 Main.pref.getBoolean("mapillary.move-to-picture", true)); 187 break; 188 } 189 } 181 selectNext(Main.pref.getBoolean("mapillary.move-to-picture", true)); 190 182 } 191 183 … … 197 189 * @param moveToPicture 198 190 * True if the view must me moved to the next picture. 191 * @throws IllegalStateException 192 * if the selected image is null or the selected image doesn't 193 * belong to a sequence. 199 194 */ 200 195 public void selectNext(boolean moveToPicture) { 201 196 if (getSelectedImage() == null) 202 return;197 throw new IllegalStateException(); 203 198 if (getSelectedImage().getSequence() == null) 204 return;199 throw new IllegalStateException(); 205 200 MapillaryAbstractImage tempImage = this.selectedImage; 206 201 while (tempImage.next() != null) { … … 217 212 * previous visible MapillaryImage is selected. In case there is none, does 218 213 * nothing. 214 * 215 * @throws IllegalStateException 216 * if the selected image is null or the selected image doesn't 217 * belong to a sequence. 219 218 */ 220 219 public void selectPrevious() { 221 if (getSelectedImage() == null) 222 return; 223 if (getSelectedImage().getSequence() == null) 224 throw new IllegalStateException(); 225 MapillaryAbstractImage tempImage = this.selectedImage; 226 while (tempImage.previous() != null) { 227 tempImage = tempImage.previous(); 228 if (tempImage.isVisible()) { 229 setSelectedImage(tempImage, 230 Main.pref.getBoolean("mapillary.move-to-picture", true)); 231 break; 232 } 233 } 220 selectPrevious(Main.pref.getBoolean("mapillary.move-to-picture", true)); 234 221 } 235 222 … … 237 224 * If the selected MapillaryImage is part of a MapillarySequence then the 238 225 * previous visible MapillaryImage is selected. In case there is none, does 239 * nothing. 226 * nothing. * @throws IllegalStateException if the selected image is null or 227 * the selected image doesn't belong to a sequence. 240 228 * 241 229 * @param moveToPicture 242 230 * True if the view must me moved to the previous picture. 231 * @throws IllegalStateException 232 * if the selected image is null or the selected image doesn't 233 * belong to a sequence. 243 234 */ 244 235 public void selectPrevious(boolean moveToPicture) { … … 262 253 * @param image 263 254 * The MapillaryImage which is going to be selected 255 * 264 256 */ 265 257 public void setSelectedImage(MapillaryAbstractImage image) { … … 286 278 // Downloading thumbnails of surrounding pictures. 287 279 if (mapillaryImage.next() != null) { 288 Utils.downloadPicture((MapillaryImage) mapillaryImage.next());280 CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.next()); 289 281 if (mapillaryImage.next().next() != null) 290 Utils282 CacheUtils 291 283 .downloadPicture((MapillaryImage) mapillaryImage.next().next()); 292 284 } 293 285 if (mapillaryImage.previous() != null) { 294 Utils.downloadPicture((MapillaryImage) mapillaryImage.previous());286 CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.previous()); 295 287 if (mapillaryImage.previous().previous() != null) 296 Utils.downloadPicture((MapillaryImage) mapillaryImage.previous()288 CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.previous() 297 289 .previous()); 298 290 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java
r31445 r31457 69 69 */ 70 70 public BufferedImage getImage() throws IOException { 71 return this.file == null ? null :ImageIO.read(this.file);71 return ImageIO.read(this.file); 72 72 } 73 73 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31456 r31457 4 4 import static org.openstreetmap.josm.tools.I18n.marktr; 5 5 6 import org.openstreetmap.josm.plugins.mapillary.cache. Utils;6 import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils; 7 7 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader; 8 8 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog; … … 278 278 if (Main.map.mapView.getActiveLayer() == this) { 279 279 Rectangle b = mv.getBounds(); 280 // on some platforms viewport bounds seem to be offset from the 281 // left, 280 // on some platforms viewport bounds seem to be offset from the left, 282 281 // over-grow it just to be sure 283 282 b.grow(100, 100); … … 486 485 // Predownloads the thumbnails 487 486 if (ret[0] != null) 488 Utils.downloadPicture(ret[0]);487 CacheUtils.downloadPicture(ret[0]); 489 488 if (ret[1] != null) 490 Utils.downloadPicture(ret[1]);489 CacheUtils.downloadPicture(ret[1]); 491 490 return ret; 492 491 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
r31452 r31457 20 20 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryPreferenceSetting; 21 21 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog; 22 import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryUser; 22 23 import org.openstreetmap.josm.plugins.mapillary.actions.*; 23 24 import org.openstreetmap.josm.tools.ImageProvider; … … 142 143 Main.error(e); 143 144 } 145 146 if (Main.pref.get("mapillary.access-token") == null) 147 MapillaryUser.isTokenValid = false; 144 148 } 145 149 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java
r31445 r31457 107 107 * going to be returned. 108 108 * @return The next {@link MapillaryAbstractImage} object in the sequence. 109 * @throws IllegalArgumentException 110 * if the given {@link MapillaryAbstractImage} object doesn't belong 111 * the this sequence. 109 112 */ 110 113 public MapillaryAbstractImage next(MapillaryAbstractImage image) { … … 124 127 * going to be returned. 125 128 * @return The previous {@link MapillaryAbstractImage} object in the sequence. 129 * @throws IllegalArgumentException 130 * if the given {@link MapillaryAbstractImage} object doesn't belong 131 * the this sequence. 126 132 */ 127 133 public MapillaryAbstractImage previous(MapillaryAbstractImage image) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java
r31452 r31457 12 12 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 13 13 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 14 import org.openstreetmap.josm.plugins.mapillary.cache. Utils;14 import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils; 15 15 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog; 16 16 … … 66 66 break; 67 67 image = image.next(); 68 Utils.downloadPicture((MapillaryImage) image,69 Utils.PICTURE.THUMBNAIL);68 CacheUtils.downloadPicture((MapillaryImage) image, 69 CacheUtils.PICTURE.THUMBNAIL); 70 70 } 71 71 if (this.waitForFullQuality) … … 75 75 break; 76 76 image = image.next(); 77 Utils.downloadPicture((MapillaryImage) image,78 Utils.PICTURE.FULL_IMAGE);77 CacheUtils.downloadPicture((MapillaryImage) image, 78 CacheUtils.PICTURE.FULL_IMAGE); 79 79 } 80 80 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/CacheUtils.java
r31456 r31457 12 12 * 13 13 */ 14 public class Utils {14 public class CacheUtils { 15 15 16 16 private static IgnoreDownload IGNORE_DOWNLOAD = new IgnoreDownload(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java
r31454 r31457 269 269 } 270 270 271 /** Disables all the buttons in the dialog */ 271 272 private void disableAllButtons() { 272 273 this.nextButton.setEnabled(false); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
r31445 r31457 7 7 import java.awt.event.ActionEvent; 8 8 import java.io.IOException; 9 import java.net.MalformedURLException;10 9 import java.net.URI; 11 10 import java.net.URISyntaxException; … … 44 43 private JCheckBox moveTo = new JCheckBox( 45 44 tr("Move to picture's location with next/previous buttons")); 45 private JButton login; 46 46 47 47 @Override … … 56 56 this.reverseButtons.setSelected(Main.pref 57 57 .getBoolean("mapillary.reverse-buttons")); 58 this.displayHour.setSelected(Main.pref 59 .getBoolean("mapillary.display-hour",true));58 this.displayHour.setSelected(Main.pref.getBoolean("mapillary.display-hour", 59 true)); 60 60 this.format24.setSelected(Main.pref.getBoolean("mapillary.format-24")); 61 this.moveTo.setSelected(Main.pref.getBoolean("mapillary.move-to-picture", true)); 61 this.moveTo.setSelected(Main.pref.getBoolean("mapillary.move-to-picture", 62 true)); 62 63 63 64 panel.setLayout(new FlowLayout(FlowLayout.LEFT)); … … 82 83 panel.add(this.format24); 83 84 panel.add(this.moveTo); 84 JButton oauth = new JButton(new OAuthAction());85 this.login = new JButton(new LoginAction()); 85 86 if (Main.pref.get("mapillary.access-token") == null) 86 oauth.setText("Login");87 this.login.setText("Login"); 87 88 else 88 t ry {89 oauth.setText("Logged as: " + MapillaryUser.getUsername()+ ". Click to relogin.");90 } catch (MalformedURLException e) { 91 // TODO Auto-generated catch block92 e.printStackTrace();93 } catch (IOException e) {94 // TODO Auto-generated catch block95 e.printStackTrace(); 96 }97 panel.add(oauth);89 this.login.setText("Logged as: " + MapillaryUser.getUsername() 90 + ". Click to relogin."); 91 92 panel.add(this.login); 93 if (MapillaryUser.getUsername() != null) { 94 JButton logout = new JButton(new LogoutAction()); 95 logout.setText("Logout"); 96 97 panel.add(logout); 98 } 98 99 gui.getDisplayPreference().addSubTab(this, "Mapillary", panel); 99 100 } … … 102 103 public boolean ok() { 103 104 boolean mod = false; 104 Main.pref.put("mapillary.reverse-buttons", this.reverseButtons.isSelected()); 105 Main.pref 106 .put("mapillary.reverse-buttons", this.reverseButtons.isSelected()); 105 107 106 108 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, false); 107 if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[0])) 109 if (this.downloadMode.getSelectedItem() 110 .equals(MapillaryDownloader.MODES[0])) 108 111 Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[0]); 109 if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[1])) 112 if (this.downloadMode.getSelectedItem() 113 .equals(MapillaryDownloader.MODES[1])) 110 114 Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[1]); 111 if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[2])) { 115 if (this.downloadMode.getSelectedItem() 116 .equals(MapillaryDownloader.MODES[2])) { 112 117 Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[2]); 113 118 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true); … … 131 136 * 132 137 */ 133 public class OAuthAction extends AbstractAction {138 public class LoginAction extends AbstractAction { 134 139 135 140 private static final long serialVersionUID = -3908477563072057344L; … … 158 163 } 159 164 } 165 166 /** 167 * Logs the user out. 168 * 169 * @author nokutu 170 * 171 */ 172 public class LogoutAction extends AbstractAction { 173 174 private static final long serialVersionUID = 3434780936404707219L; 175 176 @Override 177 public void actionPerformed(ActionEvent arg0) { 178 MapillaryUser.reset(); 179 Main.pref.put("mapillary.access-token", null); 180 MapillaryPreferenceSetting.this.login.setText("Login"); 181 } 182 } 183 160 184 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java
r31445 r31457 2 2 3 3 import java.io.IOException; 4 import java.net.MalformedURLException;5 4 import java.net.URL; 6 5 import java.util.HashMap; 6 7 import org.openstreetmap.josm.Main; 7 8 8 9 /** … … 15 16 private static String images_policy; 16 17 private static String images_hash; 18 /** If the stored token is valid or not. */ 19 public static boolean isTokenValid = true; 17 20 18 21 /** … … 20 23 * 21 24 * @return The username of the logged in user. 22 * @throws MalformedURLException23 * @throws IOException24 25 */ 25 public static String getUsername() throws MalformedURLException, IOException { 26 public static String getUsername() { 27 if (!isTokenValid) 28 return null; 26 29 if (username == null) 27 username = OAuthUtils 28 .getWithHeader( 29 new URL( 30 "https://a.mapillary.com/v2/me?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz")) 31 .getString("username"); 30 try { 31 username = OAuthUtils 32 .getWithHeader( 33 new URL( 34 "https://a.mapillary.com/v2/me?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz")) 35 .getString("username"); 36 } catch (IOException e) { 37 Main.error(e); 38 isTokenValid = false; 39 } 32 40 33 41 return username; … … 37 45 * @return A HashMap object containing the images_policy and images_hash 38 46 * strings. 39 * @throws MalformedURLException40 * @throws IOException41 47 */ 42 public static HashMap<String, String> getSecrets() 43 throws MalformedURLException, IOException { 48 public static HashMap<String, String> getSecrets() { 49 if (!isTokenValid) 50 return null; 44 51 HashMap<String, String> hash = new HashMap<>(); 45 52 if (images_hash == null) 46 images_hash = OAuthUtils 47 .getWithHeader( 48 new URL( 49 "https://a.mapillary.com/v2/me/uploads/secrets?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz")) 50 .getString("images_hash"); 53 try { 54 images_hash = OAuthUtils 55 .getWithHeader( 56 new URL( 57 "https://a.mapillary.com/v2/me/uploads/secrets?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz")) 58 .getString("images_hash"); 59 } catch (IOException e) { 60 Main.error(e); 61 isTokenValid = false; 62 isTokenValid = false; 63 } 51 64 hash.put("images_hash", images_hash); 52 65 if (images_policy == null) 53 images_policy = OAuthUtils 54 .getWithHeader( 55 new URL( 56 "https://a.mapillary.com/v2/me/uploads/secrets?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz")) 57 .getString("images_policy"); 66 try { 67 images_policy = OAuthUtils 68 .getWithHeader( 69 new URL( 70 "https://a.mapillary.com/v2/me/uploads/secrets?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz")) 71 .getString("images_policy"); 72 } catch (IOException e) { 73 Main.error(e); 74 isTokenValid = false; 75 } 58 76 hash.put("images_policy", images_policy); 59 77 return hash; … … 67 85 images_policy = null; 68 86 images_hash = null; 87 isTokenValid = true; 69 88 } 70 89 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java
r31456 r31457 7 7 import java.io.IOException; 8 8 import java.io.OutputStream; 9 import java.io.UnsupportedEncodingException;10 import java.security.InvalidKeyException;11 import java.security.NoSuchAlgorithmException;12 9 import java.util.HashMap; 13 10 import java.util.List; … … 55 52 public class UploadUtils { 56 53 54 /** Required keys for POST */ 57 55 private static final String[] keys = { "key", "AWSAccessKeyId", "acl", 58 56 "policy", "signature", "Content-Type" }; 57 /** Mapillary upload URL */ 59 58 private static final String UPLOAD_URL = "https://s3-eu-west-1.amazonaws.com/mapillary.uploads.manual.images"; 60 59 /** Count to name temporal files. */ … … 66 65 * @param image 67 66 * 68 * @throws NoSuchAlgorithmException 69 * @throws UnsupportedEncodingException 70 * @throws InvalidKeyException 71 * 72 */ 73 public static void upload(MapillaryImportedImage image) 74 throws InvalidKeyException, UnsupportedEncodingException, 75 NoSuchAlgorithmException { 76 try { 77 upload(image, UUID.randomUUID()); 78 } catch (IOException e) { 79 Main.error(e); 80 } 67 */ 68 public static void upload(MapillaryImportedImage image) { 69 upload(image, UUID.randomUUID()); 70 81 71 } 82 72 … … 85 75 * @param uuid 86 76 * The UUID used to create the sequence. 87 * @throws NoSuchAlgorithmException 88 * @throws InvalidKeyException 89 * @throws IOException 90 */ 91 public static void upload(MapillaryImportedImage image, UUID uuid) 92 throws NoSuchAlgorithmException, InvalidKeyException, IOException { 77 */ 78 public static void upload(MapillaryImportedImage image, UUID uuid) { 93 79 String key = MapillaryUser.getUsername() + "/" + uuid.toString() + "/" 94 80 + image.getLatLon().lat() + "_" + image.getLatLon().lon() + "_" … … 110 96 try { 111 97 uploadFile(updateFile(image), hash); 112 } catch (ImageReadException | ImageWriteException e) {98 } catch (ImageReadException | ImageWriteException | IOException e) { 113 99 Main.error(e); 114 100 } 115 116 101 } 117 102 … … 120 105 * @param hash 121 106 * @throws IOException 107 * @throws IllegalArgumentException 108 * if the hash doesn't contain all the needed keys. 122 109 */ 123 110 public static void uploadFile(File file, HashMap<String, String> hash) … … 129 116 MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); 130 117 for (String key : keys) { 118 if (hash.get(key) == null) 119 throw new IllegalArgumentException(); 131 120 entityBuilder.addPart(key, new StringBody(hash.get(key), 132 121 ContentType.TEXT_PLAIN)); … … 153 142 */ 154 143 public static void uploadSequence(MapillarySequence sequence) { 155 new SequenceUploadThread(sequence.getImages()).start();144 Main.worker.submit(new SequenceUploadThread(sequence.getImages())); 156 145 } 157 146 … … 197 186 @Override 198 187 public void run() { 199 try { 200 upload(this.image, this.uuid); 201 } catch (InvalidKeyException | NoSuchAlgorithmException | IOException e) { 202 Main.error(e); 203 } 188 upload(this.image, this.uuid); 189 204 190 } 205 191 } … … 213 199 * EXIF tags. 214 200 * @throws ImageReadException 201 * if there are errors reading the image from the file. 215 202 * @throws IOException 203 * if there are errors getting the metadata from the file or writing 204 * the output. 216 205 * @throws ImageWriteException 206 * if there are errors writing the image in the file. 217 207 */ 218 208 public static File updateFile(MapillaryImportedImage image) -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java
r31456 r31457 61 61 * not one of the values mentioned above 62 62 */ 63 // TODO: Maybe move into a separate utility class?64 63 public static double degMinSecToDouble(RationalNumber[] degMinSec, String ref) { 65 64 if (degMinSec == null || degMinSec.length != 3) {
Note:
See TracChangeset
for help on using the changeset viewer.