Index: applications/editors/josm/plugins/CommandLine/build.xml
===================================================================
--- applications/editors/josm/plugins/CommandLine/build.xml	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/build.xml	(revision 33733)
@@ -4,5 +4,5 @@
     <property name="commit.message" value="JOSM/CommandLine: fix exception after JOSM update"/>
     <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
-    <property name="plugin.main.version" value="11713"/>
+    <property name="plugin.main.version" value="13007"/>
 
     <!-- Configure these properties (replace "..." accordingly).
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/AbstractOsmAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/AbstractOsmAction.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/AbstractOsmAction.java	(revision 33733)
@@ -11,9 +11,11 @@
 import java.awt.event.MouseEvent;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Logging;
 
 public abstract class AbstractOsmAction<T extends OsmPrimitive> extends MapMode implements AWTEventListener {
@@ -38,10 +40,10 @@
         super.enterMode();
         currentCursor = cursorNormal;
-        Main.map.mapView.addMouseListener(this);
-        Main.map.mapView.addMouseMotionListener(this);
+        MainApplication.getMap().mapView.addMouseListener(this);
+        MainApplication.getMap().mapView.addMouseMotionListener(this);
         try {
             Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
         } catch (SecurityException ex) {
-            Main.warn(ex);
+            Logging.warn(ex);
         }
     }
@@ -49,10 +51,10 @@
     @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);
         try {
             Toolkit.getDefaultToolkit().removeAWTEventListener(this);
         } catch (SecurityException ex) {
-            Main.warn(ex);
+            Logging.warn(ex);
         }
     }
@@ -60,9 +62,9 @@
     @Override
     public void mouseMoved(MouseEvent e) {
-        if (!Main.map.mapView.isActiveLayerDrawable())
+        if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
             return;
         processMouseEvent(e);
         updCursor();
-        Main.map.mapView.repaint();
+        MainApplication.getMap().mapView.repaint();
         super.mouseMoved(e);
     }
