Index: /applications/editors/josm/plugins/cadastre-fr/build.xml
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/build.xml	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/build.xml	(revision 33640)
@@ -4,5 +4,5 @@
     <property name="commit.message" value="Changed constructor for Plugin"/>
     <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
-    <property name="plugin.main.version" value="11713"/>
+    <property name="plugin.main.version" value="12840"/>
     
     <!-- Configure these properties (replace "..." accordingly).
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/CadastrePlugin.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/CadastrePlugin.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/CadastrePlugin.java	(revision 33640)
@@ -28,4 +28,5 @@
 import org.openstreetmap.josm.data.projection.Projection;
 import org.openstreetmap.josm.gui.IconToggleButton;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MainMenu;
 import org.openstreetmap.josm.gui.MapFrame;
@@ -50,4 +51,5 @@
 import org.openstreetmap.josm.plugins.fr.cadastre.session.CadastreSessionImporter;
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer;
+import org.openstreetmap.josm.tools.Logging;
 
 /**
@@ -213,5 +215,5 @@
     public CadastrePlugin(PluginInformation info) {
         super(info);
-        Main.info("Pluging cadastre-fr v"+VERSION+" started...");
+        Logging.info("Pluging cadastre-fr v"+VERSION+" started...");
         initCacheDir();
 
@@ -226,5 +228,5 @@
     private static void initCacheDir() {
         if (Main.pref.get("cadastrewms.cacheDir").isEmpty()) {
-            cacheDir = new File(Main.pref.getCacheDirectory(), "cadastrewms").getAbsolutePath();
+            cacheDir = new File(Main.pref.getCacheDirectory(true), "cadastrewms").getAbsolutePath();
         } else {
             cacheDir = Main.pref.get("cadastrewms.cacheDir");
@@ -232,9 +234,9 @@
         if (cacheDir.charAt(cacheDir.length()-1) != File.separatorChar)
             cacheDir += File.separatorChar;
-        Main.info("current cache directory: "+cacheDir);
+        Logging.info("current cache directory: "+cacheDir);
     }
 
     public static void refreshMenu() {
-        MainMenu menu = Main.main.menu;
+        MainMenu menu = MainApplication.getMenu();
 
         if (cadastreJMenu == null) {
@@ -253,5 +255,5 @@
                 @Override
                 public void actionPerformed(ActionEvent ev) {
-                    Main.pref.put("cadastrewms.autosourcing", menuSource.isSelected());
+                    Main.pref.putBoolean("cadastrewms.autosourcing", menuSource.isSelected());
                     autoSourcing = menuSource.isSelected();
                 }
@@ -360,6 +362,6 @@
             JOptionPane.showMessageDialog(Main.parent, tr("Please enable at least two WMS layers in the cadastre-fr "
                     + "plugin configuration.\nLayers ''Building'' and ''Parcel'' added by default."));
-            Main.pref.put("cadastrewms.layerBuilding", true);
-            Main.pref.put("cadastrewms.layerParcel", true);
+            Main.pref.putBoolean("cadastrewms.layerBuilding", true);
+            Main.pref.putBoolean("cadastrewms.layerParcel", true);
             grabLayers += LAYER_BULDINGS + "," + LAYER_PARCELS;
             grabStyles += STYLE_BUILDING + "," + STYLE_PARCELS;
@@ -391,6 +393,6 @@
             if (oldFrame == null && newFrame != null) {
                 setEnabledAll(true);
-                Main.map.addMapMode(new IconToggleButton(new WMSAdjustAction()));
-                Main.map.addMapMode(new IconToggleButton(new Address()));
+                MainApplication.getMap().addMapMode(new IconToggleButton(new WMSAdjustAction()));
+                MainApplication.getMap().addMapMode(new IconToggleButton(new Address()));
             } else if (oldFrame != null && newFrame == null) {
                 setEnabledAll(false);
@@ -450,5 +452,5 @@
             Thread.sleep(milliseconds);
         } catch (InterruptedException e) {
-            Main.debug(e);
+            Logging.debug(e);
         }
     }
@@ -461,5 +463,5 @@
                 dialog.setAlwaysOnTop(true);
             } catch (SecurityException e) {
-                Main.warn(tr("Warning: failed to put option pane dialog always on top. Exception was: {0}", e.toString()));
+                Logging.warn(tr("Warning: failed to put option pane dialog always on top. Exception was: {0}", e.toString()));
             }
         }
@@ -476,15 +478,15 @@
      */
     public static void addWMSLayer(WMSLayer wmsLayer) {
-        if (Main.map != null && Main.map.mapView != null) {
-            int wmsNewLayerPos = Main.getLayerManager().getLayers().size();
-            for (Layer l : Main.getLayerManager().getLayersOfType(WMSLayer.class)) {
-                int wmsPos = Main.getLayerManager().getLayers().indexOf(l);
+        if (MainApplication.isDisplayingMapView()) {
+            int wmsNewLayerPos = MainApplication.getLayerManager().getLayers().size();
+            for (Layer l : MainApplication.getLayerManager().getLayersOfType(WMSLayer.class)) {
+                int wmsPos = MainApplication.getLayerManager().getLayers().indexOf(l);
                 if (wmsPos < wmsNewLayerPos) wmsNewLayerPos = wmsPos;
             }
-            Main.getLayerManager().addLayer(wmsLayer);
+            MainApplication.getLayerManager().addLayer(wmsLayer);
             // Move the layer to its new position
-            Main.map.mapView.moveLayer(wmsLayer, wmsNewLayerPos);
+            MainApplication.getMap().mapView.moveLayer(wmsLayer, wmsNewLayerPos);
         } else
-            Main.getLayerManager().addLayer(wmsLayer);
+            MainApplication.getLayerManager().addLayer(wmsLayer);
     }
 
@@ -499,8 +501,8 @@
             year = Integer.decode(srcYear);
         } catch (NumberFormatException e) {
-            Main.debug(e);
+            Logging.debug(e);
         }
         if (srcYear.equals("AAAA") || (year != null && year < currentYear)) {
-            Main.info("Replace source year "+srcYear+" by current year "+currentYear);
+            Logging.info("Replace source year "+srcYear+" by current year "+currentYear);
             src = src.substring(0, src.lastIndexOf(" ")+1)+currentYear;
             Main.pref.put("cadastrewms.source", src);
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrab.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrab.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrab.java	(revision 33640)
@@ -8,6 +8,6 @@
 import java.awt.event.KeyEvent;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.DownloadWMSVectorImage;
@@ -33,5 +33,5 @@
     @Override
     public void actionPerformed(ActionEvent e) {
-        if (Main.map != null) {
+        if (MainApplication.getMap() != null) {
             if (CadastrePlugin.isCadastreProjection()) {
                 WMSLayer wmsLayer = WMSDownloadAction.getLayer();
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrabPlanImage.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrabPlanImage.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrabPlanImage.java	(revision 33640)
@@ -12,4 +12,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.DownloadWMSPlanImage;
@@ -40,7 +41,7 @@
     @Override
     protected void updateEnabledState() {
-        if (wmsLayer == null || Main.map == null || Main.map.mapView == null) return;
+        if (wmsLayer == null || !MainApplication.isDisplayingMapView()) return;
         if (!rasterImageGeoreferencer.isRunning()) return;
-        if (Main.getLayerManager().containsLayer(wmsLayer))
+        if (MainApplication.getLayerManager().containsLayer(wmsLayer))
             return;
         JOptionPane.showMessageDialog(Main.parent, tr("Georeferencing interrupted"));
@@ -50,5 +51,5 @@
     @Override
     public void actionPerformed(ActionEvent ae) {
-        if (Main.map != null) {
+        if (MainApplication.getMap() != null) {
             if (CadastrePlugin.isCadastreProjection()) {
                 wmsLayer = new MenuActionNewLocation().addNewLayer(new ArrayList<WMSLayer>());
@@ -57,5 +58,5 @@
                 downloadWMSPlanImage.download(wmsLayer);
                 // download sub-images of the cadastre scan and join them into one single
-                Main.worker.execute(this);
+                MainApplication.worker.execute(this);
             } else {
                 CadastrePlugin.askToChangeProjection();
@@ -69,5 +70,5 @@
         boolean loadedFromCache = downloadWMSPlanImage.waitFinished();
         if (loadedFromCache) {
-            Main.map.repaint();
+            wmsLayer.invalidate();
         } else if (wmsLayer.getImages().size() == 0) {
             // action canceled or image loaded from cache (and already georeferenced)
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionLoadFromCache.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionLoadFromCache.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionLoadFromCache.java	(revision 33640)
@@ -13,4 +13,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
@@ -20,4 +21,5 @@
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.CacheFileUTM20NFilter;
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer;
+import org.openstreetmap.josm.tools.Logging;
 
 public class MenuActionLoadFromCache extends JosmAction {
@@ -70,15 +72,19 @@
                                 continue nextFile;
                             } else
-                                Main.info("Load cache " + filename);
+                                Logging.info("Load cache " + filename);
                         }
                     } catch (NumberFormatException ex) {
-                        JOptionPane.showMessageDialog(Main.parent, tr("Selected file {0} is not a cache file from this plugin (invalid extension)", filename), tr("Error"), JOptionPane.ERROR_MESSAGE);
+                        JOptionPane.showMessageDialog(Main.parent,
+                                tr("Selected file {0} is not a cache file from this plugin (invalid extension)", filename),
+                                tr("Error"), JOptionPane.ERROR_MESSAGE);
                         continue nextFile;
                     }
                     // check if the selected cache is not already displayed
-                    if (Main.map != null) {
-                        for (Layer l : Main.getLayerManager().getLayers()) {
+                    if (MainApplication.getMap() != null) {
+                        for (Layer l : MainApplication.getLayerManager().getLayers()) {
                             if (l instanceof WMSLayer && l.getName().equals(location)) {
-                                JOptionPane.showMessageDialog(Main.parent, tr("The location {0} is already on screen. Cache not loaded.", filename), tr("Error"), JOptionPane.ERROR_MESSAGE);
+                                JOptionPane.showMessageDialog(Main.parent,
+                                        tr("The location {0} is already on screen. Cache not loaded.", filename),
+                                        tr("Error"), JOptionPane.ERROR_MESSAGE);
                                 continue nextFile;
                             }
@@ -93,5 +99,4 @@
             }
         }
-
     }
 
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionNewLocation.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionNewLocation.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionNewLocation.java	(revision 33640)
@@ -16,4 +16,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
@@ -21,4 +22,5 @@
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer;
 import org.openstreetmap.josm.tools.GBC;
+import org.openstreetmap.josm.tools.Logging;
 
 public class MenuActionNewLocation extends JosmAction {
@@ -116,6 +118,6 @@
             Main.pref.put("cadastrewms.codeCommune", codeCommune);
             Main.pref.put("cadastrewms.codeDepartement", codeDepartement);
-            if (Main.map != null) {
-                for (Layer l : Main.getLayerManager().getLayers()) {
+            if (MainApplication.getMap() != null) {
+                for (Layer l : MainApplication.getLayerManager().getLayers()) {
                     if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location)) {
                         return null;
@@ -128,7 +130,7 @@
             wmsLayer.setDepartement(codeDepartement);
             CadastrePlugin.addWMSLayer(wmsLayer);
-            Main.info("Add new layer with Location:" + inputTown.getText());
-        } else if (existingLayers != null && existingLayers.size() > 0 && Main.getLayerManager().getActiveLayer() instanceof WMSLayer) {
-            wmsLayer = (WMSLayer) Main.getLayerManager().getActiveLayer();
+            Logging.info("Add new layer with Location:" + inputTown.getText());
+        } else if (existingLayers != null && existingLayers.size() > 0 && MainApplication.getLayerManager().getActiveLayer() instanceof WMSLayer) {
+            wmsLayer = (WMSLayer) MainApplication.getLayerManager().getActiveLayer();
         }
 
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionRefineGeoRef.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionRefineGeoRef.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionRefineGeoRef.java	(revision 33640)
@@ -7,9 +7,9 @@
 import java.awt.event.ActionEvent;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.RasterImageGeoreferencer;
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer;
+import org.openstreetmap.josm.tools.Logging;
 
 public class MenuActionRefineGeoRef extends JosmAction {
@@ -33,5 +33,5 @@
     public void actionPerformed(ActionEvent arg0) {
         if (!wmsLayer.isRaster()) {
-            Main.info("MenuActionRefineGeoRef called for unexpected layer type");
+            Logging.info("MenuActionRefineGeoRef called for unexpected layer type");
             return;
         }
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionSaveRasterAs.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionSaveRasterAs.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionSaveRasterAs.java	(revision 33640)
@@ -28,4 +28,5 @@
 import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer;
+import org.openstreetmap.josm.tools.Logging;
 
 public class MenuActionSaveRasterAs extends JosmAction {
@@ -107,5 +108,5 @@
             } else if (fc.getFileFilter().equals(filtreTiff)) {
                 boolean alpha = bi.getColorModel().hasAlpha();
-                Main.info("image with alpha channel : " + alpha);
+                Logging.info("image with alpha channel : " + alpha);
                 try {
                     double x = wmsLayer.getImage(0).min.east();
@@ -132,5 +133,5 @@
                     coverage.dispose(true);
                 } catch (Exception e) {
-                    Main.error(e);
+                    Logging.error(e);
                 }
             }
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/WMSDownloadAction.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/WMSDownloadAction.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/WMSDownloadAction.java	(revision 33640)
@@ -10,18 +10,23 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.MainApplication;
 //import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer;
 
-public class WMSDownloadAction {
+final class WMSDownloadAction {
 
-    public static WMSLayer getLayer() {
+    private WMSDownloadAction() {
+        // Hide default constructor
+    }
+
+    static WMSLayer getLayer() {
         // check if we already have a layer created. if not, create; if yes, reuse.
         ArrayList<WMSLayer> existingWMSlayers = new ArrayList<>();
-        if (Main.map != null) {
-            Layer activeLayer = Main.getLayerManager().getActiveLayer();
+        if (MainApplication.getMap() != null) {
+            Layer activeLayer = MainApplication.getLayerManager().getActiveLayer();
             if (activeLayer instanceof WMSLayer)
                 return (WMSLayer) activeLayer;
-            for (Layer l : Main.getLayerManager().getLayers()) {
+            for (Layer l : MainApplication.getLayerManager().getLayers()) {
                 if (l instanceof WMSLayer) {
                     existingWMSlayers.add((WMSLayer) l);
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/Address.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/Address.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/Address.java	(revision 33640)
@@ -56,7 +56,9 @@
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.data.osm.WaySegment;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.tools.GBC;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Logging;
 import org.openstreetmap.josm.tools.Pair;
 import org.openstreetmap.josm.tools.Shortcut;
@@ -108,11 +110,11 @@
         }
         dialog.setVisible(true);
-        Main.map.mapView.addMouseListener(this);
+        MainApplication.getMap().mapView.addMouseListener(this);
     }
 
     @Override public void exitMode() {
-        if (Main.map.mapView != null) {
+        if (MainApplication.getMap().mapView != null) {
             super.exitMode();
-            Main.map.mapView.removeMouseListener(this);
+            MainApplication.getMap().mapView.removeMouseListener(this);
         }
         // kill the window completely to fix an issue on some linux distro and full screen mode.
@@ -129,5 +131,5 @@
         shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
         ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
-        MapView mv = Main.map.mapView;
+        MapView mv = MainApplication.getMap().mapView;
         Point mousePos = e.getPoint();
         List<Way> mouseOnExistingWays = new ArrayList<>();
@@ -155,6 +157,6 @@
                         inputNumber.setText(num);
                         applyInputNumberChange();
-                    } catch (NumberFormatException en) {
-                        Main.warn("Unable to parse house number \"" + num + "\"");
+                    } catch (NumberFormatException ex) {
+                        Logging.warn("Unable to parse house number \"" + num + "\"");
                     }
                 }
@@ -248,6 +250,6 @@
             try {
                 revertInputNumberChange();
-            } catch (NumberFormatException en) {
-                Main.warn("Unable to parse house number \"" + inputNumber.getText() + "\"");
+            } catch (NumberFormatException ex) {
+                Logging.warn("Unable to parse house number \"" + inputNumber.getText() + "\"");
             }
         }
@@ -259,6 +261,6 @@
             Main.main.undoRedo.add(c);
             setNewSelection(osm);
-        } catch (NumberFormatException en) {
-            Main.warn("Unable to parse house number \"" + inputNumber.getText() + "\"");
+        } catch (NumberFormatException ex) {
+            Logging.warn("Unable to parse house number \"" + inputNumber.getText() + "\"");
         }
     }
@@ -292,5 +294,5 @@
                 newRel.addMember(new RelationMember(relationAddrStreetRole, selectedWay));
                 newRel.addMember(new RelationMember(relationMemberHouse, osm));
-                cmds.add(new AddCommand(newRel));
+                cmds.add(new AddCommand(Main.main.getEditDataSet(), newRel));
             }
         }
@@ -299,7 +301,7 @@
     private static Node createNewNode(MouseEvent e, Collection<Command> cmds) {
         // DrawAction.mouseReleased() but without key modifiers
-        Node n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY()));
-        cmds.add(new AddCommand(n));
-        List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(e.getPoint(), OsmPrimitive::isSelectable);
+        Node n = new Node(MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY()));
+        cmds.add(new AddCommand(Main.main.getEditDataSet(), n));
+        List<WaySegment> wss = MainApplication.getMap().mapView.getNearestWaySegments(e.getPoint(), OsmPrimitive::isSelectable);
         Map<Way, List<Integer>> insertPoints = new HashMap<>();
         for (WaySegment ws : wss) {
@@ -370,10 +372,10 @@
 
             int snapToIntersectionThreshold
-            = Main.pref.getInteger("edit.snap-intersection-threshold", 10);
+            = Main.pref.getInt("edit.snap-intersection-threshold", 10);
 
             // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise
             // fall through to default action.
             // (for semi-parallel lines, intersection might be miles away!)
-            if (Main.map.mapView.getPoint(n).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) {
+            if (MainApplication.getMap().mapView.getPoint(n).distance(MainApplication.getMap().mapView.getPoint(intersection)) < snapToIntersectionThreshold) {
                 n.setEastNorth(intersection);
                 return;
@@ -414,5 +416,5 @@
             return ImageProvider.getCursor("crosshair", null);
         } catch (RuntimeException e) {
-            Main.warn(e);
+            Logging.warn(e);
         }
         return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
@@ -480,5 +482,5 @@
             @Override
             public void stateChanged(ChangeEvent arg0) {
-                Main.pref.put("cadastrewms.addr.onBuilding", tagPolygon.isSelected());
+                Main.pref.putBoolean("cadastrewms.addr.onBuilding", tagPolygon.isSelected());
             }
         });
@@ -511,5 +513,5 @@
             @Override
             public void windowClosing(WindowEvent arg) {
-                Main.map.selectMapMode((MapMode) Main.map.getDefaultButtonAction());
+                MainApplication.getMap().selectMapMode((MapMode) MainApplication.getMap().getDefaultButtonAction());
             }
         });
@@ -532,5 +534,5 @@
 
     private static void setNewSelection(OsmPrimitive osm) {
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         Collection<OsmPrimitive> newSelection = new LinkedList<>(ds.getSelected());
         newSelection.clear();
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/WMSAdjustAction.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/WMSAdjustAction.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/WMSAdjustAction.java	(revision 33640)
@@ -15,7 +15,7 @@
 import javax.swing.JOptionPane;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
 import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.plugins.fr.cadastre.wms.CacheControl;
@@ -45,10 +45,10 @@
 
     @Override public void enterMode() {
-        if (Main.map != null) {
-            if (Main.getLayerManager().getActiveLayer() instanceof WMSLayer) {
-                modifiedLayer = (WMSLayer) Main.getLayerManager().getActiveLayer();
+        if (MainApplication.getMap() != null) {
+            if (MainApplication.getLayerManager().getActiveLayer() instanceof WMSLayer) {
+                modifiedLayer = (WMSLayer) MainApplication.getLayerManager().getActiveLayer();
                 super.enterMode();
-                Main.map.mapView.addMouseListener(this);
-                Main.map.mapView.addMouseMotionListener(this);
+                MainApplication.getMap().mapView.addMouseListener(this);
+                MainApplication.getMap().mapView.addMouseMotionListener(this);
                 rasterMoved = false;
                 modifiedLayer.adjustModeEnabled = true;
@@ -58,5 +58,5 @@
                     exitMode();
                 }
-                Main.map.selectMapMode((MapMode) Main.map.getDefaultButtonAction());
+                MainApplication.getMap().selectMapMode((MapMode) MainApplication.getMap().getDefaultButtonAction());
             }
         }
@@ -65,6 +65,6 @@
     @Override public void exitMode() {
         super.exitMode();
-        Main.map.mapView.removeMouseListener(this);
-        Main.map.mapView.removeMouseMotionListener(this);
+        MainApplication.getMap().mapView.removeMouseListener(this);
+        MainApplication.getMap().mapView.removeMouseMotionListener(this);
         if (rasterMoved && CacheControl.cacheEnabled && modifiedLayer.isRaster()) {
             int reply = JOptionPane.showConfirmDialog(null,
@@ -98,10 +98,10 @@
             mode = Mode.moveXY;
         rasterMoved = true;
-        prevEastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY());
-        Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
+        prevEastNorth = MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY());
+        MainApplication.getMap().mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
     }
 
     @Override public void mouseDragged(MouseEvent e) {
-        EastNorth newEastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY());
+        EastNorth newEastNorth = MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY());
         if (mode == Mode.rotate) {
             rotateFrameOnly(prevEastNorth, newEastNorth);
@@ -168,5 +168,5 @@
     public void mouseReleased(MouseEvent e) {
         if (mode == Mode.rotate) {
-            EastNorth newEastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY());
+            EastNorth newEastNorth = MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY());
             rotate(prevEastNorth, newEastNorth);
             if (modifiedLayer != null) {
@@ -174,5 +174,5 @@
             }
         }
-        Main.map.mapView.setCursor(Cursor.getDefaultCursor());
+        MainApplication.getMap().mapView.setCursor(Cursor.getDefaultCursor());
         prevEastNorth = null;
         mode = null;
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/preferences/CadastrePreferenceSetting.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/preferences/CadastrePreferenceSetting.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/preferences/CadastrePreferenceSetting.java	(revision 33640)
@@ -31,4 +31,5 @@
 import org.openstreetmap.josm.tools.I18n;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Logging;
 
 /**
@@ -385,9 +386,9 @@
         Main.pref.put("cadastrewms.source", sourcing.getText());
         CadastrePlugin.source = sourcing.getText();
-        Main.pref.put("cadastrewms.alterColors", alterColors.isSelected());
-        Main.pref.put("cadastrewms.invertGrey", reversGrey.isSelected());
-        Main.pref.put("cadastrewms.backgroundTransparent", transparency.isSelected());
+        Main.pref.putBoolean("cadastrewms.alterColors", alterColors.isSelected());
+        Main.pref.putBoolean("cadastrewms.invertGrey", reversGrey.isSelected());
+        Main.pref.putBoolean("cadastrewms.backgroundTransparent", transparency.isSelected());
         Main.pref.put("cadastrewms.brightness", Float.toString((float) sliderTrans.getValue()/10));
-        Main.pref.put("cadastrewms.drawBoundaries", drawBoundaries.isSelected());
+        Main.pref.putBoolean("cadastrewms.drawBoundaries", drawBoundaries.isSelected());
         if (grabRes1.isSelected())
             Main.pref.put("cadastrewms.resolution", "high");
@@ -415,16 +416,16 @@
                     Main.pref.put("cadastrewms.squareSize", grabMultiplier4Size.getText());
             } catch (NumberFormatException e) {
-                Main.debug(e);
+                Logging.debug(e);
             }
         }
-        Main.pref.put("cadastrewms.layerWater", layerLS3.isSelected());
-        Main.pref.put("cadastrewms.layerBuilding", layerLS2.isSelected());
-        Main.pref.put("cadastrewms.layerSymbol", layerLS1.isSelected());
-        Main.pref.put("cadastrewms.layerParcel", layerParcel.isSelected());
-        Main.pref.put("cadastrewms.layerLabel", layerLabel.isSelected());
-        Main.pref.put("cadastrewms.layerNumero", layerNumero.isSelected());
-        Main.pref.put("cadastrewms.layerLieudit", layerLieudit.isSelected());
-        Main.pref.put("cadastrewms.layerSection", layerSection.isSelected());
-        Main.pref.put("cadastrewms.layerCommune", layerCommune.isSelected());
+        Main.pref.putBoolean("cadastrewms.layerWater", layerLS3.isSelected());
+        Main.pref.putBoolean("cadastrewms.layerBuilding", layerLS2.isSelected());
+        Main.pref.putBoolean("cadastrewms.layerSymbol", layerLS1.isSelected());
+        Main.pref.putBoolean("cadastrewms.layerParcel", layerParcel.isSelected());
+        Main.pref.putBoolean("cadastrewms.layerLabel", layerLabel.isSelected());
+        Main.pref.putBoolean("cadastrewms.layerNumero", layerNumero.isSelected());
+        Main.pref.putBoolean("cadastrewms.layerLieudit", layerLieudit.isSelected());
+        Main.pref.putBoolean("cadastrewms.layerSection", layerSection.isSelected());
+        Main.pref.putBoolean("cadastrewms.layerCommune", layerCommune.isSelected());
         try {
             int i = Integer.parseInt(rasterDivider.getText());
@@ -432,14 +433,14 @@
                 Main.pref.put("cadastrewms.rasterDivider", String.valueOf(i));
         } catch (NumberFormatException e) {
-            Main.debug(e);
+            Logging.debug(e);
         }
-        Main.pref.put("cadastrewms.noImageCropping", disableImageCropping.isSelected());
-        Main.pref.put("cadastrewms.useTA", enableTableauAssemblage.isSelected());
-        Main.pref.put("cadastrewms.raster2bitsColors", simplify2BitsColors.isSelected());
+        Main.pref.putBoolean("cadastrewms.noImageCropping", disableImageCropping.isSelected());
+        Main.pref.putBoolean("cadastrewms.useTA", enableTableauAssemblage.isSelected());
+        Main.pref.putBoolean("cadastrewms.raster2bitsColors", simplify2BitsColors.isSelected());
         if (crosspiece1.isSelected()) Main.pref.put("cadastrewms.crosspieces", "0");
         else if (crosspiece2.isSelected()) Main.pref.put("cadastrewms.crosspieces", "1");
         else if (crosspiece3.isSelected()) Main.pref.put("cadastrewms.crosspieces", "2");
         else if (crosspiece4.isSelected()) Main.pref.put("cadastrewms.crosspieces", "3");
-        Main.pref.put("cadastrewms.enableCaching", enableCache.isSelected());
+        Main.pref.putBoolean("cadastrewms.enableCaching", enableCache.isSelected());
 
         // spread data into objects instead of restarting the application
@@ -448,9 +449,9 @@
             Main.pref.put("cadastrewms.cacheSize", String.valueOf(CacheControl.cacheSize));
         } catch (NumberFormatException e) {
-            Main.debug(e);
+            Logging.debug(e);
         }
-        Main.pref.put("cadastrewms.autoFirstLayer", autoFirstLayer.isSelected());
+        Main.pref.putBoolean("cadastrewms.autoFirstLayer", autoFirstLayer.isSelected());
         CacheControl.cacheEnabled = enableCache.isSelected();
-        Main.pref.put("cadastrewms.addr.dontUseRelation", dontUseRelation.isSelected());
+        Main.pref.putBoolean("cadastrewms.addr.dontUseRelation", dontUseRelation.isSelected());
         CadastrePlugin.refreshConfiguration();
         CadastrePlugin.refreshMenu();
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheControl.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheControl.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheControl.java	(revision 33640)
@@ -24,4 +24,5 @@
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
 import org.openstreetmap.josm.plugins.fr.cadastre.preferences.CadastrePreferenceSetting;
+import org.openstreetmap.josm.tools.Logging;
 
 /**
@@ -97,5 +98,5 @@
             }
             if (size > (long) cacheSize*1024*1024) {
-                Main.info("Delete oldest file  \""+ files[oldestFile].getName()
+                Logging.info("Delete oldest file  \""+ files[oldestFile].getName()
                         + "\" in cache dir to stay under the limit of " + cacheSize + " MB.");
                 files[oldestFile].delete();
@@ -142,5 +143,5 @@
 
     private static void delete(File file) {
-        Main.info("Delete file "+file);
+        Logging.info("Delete file "+file);
         if (file.exists())
             file.delete();
@@ -158,12 +159,8 @@
             successfulRead = wmsLayer.read(file, ois, currentLambertZone);
         } catch (IOException | ClassNotFoundException ex) {
-            Main.error(ex);
-            GuiHelper.runInEDTAndWait(new Runnable() {
-                @Override
-                public void run() {
-                    JOptionPane.showMessageDialog(Main.parent, tr("Error loading file.\nProbably an old version of the cache file."),
-                            tr("Error"), JOptionPane.ERROR_MESSAGE);
-                }
-            });
+            Logging.error(ex);
+            GuiHelper.runInEDTAndWait(() -> JOptionPane.showMessageDialog(Main.parent,
+                    tr("Error loading file.\nProbably an old version of the cache file."),
+                    tr("Error"), JOptionPane.ERROR_MESSAGE));
             return false;
         }
@@ -211,5 +208,5 @@
                     }
                 } catch (IOException e) {
-                    Main.error(e);
+                    Logging.error(e);
                 }
                 imagesLock.lock();
@@ -222,5 +219,5 @@
                 wait();
             } catch (InterruptedException e) {
-                Main.error(e);
+                Logging.error(e);
             }
         }
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreGrabber.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreGrabber.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreGrabber.java	(revision 33640)
@@ -12,8 +12,8 @@
 import javax.imageio.ImageIO;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.io.OsmTransferException;
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
+import org.openstreetmap.josm.tools.Logging;
 
 public class CadastreGrabber {
@@ -56,5 +56,5 @@
         str += (int) (cRasterX*(wmsLayer.communeBBox.max.getY() - wmsLayer.communeBBox.min.getY())/(wmsLayer.communeBBox.max.getX() - wmsLayer.communeBBox.min.getX()));
         str += "&exception=application/vnd.ogc.se_inimage&styles="; // required for raster images
-        Main.info("URL="+str);
+        Logging.info("URL="+str);
         return new URL(str.replace(" ", "%20"));
     }
@@ -73,5 +73,5 @@
         str += "&exception=application/vnd.ogc.se_inimage"; // works also without (but slower ?)
         str += "&styles=" + styles;
-        Main.info("URL="+str);
+        Logging.info("URL="+str);
         return new URL(str.replace(" ", "%20"));
     }
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java	(revision 33640)
@@ -29,4 +29,5 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.validation.util.Entities;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
@@ -36,4 +37,5 @@
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
 import org.openstreetmap.josm.tools.GBC;
+import org.openstreetmap.josm.tools.Logging;
 
 public class CadastreInterface {
@@ -103,5 +105,5 @@
             openInterface();
         } catch (IOException e) {
-            Main.error(e);
+            Logging.error(e);
             GuiHelper.runInEDT(() ->
                 JOptionPane.showMessageDialog(Main.parent,
@@ -129,5 +131,5 @@
                 urlConn.connect();
                 if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
-                    Main.info("GET "+searchFormURL);
+                    Logging.info("GET "+searchFormURL);
                     BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8));
                     while (in.readLine() != null) {
@@ -151,5 +153,5 @@
                     }
                 } else {
-                    Main.warn("Request to home page failed. Http error:"+urlConn.getResponseCode()+". Try again "+retries+" times");
+                    Logging.warn("Request to home page failed. Http error:"+urlConn.getResponseCode()+". Try again "+retries+" times");
                     CadastrePlugin.safeSleep(3000);
                     retries--;
@@ -164,5 +166,5 @@
         cookie = pCookie;
         if (cookie == null || cookie.isEmpty()) {
-            Main.warn("received empty cookie");
+            Logging.warn("received empty cookie");
             cookie = null;
         } else {
@@ -172,5 +174,5 @@
             }
             cookieTimestamp = new Date().getTime();
-            Main.info("received cookie=" + cookie + " at " + new Date(cookieTimestamp));
+            Logging.info("received cookie=" + cookie + " at " + new Date(cookieTimestamp));
         }
         return cookie != null;
@@ -185,5 +187,5 @@
         long now = new Date().getTime();
         if ((now - cookieTimestamp) > COOKIE_EXPIRATION) {
-            Main.info("cookie received at "+new Date(cookieTimestamp)+" expired (now is "+new Date(now)+")");
+            Logging.info("cookie received at "+new Date(cookieTimestamp)+" expired (now is "+new Date(now)+")");
             return true;
         }
@@ -256,5 +258,5 @@
                 throw new IOException("Cannot open Cadastre interface. GET response:"+urlConn.getResponseCode());
             }
-            Main.info("GET "+interfaceURL);
+            Logging.info("GET "+interfaceURL);
             BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8));
             // read the buffer otherwise we sent POST too early
@@ -262,10 +264,10 @@
             String ln;
             while ((ln = in.readLine()) != null) {
-                if (Main.isDebugEnabled()) {
+                if (Logging.isDebugEnabled()) {
                     lines.append(ln);
                 }
             }
-            if (Main.isDebugEnabled()) {
-                Main.debug(lines.toString());
+            if (Logging.isDebugEnabled()) {
+                Logging.debug(lines.toString());
             }
         } catch (MalformedURLException e) {
@@ -319,5 +321,5 @@
             try (OutputStream wr = urlConn.getOutputStream()) {
                 wr.write(content.getBytes(StandardCharsets.UTF_8));
-                Main.info("POST "+content);
+                Logging.info("POST "+content);
                 wr.flush();
             }
@@ -342,5 +344,5 @@
                     lines = lines.substring(0, lines.indexOf('\''));
                     lines = Entities.unescape(lines);
-                    Main.info("interface ref.:"+lines);
+                    Logging.info("interface ref.:"+lines);
                     return lines;
                 } else if (wmsLayer.isRaster() && lines.indexOf(C_INTERFACE_RASTER_TA) != -1) { // "afficherCarteTa.do"
@@ -358,5 +360,5 @@
                                 lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.get(res).ref);
                                 lines = Entities.unescape(lines);
-                                Main.info("interface ref.:"+lines);
+                                Logging.info("interface ref.:"+lines);
                                 return lines;
                             }
@@ -374,5 +376,5 @@
             throw (IOException) new IOException("Illegal url.").initCause(e);
         } catch (DuplicateLayerException e) {
-            Main.error(e);
+            Logging.error(e);
         }
         return null;
@@ -388,8 +390,8 @@
                     String lov = input.substring(i+C_OPTION_LIST_START.length()-1, j);
                     if (lov.indexOf('>') != -1) {
-                        Main.info("parse "+lov);
+                        Logging.info("parse "+lov);
                         listOfCommunes.add(lov);
                     } else
-                        Main.error("unable to parse commune string:"+lov);
+                        Logging.error("unable to parse commune string:"+lov);
                 }
                 input = input.substring(j+C_OPTION_LIST_END.length());
@@ -408,5 +410,5 @@
             setCookie(urlConn2);
             urlConn2.connect();
-            Main.info("GET "+getAllImagesURL);
+            Logging.info("GET "+getAllImagesURL);
             try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn2.getInputStream(), StandardCharsets.UTF_8))) {
                 while ((ln = rd.readLine()) != null) {
@@ -417,5 +419,5 @@
         } catch (IOException e) {
             listOfFeuilles.clear();
-            Main.error(e);
+            Logging.error(e);
         }
         return lines.toString();
@@ -510,5 +512,5 @@
             throw new IOException("Cannot get Cadastre response.");
         }
-        Main.info("GET "+searchFormURL);
+        Logging.info("GET "+searchFormURL);
         String ln;
         StringBuilder sb = new StringBuilder();
@@ -578,10 +580,10 @@
 
     private static void checkLayerDuplicates(WMSLayer wmsLayer) throws DuplicateLayerException {
-        if (Main.map != null) {
-            for (Layer l : Main.getLayerManager().getLayers()) {
+        if (MainApplication.getMap() != null) {
+            for (Layer l : MainApplication.getLayerManager().getLayers()) {
                 if (l instanceof WMSLayer && l.getName().equals(wmsLayer.getName()) && (!l.equals(wmsLayer))) {
-                    Main.info("Try to grab into a new layer when "+wmsLayer.getName()+" is already opened.");
+                    Logging.info("Try to grab into a new layer when "+wmsLayer.getName()+" is already opened.");
                     // remove the duplicated layer
-                    Main.getLayerManager().removeLayer(wmsLayer);
+                    MainApplication.getLayerManager().removeLayer(wmsLayer);
                     throw new DuplicateLayerException();
                 }
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadSVGBuilding.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadSVGBuilding.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadSVGBuilding.java	(revision 33640)
@@ -28,8 +28,10 @@
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
 import org.openstreetmap.josm.io.OsmTransferException;
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
+import org.openstreetmap.josm.tools.Logging;
 
 public class DownloadSVGBuilding extends PleaseWaitRunnable {
@@ -67,5 +69,5 @@
             }
         } catch (DuplicateLayerException e) {
-            Main.warn("removed a duplicated layer");
+            Logging.warn("removed a duplicated layer");
         } catch (WMSException e) {
             errorMessage = e.getMessage();
@@ -91,5 +93,5 @@
             return true;
         }
-        Main.warn("Unable to parse SVG data (viewBox)");
+        Logging.warn("Unable to parse SVG data (viewBox)");
         return false;
     }
@@ -137,5 +139,5 @@
         // check if the new way or its nodes is already in OSM layer
         for (Node n : svgDataSet.getNodes()) {
-            Node nearestNewNode = checkNearestNode(n, Main.getLayerManager().getEditDataSet().getNodes());
+            Node nearestNewNode = checkNearestNode(n, MainApplication.getLayerManager().getEditDataSet().getNodes());
             if (nearestNewNode != n) {
                 // replace the SVG node by the OSM node
@@ -153,18 +155,18 @@
                 n.setDeleted(true);
             }
-
-        }
-
+        }
+
+        DataSet ds = Main.main.getEditDataSet();
         Collection<Command> cmds = new LinkedList<>();
         for (Node node : svgDataSet.getNodes()) {
             if (!node.isDeleted())
-                cmds.add(new AddCommand(node));
+                cmds.add(new AddCommand(ds, node));
         }
         for (Way way : svgDataSet.getWays()) {
             if (!way.isDeleted())
-                cmds.add(new AddCommand(way));
+                cmds.add(new AddCommand(ds, way));
         }
         Main.main.undoRedo.add(new SequenceCommand(tr("Create buildings"), cmds));
-        Main.map.repaint();
+        MainApplication.getMap().repaint();
     }
 
@@ -233,5 +235,5 @@
         str += "&styles=";
         str += "LS2_90";
-        Main.info("URL="+str);
+        Logging.info("URL="+str);
         return new URL(str.replace(" ", "%20"));
     }
@@ -254,5 +256,5 @@
             }
         } catch (IOException e) {
-            Main.error(e);
+            Logging.error(e);
         }
         return svg;
@@ -260,5 +262,5 @@
 
     public static void download(WMSLayer wmsLayer) {
-        MapView mv = Main.map.mapView;
+        MapView mv = MainApplication.getMap().mapView;
         currentView = new EastNorthBound(mv.getEastNorth(0, mv.getHeight()),
                 mv.getEastNorth(mv.getWidth(), 0));
@@ -274,5 +276,5 @@
             return;
         }
-        Main.worker.execute(new DownloadSVGBuilding(wmsLayer));
+        MainApplication.worker.execute(new DownloadSVGBuilding(wmsLayer));
         if (errorMessage != null)
             JOptionPane.showMessageDialog(Main.parent, errorMessage);
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadSVGTask.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadSVGTask.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadSVGTask.java	(revision 33640)
@@ -27,9 +27,12 @@
 import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
 import org.openstreetmap.josm.io.OsmTransferException;
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
+import org.openstreetmap.josm.tools.Logging;
 
 /**
@@ -74,5 +77,5 @@
             }
         } catch (DuplicateLayerException e) {
-            Main.warn("removed a duplicated layer");
+            Logging.warn("removed a duplicated layer");
         } catch (WMSException e) {
             errorMessage = e.getMessage();
@@ -98,5 +101,5 @@
             return true;
         }
-        Main.warn("Unable to parse SVG data (viewBox)");
+        Logging.warn("Unable to parse SVG data (viewBox)");
         return false;
     }
@@ -123,14 +126,15 @@
         }
         Way wayToAdd = new Way();
+        DataSet ds = Main.main.getEditDataSet();
         Collection<Command> cmds = new LinkedList<>();
         for (Node node : nodeList) {
-            cmds.add(new AddCommand(node));
+            cmds.add(new AddCommand(ds, node));
             wayToAdd.addNode(node);
         }
         wayToAdd.addNode(wayToAdd.getNode(0)); // close the circle
 
-        cmds.add(new AddCommand(wayToAdd));
+        cmds.add(new AddCommand(ds, wayToAdd));
         Main.main.undoRedo.add(new SequenceCommand(tr("Create boundary"), cmds));
-        Main.map.repaint();
+        MainApplication.getMap().repaint();
     }
 
@@ -183,5 +187,5 @@
         str += "&styles=";
         str += "COMMUNE_90";
-        Main.info("URL="+str);
+        Logging.info("URL="+str);
         return new URL(str.replace(" ", "%20"));
     }
@@ -204,5 +208,5 @@
             }
         } catch (IOException e) {
-            Main.error(e);
+            Logging.error(e);
         }
         return svg;
@@ -215,5 +219,5 @@
             return;
         }
-        Main.worker.execute(new DownloadSVGTask(wmsLayer));
+        MainApplication.worker.execute(new DownloadSVGTask(wmsLayer));
         if (errorMessage != null)
             JOptionPane.showMessageDialog(Main.parent, errorMessage);
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSPlanImage.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSPlanImage.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSPlanImage.java	(revision 33640)
@@ -12,7 +12,9 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
+import org.openstreetmap.josm.tools.Logging;
 
 public class DownloadWMSPlanImage {
@@ -83,5 +85,5 @@
             } catch (DuplicateLayerException e) {
                 // we tried to grab onto a duplicated layer (removed)
-                Main.warn("removed a duplicated layer");
+                Logging.warn("removed a duplicated layer");
             } catch (WMSException e) {
                 errorMessage = e.getMessage();
@@ -102,5 +104,5 @@
 
     public void download(WMSLayer wmsLayer) {
-        MapView mv = Main.map.mapView;
+        MapView mv = MainApplication.getMap().mapView;
         Bounds bounds = new Bounds(mv.getLatLon(0, mv.getHeight()), mv.getLatLon(mv.getWidth(), 0));
         dontGeoreference = false;
@@ -110,5 +112,5 @@
         this.wmsLayer = wmsLayer;
         this.bounds = bounds;
-        task = Main.worker.submit(t, t);
+        task = MainApplication.worker.submit(t, t);
         if (errorMessage != null)
             JOptionPane.showMessageDialog(Main.parent, errorMessage);
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSVectorImage.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSVectorImage.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSVectorImage.java	(revision 33640)
@@ -10,6 +10,8 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
+import org.openstreetmap.josm.tools.Logging;
 
 public class DownloadWMSVectorImage extends PleaseWaitRunnable {
@@ -36,5 +38,5 @@
                     if (CacheControl.cacheEnabled) {
                         if (wmsLayer.grabThread.getCacheControl().loadCacheIfExist()) {
-                            Main.map.mapView.zoomTo(wmsLayer.getFirstViewFromCacheBBox().toBounds());
+                            MainApplication.getMap().mapView.zoomTo(wmsLayer.getFirstViewFromCacheBBox().toBounds());
                             return;
                         }
@@ -44,5 +46,5 @@
                         JOptionPane.showMessageDialog(Main.parent,
                                 tr("This commune is not vectorized.\nPlease use the other menu entry to georeference a \"Plan image\""));
-                        Main.getLayerManager().removeLayer(wmsLayer);
+                        MainApplication.getLayerManager().removeLayer(wmsLayer);
                         wmsLayer = null;
                         return;
@@ -56,11 +58,11 @@
             } else if (!wmsLayer.hasImages()) {
               // failed to contact WMS of find this commune. Remove layer if empty.
-              Main.getLayerManager().removeLayer(wmsLayer);
+              MainApplication.getLayerManager().removeLayer(wmsLayer);
             }
         } catch (DuplicateLayerException e) {
             // we tried to grab onto a duplicated layer (removed)
-            Main.warn("removed a duplicated layer");
+            Logging.warn("removed a duplicated layer");
         } catch (WMSException e) {
-            Main.warn(e);
+            Logging.warn(e);
             errorMessage = e.getMessage();
             wmsLayer.grabber.getWmsInterface().resetCookie();
@@ -80,8 +82,8 @@
 
     public static void download(WMSLayer wmsLayer) {
-        MapView mv = Main.map.mapView;
+        MapView mv = MainApplication.getMap().mapView;
         Bounds bounds = new Bounds(mv.getLatLon(0, mv.getHeight()), mv.getLatLon(mv.getWidth(), 0));
 
-        Main.worker.execute(new DownloadWMSVectorImage(wmsLayer, bounds));
+        MainApplication.worker.execute(new DownloadWMSVectorImage(wmsLayer, bounds));
         if (errorMessage != null)
             JOptionPane.showMessageDialog(Main.parent, errorMessage);
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/GrabThread.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/GrabThread.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/GrabThread.java	(revision 33640)
@@ -10,9 +10,9 @@
 import java.util.concurrent.locks.ReentrantLock;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.io.OsmTransferException;
 import org.openstreetmap.josm.plugins.fr.cadastre.CadastrePlugin;
+import org.openstreetmap.josm.tools.Logging;
 
 public class GrabThread extends Thread {
@@ -44,5 +44,5 @@
             this.notify();
         }
-        Main.info("Added " + moreImages.size() + " to the grab thread");
+        Logging.info("Added " + moreImages.size() + " to the grab thread");
         if (wmsLayer.isRaster()) {
             waitNotification();
@@ -89,17 +89,17 @@
                     GeorefImage newImage;
                     try {
-                        Main.map.repaint(); // paint the current grab box
+                        wmsLayer.invalidate(); // paint the current grab box
                         newImage = grabber.grab(wmsLayer, currentGrabImage.min, currentGrabImage.max);
                     } catch (IOException e) {
-                        Main.warn("Download action canceled by user or server did not respond");
+                        Logging.warn("Download action canceled by user or server did not respond");
                         setCanceled(true);
                         break;
                     } catch (OsmTransferException e) {
-                        Main.error("OSM transfer failed");
+                        Logging.error("OSM transfer failed");
                         setCanceled(true);
                         break;
                     }
                     if (grabber.getWmsInterface().downloadCanceled) {
-                        Main.info("Download action canceled by user");
+                        Logging.info("Download action canceled by user");
                         setCanceled(true);
                         break;
@@ -123,10 +123,10 @@
                         saveToCache(newImage);
                     } catch (NullPointerException e) {
-                        Main.info("Layer destroyed. Cancel grab thread");
+                        Logging.info("Layer destroyed. Cancel grab thread");
                         setCanceled(true);
                     }
                 }
             }
-            Main.info("grab thread list empty");
+            Logging.info("grab thread list empty");
             lockCurrentGrabImage.lock();
             currentGrabImage = null;
@@ -164,5 +164,5 @@
         if (cacheControl != null) {
             while (!cacheControl.isCachePipeEmpty()) {
-                Main.info("Try to close a WMSLayer which is currently saving in cache : wait 1 sec.");
+                Logging.info("Try to close a WMSLayer which is currently saving in cache : wait 1 sec.");
                 CadastrePlugin.safeSleep(1000);
             }
@@ -231,5 +231,5 @@
             wait();
         } catch (InterruptedException e) {
-            Main.error(e);
+            Logging.error(e);
         }
     }
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/RasterImageGeoreferencer.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/RasterImageGeoreferencer.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/RasterImageGeoreferencer.java	(revision 33640)
@@ -18,5 +18,7 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.tools.GBC;
+import org.openstreetmap.josm.tools.Logging;
 
 public class RasterImageGeoreferencer implements MouseListener {
@@ -41,5 +43,5 @@
 
     public void addListener() {
-        Main.map.mapView.addMouseListener(this);
+        MainApplication.getMap().mapView.addMouseListener(this);
     }
 
@@ -52,5 +54,5 @@
        mode = cGetCorners;
        countMouseClicked = 0;
-       initialClickDelay = Main.pref.getInteger("cadastrewms.georef-click-delay", 200);
+       initialClickDelay = Main.pref.getInt("cadastrewms.georef-click-delay", 200);
        mouseClickedTime = System.currentTimeMillis();
        Object[] options = {"OK", "Cancel"};
@@ -76,5 +78,5 @@
       countMouseClicked = 0;
       mode = cGetLambertCrosspieces;
-      initialClickDelay = Main.pref.getInteger("cadastrewms.georef-click-delay", 200);
+      initialClickDelay = Main.pref.getInt("cadastrewms.georef-click-delay", 200);
       mouseClickedTime = System.currentTimeMillis();
       Object[] options = {"OK", "Cancel"};
@@ -99,5 +101,5 @@
   public void mouseClicked(MouseEvent e) {
       if (System.currentTimeMillis() - mouseClickedTime < initialClickDelay) {
-          Main.info("mouse click bounce detected");
+          Logging.info("mouse click bounce detected");
           return; // mouse click anti-bounce
       } else
@@ -106,6 +108,6 @@
           return;
       if (ignoreMouseClick) return; // In case we are currently just allowing zooming to read lambert coordinates
-      EastNorth ea = Main.getProjection().latlon2eastNorth(Main.map.mapView.getLatLon(e.getX(), e.getY()));
-      Main.info("click:"+countMouseClicked+" ,"+ea+", mode:"+mode);
+      EastNorth ea = Main.getProjection().latlon2eastNorth(MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY()));
+      Logging.info("click:"+countMouseClicked+" ,"+ea+", mode:"+mode);
       if (clickOnTheMap) {
           clickOnTheMap = false;
@@ -115,5 +117,5 @@
           if (ea.east() < wmsLayer.getImage(0).min.east() || ea.east() > wmsLayer.getImage(0).max.east()
                   || ea.north() < wmsLayer.getImage(0).min.north() || ea.north() > wmsLayer.getImage(0).max.north()) {
-              Main.info("ignore click outside the image");
+              Logging.info("ignore click outside the image");
               return;
           }
@@ -156,7 +158,7 @@
      if (selectedValue == 0) { // "Cancel"
          // remove layer
-         Main.getLayerManager().removeLayer(wmsLayer);
+         MainApplication.getLayerManager().removeLayer(wmsLayer);
          wmsLayer = null;
-         Main.map.mapView.removeMouseListener(this);
+         MainApplication.getMap().mapView.removeMouseListener(this);
          return false;
      }
@@ -178,5 +180,5 @@
                  tr("Ooops. I failed to catch all coordinates\n"+
                     "correctly. Retry please."));
-         Main.warn("failed to transform: one coordinate missing:"
+         Logging.warn("failed to transform: one coordinate missing:"
                     +"org1="+org1+", org2="+org2+", dst1="+dst1+", dst2="+dst2);
          return;
@@ -198,5 +200,5 @@
   */
  private void endGeoreferencing() {
-     Main.map.mapView.removeMouseListener(this);
+     MainApplication.getMap().mapView.removeMouseListener(this);
      affineTransform(ea1, ea2, georefpoint1, georefpoint2);
      wmsLayer.grabThread.saveNewCache();
@@ -341,5 +343,5 @@
      actionCompleted();
      if (wmsLayer != null) {
-         Main.getLayerManager().removeLayer(wmsLayer);
+         MainApplication.getLayerManager().removeLayer(wmsLayer);
          wmsLayer = null;
      }
@@ -347,17 +349,17 @@
 
  @Override
- public void mouseEntered(MouseEvent arg0) {
+ public void mouseEntered(MouseEvent e) {
  }
 
  @Override
- public void mouseExited(MouseEvent arg0) {
+ public void mouseExited(MouseEvent e) {
  }
 
  @Override
- public void mousePressed(MouseEvent arg0) {
+ public void mousePressed(MouseEvent e) {
  }
 
  @Override
- public void mouseReleased(MouseEvent arg0) {
+ public void mouseReleased(MouseEvent e) {
  }
 }
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/WMSLayer.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/WMSLayer.java	(revision 33639)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/WMSLayer.java	(revision 33640)
@@ -36,4 +36,5 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
@@ -48,4 +49,5 @@
 import org.openstreetmap.josm.plugins.fr.cadastre.actions.mapmode.WMSAdjustAction;
 import org.openstreetmap.josm.plugins.fr.cadastre.preferences.CadastrePreferenceSetting;
+import org.openstreetmap.josm.tools.Logging;
 
 /**
@@ -149,5 +151,5 @@
         images = null;
         dividedBbox = null;
-        Main.info("Layer "+location+" destroyed");
+        Logging.info("Layer "+location+" destroyed");
     }
 
@@ -167,12 +169,7 @@
         grabThread.setGrabber(grabber);
         // if it is the first layer, use the communeBBox as grab bbox (and not divided)
-        if (Main.getLayerManager().getLayers().size() == 1) {
+        if (MainApplication.getLayerManager().getLayers().size() == 1) {
             final Bounds bounds = this.getCommuneBBox().toBounds();
-            GuiHelper.runInEDTAndWait(new Runnable() {
-                @Override
-                public void run() {
-                    Main.map.mapView.zoomTo(bounds);
-                }
-            });
+            GuiHelper.runInEDTAndWait(() -> MainApplication.getMap().mapView.zoomTo(bounds));
             divideBbox(bounds, 1);
         } else {
@@ -538,8 +535,8 @@
             } catch (EOFException ex) {
                 // expected exception when all images are read
-                Main.trace(ex);
-            }
-        }
-        Main.info("Cache loaded for location "+location+" with "+images.size()+" images");
+                Logging.trace(ex);
+            }
+        }
+        Logging.info("Cache loaded for location "+location+" with "+images.size()+" images");
         return true;
     }
@@ -703,5 +700,5 @@
             img = this.images.get(index);
         } catch (ArrayIndexOutOfBoundsException e) {
-            Main.error(e);
+            Logging.error(e);
         }
         imagesLock.unlock();
