Changeset 31417 in osm for applications/editors/josm
- Timestamp:
- 2015-07-30T13:17:43+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 3 added
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
r31399 r31417 1 1 package org.openstreetmap.josm.plugins.mapillary; 2 2 3 import java.io.File; 3 4 import java.io.IOException; 4 5 … … 31 32 public class MapillaryPlugin extends Plugin { 32 33 34 /** Plugin's directory */ 35 public static String directory; 33 36 /** 24x24 icon. */ 34 public static final ImageIcon ICON24 = new ImageProvider("icon24.png").get();37 public static ImageIcon ICON24; 35 38 /** 16x16 icon. */ 36 public static final ImageIcon ICON16 = new ImageProvider("icon16.png").get();39 public static ImageIcon ICON16; 37 40 /** Icon representing an image in the map. */ 38 public static final ImageIcon MAP_ICON = new ImageProvider("mapicon.png") 39 .get(); 41 public static ImageIcon MAP_ICON; 40 42 /** Icon representing a selected image in the map. */ 41 public static final ImageIcon MAP_ICON_SELECTED = new ImageProvider( 42 "mapiconselected.png").get(); 43 public static ImageIcon MAP_ICON_SELECTED; 43 44 /** Icon representing an imported image in the map. */ 44 public static final ImageIcon MAP_ICON_IMPORTED = new ImageProvider( 45 "mapiconimported.png").get(); 45 public static ImageIcon MAP_ICON_IMPORTED; 46 46 /** Icon used to identify which images have signs on them */ 47 public static final ImageIcon MAP_SIGN = new ImageProvider("sign.png").get();47 public static ImageIcon MAP_SIGN; 48 48 49 49 /** Cache that stores the pictures the downloaded pictures. */ … … 52 52 private final MapillaryDownloadAction downloadAction; 53 53 private final MapillaryExportAction exportAction; 54 p rivate finalMapillaryImportAction importAction;54 public static MapillaryImportAction importAction; 55 55 private final MapillaryZoomAction zoomAction; 56 56 private final MapillaryDownloadViewAction downloadViewAction; … … 58 58 private final MapillaryJoinAction joinAction; 59 59 /** Walk action */ 60 public final static MapillaryWalkAction walkAction = new MapillaryWalkAction();60 public static MapillaryWalkAction walkAction; 61 61 62 62 /** Menu button for the {@link MapillaryDownloadAction} action. */ … … 84 84 public MapillaryPlugin(PluginInformation info) { 85 85 super(info); 86 87 directory = new File("").getAbsolutePath() + "/"; 88 ICON24 = new ImageProvider(directory + "images/icon24.png").get(); 89 ICON16 = new ImageProvider(directory + "images/icon16.png").get(); 90 MAP_ICON = new ImageProvider(directory + "images/mapicon.png").get(); 91 MAP_ICON_SELECTED = new ImageProvider(directory 92 + "images/mapiconselected.png").get(); 93 MAP_ICON_IMPORTED = new ImageProvider(directory 94 + "images/mapiconimported.png").get(); 95 MAP_SIGN = new ImageProvider(directory + "images/sign.png").get(); 96 86 97 downloadAction = new MapillaryDownloadAction(); 98 walkAction = new MapillaryWalkAction(); 87 99 exportAction = new MapillaryExportAction(); 88 100 importAction = new MapillaryImportAction(); … … 106 118 JOIN_MENU = MainMenu.add(Main.main.menu.dataMenu, joinAction, false); 107 119 WALK_MENU = MainMenu.add(Main.main.menu.moreToolsMenu, walkAction, false); 120 121 EXPORT_MENU.setEnabled(false); 122 DOWNLOAD_MENU.setEnabled(false); 123 IMPORT_MENU.setEnabled(false); 124 IMPORT_INTO_SEQUENCE_MENU.setEnabled(false); 125 ZOOM_MENU.setEnabled(false); 126 DOWNLOAD_VIEW_MENU.setEnabled(false); 127 JOIN_MENU.setEnabled(false); 128 WALK_MENU.setEnabled(false); 108 129 } 109 110 EXPORT_MENU.setEnabled(false);111 DOWNLOAD_MENU.setEnabled(false);112 IMPORT_MENU.setEnabled(false);113 IMPORT_INTO_SEQUENCE_MENU.setEnabled(false);114 ZOOM_MENU.setEnabled(false);115 DOWNLOAD_VIEW_MENU.setEnabled(false);116 JOIN_MENU.setEnabled(false);117 WALK_MENU.setEnabled(false);118 130 119 131 try { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadAction.java
r31409 r31417 12 12 import org.openstreetmap.josm.actions.JosmAction; 13 13 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 14 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 14 15 import org.openstreetmap.josm.tools.ImageProvider; 15 16 import org.openstreetmap.josm.tools.Shortcut; … … 30 31 */ 31 32 public MapillaryDownloadAction() { 32 super(tr("Mapillary"), new ImageProvider( "icon24.png"),33 super(tr("Mapillary"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"), 33 34 tr("Create Mapillary layer"), Shortcut.registerShortcut("Mapillary", 34 35 tr("Start Mapillary layer"), KeyEvent.VK_COMMA, Shortcut.SHIFT), -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadViewAction.java
r31399 r31417 11 11 import org.openstreetmap.josm.actions.JosmAction; 12 12 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 13 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 13 14 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader; 14 15 import org.openstreetmap.josm.tools.ImageProvider; … … 34 35 public MapillaryDownloadViewAction() { 35 36 super(tr("Download Mapillary images in current view"), new ImageProvider( 36 "icon24.png"), tr("Download Mapillary images in current view"),37 MapillaryPlugin.directory + "images/icon24.png"), tr("Download Mapillary images in current view"), 37 38 Shortcut.registerShortcut("Mapillary area", 38 39 tr("Download Mapillary images in current view"), -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java
r31401 r31417 21 21 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 22 22 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 23 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 23 24 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryExportManager; 24 25 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryExportDialog; … … 42 43 */ 43 44 public MapillaryExportAction() { 44 super(tr("Export pictures"), new ImageProvider( "icon24.png"),45 super(tr("Export pictures"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"), 45 46 tr("Export pictures"), Shortcut.registerShortcut("Export Mapillary", 46 47 tr("Export Mapillary pictures"), KeyEvent.CHAR_UNDEFINED, -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
r31415 r31417 25 25 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 26 26 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 27 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 27 28 import org.openstreetmap.josm.tools.ImageProvider; 28 29 import org.openstreetmap.josm.tools.Shortcut; … … 49 50 */ 50 51 public MapillaryImportAction() { 51 super(tr("Import pictures"), new ImageProvider( "icon24.png"),52 super(tr("Import pictures"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"), 52 53 tr("Import local pictures"), Shortcut.registerShortcut( 53 54 "Import Mapillary", tr("Import pictures into Mapillary layer"), … … 85 86 try { 86 87 if (extension.equals("jpg") || extension.equals("jpeg")) 87 readJPG(file.listFiles()[j]);88 MapillaryData.getInstance().add(readJPG(file.listFiles()[j])); 88 89 89 90 else if (extension.equals("png")) 90 readPNG(file.listFiles()[j]);91 MapillaryData.getInstance().add(readPNG(file.listFiles()[j])); 91 92 } catch (ImageReadException | IOException | NullPointerException e1) { 92 93 Main.error(e1); … … 99 100 .equals(".jpeg")) { 100 101 try { 101 readJPG(file);102 MapillaryData.getInstance().add(readJPG(file)); 102 103 } catch (ImageReadException ex) { 103 104 Main.error(ex); … … 107 108 } else if (file.getPath().substring(file.getPath().length() - 4) 108 109 .equals(".png")) { 109 readPNG(file);110 MapillaryData.getInstance().add(readPNG(file)); 110 111 } 111 112 } 112 113 } 113 } 114 } 115 116 /** 117 * Reads a jpg pictures that contains the needed GPS information (position and 114 MapillaryLayer.getInstance().showAllPictures(); 115 116 } 117 } 118 119 /** 120 * Reads a JPG pictures that contains the needed GPS information (position and 118 121 * direction) and creates a new icon in that position. 119 122 * 120 123 * @param file 124 * @return The imported image. 121 125 * @throws ImageReadException 122 126 * @throws IOException 123 127 */ 124 public void readJPG(File file) throws ImageReadException, IOException { 128 public MapillaryImportedImage readJPG(File file) throws ImageReadException, 129 IOException { 125 130 final ImageMetadata metadata = Imaging.getMetadata(file); 126 131 if (metadata instanceof JpegImageMetadata) { … … 139 144 .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); 140 145 if (lat_ref == null || lat == null || lon == null || lon_ref == null) { 141 readNoTags(file); 142 return; 146 return readNoTags(file); 143 147 } 144 148 double latValue = 0; … … 154 158 caValue = ((RationalNumber) ca.getValue()).doubleValue(); 155 159 if (datetimeOriginal != null) 156 MapillaryData.getInstance().add( 157 new MapillaryImportedImage(latValue, lonValue, caValue, file, 158 datetimeOriginal.getStringValue())); 160 return new MapillaryImportedImage(latValue, lonValue, caValue, file, 161 datetimeOriginal.getStringValue()); 159 162 else 160 MapillaryData.getInstance().add( 161 new MapillaryImportedImage(latValue, lonValue, caValue, file)); 162 } 163 164 MapillaryLayer.getInstance().showAllPictures(); 163 return new MapillaryImportedImage(latValue, lonValue, caValue, file); 164 } 165 throw new IllegalStateException("Invalid format."); 165 166 } 166 167 … … 170 171 * 171 172 * @param file 172 */ 173 private void readNoTags(File file) { 173 * @return The imported image. 174 */ 175 public MapillaryImportedImage readNoTags(File file) { 174 176 double HORIZONTAL_DISTANCE = 0.0001; 175 177 double horDev; … … 180 182 LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon( 181 183 Main.map.mapView.getCenter()); 182 MapillaryData.getInstance().add(183 new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file));184 184 noTagsPics++; 185 } 186 187 private void readPNG(File file) { 188 readNoTags(file); 185 return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file); 186 } 187 188 /** 189 * Reads an image in PNG format. 190 * 191 * @param file 192 * @return The imported image. 193 */ 194 public MapillaryImportedImage readPNG(File file) { 195 return readNoTags(file); 189 196 } 190 197 … … 219 226 public static double degMinSecToDouble(RationalNumber[] degMinSec, String ref) { 220 227 if (degMinSec == null || degMinSec.length != 3) { 221 throw new IllegalArgumentException(); 222 } 228 throw new IllegalArgumentException("Array's length must be 3."); 229 } 230 for (int i = 0; i < 3; i++) 231 if (degMinSec[i] == null) 232 throw new IllegalArgumentException("Null value in array."); 233 223 234 switch (ref) { 224 235 case GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH: … … 228 239 break; 229 240 default: 230 throw new IllegalArgumentException( );241 throw new IllegalArgumentException("Invalid ref."); 231 242 } 232 243 … … 235 246 result += degMinSec[2].doubleValue() / 3600; // seconds 236 247 248 while (result >= 180) { 249 result -= 180; 250 } 251 while (result <= -180) { 252 result += 180; 253 } 254 237 255 if (GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH.equals(ref) 238 256 || GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST.equals(ref)) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java
r31415 r31417 28 28 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 29 29 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 30 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 30 31 import org.openstreetmap.josm.plugins.mapillary.MapillarySequence; 31 32 import org.openstreetmap.josm.tools.ImageProvider; … … 50 51 */ 51 52 public MapillaryImportIntoSequenceAction() { 52 super(tr("Import pictures into sequence"), new ImageProvider( "icon24.png"),53 super(tr("Import pictures into sequence"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"), 53 54 tr("Import local pictures"), Shortcut.registerShortcut( 54 55 "Import Mapillary Sequence", -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryJoinAction.java
r31386 r31417 8 8 import org.openstreetmap.josm.actions.JosmAction; 9 9 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 10 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 10 11 import org.openstreetmap.josm.plugins.mapillary.mode.JoinMode; 11 12 import org.openstreetmap.josm.plugins.mapillary.mode.SelectMode; … … 27 28 */ 28 29 public MapillaryJoinAction() { 29 super(tr("Join mode"), new ImageProvider( "icon24.png"),30 super(tr("Join mode"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"), 30 31 tr("Join/unjoin pictures"), Shortcut.registerShortcut("Mapillary join", 31 32 tr("Join Mapillary pictures"), KeyEvent.CHAR_UNDEFINED, -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryWalkAction.java
r31416 r31417 39 39 */ 40 40 public MapillaryWalkAction() { 41 super(tr("Walk mode"), new ImageProvider( "icon24.png"), tr("Walk mode"),42 Shortcut.registerShortcut("Mapillary walk", tr("Start walk mode"),43 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, "mapillaryWalk",44 false);41 super(tr("Walk mode"), new ImageProvider(MapillaryPlugin.directory 42 + "images/icon24.png"), tr("Walk mode"), Shortcut.registerShortcut( 43 "Mapillary walk", tr("Start walk mode"), KeyEvent.CHAR_UNDEFINED, 44 Shortcut.NONE), false, "mapillaryWalk", false); 45 45 this.setEnabled(false); 46 46 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryZoomAction.java
r31387 r31417 30 30 */ 31 31 public MapillaryZoomAction() { 32 super(tr("Zoom to selected image"), new ImageProvider( "icon24.png"),32 super(tr("Zoom to selected image"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"), 33 33 tr("Zoom to selected image"), Shortcut.registerShortcut( 34 34 "Zoom Mapillary", -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java
r31415 r31417 96 96 LOCK.lock(); 97 97 MapillaryImage.LOCK.lock(); 98 for (MapillaryImage img : finalImages) { 99 if (layer.getMapillaryData().getImages().contains(img)) { 100 // The image in finalImages is substituted by the one in the 101 // database, as they represent the same picture. 102 img = (MapillaryImage) layer.getMapillaryData().getImages() 103 .get(layer.getMapillaryData().getImages().indexOf(img)); 104 sequence.add(img); 105 ((MapillaryImage) layer.getMapillaryData().getImages() 106 .get(layer.getMapillaryData().getImages().indexOf(img))) 107 .setSequence(sequence); 108 finalImages.set(finalImages.indexOf(img), img); 109 } else { 110 img.setSequence(sequence); 111 sequence.add(img); 98 try { 99 for (MapillaryImage img : finalImages) { 100 if (layer.getMapillaryData().getImages().contains(img)) { 101 // The image in finalImages is substituted by the one in the 102 // database, as they represent the same picture. 103 img = (MapillaryImage) layer.getMapillaryData().getImages() 104 .get(layer.getMapillaryData().getImages().indexOf(img)); 105 sequence.add(img); 106 ((MapillaryImage) layer.getMapillaryData().getImages() 107 .get(layer.getMapillaryData().getImages().indexOf(img))) 108 .setSequence(sequence); 109 finalImages.set(finalImages.indexOf(img), img); 110 } else { 111 img.setSequence(sequence); 112 sequence.add(img); 113 } 112 114 } 115 } finally { 116 MapillaryImage.LOCK.unlock(); 117 LOCK.unlock(); 113 118 } 114 MapillaryImage.LOCK.unlock();115 LOCK.unlock();116 119 117 120 layer.getMapillaryData().addWithoutUpdate( … … 121 124 Main.error("Error reading the url " + URL + queryString 122 125 + " might be a Mapillary problem."); 123 } finally {124 LOCK.unlock();125 MapillaryImage.LOCK.unlock();126 126 } 127 127 } -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/util/TestUtil.java
r31347 r31417 1 1 package org.openstreetmap.josm.plugins.mapillary.util; 2 3 import java.io.File; 2 4 3 5 import org.openstreetmap.josm.Main; 4 6 import org.openstreetmap.josm.data.projection.Projections; 7 import org.openstreetmap.josm.plugins.PluginException; 8 import org.openstreetmap.josm.plugins.PluginInformation; 5 9 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 10 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 6 11 import org.openstreetmap.josm.tools.I18n; 7 12 … … 30 35 I18n.set(Main.pref.get("language", "en")); 31 36 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator 32 37 try { 38 new MapillaryPlugin(new PluginInformation(new File("/home/nokutu/.josm/plugins/Mapillary.jar"))); 39 } catch (PluginException e) { 40 // TODO Auto-generated catch block 41 e.printStackTrace(); 42 } 33 43 isInitialized = true; 34 44 }
Note:
See TracChangeset
for help on using the changeset viewer.