Index: applications/editors/josm/plugins/photoadjust/build.xml
===================================================================
--- applications/editors/josm/plugins/photoadjust/build.xml	(revision 33744)
+++ applications/editors/josm/plugins/photoadjust/build.xml	(revision 33745)
@@ -5,5 +5,5 @@
     <property name="commit.message" value="Commit message"/>
     <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
-    <property name="plugin.main.version" value="11713"/>
+    <property name="plugin.main.version" value="12792"/>
 
     <!-- Configure these properties (replace "..." accordingly).
Index: applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java
===================================================================
--- applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java	(revision 33744)
+++ applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java	(revision 33745)
@@ -12,7 +12,7 @@
 import java.util.List;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
 import org.openstreetmap.josm.gui.IconToggleButton;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.gui.layer.Layer;
@@ -21,4 +21,5 @@
 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
+import org.openstreetmap.josm.gui.layer.MainLayerManager;
 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
@@ -57,6 +58,6 @@
         initAdapters();
         this.worker = worker;
-        Main.getLayerManager().addLayerChangeListener(this);
-        Main.getLayerManager().addActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().addLayerChangeListener(this);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
     }
 
@@ -115,6 +116,6 @@
     private void activateMode() {
         if (modeSelected && !modeActive) {
-            Main.map.mapView.addMouseListener(mouseAdapter);
-            Main.map.mapView.addMouseMotionListener(mouseMotionAdapter);
+            MainApplication.getMap().mapView.addMouseListener(mouseAdapter);
+            MainApplication.getMap().mapView.addMouseMotionListener(mouseMotionAdapter);
             modeActive = true;
             updateStatusLine();
@@ -127,6 +128,6 @@
     private void deactivateMode() {
         if (modeActive) {
-            Main.map.mapView.removeMouseListener(mouseAdapter);
-            Main.map.mapView.removeMouseMotionListener(mouseMotionAdapter);
+            MainApplication.getMap().mapView.removeMouseListener(mouseAdapter);
+            MainApplication.getMap().mapView.removeMouseMotionListener(mouseMotionAdapter);
             modeActive = false;
         }
@@ -139,5 +140,5 @@
         // Activate the mode only if the current layer is not a GeoImageLayer.
         // GeoImageLayer's are handled by the plug-in directly.
-        if (!(Main.getLayerManager().getActiveLayer() instanceof GeoImageLayer)) {
+        if (!(MainApplication.getLayerManager().getActiveLayer() instanceof GeoImageLayer)) {
             activateMode();
         }
@@ -154,5 +155,5 @@
     public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
         // The main part of the plugin takes care of all operations if a GeoImageLayer is active.
-        if (Main.getLayerManager().getActiveLayer() instanceof GeoImageLayer) {
+        if (MainApplication.getLayerManager().getActiveLayer() instanceof GeoImageLayer) {
             deactivateMode();
         } else {
@@ -219,6 +220,7 @@
      */
     private boolean hasLayersToAdjust() {
-        if (Main.map == null || Main.map.mapView == null) return false;
-        int giLayerNum = Main.getLayerManager().getLayersOfType(GeoImageLayer.class).size();
+        final MainLayerManager layerManager = MainApplication.getLayerManager();
+        if (layerManager == null) return false;
+        int giLayerNum = layerManager.getLayersOfType(GeoImageLayer.class).size();
         if (ignoreOneGILayer) {
             giLayerNum--;
@@ -233,5 +235,5 @@
      */
     private List<GeoImageLayer> getVisibleGeoImageLayers() {
-        List<GeoImageLayer> all = new ArrayList<>(Main.getLayerManager().getLayersOfType(GeoImageLayer.class));
+        List<GeoImageLayer> all = new ArrayList<>(MainApplication.getLayerManager().getLayersOfType(GeoImageLayer.class));
         Iterator<GeoImageLayer> it = all.iterator();
         while (it.hasNext()) {
@@ -245,6 +247,6 @@
     public void destroy() { 
         super.destroy(); 
-        Main.getLayerManager().removeActiveLayerChangeListener(this);
-        Main.getLayerManager().removeLayerChangeListener(this);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().removeLayerChangeListener(this);
     } 
 
Index: applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustPlugin.java
===================================================================
--- applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustPlugin.java	(revision 33744)
+++ applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustPlugin.java	(revision 33745)
@@ -7,5 +7,5 @@
 import java.util.List;
 
-import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.gui.layer.Layer;
@@ -77,9 +77,9 @@
     public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
         if (oldFrame == null && newFrame != null) {
-            Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
+            MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this);
             PhotoAdjustMapMode adjustMode = new PhotoAdjustMapMode(worker);
             adjustMode.installMapMode(newFrame);
         } else {
-            Main.getLayerManager().removeActiveLayerChangeListener(this);
+            MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
         }
     }
@@ -89,5 +89,5 @@
         worker.reset();
         Layer oldLayer = e.getPreviousActiveLayer();
-        Layer newLayer = Main.getLayerManager().getActiveLayer();
+        Layer newLayer = MainApplication.getLayerManager().getActiveLayer();
         if ( oldLayer instanceof GeoImageLayer
              && newLayer instanceof GeoImageLayer) {
@@ -96,12 +96,12 @@
         else {
             if (oldLayer instanceof GeoImageLayer) {
-                Main.map.mapView.removeMouseListener(mouseAdapter);
-                Main.map.mapView.removeMouseMotionListener(mouseMotionAdapter);
+                MainApplication.getMap().mapView.removeMouseListener(mouseAdapter);
+                MainApplication.getMap().mapView.removeMouseMotionListener(mouseMotionAdapter);
                 imageLayer = null;
             }
             if (newLayer instanceof GeoImageLayer) {
                 imageLayer = (GeoImageLayer)newLayer;
-                Main.map.mapView.addMouseListener(mouseAdapter);
-                Main.map.mapView.addMouseMotionListener(mouseMotionAdapter);
+                MainApplication.getMap().mapView.addMouseListener(mouseAdapter);
+                MainApplication.getMap().mapView.addMouseMotionListener(mouseMotionAdapter);
             }
         }
Index: applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java
===================================================================
--- applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java	(revision 33744)
+++ applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java	(revision 33745)
@@ -6,6 +6,6 @@
 import java.util.List;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
 import org.openstreetmap.josm.gui.layer.geoimage.ImageEntry;
@@ -139,4 +139,8 @@
     public void doMouseReleased(MouseEvent evt) {
         restoreCenterView();
+        //if (dragLayer != null && dragPhoto != null) {
+        //    // Re-display the photo to update the OSD.
+        //    ImageViewerDialog.showImage(dragLayer, dragPhoto);
+        //}
     }
 
@@ -166,5 +170,5 @@
      */
     private void setDragOffset(ImageEntry photo, MouseEvent evt) {
-        final Point2D centerPoint = Main.map.mapView.getPoint2D(photo.getPos());
+        final Point2D centerPoint = MainApplication.getMap().mapView.getPoint2D(photo.getPos());
         dragOffset = new Point2D.Double(centerPoint.getX() - evt.getX(),
                                         centerPoint.getY() - evt.getY());
@@ -182,16 +186,17 @@
         LatLon newPos;
         if (dragOffset != null) {
-            newPos = Main.map.mapView.getLatLon(dragOffset.getX() + evt.getX(),
-                                                dragOffset.getY() + evt.getY());
+            newPos = MainApplication.getMap().mapView.getLatLon(
+                dragOffset.getX() + evt.getX(),
+                dragOffset.getY() + evt.getY());
         }
         else {
-            newPos = Main.map.mapView.getLatLon(evt.getX(), evt.getY());
+            newPos = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY());
         }
         photo.setPos(newPos);
         photo.flagNewGpsData();
         layer.updateBufferAndRepaint();
-        // Need to re-display the photo because the OSD data might change (new
-        // coordinates).
-        ImageViewerDialog.showImage(layer, photo);
+        // Re-display the photo because the OSD data might change (new
+        // coordinates).  Or do that in doMouseReleased().
+        //ImageViewerDialog.showImage(layer, photo);
     }
 
@@ -210,7 +215,7 @@
             return;
         }
-        final LatLon mouseLL = Main.map.mapView.getLatLon(evt.getX(), evt.getY());
+        final LatLon mouseLL = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY());
         // The projection doesn't matter here.
-        double direction = 360.0 - photoLL.heading(mouseLL) * 360.0 / 2.0 / Math.PI;
+        double direction = photoLL.bearing(mouseLL) * 360.0 / 2.0 / Math.PI;
         if (direction < 0.0) {
             direction += 360.0;
Index: applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoPropertyEditor.java
===================================================================
--- applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoPropertyEditor.java	(revision 33744)
+++ applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoPropertyEditor.java	(revision 33745)
@@ -24,5 +24,8 @@
 import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
+import org.openstreetmap.josm.data.coor.conversion.LatLonParser;
 import org.openstreetmap.josm.gui.ExtendedDialog;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MainMenu;
 import org.openstreetmap.josm.gui.dialogs.LatLonDialog;
@@ -40,5 +43,5 @@
 
     public PhotoPropertyEditor() {
-        MainMenu.add(Main.main.menu.editMenu, new PropertyEditorAction());
+        MainMenu.add(MainApplication.getMenu().editMenu, new PropertyEditorAction());
     }
 
@@ -88,5 +91,15 @@
                 if (dialog.getValue() == 1) {
                     dialog.updateImageTmp();
+                    // FIXME: Remove next line, see below.
+                    boolean isNewGpsData = photo.getTmp().hasNewGpsData();
+                    // There are cases where isNewGpsData is not set but there
+                    // is still new data, e.g. if the EXIF data was re-read
+                    // from the image file.
                     photo.applyTmp();
+                    // FIXME: Remove the next lines once the patch in ticket
+                    // #15502 is active.
+                    if (isNewGpsData) {
+                        photo.flagNewGpsData();
+                    }
                 } else {
                     photo.discardTmp();
@@ -135,4 +148,6 @@
         private final ImageEntry image;
         private final GeoImageLayer layer;
+        // Image as it was when the dialog was opened.
+        private final ImageEntry imgOrig;
         private static final Color BG_COLOR_ERROR = new Color(255, 224, 224);
 
@@ -142,4 +157,5 @@
             this.image = image;
             this.layer = layer;
+            imgOrig = image.clone();
             setButtonIcons(new String[] {"ok", "cancel"});
             final JPanel content = new JPanel(new GridBagLayout());
@@ -174,13 +190,13 @@
             Action editCoordAction = new AbstractAction(tr("Edit")) {
                 @Override public void actionPerformed(ActionEvent evt) {
-                    final LatLonDialog dialog 
+                    final LatLonDialog llDialog 
                         = new LatLonDialog(Main.parent,
                                            tr("Edit Image Coordinates"), null);
-                    dialog.setCoordinates(getLatLon());
-                    dialog.showDialog();
-                    if (dialog.getValue() == 1) {
-                        LatLon coordinates = dialog.getCoordinates();
+                    llDialog.setCoordinates(getLatLon());
+                    llDialog.showDialog();
+                    if (llDialog.getValue() == 1) {
+                        final LatLon coordinates = llDialog.getCoordinates();
                         if (coordinates != null) {
-                            coords.setText(coordinates.toStringCSV(" "));
+                            coords.setText(posToText(coordinates));
                         }
                     }
@@ -302,4 +318,19 @@
         }
 
+        /**
+         * Convert an image position into a display string.
+         *
+         * @param pos Coordinates of image position.
+         * @return Image position as text.
+         */
+        private String posToText(LatLon pos) {
+            // See josm.gui.dialogs.LatLonDialog.setCoordinates().
+            String posStr =
+                pos == null ? "" :
+                CoordinateFormatManager.getDefaultFormat().latToString(pos) +
+                ' ' +
+                CoordinateFormatManager.getDefaultFormat().lonToString(pos);
+            return posStr;
+        }
 
         /**
@@ -311,5 +342,5 @@
             if (image.getPos() != null) {
                 //coords.setText(image.getPos().toDisplayString());
-                coords.setText(image.getPos().toStringCSV(" "));
+                coords.setText(posToText(image.getPos()));
             } else {
                 coords.setText(null);
@@ -382,15 +413,26 @@
         public void updateImageTmp() {
             ImageEntry imgTmp = image.getTmp();
+
             String text = coords.getText();
+            // The position of imgTmp is set in any case because it was
+            // modified while the dialog was open.
             if (text == null || text.isEmpty()) {
-                if (imgTmp.getPos() != null) {
+                imgTmp.setPos(null);
+                if (imgOrig.getPos() != null) {
                     imgTmp.flagNewGpsData();
-                    imgTmp.setPos(null);
-                }
-            } else {
-                if ( imgTmp.getPos() == null
-                     || !text.equals(imgTmp.getPos().toStringCSV(" "))) {
+                }
+            } else {
+                // Coordinates field is not empty.
+                imgTmp.setPos(getLatLon());
+                // Flag new GPS data if the temporary image is at a different
+                // position as the original image.  It doesn't work to compare
+                // against the coords text field as that might contain data
+                // (e.g. trailing zeros) that do not change the value.  It
+                // doesn't work to compare imgTmp.getPos() with getLatLon()
+                // because the dialog will round the initial position.
+                if ( imgOrig.getPos() == null
+                     || !posToText(imgOrig.getPos()).equals(posToText(imgTmp.getPos()))
+                     ) {
                     imgTmp.flagNewGpsData();
-                    imgTmp.setPos(getLatLon());
                 }
             }
@@ -431,5 +473,5 @@
             LatLon latLon;
             try {
-                latLon = LatLon.parse(coords.getText());
+                latLon = LatLonParser.parse(coords.getText());
                 if (!latLon.isValid()) {
                     latLon = null;
@@ -453,5 +495,5 @@
             final String coordsText = coords.getText();
             try {
-                latLon = LatLon.parse(coordsText);
+                latLon = LatLonParser.parse(coordsText);
             } catch (IllegalArgumentException exn) {
                 latLon = null;
Index: applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/UntaggedGeoImageLayerAction.java
===================================================================
--- applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/UntaggedGeoImageLayerAction.java	(revision 33744)
+++ applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/UntaggedGeoImageLayerAction.java	(revision 33745)
@@ -11,5 +11,5 @@
 import javax.swing.JMenuItem;
 
-import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
 import org.openstreetmap.josm.gui.layer.Layer;
@@ -53,7 +53,8 @@
                 }
             }
-            Main.getLayerManager().addLayer(new GeoImageLayer(untagged, layer.getGpxLayer(),
-                                                 tr("Untagged Images"),
-                                                 layer.isUseThumbs()));
+            MainApplication.getLayerManager()
+                .addLayer(new GeoImageLayer(untagged, layer.getGpxLayer(),
+                                            tr("Untagged Images"),
+                                            layer.isUseThumbs()));
         }
     }