@@ -70,12 +72,13 @@
     @Override
     public void mousePressed(MouseEvent e) {
-        if (!Main.map.mapView.isActiveLayerDrawable())
+        MapFrame map = MainApplication.getMap();
+        if (!map.mapView.isActiveLayerDrawable())
             return;
         processMouseEvent(e);
         if (nearestPrimitive != null) {
-            DataSet ds = Main.getLayerManager().getEditDataSet();
+            DataSet ds = MainApplication.getLayerManager().getEditDataSet();
             if (isCtrlDown) {
                 ds.clearSelection(nearestPrimitive);
-                Main.map.mapView.repaint();
+                map.mapView.repaint();
             } else {
                 int maxInstances = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum).maxInstances;
@@ -83,16 +86,16 @@
                 case 0:
                     ds.addSelected(nearestPrimitive);
-                    Main.map.mapView.repaint();
+                    map.mapView.repaint();
                     break;
                 case 1:
                     ds.addSelected(nearestPrimitive);
-                    Main.map.mapView.repaint();
+                    map.mapView.repaint();
                     parentPlugin.loadParameter(nearestPrimitive, true);
-                    Main.map.selectSelectTool(false);
+                    map.selectSelectTool(false);
                     break;
                 default:
                     if (ds.getSelected().size() < maxInstances) {
                         ds.addSelected(nearestPrimitive);
-                        Main.map.mapView.repaint();
+                        map.mapView.repaint();
                     } else
                         parentPlugin.printHistory("Maximum instances is " + maxInstances);
@@ -117,5 +120,5 @@
     private void updCursor() {
         if (mousePos != null) {
-            if (!Main.isDisplayingMapView())
+            if (!MainApplication.isDisplayingMapView())
                 return;
             nearestPrimitive = getNearest(mousePos);
@@ -143,20 +146,21 @@
             EventQueue.invokeLater(() -> {
                 // Don't change cursor when mode has changed already
-                if (!AbstractOsmAction.this.getClass().isAssignableFrom(Main.map.mapMode.getClass()))
+                if (!AbstractOsmAction.this.getClass().isAssignableFrom(MainApplication.getMap().mapMode.getClass()))
                     return;
-                Main.map.mapView.setCursor(c);
+                MainApplication.getMap().mapView.setCursor(c);
             });
             currentCursor = c;
         } catch (Exception e) {
-            Main.warn(e);
+            Logging.warn(e);
         }
     }
 
     public void cancelDrawing() {
-        if (Main.map == null || Main.map.mapView == null)
+        MapFrame map = MainApplication.getMap();
+        if (map == null || map.mapView == null)
             return;
-        Main.map.statusLine.setHeading(-1);
-        Main.map.statusLine.setAngle(-1);
-        Main.map.mapView.repaint();
+        map.statusLine.setHeading(-1);
+        map.statusLine.setAngle(-1);
+        map.mapView.repaint();
         updateStatusLine();
         parentPlugin.abortInput();
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java	(revision 33733)
@@ -4,6 +4,6 @@
 import java.awt.Point;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.gui.MainApplication;
 
 public class AnyAction extends AbstractOsmAction<OsmPrimitive> {
@@ -15,5 +15,5 @@
     @Override
     protected OsmPrimitive getNearest(Point mousePos) {
-        return Main.map.mapView.getNearestNodeOrWay(mousePos, OsmPrimitive::isUsable, false);
+        return MainApplication.getMap().mapView.getNearestNodeOrWay(mousePos, OsmPrimitive::isUsable, false);
     }
 }
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java	(revision 33733)
@@ -43,4 +43,5 @@
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MainMenu;
 import org.openstreetmap.josm.gui.MapFrame;
@@ -56,4 +57,5 @@
 import org.openstreetmap.josm.plugins.PluginInformation;
 import org.openstreetmap.josm.tools.HttpClient;
+import org.openstreetmap.josm.tools.Logging;
 import org.openstreetmap.josm.tools.SubclassFilteredCollection;
 import org.openstreetmap.josm.tools.Utils;
@@ -82,7 +84,8 @@
         textField = new CommandTextField();
 
-        if (Main.main.menu != null) {
-            commandMenu = Main.main.menu.addMenu("Commands", tr("Commands"), KeyEvent.VK_O,
-                    Main.main.menu.getDefaultMenuPos(), ht("/Plugin/CommandLine"));
+        MainMenu mainMenu = MainApplication.getMenu();
+        if (mainMenu != null) {
+            commandMenu = mainMenu.addMenu("Commands", tr("Commands"), KeyEvent.VK_O,
+                    mainMenu.getDefaultMenuPos(), ht("/Plugin/CommandLine"));
             MainMenu.add(commandMenu, new CommandLineAction(this));
         }
@@ -99,7 +102,8 @@
 
     protected void startCommand(Command command) {
-        if (Main.map == null)
+        MapFrame map = MainApplication.getMap();
+        if (map == null)
             return;
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         if (ds == null)
             return;
@@ -107,12 +111,12 @@
         currentCommand.resetLoading();
         parseSelection(ds.getSelected());
-        if (!(Main.map.mapMode instanceof AnyAction
-           || Main.map.mapMode instanceof DummyAction
-           || Main.map.mapMode instanceof LengthAction
-           || Main.map.mapMode instanceof NodeAction
-           || Main.map.mapMode instanceof PointAction
-           || Main.map.mapMode instanceof RelationAction
-           || Main.map.mapMode instanceof WayAction)) {
-            previousMode = Main.map.mapMode;
+        if (!(map.mapMode instanceof AnyAction
+           || map.mapMode instanceof DummyAction
+           || map.mapMode instanceof LengthAction
+           || map.mapMode instanceof NodeAction
+           || map.mapMode instanceof PointAction
+           || map.mapMode instanceof RelationAction
+           || map.mapMode instanceof WayAction)) {
+            previousMode = map.mapMode;
         }
         if (currentCommand.currentParameterNum < currentCommand.parameters.size())
@@ -138,14 +142,9 @@
 
     protected void printHistory(final String text) {
-        SwingUtilities.invokeLater(new Runnable() {
-            @Override
-            public void run() {
-                historyField.setText(text);
-            }
-        });
+        SwingUtilities.invokeLater(() -> historyField.setText(text));
     }
 
     private void loadCommands() {
-        commands = (new Loader(getPluginDir())).load();
+        commands = (new Loader(getPluginDirs().getUserDataDirectory(false))).load();
         if (commands.isEmpty()) {
             if (!GraphicsEnvironment.isHeadless() && JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(Main.parent,
@@ -154,9 +153,9 @@
                 try {
                     downloadAndInstallDefaultCommands();
-                    commands = (new Loader(getPluginDir())).load();
+                    commands = (new Loader(getPluginDirs().getUserDataDirectory(false))).load();
                     JOptionPane.showMessageDialog(Main.parent, tr("Default commands have been successfully installed"),
                             tr("Success"), JOptionPane.INFORMATION_MESSAGE);
                 } catch (IOException e) {
-                    Main.warn(e);
+                    Logging.warn(e);
                     JOptionPane.showMessageDialog(Main.parent,
                             tr("Failed to download and install default commands.\n\nError: {0}", e.getMessage()),
@@ -174,5 +173,5 @@
                 "https://github.com/Foxhind/JOSM-CommandLine-commands/archive/master.zip");
         try (ZipInputStream zis = new ZipInputStream(HttpClient.create(new URL(url)).connect().getContent(), StandardCharsets.UTF_8)) {
-            File dir = new File(getPluginDir());
+            File dir = getPluginDirs().getUserDataDirectory(false);
             if (!dir.exists()) {
                 dir.mkdirs();
@@ -186,5 +185,5 @@
                     }
                     File file = new File(dir + File.separator + name);
-                    Main.info("Installing command file: "+file);
+                    Logging.info("Installing command file: "+file);
                     if (!file.createNewFile()) {
                         throw new IOException("Could not create file: " + file.getAbsolutePath());
@@ -216,8 +215,8 @@
 
     protected void setMode(Mode targetMode) {
-        DataSet currentDataSet = Main.getLayerManager().getEditDataSet();
+        DataSet currentDataSet = MainApplication.getLayerManager().getEditDataSet();
         if (currentDataSet != null) {
             currentDataSet.clearSelection();
-            Main.map.mapView.repaint();
+            MainApplication.getMap().mapView.repaint();
         }
         if (targetMode == Mode.IDLE) {
@@ -261,8 +260,8 @@
                 break;
             case IMAGERYURL:
-                Layer layer = Main.getLayerManager().getActiveLayer();
+                Layer layer = MainApplication.getLayerManager().getActiveLayer();
                 if (layer != null) {
                     if (!(layer instanceof ImageryLayer)) {
-                        List<ImageryLayer> imageryLayers = Main.getLayerManager().getLayersOfType(ImageryLayer.class);
+                        List<ImageryLayer> imageryLayers = MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class);
                         if (imageryLayers.size() == 1) {
                             layer = imageryLayers.get(0);
@@ -281,8 +280,8 @@
                 break;
             case IMAGERYOFFSET:
-                Layer olayer = Main.getLayerManager().getActiveLayer();
+                Layer olayer = MainApplication.getLayerManager().getActiveLayer();
                 if (olayer != null) {
                     if (!(olayer instanceof ImageryLayer)) {
-                        List<ImageryLayer> imageryLayers = Main.getLayerManager().getLayersOfType(ImageryLayer.class);
+                        List<ImageryLayer> imageryLayers = MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class);
                         if (imageryLayers.size() == 1) {
                             olayer = imageryLayers.get(0);
@@ -307,5 +306,5 @@
             prefix = tr("Processing...");
             textField.setText(prefix);
-            Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+            MainApplication.getMap().mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
         }
     }
@@ -317,5 +316,5 @@
 
     public void deactivate() {
-        Main.map.mapView.requestFocus();
+        MainApplication.getMap().mapView.requestFocus();
     }
 
@@ -327,6 +326,6 @@
     public void endInput() {
         setMode(Mode.IDLE);
-        Main.map.selectMapMode(previousMode);
-        Main.map.mapView.repaint();
+        MainApplication.getMap().selectMapMode(previousMode);
+        MainApplication.getMap().mapView.repaint();
     }
 
@@ -347,5 +346,5 @@
             }
         } else {
-            Main.info("Invalid argument");
+            Logging.info("Invalid argument");
             endInput();
         }
@@ -392,5 +391,5 @@
                          || currentMapFrame.mapMode instanceof RelationAction
                          || currentMapFrame.mapMode instanceof AnyAction) {
-                            Collection<OsmPrimitive> selected = Main.getLayerManager().getEditDataSet().getSelected();
+                            Collection<OsmPrimitive> selected = MainApplication.getLayerManager().getEditDataSet().getSelected();
                             if (!selected.isEmpty())
                                 loadParameter(selected, true);
@@ -488,5 +487,5 @@
         ProcessBuilder builder;
         builder = new ProcessBuilder(listToRun);
-        builder.directory(new File(getPluginDir()));
+        builder.directory(getPluginDirs().getUserDataDirectory(false));
 
         final StringBuilder debugstr = new StringBuilder();
@@ -497,5 +496,5 @@
         }
         debugstr.append("\n");
-        Main.info(debugstr.toString());
+        Logging.info(debugstr.toString());
 
         final ToolProcess tp = new ToolProcess();
@@ -504,5 +503,5 @@
         } catch (final IOException e) {
             synchronized (debugstr) {
-                Main.error(
+                Logging.error(
                         tr("Error executing the script: ") +
                         debugstr.toString() + e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
@@ -525,5 +524,5 @@
                 }
             } catch (IOException e) {
-                Main.warn(e);
+                Logging.warn(e);
             }
         }).start();
@@ -537,5 +536,5 @@
                 printWriter = new PrintWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
             } catch (Exception e1) {
-                Main.error(e1);
+                Logging.error(e1);
             }
             final OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(printWriter, true, null);
@@ -581,5 +580,5 @@
                     GpxFilter gpxFilter = new GpxFilter();
                     gpxFilter.initBboxFilter(bbox);
-                    List<GpxLayer> gpxLayers = Main.getLayerManager().getLayersOfType(GpxLayer.class);
+                    List<GpxLayer> gpxLayers = MainApplication.getLayerManager().getLayersOfType(GpxLayer.class);
                     for (GpxLayer gpxLayer : gpxLayers) {
                         gpxFilter.addGpxData(gpxLayer.data);
@@ -587,5 +586,5 @@
                     gpxWriter.write(gpxFilter.getGpxData());
                 } catch (IOException e2) {
-                    Main.warn(e2);
+                    Logging.warn(e2);
                 }
             }
@@ -600,34 +599,25 @@
 
         // Read stdout stream
-        final DataSet currentDataSet = Main.getLayerManager().getEditDataSet();
+        final DataSet currentDataSet = MainApplication.getLayerManager().getEditDataSet();
         final CommandLine that = this;
-        Thread osmParseThread = new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    final OsmToCmd osmToCmd = new OsmToCmd(that, currentDataSet);
-                    String commandName = currentCommand.name;
-                    final InputStream inputStream = tp.process.getInputStream();
-                    osmToCmd.parseStream(inputStream);
-                    final List<org.openstreetmap.josm.command.Command> cmdlist = osmToCmd.getCommandList();
-                    if (!cmdlist.isEmpty()) {
-                        final SequenceCommand cmd = new SequenceCommand(commandName, cmdlist);
-                        SwingUtilities.invokeLater(new Runnable() {
-                            @Override
-                            public void run() {
-                                Main.main.undoRedo.add(cmd);
-                            }
-                        });
-                    }
-                } catch (Exception e) {
-                    Main.warn(e);
-                } finally {
-                    synchronized (syncObj) {
-                        tp.running = false;
-                        syncObj.notifyAll();
-                    }
-                }
-            }
-
+        Thread osmParseThread = new Thread(() -> {
+            try {
+                final OsmToCmd osmToCmd = new OsmToCmd(that, currentDataSet);
+                String commandName = currentCommand.name;
+                final InputStream inputStream = tp.process.getInputStream();
+                osmToCmd.parseStream(inputStream);
+                final List<org.openstreetmap.josm.command.Command> cmdlist = osmToCmd.getCommandList();
+                if (!cmdlist.isEmpty()) {
+                    final SequenceCommand cmd = new SequenceCommand(commandName, cmdlist);
+                    SwingUtilities.invokeLater(() -> Main.main.undoRedo.add(cmd));
+                }
+            } catch (Exception e) {
+                Logging.warn(e);
+            } finally {
+                synchronized (syncObj) {
+                    tp.running = false;
+                    syncObj.notifyAll();
+                }
+            }
         });
 
@@ -637,7 +627,7 @@
         synchronized (syncObj) {
             try {
-                syncObj.wait(Main.pref.getInteger("commandline.timeout", 20000));
+                syncObj.wait(Main.pref.getInt("commandline.timeout", 20000));
             } catch (InterruptedException e) {
-                Main.warn(e);
+                Logging.warn(e);
             }
         }
@@ -653,5 +643,5 @@
                         }
                     } catch (InterruptedException e) {
-                        Main.warn(e);
+                        Logging.warn(e);
                     }
                 }
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java	(revision 33733)
@@ -6,6 +6,7 @@
 import java.awt.event.KeyEvent;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
+import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -30,9 +31,10 @@
 
     public void cancelDrawing() {
-        if (Main.map == null || Main.map.mapView == null)
+        if (!MainApplication.isDisplayingMapView())
             return;
-        Main.map.statusLine.setHeading(-1);
-        Main.map.statusLine.setAngle(-1);
-        Main.map.mapView.repaint();
+        MapFrame map = MainApplication.getMap();
+        map.statusLine.setHeading(-1);
+        map.statusLine.setAngle(-1);
+        map.mapView.repaint();
         updateStatusLine();
         parentPlugin.abortInput();
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java	(revision 33733)
@@ -18,5 +18,4 @@
 import java.awt.geom.GeneralPath;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
 import org.openstreetmap.josm.data.Bounds;
@@ -24,5 +23,7 @@
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.preferences.ColorProperty;
+import org.openstreetmap.josm.data.preferences.NamedColorProperty;
+import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.layer.Layer;
@@ -30,4 +31,5 @@
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Logging;
 
 public class LengthAction extends MapMode implements MapViewPaintable, AWTEventListener {
@@ -48,5 +50,5 @@
         super(null, "addsegment.png", null, ImageProvider.getCursor("crosshair", null));
         this.parentPlugin = parentPlugin;
-        selectedColor = new ColorProperty(marktr("selected"), Color.red).get();
+        selectedColor = new NamedColorProperty(marktr("selected"), Color.red).get();
         cursorCrosshair = ImageProvider.getCursor("crosshair", null);
         cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode");
@@ -58,11 +60,12 @@
     public void enterMode() {
         super.enterMode();
-        Main.map.mapView.addMouseListener(this);
-        Main.map.mapView.addMouseMotionListener(this);
-        Main.map.mapView.addTemporaryLayer(this);
+        MapView mapView = MainApplication.getMap().mapView;
+        mapView.addMouseListener(this);
+        mapView.addMouseMotionListener(this);
+        mapView.addTemporaryLayer(this);
         try {
             Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
         } catch (SecurityException ex) {
-            Main.warn(ex);
+            Logging.warn(ex);
         }
     }
@@ -71,21 +74,23 @@
     public void exitMode() {
         super.exitMode();
-        Main.map.mapView.removeMouseListener(this);
-        Main.map.mapView.removeMouseMotionListener(this);
-        Main.map.mapView.removeTemporaryLayer(this);
+        MapView mapView = MainApplication.getMap().mapView;
+        mapView.removeMouseListener(this);
+        mapView.removeMouseMotionListener(this);
+        mapView.removeTemporaryLayer(this);
         try {
             Toolkit.getDefaultToolkit().removeAWTEventListener(this);
         } catch (SecurityException ex) {
-            Main.warn(ex);
+            Logging.warn(ex);
         }
         if (drawing)
-            Main.map.mapView.repaint();
+            mapView.repaint();
     }
 
     public void cancelDrawing() {
-        if (Main.map == null || Main.map.mapView == null)
-            return;
-        Main.map.statusLine.setHeading(-1);
-        Main.map.statusLine.setAngle(-1);
+        MapFrame map = MainApplication.getMap();
+        if (map == null || map.mapView == null)
+            return;
+        map.statusLine.setHeading(-1);
+        map.statusLine.setAngle(-1);
         updateStatusLine();
         parentPlugin.abortInput();
@@ -93,8 +98,8 @@
 
     @Override
-    public void eventDispatched(AWTEvent arg0) {
-        if (!(arg0 instanceof KeyEvent))
-            return;
-        KeyEvent ev = (KeyEvent) arg0;
+    public void eventDispatched(AWTEvent event) {
+        if (!(event instanceof KeyEvent))
+            return;
+        KeyEvent ev = (KeyEvent) event;
         if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) {
             if (drawing)
@@ -132,10 +137,10 @@
         mousePos = e.getPoint();
         if (nearestNode != null) {
-            drawStartPos = Main.map.mapView.getPoint(nearestNode.getCoor());
+            drawStartPos = MainApplication.getMap().mapView.getPoint(nearestNode.getCoor());
         } else {
             drawStartPos = mousePos;
         }
         drawEndPos = drawStartPos;
-        startCoor = Main.map.mapView.getLatLon(drawStartPos.x, drawStartPos.y);
+        startCoor = MainApplication.getMap().mapView.getLatLon(drawStartPos.x, drawStartPos.y);
         endCoor = startCoor;
         drawing = true;
@@ -153,5 +158,5 @@
     public void mousePressed(MouseEvent e) {
         if (e.getButton() == MouseEvent.BUTTON1) {
-            if (!Main.map.mapView.isActiveLayerDrawable())
+            if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
                 return;
             requestFocusInMapView();
@@ -165,5 +170,5 @@
         if (e.getButton() != MouseEvent.BUTTON1)
             return;
-        if (!Main.map.mapView.isActiveLayerDrawable())
+        if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
             return;
         boolean dragged = true;
@@ -179,12 +184,13 @@
         processMouseEvent(e);
         updCursor();
+        MapFrame map = MainApplication.getMap();
         if (nearestNode != null)
-            drawEndPos = Main.map.mapView.getPoint(nearestNode.getCoor());
+            drawEndPos = map.mapView.getPoint(nearestNode.getCoor());
         else
             drawEndPos = mousePos;
-        endCoor = Main.map.mapView.getLatLon(drawEndPos.x, drawEndPos.y);
+        endCoor = map.mapView.getLatLon(drawEndPos.x, drawEndPos.y);
         if (drawing) {
-            Main.map.statusLine.setDist(startCoor.greatCircleDistance(endCoor));
-            Main.map.mapView.repaint();
+            map.statusLine.setDist(startCoor.greatCircleDistance(endCoor));
+            map.mapView.repaint();
         }
     }
@@ -192,10 +198,10 @@
     @Override
     public void mouseMoved(MouseEvent e) {
-        if (!Main.map.mapView.isActiveLayerDrawable())
+        if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
             return;
         processMouseEvent(e);
         updCursor();
         if (drawing)
-            Main.map.mapView.repaint();
+            MainApplication.getMap().mapView.repaint();
     }
 
@@ -215,7 +221,7 @@
     private void updCursor() {
         if (mousePos != null) {
-            if (!Main.isDisplayingMapView())
+            if (!MainApplication.isDisplayingMapView())
                 return;
-            nearestNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
+            nearestNode = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
             if (nearestNode != null) {
                 setCursor(cursorJoinNode);
@@ -231,16 +237,13 @@
         try {
             // We invoke this to prevent strange things from happening
-            EventQueue.invokeLater(new Runnable() {
-                @Override
-                public void run() {
-                    // Don't change cursor when mode has changed already
-                    if (!(Main.map.mapMode instanceof LengthAction))
-                        return;
-                    Main.map.mapView.setCursor(c);
-                }
+            EventQueue.invokeLater(() -> {
+                // Don't change cursor when mode has changed already
+                if (!(MainApplication.getMap().mapMode instanceof LengthAction))
+                    return;
+                MainApplication.getMap().mapView.setCursor(c);
             });
             currentCursor = c;
         } catch (Exception e) {
-            Main.warn(e);
+            Logging.warn(e);
         }
     }
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java	(revision 33733)
@@ -8,5 +8,5 @@
 import javax.xml.parsers.SAXParserFactory;
 
-import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.tools.Logging;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
@@ -15,5 +15,5 @@
 
 public class Loader extends DefaultHandler {
-    private final String dirToScan;
+    private final File dirToScan;
     private String currentFile; // For debug XML-files
     private String currentTag;
@@ -22,5 +22,5 @@
     private final ArrayList<Command> loadingCommands;
 
-    public Loader(String dir) {
+    public Loader(File dir) {
         dirToScan = dir;
         currentTag = "";
@@ -34,9 +34,9 @@
 
             // Files loading
-            String[] list = new File(dirToScan + "/").list();
+            String[] list = dirToScan.list();
             if (list != null) {
                 for (int i = 0; i < list.length; i++) {
                     if (list[i].endsWith(".xml")) {
-                        currentFile = dirToScan + "/" + list[i];
+                        currentFile = dirToScan.getPath() + "/" + list[i];
                         loadFile(sp, currentFile);
                     }
@@ -44,5 +44,5 @@
             }
         } catch (Exception e) {
-            Main.error(e);
+            Logging.error(e);
         }
         return loadingCommands;
@@ -52,8 +52,8 @@
         try {
             String a = new File(fileName).toURI().toString().replace("file:/", "file:///");
-            Main.info(a);
+            Logging.info(a);
             parser.parse(a, this);
         } catch (Exception e) {
-            Main.error(e);
+            Logging.error(e);
         }
         // TODO: Create links for each argument
@@ -153,15 +153,15 @@
     @Override
     public void warning(SAXParseException ex) {
-        Main.warn("Warning in command xml file " + currentFile + ": " + ex.getMessage());
+        Logging.warn("Warning in command xml file " + currentFile + ": " + ex.getMessage());
     }
 
     @Override
     public void error(SAXParseException ex) {
-        Main.error("Error in command xml file " + currentFile + ": " + ex.getMessage());
+        Logging.error("Error in command xml file " + currentFile + ": " + ex.getMessage());
     }
 
     @Override
     public void fatalError(SAXParseException ex) throws SAXException {
-        Main.error("Error in command xml file " + currentFile + ": " + ex.getMessage());
+        Logging.error("Error in command xml file " + currentFile + ": " + ex.getMessage());
         throw ex;
     }
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java	(revision 33733)
@@ -4,7 +4,7 @@
 import java.awt.Point;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.gui.MainApplication;
 
 public class NodeAction extends AbstractOsmAction<Node> {
@@ -16,5 +16,5 @@
     @Override
     protected Node getNearest(Point mousePos) {
-        return Main.map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
+        return MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
     }
 }
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java	(revision 33733)
@@ -14,5 +14,4 @@
 import javax.xml.parsers.SAXParserFactory;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.command.AddCommand;
 import org.openstreetmap.josm.command.ChangeCommand;
@@ -34,6 +33,8 @@
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.data.osm.WayData;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.io.IllegalDataException;
 import org.openstreetmap.josm.io.UTFInputStreamReader;
+import org.openstreetmap.josm.tools.Logging;
 import org.openstreetmap.josm.tools.XmlParsingException;
 import org.openstreetmap.josm.tools.date.DateUtils;
@@ -218,5 +219,5 @@
                     currentPrimitive.put(key.intern(), value.intern());
                 } else {
-                    Main.warn(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName));
+                    Logging.warn(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName));
                 }
             } catch (Exception e) {
@@ -227,12 +228,13 @@
         @Override
         public void endElement(String namespaceURI, String localName, String qName) {
+            DataSet ds = MainApplication.getLayerManager().getEditDataSet();
             if (qName.equals("node")) {
                 if (currentPrimitive.isDeleted()) {
                     cmds.add(new DeleteCommand(targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId())));
                 } else if (currentPrimitive.isModified()) {
-                    cmds.add(new ChangeCommand(Main.getLayerManager().getEditLayer(),
+                    cmds.add(new ChangeCommand(ds,
                             targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
                 } else if (currentPrimitive.isNew()) {
-                    cmds.add(new AddCommand(currentPrimitive));
+                    cmds.add(new AddCommand(ds, currentPrimitive));
                 }
             } else if (qName.equals("way")) {
@@ -241,8 +243,8 @@
                     cmds.add(new DeleteCommand(targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId())));
                 } else if (currentPrimitive.isModified()) {
-                    cmds.add(new ChangeCommand(Main.getLayerManager().getEditLayer(),
+                    cmds.add(new ChangeCommand(ds,
                             targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
                 } else if (currentPrimitive.isNew()) {
-                    cmds.add(new AddCommand(currentPrimitive));
+                    cmds.add(new AddCommand(ds, currentPrimitive));
                 }
             } else if (qName.equals("relation")) {
@@ -251,8 +253,8 @@
                     cmds.add(new DeleteCommand(targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId())));
                 } else if (currentPrimitive.isModified()) {
-                    cmds.add(new ChangeCommand(Main.getLayerManager().getEditLayer(),
+                    cmds.add(new ChangeCommand(ds,
                             targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
                 } else if (currentPrimitive.isNew()) {
-                    cmds.add(new AddCommand(currentPrimitive));
+                    cmds.add(new AddCommand(ds, currentPrimitive));
                 }
             }
@@ -370,5 +372,5 @@
                 } catch (NumberFormatException e) {
                     if (current.getUniqueId() <= 0) {
-                        Main.warn(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.",
+                        Logging.warn(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.",
                                 v, current.getUniqueId()));
                         current.setChangesetId(0);
@@ -379,5 +381,5 @@
                 if (current.getChangesetId() <= 0) {
                     if (current.getUniqueId() <= 0) {
-                        Main.warn(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.",
+                        Logging.warn(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.",
                                 v, current.getUniqueId()));
                         current.setChangesetId(0);
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java	(revision 33733)
@@ -21,5 +21,8 @@
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Logging;
 
 public class PointAction extends MapMode implements AWTEventListener {
@@ -46,14 +49,14 @@
         super.enterMode();
         if (getLayerManager().getEditDataSet() == null) {
-            Main.map.selectSelectTool(false);
+            MainApplication.getMap().selectSelectTool(false);
             return;
         }
         currentCursor = cursorCrosshair;
-        Main.map.mapView.addMouseListener(this);
-        Main.map.mapView.addMouseMotionListener(this);
+        MainApplication.getMap().mapView.addMouseListener(this);
+        MainApplication.getMap().mapView.addMouseMotionListener(this);
         try {
             Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
         } catch (SecurityException ex) {
-            Main.warn(ex);
+            Logging.warn(ex);
         }
     }
@@ -61,10 +64,10 @@
     @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);
         try {
             Toolkit.getDefaultToolkit().removeAWTEventListener(this);
         } catch (SecurityException ex) {
-            Main.warn(ex);
+            Logging.warn(ex);
         }
     }
@@ -80,5 +83,5 @@
                 LatLon coor;
                 if (nearestNode == null)
-                    coor = Main.map.mapView.getLatLon(e.getX(), e.getY());
+                    coor = MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY());
                 else
                     coor = nearestNode.getCoor();
@@ -91,5 +94,5 @@
                 if (maxInstances == 1) {
                     parentPlugin.loadParameter(point, true);
-                    Main.map.selectSelectTool(false);
+                    MainApplication.getMap().selectSelectTool(false);
                 } else {
                     if (pointList.size() < maxInstances || maxInstances == 0) {
@@ -97,5 +100,5 @@
                         updateTextEdit();
                     } else
-                        Main.info("Maximum instances!");
+                        Logging.info("Maximum instances!");
                 }
             }
@@ -105,9 +108,9 @@
     @Override
     public void mouseMoved(MouseEvent e) {
-        if (!Main.map.mapView.isActiveLayerDrawable())
+        if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
             return;
         processMouseEvent(e);
         updCursor();
-        Main.map.mapView.repaint();
+        MainApplication.getMap().mapView.repaint();
     }
 
@@ -126,7 +129,7 @@
     private void updCursor() {
         if (mousePos != null) {
-            if (!Main.isDisplayingMapView())
+            if (!MainApplication.isDisplayingMapView())
                 return;
-            nearestNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
+            nearestNode = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
             if (nearestNode != null) {
                 setCursor(cursorJoinNode);
@@ -148,25 +151,23 @@
         try {
             // We invoke this to prevent strange things from happening
-            EventQueue.invokeLater(new Runnable() {
-                @Override
-                public void run() {
-                    // Don't change cursor when mode has changed already
-                    if (!(Main.map.mapMode instanceof PointAction))
-                        return;
-                    Main.map.mapView.setCursor(c);
-                }
+            EventQueue.invokeLater(() -> {
+                // Don't change cursor when mode has changed already
+                if (!(MainApplication.getMap().mapMode instanceof PointAction))
+                    return;
+                MainApplication.getMap().mapView.setCursor(c);
             });
             currentCursor = c;
         } catch (Exception e) {
-            Main.warn(e);
+            Logging.warn(e);
         }
     }
 
     public void cancelDrawing() {
-        if (Main.map == null || Main.map.mapView == null)
+        if (!MainApplication.isDisplayingMapView())
             return;
-        Main.map.statusLine.setHeading(-1);
-        Main.map.statusLine.setAngle(-1);
-        Main.map.mapView.repaint();
+        MapFrame map = MainApplication.getMap();
+        map.statusLine.setHeading(-1);
+        map.statusLine.setAngle(-1);
+        map.mapView.repaint();
         updateStatusLine();
         parentPlugin.abortInput();
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java	(revision 33733)
@@ -6,6 +6,7 @@
 import java.awt.event.KeyEvent;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
+import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -30,9 +31,10 @@
 
     public void cancelDrawing() {
-        if (Main.map == null || Main.map.mapView == null)
+        if (!MainApplication.isDisplayingMapView())
             return;
-        Main.map.statusLine.setHeading(-1);
-        Main.map.statusLine.setAngle(-1);
-        Main.map.mapView.repaint();
+        MapFrame map = MainApplication.getMap();
+        map.statusLine.setHeading(-1);
+        map.statusLine.setAngle(-1);
+        map.mapView.repaint();
         updateStatusLine();
         parentPlugin.abortInput();
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java	(revision 33368)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java	(revision 33733)
@@ -4,7 +4,7 @@
 import java.awt.Point;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.gui.MainApplication;
 
 public class WayAction extends AbstractOsmAction<Way> {
@@ -16,5 +16,5 @@
     @Override
     protected Way getNearest(Point mousePos) {
-        return Main.map.mapView.getNearestWay(mousePos, OsmPrimitive::isUsable);
+        return MainApplication.getMap().mapView.getNearestWay(mousePos, OsmPrimitive::isUsable);
     }
 }
