Changeset 31313 in osm for applications/editors/josm
- Timestamp:
- 2015-06-26T16:08:28+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 13 edited
-
MapillaryData.java (modified) (4 diffs)
-
MapillaryLayer.java (modified) (2 diffs)
-
MapillaryMouseAdapter.java (modified) (1 diff)
-
MapillaryPlugin.java (modified) (1 diff)
-
actions/MapillaryDownloadAction.java (modified) (1 diff)
-
actions/MapillaryDownloadViewAction.java (modified) (1 diff)
-
actions/MapillaryExportAction.java (modified) (1 diff)
-
actions/MapillaryImportAction.java (modified) (1 diff)
-
actions/MapillaryZoomAction.java (modified) (2 diffs)
-
downloads/MapillarySquareDownloadManagerThread.java (modified) (2 diffs)
-
gui/MapillaryFilterDialog.java (modified) (1 diff)
-
gui/MapillaryPreferenceSetting.java (modified) (4 diffs)
-
gui/MapillaryToggleDialog.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31312 r31313 6 6 import org.openstreetmap.josm.data.cache.ICachedLoaderListener; 7 7 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; 8 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;9 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryToggleDialog;10 8 11 9 import java.util.ArrayList; … … 131 129 if (!TEST_MODE) 132 130 Main.map.mapView.repaint(); 133 MapillaryFilterDialog.getInstance().refresh();134 MapillaryToggleDialog.getInstance().updateImage();135 131 } 136 132 … … 177 173 tempImage = tempImage.next(); 178 174 if (tempImage.isVisible()) { 179 setSelectedImage(tempImage, true);175 setSelectedImage(tempImage, Main.pref.getBoolean("mapillary.move-to-picture", true)); 180 176 break; 181 177 } … … 202 198 tempImage = tempImage.previous(); 203 199 if (tempImage.isVisible()) { 204 setSelectedImage(tempImage,true);200 setSelectedImage(tempImage, Main.pref.getBoolean("mapillary.move-to-picture", true)); 205 201 break; 206 202 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31311 r31313 108 108 } 109 109 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, true); 110 Main.map.mapView.setActiveLayer(this); 110 if (!MapillaryToggleDialog.getInstance().isShowing()) 111 MapillaryToggleDialog.getInstance().getButton().doClick(); 111 112 createHatchTexture(); 112 113 data.dataUpdated(); … … 179 180 MapillaryToggleDialog.getInstance().mapillaryImageDisplay 180 181 .setImage(null); 182 MapillaryToggleDialog.getInstance().updateImage(); 181 183 data.getImages().clear(); 182 184 MapillaryLayer.INSTANCE = null; -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryMouseAdapter.java
r31306 r31313 22 22 */ 23 23 public class MapillaryMouseAdapter extends MouseAdapter { 24 private Point start; 25 private int lastButton; 26 private MapillaryAbstractImage closest; 27 private MapillaryAbstractImage lastClicked; 28 private MapillaryData mapillaryData; 29 private MapillaryRecord record; 30 31 private boolean nothingHighlighted; 32 private boolean imageHighlighted = false; 33 34 public MapillaryMouseAdapter() { 35 mapillaryData = MapillaryData.getInstance(); 36 record = MapillaryRecord.getInstance(); 37 } 38 39 @Override 40 public void mousePressed(MouseEvent e) { 41 lastButton = e.getButton(); 42 if (e.getButton() != MouseEvent.BUTTON1) 43 return; 44 MapillaryAbstractImage closestTemp = getClosest(e.getPoint()); 45 if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 46 && closestTemp != null 47 && Main.map.mapMode == Main.map.mapModeSelect) { 48 this.lastClicked = this.closest; 49 MapillaryData.getInstance().setSelectedImage(closestTemp); 50 return; 51 } else if (Main.map.mapView.getActiveLayer() != MapillaryLayer 52 .getInstance()) 53 return; 54 if (closestTemp instanceof MapillaryImage || closestTemp == null) { 55 MapillaryImage closest = (MapillaryImage) closestTemp; 56 // Doube click 57 if (e.getClickCount() == 2 58 && mapillaryData.getSelectedImage() != null 59 && closest != null) { 60 for (MapillaryAbstractImage img : closest.getSequence() 61 .getImages()) { 62 mapillaryData.addMultiSelectedImage(img); 63 } 64 } 65 this.start = e.getPoint(); 66 this.lastClicked = this.closest; 67 this.closest = closest; 68 if (mapillaryData.getMultiSelectedImages().contains(closest)) 69 return; 70 // ctrl+click 71 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) 72 && closest != null) 73 mapillaryData.addMultiSelectedImage(closest); 74 // shift + click 75 else if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK) 76 && this.closest instanceof MapillaryImage 77 && this.lastClicked instanceof MapillaryImage) { 78 if (this.closest != null 79 && this.lastClicked != null 80 && ((MapillaryImage) this.closest).getSequence() == ((MapillaryImage) this.lastClicked) 81 .getSequence()) { 82 int i = ((MapillaryImage) this.closest).getSequence() 83 .getImages().indexOf(this.closest); 84 int j = ((MapillaryImage) this.lastClicked).getSequence() 85 .getImages().indexOf(this.lastClicked); 86 if (i < j) 87 mapillaryData 88 .addMultiSelectedImage(new ArrayList<MapillaryAbstractImage>( 89 ((MapillaryImage) this.closest) 90 .getSequence().getImages() 91 .subList(i, j + 1))); 92 else 93 mapillaryData 94 .addMultiSelectedImage(new ArrayList<MapillaryAbstractImage>( 95 ((MapillaryImage) this.closest) 96 .getSequence().getImages() 97 .subList(j, i + 1))); 98 } 99 // click 100 } else 101 mapillaryData.setSelectedImage(closest); 102 // If you select an imported image 103 } else if (closestTemp instanceof MapillaryImportedImage) { 104 MapillaryImportedImage closest = (MapillaryImportedImage) closestTemp; 105 this.start = e.getPoint(); 106 this.lastClicked = this.closest; 107 this.closest = closest; 108 if (mapillaryData.getMultiSelectedImages().contains(closest)) 109 return; 110 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) 111 && closest != null) 112 mapillaryData.addMultiSelectedImage(closest); 113 else 114 mapillaryData.setSelectedImage(closest); 115 } 116 } 117 118 private MapillaryAbstractImage getClosest(Point clickPoint) { 119 double snapDistance = 10; 120 double minDistance = Double.MAX_VALUE; 121 MapillaryAbstractImage closest = null; 122 for (MapillaryAbstractImage image : mapillaryData.getImages()) { 123 Point imagePoint = Main.map.mapView.getPoint(image.getLatLon()); 124 imagePoint.setLocation(imagePoint.getX(), imagePoint.getY()); 125 double dist = clickPoint.distanceSq(imagePoint); 126 if (minDistance > dist 127 && clickPoint.distance(imagePoint) < snapDistance && image.isVisible()) { 128 minDistance = dist; 129 closest = image; 130 } 131 } 132 return closest; 133 } 134 135 @Override 136 public void mouseDragged(MouseEvent e) { 137 if (Main.map.mapView.getActiveLayer() != MapillaryLayer.getInstance()) 138 return; 139 140 if (!Main.pref.getBoolean("mapillary.developer")) 141 for (MapillaryAbstractImage img : MapillaryData.getInstance() 142 .getMultiSelectedImages()) { 143 if (img instanceof MapillaryImage) 144 return; 145 } 146 if (MapillaryData.getInstance().getSelectedImage() != null) { 147 if (lastButton == MouseEvent.BUTTON1 && !e.isShiftDown()) { 148 LatLon to = Main.map.mapView.getLatLon(e.getX(), e.getY()); 149 LatLon from = Main.map.mapView.getLatLon(start.getX(), 150 start.getY()); 151 for (MapillaryAbstractImage img : MapillaryData.getInstance() 152 .getMultiSelectedImages()) { 153 154 img.move(to.getX() - from.getX(), to.getY() - from.getY()); 155 } 156 Main.map.repaint(); 157 } else if (lastButton == MouseEvent.BUTTON1 && e.isShiftDown()) { 158 this.closest.turn(Math.toDegrees(Math.atan2( 159 (e.getX() - start.x), -(e.getY() - start.y))) 160 - closest.getTempCa()); 161 for (MapillaryAbstractImage img : MapillaryData.getInstance() 162 .getMultiSelectedImages()) { 163 img.turn(Math.toDegrees(Math.atan2((e.getX() - start.x), 164 -(e.getY() - start.y))) - closest.getTempCa()); 165 } 166 Main.map.repaint(); 167 } 168 } 169 } 170 171 @Override 172 public void mouseReleased(MouseEvent e) { 173 if (mapillaryData.getSelectedImage() == null) 174 return; 175 if (mapillaryData.getSelectedImage().getTempCa() != mapillaryData 176 .getSelectedImage().getCa()) { 177 double from = mapillaryData.getSelectedImage().getTempCa(); 178 double to = mapillaryData.getSelectedImage().getCa(); 179 record.addCommand(new CommandTurnImage(mapillaryData 180 .getMultiSelectedImages(), to - from)); 181 } else if (mapillaryData.getSelectedImage().getTempLatLon() != mapillaryData 182 .getSelectedImage().getLatLon()) { 183 LatLon from = mapillaryData.getSelectedImage().getTempLatLon(); 184 LatLon to = mapillaryData.getSelectedImage().getLatLon(); 185 record.addCommand(new CommandMoveImage(mapillaryData 186 .getMultiSelectedImages(), to.getX() - from.getX(), to 187 .getY() - from.getY())); 188 } 189 for (MapillaryAbstractImage img : mapillaryData 190 .getMultiSelectedImages()) { 191 if (img != null) 192 img.stopMoving(); 193 } 194 } 195 196 /** 197 * Checks if the mouse is over pictures. 198 */ 199 @Override 200 public void mouseMoved(MouseEvent e) { 201 MapillaryAbstractImage closestTemp = getClosest(e.getPoint()); 202 if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 203 && Main.map.mapMode != Main.map.mapModeSelect) 204 return; 205 if (closestTemp != null 206 && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 207 && !imageHighlighted) { 208 Main.map.mapMode.putValue("active", Boolean.FALSE); 209 imageHighlighted = true; 210 211 } else if (closestTemp == null 212 && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 213 && imageHighlighted && nothingHighlighted) { 214 nothingHighlighted = false; 215 Main.map.mapMode.putValue("active", Boolean.TRUE); 216 217 } else if (imageHighlighted && !nothingHighlighted 218 && Main.map.mapView != null 219 && Main.map.mapView.getEditLayer().data != null 220 && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer) { 221 222 for (OsmPrimitive primivitive : Main.map.mapView.getEditLayer().data 223 .allPrimitives()) { 224 primivitive.setHighlighted(false); 225 } 226 imageHighlighted = false; 227 nothingHighlighted = true; 228 } 229 230 if (MapillaryData.getInstance().getHoveredImage() != closestTemp 231 && closestTemp != null) { 232 MapillaryData.getInstance().setHoveredImage(closestTemp); 233 MapillaryToggleDialog.getInstance().setImage(closestTemp); 234 MapillaryToggleDialog.getInstance().updateImage(); 235 } else if (MapillaryData.getInstance().getHoveredImage() != closestTemp 236 && closestTemp == null) { 237 MapillaryData.getInstance().setHoveredImage(null); 238 MapillaryToggleDialog.getInstance().setImage( 239 MapillaryData.getInstance().getSelectedImage()); 240 MapillaryToggleDialog.getInstance().updateImage(); 241 } 242 MapillaryData.getInstance().dataUpdated(); 243 } 24 private Point start; 25 private int lastButton; 26 private MapillaryAbstractImage closest; 27 private MapillaryAbstractImage lastClicked; 28 private MapillaryData mapillaryData; 29 private MapillaryRecord record; 30 31 private boolean nothingHighlighted; 32 private boolean imageHighlighted = false; 33 34 public MapillaryMouseAdapter() { 35 mapillaryData = MapillaryData.getInstance(); 36 record = MapillaryRecord.getInstance(); 37 } 38 39 @Override 40 public void mousePressed(MouseEvent e) { 41 lastButton = e.getButton(); 42 if (e.getButton() != MouseEvent.BUTTON1) 43 return; 44 MapillaryAbstractImage closestTemp = getClosest(e.getPoint()); 45 if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 46 && closestTemp != null 47 && Main.map.mapMode == Main.map.mapModeSelect) { 48 this.lastClicked = this.closest; 49 MapillaryData.getInstance().setSelectedImage(closestTemp); 50 return; 51 } else if (Main.map.mapView.getActiveLayer() != MapillaryLayer 52 .getInstance()) 53 return; 54 if (closestTemp instanceof MapillaryImage || closestTemp == null) { 55 MapillaryImage closest = (MapillaryImage) closestTemp; 56 // Doube click 57 if (e.getClickCount() == 2 58 && mapillaryData.getSelectedImage() != null 59 && closest != null) { 60 for (MapillaryAbstractImage img : closest.getSequence() 61 .getImages()) { 62 mapillaryData.addMultiSelectedImage(img); 63 } 64 } 65 this.start = e.getPoint(); 66 this.lastClicked = this.closest; 67 this.closest = closest; 68 if (mapillaryData.getMultiSelectedImages().contains(closest)) 69 return; 70 // ctrl+click 71 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) 72 && closest != null) 73 mapillaryData.addMultiSelectedImage(closest); 74 // shift + click 75 else if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK) 76 && this.closest instanceof MapillaryImage 77 && this.lastClicked instanceof MapillaryImage) { 78 if (this.closest != null 79 && this.lastClicked != null 80 && ((MapillaryImage) this.closest).getSequence() == ((MapillaryImage) this.lastClicked) 81 .getSequence()) { 82 int i = ((MapillaryImage) this.closest).getSequence() 83 .getImages().indexOf(this.closest); 84 int j = ((MapillaryImage) this.lastClicked).getSequence() 85 .getImages().indexOf(this.lastClicked); 86 if (i < j) 87 mapillaryData 88 .addMultiSelectedImage(new ArrayList<MapillaryAbstractImage>( 89 ((MapillaryImage) this.closest) 90 .getSequence().getImages() 91 .subList(i, j + 1))); 92 else 93 mapillaryData 94 .addMultiSelectedImage(new ArrayList<MapillaryAbstractImage>( 95 ((MapillaryImage) this.closest) 96 .getSequence().getImages() 97 .subList(j, i + 1))); 98 } 99 // click 100 } else 101 mapillaryData.setSelectedImage(closest); 102 // If you select an imported image 103 } else if (closestTemp instanceof MapillaryImportedImage) { 104 MapillaryImportedImage closest = (MapillaryImportedImage) closestTemp; 105 this.start = e.getPoint(); 106 this.lastClicked = this.closest; 107 this.closest = closest; 108 if (mapillaryData.getMultiSelectedImages().contains(closest)) 109 return; 110 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) 111 && closest != null) 112 mapillaryData.addMultiSelectedImage(closest); 113 else 114 mapillaryData.setSelectedImage(closest); 115 } 116 } 117 118 private MapillaryAbstractImage getClosest(Point clickPoint) { 119 double snapDistance = 10; 120 double minDistance = Double.MAX_VALUE; 121 MapillaryAbstractImage closest = null; 122 for (MapillaryAbstractImage image : mapillaryData.getImages()) { 123 Point imagePoint = Main.map.mapView.getPoint(image.getLatLon()); 124 imagePoint.setLocation(imagePoint.getX(), imagePoint.getY()); 125 double dist = clickPoint.distanceSq(imagePoint); 126 if (minDistance > dist 127 && clickPoint.distance(imagePoint) < snapDistance 128 && image.isVisible()) { 129 minDistance = dist; 130 closest = image; 131 } 132 } 133 return closest; 134 } 135 136 @Override 137 public void mouseDragged(MouseEvent e) { 138 if (Main.map.mapView.getActiveLayer() != MapillaryLayer.getInstance()) 139 return; 140 141 if (!Main.pref.getBoolean("mapillary.developer")) 142 for (MapillaryAbstractImage img : MapillaryData.getInstance() 143 .getMultiSelectedImages()) { 144 if (img instanceof MapillaryImage) 145 return; 146 } 147 if (MapillaryData.getInstance().getSelectedImage() != null) { 148 if (lastButton == MouseEvent.BUTTON1 && !e.isShiftDown()) { 149 LatLon to = Main.map.mapView.getLatLon(e.getX(), e.getY()); 150 LatLon from = Main.map.mapView.getLatLon(start.getX(), 151 start.getY()); 152 for (MapillaryAbstractImage img : MapillaryData.getInstance() 153 .getMultiSelectedImages()) { 154 155 img.move(to.getX() - from.getX(), to.getY() - from.getY()); 156 } 157 Main.map.repaint(); 158 } else if (lastButton == MouseEvent.BUTTON1 && e.isShiftDown()) { 159 this.closest.turn(Math.toDegrees(Math.atan2( 160 (e.getX() - start.x), -(e.getY() - start.y))) 161 - closest.getTempCa()); 162 for (MapillaryAbstractImage img : MapillaryData.getInstance() 163 .getMultiSelectedImages()) { 164 img.turn(Math.toDegrees(Math.atan2((e.getX() - start.x), 165 -(e.getY() - start.y))) - closest.getTempCa()); 166 } 167 Main.map.repaint(); 168 } 169 } 170 } 171 172 @Override 173 public void mouseReleased(MouseEvent e) { 174 if (mapillaryData.getSelectedImage() == null) 175 return; 176 if (mapillaryData.getSelectedImage().getTempCa() != mapillaryData 177 .getSelectedImage().getCa()) { 178 double from = mapillaryData.getSelectedImage().getTempCa(); 179 double to = mapillaryData.getSelectedImage().getCa(); 180 record.addCommand(new CommandTurnImage(mapillaryData 181 .getMultiSelectedImages(), to - from)); 182 } else if (mapillaryData.getSelectedImage().getTempLatLon() != mapillaryData 183 .getSelectedImage().getLatLon()) { 184 LatLon from = mapillaryData.getSelectedImage().getTempLatLon(); 185 LatLon to = mapillaryData.getSelectedImage().getLatLon(); 186 record.addCommand(new CommandMoveImage(mapillaryData 187 .getMultiSelectedImages(), to.getX() - from.getX(), to 188 .getY() - from.getY())); 189 } 190 for (MapillaryAbstractImage img : mapillaryData 191 .getMultiSelectedImages()) { 192 if (img != null) 193 img.stopMoving(); 194 } 195 } 196 197 /** 198 * Checks if the mouse is over pictures. 199 */ 200 @Override 201 public void mouseMoved(MouseEvent e) { 202 MapillaryAbstractImage closestTemp = getClosest(e.getPoint()); 203 if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 204 && Main.map.mapMode != Main.map.mapModeSelect) 205 return; 206 if (closestTemp != null 207 && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 208 && !imageHighlighted) { 209 Main.map.mapMode.putValue("active", Boolean.FALSE); 210 imageHighlighted = true; 211 212 } else if (closestTemp == null 213 && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 214 && imageHighlighted && nothingHighlighted) { 215 nothingHighlighted = false; 216 Main.map.mapMode.putValue("active", Boolean.TRUE); 217 218 } else if (imageHighlighted && !nothingHighlighted 219 && Main.map.mapView != null 220 && Main.map.mapView.getEditLayer().data != null 221 && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer) { 222 223 for (OsmPrimitive primivitive : Main.map.mapView.getEditLayer().data 224 .allPrimitives()) { 225 primivitive.setHighlighted(false); 226 } 227 imageHighlighted = false; 228 nothingHighlighted = true; 229 } 230 231 if (MapillaryData.getInstance().getHoveredImage() != closestTemp 232 && closestTemp != null) { 233 MapillaryData.getInstance().setHoveredImage(closestTemp); 234 MapillaryToggleDialog.getInstance().setImage(closestTemp); 235 MapillaryToggleDialog.getInstance().updateImage(); 236 } else if (MapillaryData.getInstance().getHoveredImage() != closestTemp 237 && closestTemp == null) { 238 MapillaryData.getInstance().setHoveredImage(null); 239 MapillaryToggleDialog.getInstance().setImage( 240 MapillaryData.getInstance().getSelectedImage()); 241 MapillaryToggleDialog.getInstance().updateImage(); 242 } 243 MapillaryData.getInstance().dataUpdated(); 244 } 244 245 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
r31298 r31313 33 33 public class MapillaryPlugin extends Plugin implements EditLayerChangeListener { 34 34 35 public static final ImageIcon ICON24 = new ImageProvider("icon24.png")36 .get();37 public static final ImageIcon ICON16 = new ImageProvider("icon16.png")38 .get();39 public static final ImageIcon MAP_ICON = new ImageProvider("mapicon.png")40 .get();41 public static final ImageIcon MAP_ICON_SELECTED = new ImageProvider(42 "mapiconselected.png").get();43 public static final ImageIcon MAP_ICON_IMPORTED = new ImageProvider(44 "mapiconimported.png").get();45 public static final ImageIcon MAP_SIGN = new ImageProvider("sign.png")46 .get();47 public static final int ICON_SIZE = 24;35 public static final ImageIcon ICON24 = new ImageProvider("icon24.png") 36 .get(); 37 public static final ImageIcon ICON16 = new ImageProvider("icon16.png") 38 .get(); 39 public static final ImageIcon MAP_ICON = new ImageProvider("mapicon.png") 40 .get(); 41 public static final ImageIcon MAP_ICON_SELECTED = new ImageProvider( 42 "mapiconselected.png").get(); 43 public static final ImageIcon MAP_ICON_IMPORTED = new ImageProvider( 44 "mapiconimported.png").get(); 45 public static final ImageIcon MAP_SIGN = new ImageProvider("sign.png") 46 .get(); 47 public static final int ICON_SIZE = 24; 48 48 49 public static CacheAccess<String, BufferedImageCacheEntry> CACHE;49 public static CacheAccess<String, BufferedImageCacheEntry> CACHE; 50 50 51 private final MapillaryDownloadAction downloadAction;52 private final MapillaryExportAction exportAction;53 private final MapillaryImportAction importAction;54 private final MapillaryZoomAction zoomAction;55 private final MapillaryDownloadViewAction downloadViewAction;51 private final MapillaryDownloadAction downloadAction; 52 private final MapillaryExportAction exportAction; 53 private final MapillaryImportAction importAction; 54 private final MapillaryZoomAction zoomAction; 55 private final MapillaryDownloadViewAction downloadViewAction; 56 56 57 public static JMenuItem DOWNLOAD_MENU;58 public static JMenuItem EXPORT_MENU;59 public static JMenuItem IMPORT_MENU;60 public static JMenuItem ZOOM_MENU;61 public static JMenuItem DOWNLOAD_VIEW_MENU;57 public static JMenuItem DOWNLOAD_MENU; 58 public static JMenuItem EXPORT_MENU; 59 public static JMenuItem IMPORT_MENU; 60 public static JMenuItem ZOOM_MENU; 61 public static JMenuItem DOWNLOAD_VIEW_MENU; 62 62 63 public MapillaryPlugin(PluginInformation info) {64 super(info);65 downloadAction = new MapillaryDownloadAction();66 exportAction = new MapillaryExportAction();67 importAction = new MapillaryImportAction();68 zoomAction = new MapillaryZoomAction();69 downloadViewAction = new MapillaryDownloadViewAction();63 public MapillaryPlugin(PluginInformation info) { 64 super(info); 65 downloadAction = new MapillaryDownloadAction(); 66 exportAction = new MapillaryExportAction(); 67 importAction = new MapillaryImportAction(); 68 zoomAction = new MapillaryZoomAction(); 69 downloadViewAction = new MapillaryDownloadViewAction(); 70 70 71 DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu,72 downloadAction, false);73 EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, exportAction,74 false, 14);75 IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction,76 false, 14);77 ZOOM_MENU = MainMenu78 .add(Main.main.menu.viewMenu, zoomAction, false, 15);79 DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu,80 downloadViewAction, false, 14);71 DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu, 72 downloadAction, false); 73 EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, exportAction, 74 false, 14); 75 IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction, 76 false, 14); 77 ZOOM_MENU = MainMenu 78 .add(Main.main.menu.viewMenu, zoomAction, false, 15); 79 DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu, 80 downloadViewAction, false, 14); 81 81 82 EXPORT_MENU.setEnabled(false);83 DOWNLOAD_MENU.setEnabled(false);84 IMPORT_MENU.setEnabled(false);85 ZOOM_MENU.setEnabled(false);86 DOWNLOAD_VIEW_MENU.setEnabled(false);82 EXPORT_MENU.setEnabled(false); 83 DOWNLOAD_MENU.setEnabled(false); 84 IMPORT_MENU.setEnabled(false); 85 ZOOM_MENU.setEnabled(false); 86 DOWNLOAD_VIEW_MENU.setEnabled(false); 87 87 88 MapView.addEditLayerChangeListener(this);89 try {90 CACHE = JCSCacheManager.getCache("mapillary", 10, 10000,91 this.getPluginDir() + "/cache/");92 } catch (IOException e) {93 Main.error(e);94 }95 }88 MapView.addEditLayerChangeListener(this); 89 try { 90 CACHE = JCSCacheManager.getCache("mapillary", 10, 10000, 91 this.getPluginDir() + "/cache/"); 92 } catch (IOException e) { 93 Main.error(e); 94 } 95 } 96 96 97 /**98 * Called when the JOSM map frame is created or destroyed.99 */100 @Override101 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {102 if (oldFrame == null && newFrame != null) { // map frame added103 Main.map.addToggleDialog(MapillaryToggleDialog.getInstance(), false);104 Main.map.addToggleDialog(MapillaryHistoryDialog.getInstance(),105 false);106 Main.map.addToggleDialog(MapillaryFilterDialog.getInstance(), false);107 }108 if (oldFrame != null && newFrame == null) { // map frame destroyed109 MapillaryToggleDialog.destroyInstance();110 MapillaryHistoryDialog.destroyInstance();111 MapillaryFilterDialog.destroyInstance();112 }113 }97 /** 98 * Called when the JOSM map frame is created or destroyed. 99 */ 100 @Override 101 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 102 if (oldFrame == null && newFrame != null) { // map frame added 103 Main.map.addToggleDialog(MapillaryToggleDialog.getInstance(), false); 104 Main.map.addToggleDialog(MapillaryHistoryDialog.getInstance(), 105 false); 106 Main.map.addToggleDialog(MapillaryFilterDialog.getInstance(), false); 107 } 108 if (oldFrame != null && newFrame == null) { // map frame destroyed 109 MapillaryToggleDialog.destroyInstance(); 110 MapillaryHistoryDialog.destroyInstance(); 111 MapillaryFilterDialog.destroyInstance(); 112 } 113 } 114 114 115 public static void setMenuEnabled(JMenuItem menu, boolean value) {116 menu.setEnabled(value);117 menu.getAction().setEnabled(value);118 }115 public static void setMenuEnabled(JMenuItem menu, boolean value) { 116 menu.setEnabled(value); 117 menu.getAction().setEnabled(value); 118 } 119 119 120 @Override121 public PreferenceSetting getPreferenceSetting() {122 return new MapillaryPreferenceSetting();123 }120 @Override 121 public PreferenceSetting getPreferenceSetting() { 122 return new MapillaryPreferenceSetting(); 123 } 124 124 125 @Override126 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {127 if (oldLayer == null && newLayer != null) {128 setMenuEnabled(DOWNLOAD_MENU, true);129 if (Main.pref.getBoolean("mapillary.download-manually")) 130 setMenuEnabled(IMPORT_MENU, true); 131 setMenuEnabled(DOWNLOAD_VIEW_MENU, true);132 } else if (oldLayer != null && newLayer == null) {133 setMenuEnabled(DOWNLOAD_MENU, false);134 setMenuEnabled(IMPORT_MENU, false);135 setMenuEnabled(DOWNLOAD_VIEW_MENU, false);136 }137 }125 @Override 126 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 127 if (oldLayer == null && newLayer != null) { 128 setMenuEnabled(DOWNLOAD_MENU, true); 129 setMenuEnabled(IMPORT_MENU, true); 130 if (Main.pref.getBoolean("mapillary.download-manually")) 131 setMenuEnabled(DOWNLOAD_VIEW_MENU, true); 132 } else if (oldLayer != null && newLayer == null) { 133 setMenuEnabled(DOWNLOAD_MENU, false); 134 setMenuEnabled(IMPORT_MENU, false); 135 setMenuEnabled(DOWNLOAD_VIEW_MENU, false); 136 } 137 } 138 138 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadAction.java
r31297 r31313 27 27 tr("Create Mapillary layer"), Shortcut.registerShortcut( 28 28 "Mapillary", tr("Start Mapillary layer"), 29 KeyEvent.VK_ M, Shortcut.ALT_CTRL_SHIFT), false,29 KeyEvent.VK_COMMA, Shortcut.SHIFT), false, 30 30 "mapillaryDownload", false); 31 31 this.setEnabled(false); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadViewAction.java
r31278 r31313 26 26 Shortcut.registerShortcut("Mapillary area", 27 27 tr("Download Mapillary images in current view"), 28 KeyEvent.VK_ M, Shortcut.NONE), false, "mapillaryArea",29 false); 28 KeyEvent.VK_PERIOD, Shortcut.SHIFT), false, 29 "mapillaryArea", false); 30 30 this.setEnabled(false); 31 31 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java
r31278 r31313 38 38 tr("Export pictures"), Shortcut.registerShortcut( 39 39 "Export Mapillary", tr("Export Mapillary pictures"), 40 KeyEvent. VK_M, Shortcut.NONE), false,40 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, 41 41 "mapillaryExport", false); 42 42 this.setEnabled(false); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java
r31311 r31313 36 36 public class MapillaryImportAction extends JosmAction { 37 37 38 public JFileChooser chooser;38 public JFileChooser chooser; 39 39 40 /**41 * Amount of pictures without the proper EXIF tags.42 */43 private int noTagsPics = 0;40 /** 41 * Amount of pictures without the proper EXIF tags. 42 */ 43 private int noTagsPics = 0; 44 44 45 public MapillaryImportAction() {46 super(tr("Import pictures"), new ImageProvider("icon24.png"),47 tr("Import local pictures"), Shortcut.registerShortcut(48 "Import Mapillary",49 tr("Import pictures into Mapillary layer"),50 KeyEvent.VK_M, Shortcut.NONE), false,51 "mapillaryImport", false);52 this.setEnabled(false);53 }45 public MapillaryImportAction() { 46 super(tr("Import pictures"), new ImageProvider("icon24.png"), 47 tr("Import local pictures"), Shortcut.registerShortcut( 48 "Import Mapillary", 49 tr("Import pictures into Mapillary layer"), 50 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, 51 "mapillaryImport", false); 52 this.setEnabled(false); 53 } 54 54 55 @Override56 public void actionPerformed(ActionEvent e) {57 chooser = new JFileChooser();58 chooser.setCurrentDirectory(new java.io.File(System59 .getProperty("user.home")));60 chooser.setDialogTitle(tr("Select pictures"));61 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);62 chooser.setAcceptAllFileFilterUsed(false);63 chooser.addChoosableFileFilter(new FileNameExtensionFilter("images",64 "jpg", "jpeg", "png"));65 chooser.setMultiSelectionEnabled(true);66 if (chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {67 for (int i = 0; i < chooser.getSelectedFiles().length; i++) {68 File file = chooser.getSelectedFiles()[i];69 if (file.isDirectory()) {55 @Override 56 public void actionPerformed(ActionEvent e) { 57 chooser = new JFileChooser(); 58 chooser.setCurrentDirectory(new java.io.File(System 59 .getProperty("user.home"))); 60 chooser.setDialogTitle(tr("Select pictures")); 61 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 62 chooser.setAcceptAllFileFilterUsed(false); 63 chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", 64 "jpg", "jpeg", "png")); 65 chooser.setMultiSelectionEnabled(true); 66 if (chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { 67 for (int i = 0; i < chooser.getSelectedFiles().length; i++) { 68 File file = chooser.getSelectedFiles()[i]; 69 if (file.isDirectory()) { 70 70 71 } else { 72 if (file.getPath().substring(file.getPath().length() - 4) 73 .equals(".jpg") 74 || file.getPath() 75 .substring(file.getPath().length() - 5) 76 .equals(".jpeg")) { 77 try { 78 readJPG(file); 79 } catch (ImageReadException ex) { 80 Main.error(ex); 81 } catch (IOException ex) { 82 Main.error(ex); 83 } 84 } else if (file.getPath() 85 .substring(file.getPath().length() - 4) 86 .equals(".png")) { 87 readPNG(file); 88 } 89 } 90 } 91 } 92 MapillaryLayer.getInstance(); 93 } 71 } else { 72 if (file.getPath().substring(file.getPath().length() - 4) 73 .equals(".jpg") 74 || file.getPath() 75 .substring(file.getPath().length() - 5) 76 .equals(".jpeg")) { 77 try { 78 readJPG(file); 79 } catch (ImageReadException ex) { 80 Main.error(ex); 81 } catch (IOException ex) { 82 Main.error(ex); 83 } 84 } else if (file.getPath() 85 .substring(file.getPath().length() - 4) 86 .equals(".png")) { 87 readPNG(file); 88 } 89 } 90 } 91 } 92 } 94 93 95 /**96 * Reads a jpg pictures that contains the needed GPS information (position97 * and direction) and creates a new icon in that position.98 *99 * @param file100 * @throws ImageReadException101 * @throws IOException102 */103 public void readJPG(File file) throws ImageReadException, IOException {104 final ImageMetadata metadata = Imaging.getMetadata(file);105 if (metadata instanceof JpegImageMetadata) {106 final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;107 final TiffField lat_ref = jpegMetadata108 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);109 final TiffField lat = jpegMetadata110 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);111 final TiffField lon_ref = jpegMetadata112 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);113 final TiffField lon = jpegMetadata114 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);115 final TiffField ca = jpegMetadata116 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);117 final TiffField datetimeOriginal = jpegMetadata118 .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);119 if (lat_ref == null || lat == null || lon == null120 || lon_ref == null) {121 readNoTags(file);122 }123 double latValue = 0;124 double lonValue = 0;125 double caValue = 0;126 if (lat != null && lat.getValue() instanceof RationalNumber[])127 latValue = DegMinSecToDouble((RationalNumber[]) lat.getValue(),128 lat_ref.getValue().toString());129 if (lon != null && lon.getValue() instanceof RationalNumber[])130 lonValue = DegMinSecToDouble((RationalNumber[]) lon.getValue(),131 lon_ref.getValue().toString());132 if (ca != null && ca.getValue() instanceof RationalNumber)133 caValue = ((RationalNumber) ca.getValue()).doubleValue();134 if (lat_ref.getValue().toString().equals("S"))135 latValue = -latValue;136 if (lon_ref.getValue().toString().equals("W"))137 lonValue = -lonValue;138 if (datetimeOriginal != null)139 MapillaryData.getInstance().add(140 new MapillaryImportedImage(latValue, lonValue, caValue,141 file, datetimeOriginal.getStringValue()));142 else143 MapillaryData.getInstance().add(144 new MapillaryImportedImage(latValue, lonValue, caValue,145 file));146 }147 }94 /** 95 * Reads a jpg pictures that contains the needed GPS information (position 96 * and direction) and creates a new icon in that position. 97 * 98 * @param file 99 * @throws ImageReadException 100 * @throws IOException 101 */ 102 public void readJPG(File file) throws ImageReadException, IOException { 103 final ImageMetadata metadata = Imaging.getMetadata(file); 104 if (metadata instanceof JpegImageMetadata) { 105 final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; 106 final TiffField lat_ref = jpegMetadata 107 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); 108 final TiffField lat = jpegMetadata 109 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE); 110 final TiffField lon_ref = jpegMetadata 111 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); 112 final TiffField lon = jpegMetadata 113 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE); 114 final TiffField ca = jpegMetadata 115 .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); 116 final TiffField datetimeOriginal = jpegMetadata 117 .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); 118 if (lat_ref == null || lat == null || lon == null 119 || lon_ref == null) { 120 readNoTags(file); 121 } 122 double latValue = 0; 123 double lonValue = 0; 124 double caValue = 0; 125 if (lat != null && lat.getValue() instanceof RationalNumber[]) 126 latValue = DegMinSecToDouble((RationalNumber[]) lat.getValue(), 127 lat_ref.getValue().toString()); 128 if (lon != null && lon.getValue() instanceof RationalNumber[]) 129 lonValue = DegMinSecToDouble((RationalNumber[]) lon.getValue(), 130 lon_ref.getValue().toString()); 131 if (ca != null && ca.getValue() instanceof RationalNumber) 132 caValue = ((RationalNumber) ca.getValue()).doubleValue(); 133 if (lat_ref.getValue().toString().equals("S")) 134 latValue = -latValue; 135 if (lon_ref.getValue().toString().equals("W")) 136 lonValue = -lonValue; 137 if (datetimeOriginal != null) 138 MapillaryData.getInstance().add( 139 new MapillaryImportedImage(latValue, lonValue, caValue, 140 file, datetimeOriginal.getStringValue())); 141 else 142 MapillaryData.getInstance().add( 143 new MapillaryImportedImage(latValue, lonValue, caValue, 144 file)); 145 } 146 } 148 147 149 /**150 * Reads a image file that doesn't contain the needed GPS information. And151 * creates a new icon in the middle of the map.152 *153 * @param file154 */155 private void readNoTags(File file) {156 double HORIZONTAL_DISTANCE = 0.0001;157 double horDev;158 if (noTagsPics % 2 == 0)159 horDev = HORIZONTAL_DISTANCE * noTagsPics / 2;160 else161 horDev = -HORIZONTAL_DISTANCE * (noTagsPics + 1) / 2;162 LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(163 Main.map.mapView.getCenter());164 MapillaryData.getInstance().add(165 new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0,166 file));167 noTagsPics++;168 }148 /** 149 * Reads a image file that doesn't contain the needed GPS information. And 150 * creates a new icon in the middle of the map. 151 * 152 * @param file 153 */ 154 private void readNoTags(File file) { 155 double HORIZONTAL_DISTANCE = 0.0001; 156 double horDev; 157 if (noTagsPics % 2 == 0) 158 horDev = HORIZONTAL_DISTANCE * noTagsPics / 2; 159 else 160 horDev = -HORIZONTAL_DISTANCE * (noTagsPics + 1) / 2; 161 LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon( 162 Main.map.mapView.getCenter()); 163 MapillaryData.getInstance().add( 164 new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, 165 file)); 166 noTagsPics++; 167 } 169 168 170 private void readPNG(File file) {171 readNoTags(file);172 }169 private void readPNG(File file) { 170 readNoTags(file); 171 } 173 172 174 private double DegMinSecToDouble(RationalNumber[] degMinSec, String ref) {175 RationalNumber deg = degMinSec[0];176 RationalNumber min = degMinSec[1];177 RationalNumber sec = degMinSec[2];178 return deg.doubleValue() + min.doubleValue() / 60 + sec.doubleValue()179 / 3600;180 }173 private double DegMinSecToDouble(RationalNumber[] degMinSec, String ref) { 174 RationalNumber deg = degMinSec[0]; 175 RationalNumber min = degMinSec[1]; 176 RationalNumber sec = degMinSec[2]; 177 return deg.doubleValue() + min.doubleValue() / 60 + sec.doubleValue() 178 / 3600; 179 } 181 180 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryZoomAction.java
r31284 r31313 29 29 "Zoom Mapillary", 30 30 tr("Zoom to the currently selected Mapillary image"), 31 KeyEvent. VK_M, Shortcut.NONE), false, "mapillaryZoom",32 false); 31 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, 32 "mapillaryZoom", false); 33 33 MapillaryData.getInstance().addListener(this); 34 34 this.setEnabled(false); … … 53 53 54 54 @Override 55 public void imagesAdded() { 55 public void imagesAdded() { 56 56 } 57 57 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java
r31306 r31313 10 10 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 11 11 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog; 12 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryToggleDialog; 12 13 13 14 /** … … 51 52 MapillaryData.getInstance().dataUpdated(); 52 53 MapillaryFilterDialog.getInstance().refresh(); 54 MapillaryToggleDialog.getInstance().updateImage(); 53 55 } 54 56 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java
r31311 r31313 193 193 } 194 194 } 195 Ma pillaryData.getInstance().dataUpdated();195 Main.map.repaint(); 196 196 } 197 197 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
r31298 r31313 22 22 private JCheckBox displayHour = new JCheckBox(tr("Display hour when the picture was taken")); 23 23 private JCheckBox format24 = new JCheckBox(tr("Use 24 hour format")); 24 private JCheckBox moveTo = new JCheckBox(tr("Move to picture's location with next/previous buttons")); 24 25 25 26 @Override … … 38 39 displayHour.setSelected(Main.pref.getBoolean("mapillary.display-hour", true)); 39 40 format24.setSelected(Main.pref.getBoolean("mapillary.format-24")); 41 moveTo.setSelected(Main.pref.getBoolean("mapillary.move-to-picture", true)); 40 42 41 43 panel.setLayout(new FlowLayout(FlowLayout.LEFT)); … … 44 46 panel.add(displayHour); 45 47 panel.add(format24); 48 panel.add(moveTo); 46 49 gui.getDisplayPreference().addSubTab(this, "Mapillary", panel); 47 50 } … … 56 59 Main.pref.put("mapillary.display-hour", displayHour.isSelected()); 57 60 Main.pref.put("mapillary.format-24", format24.isSelected()); 61 Main.pref.put("mapillary.move-to-picture", moveTo.isSelected()); 58 62 return mod; 59 63 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryToggleDialog.java
r31306 r31313 9 9 import java.awt.Color; 10 10 import java.awt.Component; 11 import java.awt.Event; 11 12 import java.awt.FlowLayout; 12 13 import java.awt.GridLayout; … … 32 33 33 34 import javax.imageio.ImageIO; 35 import javax.swing.JComponent; 36 import javax.swing.KeyStroke; 34 37 import javax.swing.SwingUtilities; 35 38 import javax.swing.AbstractAction; … … 43 46 */ 44 47 public class MapillaryToggleDialog extends ToggleDialog implements 45 ICachedLoaderListener, MapillaryDataListener { 46 47 public final static String BASE_TITLE = "Mapillary picture"; 48 49 public static MapillaryToggleDialog INSTANCE; 50 51 public volatile MapillaryAbstractImage image; 52 53 public final SideButton nextButton = new SideButton(new nextPictureAction()); 54 public final SideButton previousButton = new SideButton( 55 new previousPictureAction()); 56 public final SideButton redButton = new SideButton(new redAction()); 57 public final SideButton blueButton = new SideButton(new blueAction()); 58 59 private JPanel buttonsPanel; 60 61 public MapillaryImageDisplay mapillaryImageDisplay; 62 63 private MapillaryCache imageCache; 64 private MapillaryCache thumbnailCache; 65 66 public MapillaryToggleDialog() { 67 super(tr(BASE_TITLE), "mapillary.png", tr("Open Mapillary window"), 68 Shortcut.registerShortcut(tr("Mapillary dialog"), 69 tr("Open Mapillary main dialog"), KeyEvent.VK_M, 70 Shortcut.NONE), 200); 71 MapillaryData.getInstance().addListener(this); 72 73 mapillaryImageDisplay = new MapillaryImageDisplay(); 74 75 blueButton.setForeground(Color.BLUE); 76 redButton.setForeground(Color.RED); 77 78 createLayout( 79 mapillaryImageDisplay, 80 Arrays.asList(new SideButton[] { blueButton, previousButton, 81 nextButton, redButton }), 82 Main.pref.getBoolean("mapillary.reverse-buttons")); 83 disableAllButtons(); 84 } 85 86 public static MapillaryToggleDialog getInstance() { 87 if (INSTANCE == null) 88 INSTANCE = new MapillaryToggleDialog(); 89 return INSTANCE; 90 } 91 92 public static void destroyInstance() { 93 INSTANCE = null; 94 } 95 96 /** 97 * Downloads the image of the selected MapillaryImage and sets in the 98 * MapillaryImageDisplay object. 99 */ 100 public synchronized void updateImage() { 101 if (!SwingUtilities.isEventDispatchThread()) { 102 SwingUtilities.invokeLater(new Runnable() { 103 @Override 104 public void run() { 105 updateImage(); 106 } 107 }); 108 } else { 109 if (MapillaryLayer.INSTANCE == null) { 110 return; 111 } 112 if (this.image == null) { 113 mapillaryImageDisplay.setImage(null); 114 setTitle(tr(BASE_TITLE)); 115 disableAllButtons(); 116 return; 117 } 118 if (image instanceof MapillaryImage) { 119 mapillaryImageDisplay.hyperlink.setVisible(true); 120 MapillaryImage mapillaryImage = (MapillaryImage) this.image; 121 String title = tr(BASE_TITLE); 122 if (mapillaryImage.getUser() != null) 123 title += " -- " + mapillaryImage.getUser(); 124 if (mapillaryImage.getCapturedAt() != 0) 125 title += " -- " + mapillaryImage.getDate(); 126 setTitle(title); 127 this.nextButton.setEnabled(false); 128 this.previousButton.setEnabled(false); 129 // Enables/disables next/previous buttons 130 if (((MapillaryImage) image).getSequence() != null) { 131 MapillaryImage tempImage = (MapillaryImage) image; 132 while (tempImage.next() != null) { 133 tempImage = tempImage.next(); 134 if (tempImage.isVisible()) { 135 this.nextButton.setEnabled(true); 136 break; 137 } 138 } 139 } 140 if (((MapillaryImage) image).getSequence() != null) { 141 MapillaryImage tempImage = (MapillaryImage) image; 142 while (tempImage.previous() != null) { 143 tempImage = tempImage.previous(); 144 if (tempImage.isVisible()) { 145 this.previousButton.setEnabled(true); 146 break; 147 } 148 } 149 } 150 151 mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey()); 152 // Downloads the thumbnail. 153 this.mapillaryImageDisplay.setImage(null); 154 if (thumbnailCache != null) 155 thumbnailCache.cancelOutstandingTasks(); 156 thumbnailCache = new MapillaryCache(mapillaryImage.getKey(), 157 MapillaryCache.Type.THUMBNAIL); 158 thumbnailCache.submit(this, false); 159 160 // Downloads the full resolution image. 161 if (imageCache != null) 162 imageCache.cancelOutstandingTasks(); 163 imageCache = new MapillaryCache(mapillaryImage.getKey(), 164 MapillaryCache.Type.FULL_IMAGE); 165 imageCache.submit(this, false); 166 } else if (image instanceof MapillaryImportedImage) { 167 mapillaryImageDisplay.hyperlink.setVisible(false); 168 this.nextButton.setEnabled(false); 169 this.previousButton.setEnabled(false); 170 MapillaryImportedImage mapillaryImage = (MapillaryImportedImage) this.image; 171 try { 172 mapillaryImageDisplay.setImage(mapillaryImage.getImage()); 173 } catch (IOException e) { 174 Main.error(e); 175 } 176 mapillaryImageDisplay.hyperlink.setURL(null); 177 } 178 } 179 } 180 181 private void disableAllButtons() { 182 nextButton.setEnabled(false); 183 previousButton.setEnabled(false); 184 blueButton.setEnabled(false); 185 redButton.setEnabled(false); 186 mapillaryImageDisplay.hyperlink.setVisible(false); 187 } 188 189 /** 190 * Sets a new MapillaryImage to be shown. 191 * 192 * @param image 193 */ 194 public synchronized void setImage(MapillaryAbstractImage image) { 195 this.image = image; 196 } 197 198 /** 199 * Returns the MapillaryImage objects which is being shown. 200 * 201 * @return 202 */ 203 public synchronized MapillaryAbstractImage getImage() { 204 return this.image; 205 } 206 207 /** 208 * Action class form the next image button. 209 * 210 * @author Jorge 211 * 212 */ 213 class nextPictureAction extends AbstractAction { 214 public nextPictureAction() { 215 putValue(NAME, tr("Next picture")); 216 putValue(SHORT_DESCRIPTION, 217 tr("Shows the next picture in the sequence")); 218 } 219 220 @Override 221 public void actionPerformed(ActionEvent e) { 222 if (MapillaryToggleDialog.getInstance().getImage() != null) { 223 MapillaryData.getInstance().selectNext(); 224 } 225 } 226 } 227 228 /** 229 * Action class for the previous image button. 230 * 231 * @author Jorge 232 * 233 */ 234 class previousPictureAction extends AbstractAction { 235 public previousPictureAction() { 236 putValue(NAME, tr("Previous picture")); 237 putValue(SHORT_DESCRIPTION, 238 tr("Shows the previous picture in the sequence")); 239 } 240 241 @Override 242 public void actionPerformed(ActionEvent e) { 243 if (MapillaryToggleDialog.getInstance().getImage() != null) { 244 MapillaryData.getInstance().selectPrevious(); 245 } 246 } 247 } 248 249 /** 250 * Action class to jump to the image following the red line. 251 * 252 * @author nokutu 253 * 254 */ 255 class redAction extends AbstractAction { 256 public redAction() { 257 putValue(NAME, tr("Jump to red")); 258 putValue( 259 SHORT_DESCRIPTION, 260 tr("Jumps to the picture at the other side of the red line")); 261 } 262 263 @Override 264 public void actionPerformed(ActionEvent e) { 265 if (MapillaryToggleDialog.getInstance().getImage() != null) { 266 MapillaryData.getInstance().setSelectedImage( 267 MapillaryLayer.RED, true); 268 } 269 } 270 } 271 272 /** 273 * Action class to jump to the image following the blue line. 274 * 275 * @author nokutu 276 * 277 */ 278 class blueAction extends AbstractAction { 279 public blueAction() { 280 putValue(NAME, tr("Jump to blue")); 281 putValue( 282 SHORT_DESCRIPTION, 283 tr("Jumps to the picture at the other side of the blue line")); 284 } 285 286 @Override 287 public void actionPerformed(ActionEvent e) { 288 if (MapillaryToggleDialog.getInstance().getImage() != null) { 289 MapillaryData.getInstance().setSelectedImage( 290 MapillaryLayer.BLUE, true); 291 } 292 } 293 } 294 295 /** 296 * When the pictures are returned from the cache, they are set in the 297 * {@link MapillaryImageDisplay} object. 298 */ 299 @Override 300 public void loadingFinished(final CacheEntry data, 301 final CacheEntryAttributes attributes, final LoadResult result) { 302 if (!SwingUtilities.isEventDispatchThread()) { 303 SwingUtilities.invokeLater(new Runnable() { 304 @Override 305 public void run() { 306 loadingFinished(data, attributes, result); 307 } 308 }); 309 } else if (data != null && result == LoadResult.SUCCESS) { 310 try { 311 BufferedImage img = ImageIO.read(new ByteArrayInputStream(data 312 .getContent())); 313 if (this.mapillaryImageDisplay.getImage() == null) 314 mapillaryImageDisplay.setImage(img); 315 else if (img.getHeight() > this.mapillaryImageDisplay 316 .getImage().getHeight()) { 317 mapillaryImageDisplay.setImage(img); 318 } 319 } catch (IOException e) { 320 Main.error(e); 321 } 322 } 323 } 324 325 /** 326 * Creates the layout of the dialog. 327 * 328 * @param data 329 * The content of the dialog 330 * @param buttons 331 * The buttons where you can click 332 * @param reverse 333 * {@code true} if the buttons should go at the top; 334 * {@code false} otherwise. 335 */ 336 public void createLayout(Component data, List<SideButton> buttons, 337 boolean reverse) { 338 this.removeAll(); 339 JPanel panel = new JPanel(); 340 panel.setLayout(new BorderLayout()); 341 panel.add(data, BorderLayout.CENTER); 342 if (reverse) { 343 buttonsPanel = new JPanel(new GridLayout(1, 1)); 344 if (!buttons.isEmpty() && buttons.get(0) != null) { 345 final JPanel buttonRowPanel = new JPanel(Main.pref.getBoolean( 346 "dialog.align.left", false) ? new FlowLayout( 347 FlowLayout.LEFT) : new GridLayout(1, buttons.size())); 348 buttonsPanel.add(buttonRowPanel); 349 for (SideButton button : buttons) 350 buttonRowPanel.add(button); 351 } 352 panel.add(buttonsPanel, BorderLayout.NORTH); 353 createLayout(panel, true, null); 354 } else 355 createLayout(panel, true, buttons); 356 this.add(titleBar, BorderLayout.NORTH); 357 } 358 359 @Override 360 public void selectedImageChanged(MapillaryAbstractImage oldImage, 361 MapillaryAbstractImage newImage) { 362 setImage(MapillaryData.getInstance().getSelectedImage()); 363 updateImage(); 364 } 365 366 @Override 367 public void imagesAdded() { 368 } 48 ICachedLoaderListener, MapillaryDataListener { 49 50 public final static String BASE_TITLE = "Mapillary picture"; 51 52 public static MapillaryToggleDialog INSTANCE; 53 54 public volatile MapillaryAbstractImage image; 55 56 public final SideButton nextButton = new SideButton(new nextPictureAction()); 57 public final SideButton previousButton = new SideButton( 58 new previousPictureAction()); 59 public final SideButton redButton = new SideButton(new redAction()); 60 public final SideButton blueButton = new SideButton(new blueAction()); 61 62 private JPanel buttonsPanel; 63 64 public MapillaryImageDisplay mapillaryImageDisplay; 65 66 private MapillaryCache imageCache; 67 private MapillaryCache thumbnailCache; 68 69 public MapillaryToggleDialog() { 70 super(tr(BASE_TITLE), "mapillary.png", tr("Open Mapillary window"), 71 Shortcut.registerShortcut(tr("Mapillary dialog"), 72 tr("Open Mapillary main dialog"), KeyEvent.VK_M, 73 Shortcut.NONE), 200); 74 MapillaryData.getInstance().addListener(this); 75 addShortcuts(); 76 mapillaryImageDisplay = new MapillaryImageDisplay(); 77 78 blueButton.setForeground(Color.BLUE); 79 redButton.setForeground(Color.RED); 80 81 createLayout( 82 mapillaryImageDisplay, 83 Arrays.asList(new SideButton[] { blueButton, previousButton, 84 nextButton, redButton }), 85 Main.pref.getBoolean("mapillary.reverse-buttons")); 86 disableAllButtons(); 87 88 } 89 90 /** 91 * Adds the shortcuts to the buttons. 92 */ 93 private void addShortcuts() { 94 nextButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 95 KeyStroke.getKeyStroke("PAGE_DOWN"), "next"); 96 nextButton.getActionMap().put("next", new nextPictureAction()); 97 previousButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 98 KeyStroke.getKeyStroke("PAGE_UP"), "previous"); 99 previousButton.getActionMap().put("previous", new previousPictureAction()); 100 blueButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 101 KeyStroke.getKeyStroke("control PAGE_UP"), "blue"); 102 blueButton.getActionMap().put("blue", new blueAction()); 103 redButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 104 KeyStroke.getKeyStroke("control PAGE_DOWN"), "red"); 105 redButton.getActionMap().put("red", new redAction()); 106 } 107 108 public static MapillaryToggleDialog getInstance() { 109 if (INSTANCE == null) 110 INSTANCE = new MapillaryToggleDialog(); 111 return INSTANCE; 112 } 113 114 public static void destroyInstance() { 115 INSTANCE = null; 116 } 117 118 /** 119 * Downloads the image of the selected MapillaryImage and sets in the 120 * MapillaryImageDisplay object. 121 */ 122 public synchronized void updateImage() { 123 if (!SwingUtilities.isEventDispatchThread()) { 124 SwingUtilities.invokeLater(new Runnable() { 125 @Override 126 public void run() { 127 updateImage(); 128 } 129 }); 130 } else { 131 if (MapillaryLayer.INSTANCE == null) { 132 return; 133 } 134 if (this.image == null) { 135 mapillaryImageDisplay.setImage(null); 136 setTitle(tr(BASE_TITLE)); 137 disableAllButtons(); 138 return; 139 } 140 if (image instanceof MapillaryImage) { 141 mapillaryImageDisplay.hyperlink.setVisible(true); 142 MapillaryImage mapillaryImage = (MapillaryImage) this.image; 143 String title = tr(BASE_TITLE); 144 if (mapillaryImage.getUser() != null) 145 title += " -- " + mapillaryImage.getUser(); 146 if (mapillaryImage.getCapturedAt() != 0) 147 title += " -- " + mapillaryImage.getDate(); 148 setTitle(title); 149 this.nextButton.setEnabled(false); 150 this.previousButton.setEnabled(false); 151 // Enables/disables next/previous buttons 152 if (((MapillaryImage) image).getSequence() != null) { 153 MapillaryImage tempImage = (MapillaryImage) image; 154 while (tempImage.next() != null) { 155 tempImage = tempImage.next(); 156 if (tempImage.isVisible()) { 157 this.nextButton.setEnabled(true); 158 break; 159 } 160 } 161 } 162 if (((MapillaryImage) image).getSequence() != null) { 163 MapillaryImage tempImage = (MapillaryImage) image; 164 while (tempImage.previous() != null) { 165 tempImage = tempImage.previous(); 166 if (tempImage.isVisible()) { 167 this.previousButton.setEnabled(true); 168 break; 169 } 170 } 171 } 172 173 mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey()); 174 // Downloads the thumbnail. 175 this.mapillaryImageDisplay.setImage(null); 176 if (thumbnailCache != null) 177 thumbnailCache.cancelOutstandingTasks(); 178 thumbnailCache = new MapillaryCache(mapillaryImage.getKey(), 179 MapillaryCache.Type.THUMBNAIL); 180 thumbnailCache.submit(this, false); 181 182 // Downloads the full resolution image. 183 if (imageCache != null) 184 imageCache.cancelOutstandingTasks(); 185 imageCache = new MapillaryCache(mapillaryImage.getKey(), 186 MapillaryCache.Type.FULL_IMAGE); 187 imageCache.submit(this, false); 188 } else if (image instanceof MapillaryImportedImage) { 189 mapillaryImageDisplay.hyperlink.setVisible(false); 190 this.nextButton.setEnabled(false); 191 this.previousButton.setEnabled(false); 192 MapillaryImportedImage mapillaryImage = (MapillaryImportedImage) this.image; 193 try { 194 mapillaryImageDisplay.setImage(mapillaryImage.getImage()); 195 } catch (IOException e) { 196 Main.error(e); 197 } 198 mapillaryImageDisplay.hyperlink.setURL(null); 199 } 200 } 201 } 202 203 private void disableAllButtons() { 204 nextButton.setEnabled(false); 205 previousButton.setEnabled(false); 206 blueButton.setEnabled(false); 207 redButton.setEnabled(false); 208 mapillaryImageDisplay.hyperlink.setVisible(false); 209 } 210 211 /** 212 * Sets a new MapillaryImage to be shown. 213 * 214 * @param image 215 */ 216 public synchronized void setImage(MapillaryAbstractImage image) { 217 this.image = image; 218 } 219 220 /** 221 * Returns the MapillaryImage objects which is being shown. 222 * 223 * @return 224 */ 225 public synchronized MapillaryAbstractImage getImage() { 226 return this.image; 227 } 228 229 /** 230 * Action class form the next image button. 231 * 232 * @author Jorge 233 * 234 */ 235 class nextPictureAction extends AbstractAction { 236 public nextPictureAction() { 237 putValue(NAME, tr("Next picture")); 238 putValue(SHORT_DESCRIPTION, 239 tr("Shows the next picture in the sequence")); 240 } 241 242 @Override 243 public void actionPerformed(ActionEvent e) { 244 if (MapillaryToggleDialog.getInstance().getImage() != null) { 245 MapillaryData.getInstance().selectNext(); 246 } 247 } 248 } 249 250 /** 251 * Action class for the previous image button. 252 * 253 * @author Jorge 254 * 255 */ 256 class previousPictureAction extends AbstractAction { 257 public previousPictureAction() { 258 putValue(NAME, tr("Previous picture")); 259 putValue(SHORT_DESCRIPTION, 260 tr("Shows the previous picture in the sequence")); 261 } 262 263 @Override 264 public void actionPerformed(ActionEvent e) { 265 if (MapillaryToggleDialog.getInstance().getImage() != null) { 266 MapillaryData.getInstance().selectPrevious(); 267 } 268 } 269 } 270 271 /** 272 * Action class to jump to the image following the red line. 273 * 274 * @author nokutu 275 * 276 */ 277 class redAction extends AbstractAction { 278 public redAction() { 279 putValue(NAME, tr("Jump to red")); 280 putValue( 281 SHORT_DESCRIPTION, 282 tr("Jumps to the picture at the other side of the red line")); 283 } 284 285 @Override 286 public void actionPerformed(ActionEvent e) { 287 if (MapillaryToggleDialog.getInstance().getImage() != null) { 288 MapillaryData.getInstance().setSelectedImage( 289 MapillaryLayer.RED, true); 290 } 291 } 292 } 293 294 /** 295 * Action class to jump to the image following the blue line. 296 * 297 * @author nokutu 298 * 299 */ 300 class blueAction extends AbstractAction { 301 public blueAction() { 302 putValue(NAME, tr("Jump to blue")); 303 putValue( 304 SHORT_DESCRIPTION, 305 tr("Jumps to the picture at the other side of the blue line")); 306 } 307 308 @Override 309 public void actionPerformed(ActionEvent e) { 310 if (MapillaryToggleDialog.getInstance().getImage() != null) { 311 MapillaryData.getInstance().setSelectedImage( 312 MapillaryLayer.BLUE, true); 313 } 314 } 315 } 316 317 /** 318 * When the pictures are returned from the cache, they are set in the 319 * {@link MapillaryImageDisplay} object. 320 */ 321 @Override 322 public void loadingFinished(final CacheEntry data, 323 final CacheEntryAttributes attributes, final LoadResult result) { 324 if (!SwingUtilities.isEventDispatchThread()) { 325 SwingUtilities.invokeLater(new Runnable() { 326 @Override 327 public void run() { 328 loadingFinished(data, attributes, result); 329 } 330 }); 331 } else if (data != null && result == LoadResult.SUCCESS) { 332 try { 333 BufferedImage img = ImageIO.read(new ByteArrayInputStream(data 334 .getContent())); 335 if (img == null) 336 return; 337 if (this.mapillaryImageDisplay.getImage() == null) 338 mapillaryImageDisplay.setImage(img); 339 else if (img.getHeight() > this.mapillaryImageDisplay 340 .getImage().getHeight()) { 341 mapillaryImageDisplay.setImage(img); 342 } 343 } catch (IOException e) { 344 Main.error(e); 345 } 346 } 347 } 348 349 /** 350 * Creates the layout of the dialog. 351 * 352 * @param data 353 * The content of the dialog 354 * @param buttons 355 * The buttons where you can click 356 * @param reverse 357 * {@code true} if the buttons should go at the top; 358 * {@code false} otherwise. 359 */ 360 public void createLayout(Component data, List<SideButton> buttons, 361 boolean reverse) { 362 this.removeAll(); 363 JPanel panel = new JPanel(); 364 panel.setLayout(new BorderLayout()); 365 panel.add(data, BorderLayout.CENTER); 366 if (reverse) { 367 buttonsPanel = new JPanel(new GridLayout(1, 1)); 368 if (!buttons.isEmpty() && buttons.get(0) != null) { 369 final JPanel buttonRowPanel = new JPanel(Main.pref.getBoolean( 370 "dialog.align.left", false) ? new FlowLayout( 371 FlowLayout.LEFT) : new GridLayout(1, buttons.size())); 372 buttonsPanel.add(buttonRowPanel); 373 for (SideButton button : buttons) 374 buttonRowPanel.add(button); 375 } 376 panel.add(buttonsPanel, BorderLayout.NORTH); 377 createLayout(panel, true, null); 378 } else 379 createLayout(panel, true, buttons); 380 this.add(titleBar, BorderLayout.NORTH); 381 } 382 383 @Override 384 public void selectedImageChanged(MapillaryAbstractImage oldImage, 385 MapillaryAbstractImage newImage) { 386 setImage(MapillaryData.getInstance().getSelectedImage()); 387 updateImage(); 388 } 389 390 @Override 391 public void imagesAdded() { 392 } 369 393 }
Note:
See TracChangeset
for help on using the changeset viewer.
