Changeset 33745 in osm for applications/editors/josm/plugins/photoadjust/src/org
- Timestamp:
- 2017-10-30T19:13:43+01:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java
r33303 r33745 12 12 import java.util.List; 13 13 14 import org.openstreetmap.josm.Main;15 14 import org.openstreetmap.josm.actions.mapmode.MapMode; 16 15 import org.openstreetmap.josm.gui.IconToggleButton; 16 import org.openstreetmap.josm.gui.MainApplication; 17 17 import org.openstreetmap.josm.gui.MapFrame; 18 18 import org.openstreetmap.josm.gui.layer.Layer; … … 21 21 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 22 22 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 23 import org.openstreetmap.josm.gui.layer.MainLayerManager; 23 24 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 24 25 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; … … 57 58 initAdapters(); 58 59 this.worker = worker; 59 Main .getLayerManager().addLayerChangeListener(this);60 Main .getLayerManager().addActiveLayerChangeListener(this);60 MainApplication.getLayerManager().addLayerChangeListener(this); 61 MainApplication.getLayerManager().addActiveLayerChangeListener(this); 61 62 } 62 63 … … 115 116 private void activateMode() { 116 117 if (modeSelected && !modeActive) { 117 Main .map.mapView.addMouseListener(mouseAdapter);118 Main .map.mapView.addMouseMotionListener(mouseMotionAdapter);118 MainApplication.getMap().mapView.addMouseListener(mouseAdapter); 119 MainApplication.getMap().mapView.addMouseMotionListener(mouseMotionAdapter); 119 120 modeActive = true; 120 121 updateStatusLine(); … … 127 128 private void deactivateMode() { 128 129 if (modeActive) { 129 Main .map.mapView.removeMouseListener(mouseAdapter);130 Main .map.mapView.removeMouseMotionListener(mouseMotionAdapter);130 MainApplication.getMap().mapView.removeMouseListener(mouseAdapter); 131 MainApplication.getMap().mapView.removeMouseMotionListener(mouseMotionAdapter); 131 132 modeActive = false; 132 133 } … … 139 140 // Activate the mode only if the current layer is not a GeoImageLayer. 140 141 // GeoImageLayer's are handled by the plug-in directly. 141 if (!(Main .getLayerManager().getActiveLayer() instanceof GeoImageLayer)) {142 if (!(MainApplication.getLayerManager().getActiveLayer() instanceof GeoImageLayer)) { 142 143 activateMode(); 143 144 } … … 154 155 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 155 156 // The main part of the plugin takes care of all operations if a GeoImageLayer is active. 156 if (Main .getLayerManager().getActiveLayer() instanceof GeoImageLayer) {157 if (MainApplication.getLayerManager().getActiveLayer() instanceof GeoImageLayer) { 157 158 deactivateMode(); 158 159 } else { … … 219 220 */ 220 221 private boolean hasLayersToAdjust() { 221 if (Main.map == null || Main.map.mapView == null) return false; 222 int giLayerNum = Main.getLayerManager().getLayersOfType(GeoImageLayer.class).size(); 222 final MainLayerManager layerManager = MainApplication.getLayerManager(); 223 if (layerManager == null) return false; 224 int giLayerNum = layerManager.getLayersOfType(GeoImageLayer.class).size(); 223 225 if (ignoreOneGILayer) { 224 226 giLayerNum--; … … 233 235 */ 234 236 private List<GeoImageLayer> getVisibleGeoImageLayers() { 235 List<GeoImageLayer> all = new ArrayList<>(Main .getLayerManager().getLayersOfType(GeoImageLayer.class));237 List<GeoImageLayer> all = new ArrayList<>(MainApplication.getLayerManager().getLayersOfType(GeoImageLayer.class)); 236 238 Iterator<GeoImageLayer> it = all.iterator(); 237 239 while (it.hasNext()) { … … 245 247 public void destroy() { 246 248 super.destroy(); 247 Main .getLayerManager().removeActiveLayerChangeListener(this);248 Main .getLayerManager().removeLayerChangeListener(this);249 MainApplication.getLayerManager().removeActiveLayerChangeListener(this); 250 MainApplication.getLayerManager().removeLayerChangeListener(this); 249 251 } 250 252 -
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustPlugin.java
r33303 r33745 7 7 import java.util.List; 8 8 9 import org.openstreetmap.josm. Main;9 import org.openstreetmap.josm.gui.MainApplication; 10 10 import org.openstreetmap.josm.gui.MapFrame; 11 11 import org.openstreetmap.josm.gui.layer.Layer; … … 77 77 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 78 78 if (oldFrame == null && newFrame != null) { 79 Main .getLayerManager().addAndFireActiveLayerChangeListener(this);79 MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this); 80 80 PhotoAdjustMapMode adjustMode = new PhotoAdjustMapMode(worker); 81 81 adjustMode.installMapMode(newFrame); 82 82 } else { 83 Main .getLayerManager().removeActiveLayerChangeListener(this);83 MainApplication.getLayerManager().removeActiveLayerChangeListener(this); 84 84 } 85 85 } … … 89 89 worker.reset(); 90 90 Layer oldLayer = e.getPreviousActiveLayer(); 91 Layer newLayer = Main .getLayerManager().getActiveLayer();91 Layer newLayer = MainApplication.getLayerManager().getActiveLayer(); 92 92 if ( oldLayer instanceof GeoImageLayer 93 93 && newLayer instanceof GeoImageLayer) { … … 96 96 else { 97 97 if (oldLayer instanceof GeoImageLayer) { 98 Main .map.mapView.removeMouseListener(mouseAdapter);99 Main .map.mapView.removeMouseMotionListener(mouseMotionAdapter);98 MainApplication.getMap().mapView.removeMouseListener(mouseAdapter); 99 MainApplication.getMap().mapView.removeMouseMotionListener(mouseMotionAdapter); 100 100 imageLayer = null; 101 101 } 102 102 if (newLayer instanceof GeoImageLayer) { 103 103 imageLayer = (GeoImageLayer)newLayer; 104 Main .map.mapView.addMouseListener(mouseAdapter);105 Main .map.mapView.addMouseMotionListener(mouseMotionAdapter);104 MainApplication.getMap().mapView.addMouseListener(mouseAdapter); 105 MainApplication.getMap().mapView.addMouseMotionListener(mouseMotionAdapter); 106 106 } 107 107 } -
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java
r32015 r33745 6 6 import java.util.List; 7 7 8 import org.openstreetmap.josm.Main;9 8 import org.openstreetmap.josm.data.coor.LatLon; 9 import org.openstreetmap.josm.gui.MainApplication; 10 10 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; 11 11 import org.openstreetmap.josm.gui.layer.geoimage.ImageEntry; … … 139 139 public void doMouseReleased(MouseEvent evt) { 140 140 restoreCenterView(); 141 //if (dragLayer != null && dragPhoto != null) { 142 // // Re-display the photo to update the OSD. 143 // ImageViewerDialog.showImage(dragLayer, dragPhoto); 144 //} 141 145 } 142 146 … … 166 170 */ 167 171 private void setDragOffset(ImageEntry photo, MouseEvent evt) { 168 final Point2D centerPoint = Main .map.mapView.getPoint2D(photo.getPos());172 final Point2D centerPoint = MainApplication.getMap().mapView.getPoint2D(photo.getPos()); 169 173 dragOffset = new Point2D.Double(centerPoint.getX() - evt.getX(), 170 174 centerPoint.getY() - evt.getY()); … … 182 186 LatLon newPos; 183 187 if (dragOffset != null) { 184 newPos = Main.map.mapView.getLatLon(dragOffset.getX() + evt.getX(), 185 dragOffset.getY() + evt.getY()); 188 newPos = MainApplication.getMap().mapView.getLatLon( 189 dragOffset.getX() + evt.getX(), 190 dragOffset.getY() + evt.getY()); 186 191 } 187 192 else { 188 newPos = Main .map.mapView.getLatLon(evt.getX(), evt.getY());193 newPos = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY()); 189 194 } 190 195 photo.setPos(newPos); 191 196 photo.flagNewGpsData(); 192 197 layer.updateBufferAndRepaint(); 193 // Need to re-display the photo because the OSD data might change (new194 // coordinates). 195 ImageViewerDialog.showImage(layer, photo);198 // Re-display the photo because the OSD data might change (new 199 // coordinates). Or do that in doMouseReleased(). 200 //ImageViewerDialog.showImage(layer, photo); 196 201 } 197 202 … … 210 215 return; 211 216 } 212 final LatLon mouseLL = Main .map.mapView.getLatLon(evt.getX(), evt.getY());217 final LatLon mouseLL = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY()); 213 218 // The projection doesn't matter here. 214 double direction = 360.0 - photoLL.heading(mouseLL) * 360.0 / 2.0 / Math.PI;219 double direction = photoLL.bearing(mouseLL) * 360.0 / 2.0 / Math.PI; 215 220 if (direction < 0.0) { 216 221 direction += 360.0; -
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoPropertyEditor.java
r33303 r33745 24 24 import org.openstreetmap.josm.actions.JosmAction; 25 25 import org.openstreetmap.josm.data.coor.LatLon; 26 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager; 27 import org.openstreetmap.josm.data.coor.conversion.LatLonParser; 26 28 import org.openstreetmap.josm.gui.ExtendedDialog; 29 import org.openstreetmap.josm.gui.MainApplication; 27 30 import org.openstreetmap.josm.gui.MainMenu; 28 31 import org.openstreetmap.josm.gui.dialogs.LatLonDialog; … … 40 43 41 44 public PhotoPropertyEditor() { 42 MainMenu.add(Main .main.menu.editMenu, new PropertyEditorAction());45 MainMenu.add(MainApplication.getMenu().editMenu, new PropertyEditorAction()); 43 46 } 44 47 … … 88 91 if (dialog.getValue() == 1) { 89 92 dialog.updateImageTmp(); 93 // FIXME: Remove next line, see below. 94 boolean isNewGpsData = photo.getTmp().hasNewGpsData(); 95 // There are cases where isNewGpsData is not set but there 96 // is still new data, e.g. if the EXIF data was re-read 97 // from the image file. 90 98 photo.applyTmp(); 99 // FIXME: Remove the next lines once the patch in ticket 100 // #15502 is active. 101 if (isNewGpsData) { 102 photo.flagNewGpsData(); 103 } 91 104 } else { 92 105 photo.discardTmp(); … … 135 148 private final ImageEntry image; 136 149 private final GeoImageLayer layer; 150 // Image as it was when the dialog was opened. 151 private final ImageEntry imgOrig; 137 152 private static final Color BG_COLOR_ERROR = new Color(255, 224, 224); 138 153 … … 142 157 this.image = image; 143 158 this.layer = layer; 159 imgOrig = image.clone(); 144 160 setButtonIcons(new String[] {"ok", "cancel"}); 145 161 final JPanel content = new JPanel(new GridBagLayout()); … … 174 190 Action editCoordAction = new AbstractAction(tr("Edit")) { 175 191 @Override public void actionPerformed(ActionEvent evt) { 176 final LatLonDialog dialog192 final LatLonDialog llDialog 177 193 = new LatLonDialog(Main.parent, 178 194 tr("Edit Image Coordinates"), null); 179 dialog.setCoordinates(getLatLon());180 dialog.showDialog();181 if ( dialog.getValue() == 1) {182 LatLon coordinates = dialog.getCoordinates();195 llDialog.setCoordinates(getLatLon()); 196 llDialog.showDialog(); 197 if (llDialog.getValue() == 1) { 198 final LatLon coordinates = llDialog.getCoordinates(); 183 199 if (coordinates != null) { 184 coords.setText( coordinates.toStringCSV(" "));200 coords.setText(posToText(coordinates)); 185 201 } 186 202 } … … 302 318 } 303 319 320 /** 321 * Convert an image position into a display string. 322 * 323 * @param pos Coordinates of image position. 324 * @return Image position as text. 325 */ 326 private String posToText(LatLon pos) { 327 // See josm.gui.dialogs.LatLonDialog.setCoordinates(). 328 String posStr = 329 pos == null ? "" : 330 CoordinateFormatManager.getDefaultFormat().latToString(pos) + 331 ' ' + 332 CoordinateFormatManager.getDefaultFormat().lonToString(pos); 333 return posStr; 334 } 304 335 305 336 /** … … 311 342 if (image.getPos() != null) { 312 343 //coords.setText(image.getPos().toDisplayString()); 313 coords.setText( image.getPos().toStringCSV(" "));344 coords.setText(posToText(image.getPos())); 314 345 } else { 315 346 coords.setText(null); … … 382 413 public void updateImageTmp() { 383 414 ImageEntry imgTmp = image.getTmp(); 415 384 416 String text = coords.getText(); 417 // The position of imgTmp is set in any case because it was 418 // modified while the dialog was open. 385 419 if (text == null || text.isEmpty()) { 386 if (imgTmp.getPos() != null) { 420 imgTmp.setPos(null); 421 if (imgOrig.getPos() != null) { 387 422 imgTmp.flagNewGpsData(); 388 imgTmp.setPos(null); 389 } 390 } else { 391 if ( imgTmp.getPos() == null 392 || !text.equals(imgTmp.getPos().toStringCSV(" "))) { 423 } 424 } else { 425 // Coordinates field is not empty. 426 imgTmp.setPos(getLatLon()); 427 // Flag new GPS data if the temporary image is at a different 428 // position as the original image. It doesn't work to compare 429 // against the coords text field as that might contain data 430 // (e.g. trailing zeros) that do not change the value. It 431 // doesn't work to compare imgTmp.getPos() with getLatLon() 432 // because the dialog will round the initial position. 433 if ( imgOrig.getPos() == null 434 || !posToText(imgOrig.getPos()).equals(posToText(imgTmp.getPos())) 435 ) { 393 436 imgTmp.flagNewGpsData(); 394 imgTmp.setPos(getLatLon());395 437 } 396 438 } … … 431 473 LatLon latLon; 432 474 try { 433 latLon = LatLon .parse(coords.getText());475 latLon = LatLonParser.parse(coords.getText()); 434 476 if (!latLon.isValid()) { 435 477 latLon = null; … … 453 495 final String coordsText = coords.getText(); 454 496 try { 455 latLon = LatLon .parse(coordsText);497 latLon = LatLonParser.parse(coordsText); 456 498 } catch (IllegalArgumentException exn) { 457 499 latLon = null; -
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/UntaggedGeoImageLayerAction.java
r32451 r33745 11 11 import javax.swing.JMenuItem; 12 12 13 import org.openstreetmap.josm. Main;13 import org.openstreetmap.josm.gui.MainApplication; 14 14 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 15 15 import org.openstreetmap.josm.gui.layer.Layer; … … 53 53 } 54 54 } 55 Main.getLayerManager().addLayer(new GeoImageLayer(untagged, layer.getGpxLayer(), 56 tr("Untagged Images"), 57 layer.isUseThumbs())); 55 MainApplication.getLayerManager() 56 .addLayer(new GeoImageLayer(untagged, layer.getGpxLayer(), 57 tr("Untagged Images"), 58 layer.isUseThumbs())); 58 59 } 59 60 }
Note:
See TracChangeset
for help on using the changeset viewer.