Index: trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java	(revision 12636)
@@ -58,5 +58,5 @@
         @Override
         public void actionPerformed(ActionEvent e) {
-            Collection<ImageryLayer> layers = Main.getLayerManager().getLayersOfType(ImageryLayer.class);
+            Collection<ImageryLayer> layers = MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class);
             if (layers.isEmpty()) {
                 setEnabled(false);
@@ -112,5 +112,5 @@
         super(trc("menu", "Imagery"));
         setupMenuScroller();
-        Main.getLayerManager().addLayerChangeListener(this);
+        MainApplication.getLayerManager().addLayerChangeListener(this);
         // build dynamically
         addMenuListener(new MenuListener() {
@@ -211,5 +211,5 @@
 
     private JMenuItem getNewOffsetMenu() {
-        Collection<ImageryLayer> layers = Main.getLayerManager().getLayersOfType(ImageryLayer.class);
+        Collection<ImageryLayer> layers = MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class);
         if (layers.isEmpty()) {
             offsetAction.setEnabled(false);
Index: trunk/src/org/openstreetmap/josm/gui/MainApplication.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 12636)
@@ -63,4 +63,5 @@
 import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.Version;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.validation.OsmValidator;
@@ -69,5 +70,7 @@
 import org.openstreetmap.josm.gui.download.DownloadDialog;
 import org.openstreetmap.josm.gui.io.CustomConfigurator.XMLCommandProcessor;
+import org.openstreetmap.josm.gui.io.SaveLayersDialog;
 import org.openstreetmap.josm.gui.layer.AutosaveTask;
+import org.openstreetmap.josm.gui.layer.MainLayerManager;
 import org.openstreetmap.josm.gui.layer.TMSLayer;
 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
@@ -78,4 +81,5 @@
 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
 import org.openstreetmap.josm.gui.util.GuiHelper;
+import org.openstreetmap.josm.gui.util.RedirectInputMap;
 import org.openstreetmap.josm.io.CertificateAmendment;
 import org.openstreetmap.josm.io.DefaultProxySelector;
@@ -134,4 +138,9 @@
 
     /**
+     * Provides access to the layers displayed in the main view.
+     */
+    private static final MainLayerManager layerManager = new MainLayerManager();
+
+    /**
      * Constructs a new {@code MainApplication} without a window.
      */
@@ -228,5 +237,5 @@
         } else {
             // required for running some tests.
-            panel = new MainPanel(Main.getLayerManager());
+            panel = new MainPanel(MainApplication.getLayerManager());
             menu = new MainMenu();
         }
@@ -246,4 +255,6 @@
             map.rememberToggleDialogWidth();
         }
+        // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask)
+        getLayerManager().resetState();
         super.shutdown();
         if (!GraphicsEnvironment.isHeadless()) {
@@ -264,4 +275,13 @@
     }
 
+    /**
+     * Replies the current selected primitives, from a end-user point of view.
+     * It is not always technically the same collection of primitives than {@link DataSet#getSelected()}.
+     * Indeed, if the user is currently in drawing mode, only the way currently being drawn is returned,
+     * see {@link DrawAction#getInProgressSelection()}.
+     *
+     * @return The current selected primitives, from a end-user point of view. Can be {@code null}.
+     * @since 6546
+     */
     @Override
     public Collection<OsmPrimitive> getInProgressSelection() {
@@ -269,5 +289,7 @@
             return ((DrawAction) map.mapMode).getInProgressSelection();
         } else {
-            return super.getInProgressSelection();
+            DataSet ds = getLayerManager().getEditDataSet();
+            if (ds == null) return null;
+            return ds.getSelected();
         }
     }
@@ -280,4 +302,14 @@
     public static List<String> getCommandLineArgs() {
         return Collections.unmodifiableList(COMMAND_LINE_ARGS);
+    }
+
+    /**
+     * Returns the main layer manager that is used by the map view.
+     * @return The layer manager. The value returned will never change.
+     * @since 12636 (as a replacement to {@code MainApplication.getLayerManager()})
+     */
+    @SuppressWarnings("deprecation")
+    public static MainLayerManager getLayerManager() {
+        return layerManager;
     }
 
@@ -306,4 +338,27 @@
     public static boolean isDisplayingMapView() {
         return map != null && map.mapView != null;
+    }
+
+    /**
+     * Closes JOSM and optionally terminates the Java Virtual Machine (JVM).
+     * If there are some unsaved data layers, asks first for user confirmation.
+     * @param exit If {@code true}, the JVM is terminated by running {@link System#exit} with a given return code.
+     * @param exitCode The return code
+     * @param reason the reason for exiting
+     * @return {@code true} if JOSM has been closed, {@code false} if the user has cancelled the operation.
+     * @since 12636 (specialized version of {@link Main#exitJosm})
+     */
+    public static boolean exitJosm(boolean exit, int exitCode, SaveLayersDialog.Reason reason) {
+        final boolean proceed = Boolean.TRUE.equals(GuiHelper.runInEDTAndWaitAndReturn(() ->
+                SaveLayersDialog.saveUnsavedModifications(MainApplication.getLayerManager().getLayers(),
+                        reason != null ? reason : SaveLayersDialog.Reason.EXIT)));
+        if (proceed) {
+            return Main.exitJosm(exit, exitCode);
+        }
+        return false;
+    }
+
+    public static void redirectToMainContentPane(JComponent source) {
+        RedirectInputMap.redirect(source, contentPanePrivate);
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/MainFrame.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MainFrame.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/MainFrame.java	(revision 12636)
@@ -67,5 +67,5 @@
         super();
         this.geometry = geometry;
-        this.panel = new MainPanel(Main.getLayerManager());
+        this.panel = new MainPanel(MainApplication.getLayerManager());
         setContentPane(new JPanel(new BorderLayout()));
     }
@@ -94,6 +94,6 @@
 
         // This listener is never removed, since the main frame exists forever.
-        Main.getLayerManager().addActiveLayerChangeListener(e -> refreshTitle());
-        Main.getLayerManager().addAndFireLayerChangeListener(new ManageLayerListeners());
+        MainApplication.getLayerManager().addActiveLayerChangeListener(e -> refreshTitle());
+        MainApplication.getLayerManager().addAndFireLayerChangeListener(new ManageLayerListeners());
 
         refreshTitle();
@@ -156,5 +156,5 @@
      */
     public void refreshTitle() {
-        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
         boolean dirty = editLayer != null && (editLayer.requiresSaveToFile()
                 || (editLayer.requiresUploadToServer() && !editLayer.isUploadDiscouraged()));
@@ -164,5 +164,5 @@
 
     private void onLayerChange(OsmDataLayer layer) {
-        if (layer == Main.getLayerManager().getEditLayer()) {
+        if (layer == MainApplication.getLayerManager().getEditLayer()) {
             refreshTitle();
         }
@@ -172,5 +172,5 @@
         @Override
         public void windowClosing(final WindowEvent evt) {
-            Main.exitJosm(true, 0, null);
+            MainApplication.exitJosm(true, 0, null);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/MainMenu.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MainMenu.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/MainMenu.java	(revision 12636)
@@ -893,5 +893,5 @@
         PresetsMenuEnabler(JMenu presetsMenu) {
             this.presetsMenu = presetsMenu;
-            Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
+            MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this);
         }
 
Index: trunk/src/org/openstreetmap/josm/gui/MainPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MainPanel.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/MainPanel.java	(revision 12636)
@@ -95,5 +95,5 @@
 
         //TODO: Move this to some better place
-        List<Layer> layers = Main.getLayerManager().getLayers();
+        List<Layer> layers = MainApplication.getLayerManager().getLayers();
         if (!layers.isEmpty()) {
             mapFrame.selectMapMode((MapMode) mapFrame.getDefaultButtonAction(), layers.get(0));
Index: trunk/src/org/openstreetmap/josm/gui/MapFrame.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MapFrame.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/MapFrame.java	(revision 12636)
@@ -202,5 +202,5 @@
         setLayout(new BorderLayout());
 
-        mapView = new MapView(Main.getLayerManager(), viewportData);
+        mapView = new MapView(MainApplication.getLayerManager(), viewportData);
 
         splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
@@ -282,6 +282,6 @@
         // status line below the map
         statusLine = new MapStatus(this);
-        Main.getLayerManager().addLayerChangeListener(this);
-        Main.getLayerManager().addActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().addLayerChangeListener(this);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
 
         boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0).isPresent();
@@ -342,6 +342,6 @@
     @Override
     public void destroy() {
-        Main.getLayerManager().removeLayerChangeListener(this);
-        Main.getLayerManager().removeActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().removeLayerChangeListener(this);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
         dialogsPanel.destroy();
         Main.pref.removePreferenceChangeListener(sidetoolbarPreferencesChangedListener);
Index: trunk/src/org/openstreetmap/josm/gui/MapStatus.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MapStatus.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/MapStatus.java	(revision 12636)
@@ -486,5 +486,5 @@
          */
         private void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) {
-            DataSet ds = Main.getLayerManager().getEditDataSet();
+            DataSet ds = MainApplication.getLayerManager().getEditDataSet();
             // Find some items that are required for cycling through
             OsmPrimitive firstItem = null;
@@ -577,5 +577,5 @@
          */
         private void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) {
-            DataSet ds = Main.getLayerManager().getEditDataSet();
+            DataSet ds = MainApplication.getLayerManager().getEditDataSet();
             if (ds.isSelected(osm)) {
                 lbl.setBackground(SystemColor.textHighlight);
@@ -650,5 +650,5 @@
                 @Override
                 public void mouseClicked(MouseEvent e) {
-                    DataSet ds = Main.getLayerManager().getEditDataSet();
+                    DataSet ds = MainApplication.getLayerManager().getEditDataSet();
                     // Let the user toggle the selection
                     ds.toggleSelected(osm);
Index: trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java	(revision 12636)
@@ -902,5 +902,5 @@
     private Map<Double, List<Node>> getNearestNodesImpl(Point p, Predicate<OsmPrimitive> predicate) {
         Map<Double, List<Node>> nearestMap = new TreeMap<>();
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
 
         if (ds != null) {
@@ -1111,5 +1111,5 @@
     private Map<Double, List<WaySegment>> getNearestWaySegmentsImpl(Point p, Predicate<OsmPrimitive> predicate) {
         Map<Double, List<WaySegment>> nearestMap = new TreeMap<>();
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
 
         if (ds != null) {
@@ -1472,5 +1472,5 @@
     public final OsmPrimitive getNearestNodeOrWay(Point p, Predicate<OsmPrimitive> predicate, boolean useSelected) {
         Collection<OsmPrimitive> sel;
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         if (useSelected && ds != null) {
             sel = ds.getSelected();
Index: trunk/src/org/openstreetmap/josm/gui/SelectionManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/SelectionManager.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/SelectionManager.java	(revision 12636)
@@ -18,5 +18,4 @@
 import javax.swing.Action;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.SelectByInternalPointAction;
 import org.openstreetmap.josm.data.Bounds;
@@ -183,5 +182,5 @@
     @Override
     public void mousePressed(MouseEvent e) {
-        if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1 && Main.getLayerManager().getEditDataSet() != null) {
+        if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1 && MainApplication.getLayerManager().getEditDataSet() != null) {
             SelectByInternalPointAction.performSelection(MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY()),
                     (e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0,
@@ -382,5 +381,5 @@
         } else {
             // nodes
-            for (Node n : Main.getLayerManager().getEditDataSet().getNodes()) {
+            for (Node n : MainApplication.getLayerManager().getEditDataSet().getNodes()) {
                 if (n.isSelectable() && selectionResult.contains(nc.getPoint2D(n))) {
                     selection.add(n);
@@ -389,5 +388,5 @@
 
             // ways
-            for (Way w : Main.getLayerManager().getEditDataSet().getWays()) {
+            for (Way w : MainApplication.getLayerManager().getEditDataSet().getWays()) {
                 if (!w.isSelectable() || w.getNodesCount() == 0) {
                     continue;
Index: trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java	(revision 12636)
@@ -126,5 +126,5 @@
         Main.pref.addPreferenceChangeListener(this);
         NavigatableComponent.addZoomChangeListener(this);
-        Main.getLayerManager().addLayerChangeListener(this);
+        MainApplication.getLayerManager().addLayerChangeListener(this);
         DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT_CONSOLIDATED);
         registerAutoFilterRules(AutoFilterRule.defaultRules());
@@ -194,5 +194,5 @@
 
     private static Set<String> getTagValues(String key) {
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         Set<String> values = new TreeSet<>();
         if (ds != null) {
@@ -371,5 +371,5 @@
             model.executeFilters();
             if (model.isChanged()) {
-                OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+                OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
                 if (editLayer != null) {
                     editLayer.invalidate();
@@ -422,5 +422,5 @@
     @Override
     public void layerRemoving(LayerRemoveEvent e) {
-        if (Main.getLayerManager().getEditLayer() == null) {
+        if (MainApplication.getLayerManager().getEditLayer() == null) {
             resetCurrentAutoFilter();
         }
Index: trunk/src/org/openstreetmap/josm/gui/conflict/pair/AbstractListMerger.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/conflict/pair/AbstractListMerger.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/conflict/pair/AbstractListMerger.java	(revision 12636)
@@ -31,5 +31,4 @@
 import javax.swing.event.ListSelectionListener;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.command.conflict.ConflictResolveCommand;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -37,4 +36,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.layer.OsmDataLayer;
 import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
@@ -901,5 +901,5 @@
     protected final <P extends OsmPrimitive> OsmDataLayer findLayerFor(P primitive) {
         if (primitive != null) {
-            Iterable<OsmDataLayer> layers = Main.getLayerManager().getLayersOfType(OsmDataLayer.class);
+            Iterable<OsmDataLayer> layers = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class);
             // Find layer with same dataset
             for (OsmDataLayer layer : layers) {
Index: trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolver.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolver.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolver.java	(revision 12636)
@@ -28,9 +28,9 @@
 import javax.swing.event.ChangeListener;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.command.ChangePropertyCommand;
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Tag;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
@@ -197,5 +197,5 @@
     public void prepareForEditing() {
         AutoCompletionList acList = new AutoCompletionList();
-        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
         if (editLayer != null) {
             editLayer.data.getAutoCompletionManager().populateWithMemberRoles(acList);
Index: trunk/src/org/openstreetmap/josm/gui/datatransfer/AbstractStackTransferHandler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/datatransfer/AbstractStackTransferHandler.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/datatransfer/AbstractStackTransferHandler.java	(revision 12636)
@@ -10,6 +10,6 @@
 import javax.swing.TransferHandler;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.datatransfer.importers.AbstractOsmDataPaster;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
@@ -45,5 +45,5 @@
     @Override
     public boolean importData(TransferSupport support) {
-        return importData(support, Main.getLayerManager().getEditLayer(), null);
+        return importData(support, MainApplication.getLayerManager().getEditLayer(), null);
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java	(revision 12636)
@@ -121,6 +121,6 @@
         // events and bootstrap it's content
         ChangesetCache.getInstance().addChangesetCacheListener(inActiveDataLayerModel);
-        Main.getLayerManager().addActiveLayerChangeListener(inActiveDataLayerModel);
-        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+        MainApplication.getLayerManager().addActiveLayerChangeListener(inActiveDataLayerModel);
+        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
         if (editLayer != null) {
             editLayer.data.addDataSetListener(inActiveDataLayerModel);
@@ -134,6 +134,6 @@
         //
         ChangesetCache.getInstance().removeChangesetCacheListener(inActiveDataLayerModel);
-        Main.getLayerManager().removeActiveLayerChangeListener(inActiveDataLayerModel);
-        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(inActiveDataLayerModel);
+        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
         if (editLayer != null) {
             editLayer.data.removeDataSetListener(inActiveDataLayerModel);
@@ -234,5 +234,5 @@
 
     protected void initWithCurrentData() {
-        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
         if (editLayer != null) {
             inSelectionModel.initFromPrimitives(editLayer.data.getAllSelected());
@@ -265,7 +265,7 @@
             if (sel.isEmpty())
                 return;
-            if (Main.getLayerManager().getEditDataSet() == null)
-                return;
-            new SelectObjectsAction().selectObjectsByChangesetIds(Main.getLayerManager().getEditDataSet(), sel);
+            if (MainApplication.getLayerManager().getEditDataSet() == null)
+                return;
+            new SelectObjectsAction().selectObjectsByChangesetIds(MainApplication.getLayerManager().getEditDataSet(), sel);
         }
 
@@ -313,5 +313,5 @@
         @Override
         public void actionPerformed(ActionEvent e) {
-            if (Main.getLayerManager().getEditLayer() == null)
+            if (MainApplication.getLayerManager().getEditLayer() == null)
                 return;
             ChangesetListModel model = getCurrentChangesetListModel();
@@ -320,5 +320,5 @@
                 return;
 
-            DataSet ds = Main.getLayerManager().getEditLayer().data;
+            DataSet ds = MainApplication.getLayerManager().getEditLayer().data;
             selectObjectsByChangesetIds(ds, sel);
         }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java	(revision 12636)
@@ -258,5 +258,5 @@
     private void buildTrees() {
         setTitle(tr("Command Stack"));
-        if (Main.getLayerManager().getEditLayer() == null)
+        if (MainApplication.getLayerManager().getEditLayer() == null)
             return;
 
@@ -335,5 +335,5 @@
     protected static Collection<? extends OsmPrimitive> getAffectedPrimitives(TreePath path) {
         PseudoCommand c = ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand();
-        final OsmDataLayer currentLayer = Main.getLayerManager().getEditLayer();
+        final OsmDataLayer currentLayer = MainApplication.getLayerManager().getEditLayer();
         return new SubclassFilteredCollection<>(
                 c.getParticipatingPrimitives(),
@@ -376,5 +376,5 @@
                 throw new IllegalStateException();
 
-            DataSet dataSet = Main.getLayerManager().getEditDataSet();
+            DataSet dataSet = MainApplication.getLayerManager().getEditDataSet();
             if (dataSet == null) return;
             dataSet.setSelected(getAffectedPrimitives(path));
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java	(revision 12636)
@@ -155,11 +155,11 @@
     @Override
     public void showNotify() {
-        Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this);
     }
 
     @Override
     public void hideNotify() {
-        Main.getLayerManager().removeActiveLayerChangeListener(this);
-        removeEditLayerListeners(Main.getLayerManager().getEditLayer());
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
+        removeEditLayerListeners(MainApplication.getLayerManager().getEditLayer());
     }
 
@@ -218,5 +218,5 @@
      */
     public void refreshView() {
-        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
         synchronized (this) {
             conflicts = editLayer == null ? new ConflictCollection() : editLayer.getConflicts();
@@ -483,5 +483,5 @@
                 }
             }
-            DataSet ds = Main.getLayerManager().getEditDataSet();
+            DataSet ds = MainApplication.getLayerManager().getEditDataSet();
             if (ds != null) { // Can't see how it is possible but it happened in #7942
                 ds.setSelected(sel);
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java	(revision 12636)
@@ -115,5 +115,5 @@
 
     protected static String buildMapPaintText() {
-        final Collection<OsmPrimitive> sel = Main.getLayerManager().getEditDataSet().getAllSelected();
+        final Collection<OsmPrimitive> sel = MainApplication.getLayerManager().getEditDataSet().getAllSelected();
         ElemStyles elemstyles = MapPaintStyles.getStyles();
         NavigatableComponent nc = MainApplication.getMap().mapView;
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java	(revision 12636)
@@ -1161,5 +1161,5 @@
      */
     public static Layer getLayerForIndex(int index) {
-        List<Layer> layers = Main.getLayerManager().getLayers();
+        List<Layer> layers = MainApplication.getLayerManager().getLayers();
 
         if (index < layers.size() && index >= 0)
@@ -1178,5 +1178,5 @@
         List<MultikeyInfo> result = new ArrayList<>();
 
-        List<Layer> layers = Main.getLayerManager().getLayers();
+        List<Layer> layers = MainApplication.getLayerManager().getLayers();
 
         int index = 0;
@@ -1200,5 +1200,5 @@
             return false;
 
-        return Main.getLayerManager().containsLayer(l);
+        return MainApplication.getLayerManager().containsLayer(l);
     }
 
@@ -1212,5 +1212,5 @@
             return null;
 
-        int index = Main.getLayerManager().getLayers().indexOf(l);
+        int index = MainApplication.getLayerManager().getLayers().indexOf(l);
         if (index < 0)
             return null;
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java	(revision 12636)
@@ -82,5 +82,5 @@
         uploadAction = new UploadNotesAction();
         buildDialog();
-        Main.getLayerManager().addLayerChangeListener(this);
+        MainApplication.getLayerManager().addLayerChangeListener(this);
     }
 
@@ -356,5 +356,5 @@
         public void actionPerformed(ActionEvent e) {
             if (noteData == null) { //there is no notes layer. Create one first
-                Main.getLayerManager().addLayer(new NoteLayer());
+                MainApplication.getLayerManager().addLayer(new NoteLayer());
             }
             MainApplication.getMap().selectMapMode(new AddNoteAction(noteData));
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java	(revision 12636)
@@ -217,6 +217,6 @@
     @Override
     public void showNotify() {
-        Main.getLayerManager().addLayerChangeListener(newAction);
-        Main.getLayerManager().addActiveLayerChangeListener(newAction);
+        MainApplication.getLayerManager().addLayerChangeListener(newAction);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(newAction);
         MapView.addZoomChangeListener(this);
         newAction.updateEnabledState();
@@ -230,6 +230,6 @@
     @Override
     public void hideNotify() {
-        Main.getLayerManager().removeActiveLayerChangeListener(newAction);
-        Main.getLayerManager().removeLayerChangeListener(newAction);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(newAction);
+        MainApplication.getLayerManager().removeLayerChangeListener(newAction);
         MapView.removeZoomChangeListener(this);
         DatasetEventManager.getInstance().removeDatasetListener(this);
@@ -326,5 +326,5 @@
 
         protected void setCurrentRelationAsSelection() {
-            Main.getLayerManager().getEditDataSet().setSelected(displaylist.getSelectedValue());
+            MainApplication.getLayerManager().getEditDataSet().setSelected(displaylist.getSelectedValue());
         }
 
@@ -335,5 +335,5 @@
         @Override
         public void mouseClicked(MouseEvent e) {
-            if (Main.getLayerManager().getEditLayer() == null) return;
+            if (MainApplication.getLayerManager().getEditLayer() == null) return;
             if (isDoubleClick(e)) {
                 if (e.isControlDown()) {
@@ -358,5 +358,5 @@
 
         public void run() {
-            RelationEditor.getEditor(Main.getLayerManager().getEditLayer(), null, null).setVisible(true);
+            RelationEditor.getEditor(MainApplication.getLayerManager().getEditLayer(), null, null).setVisible(true);
         }
 
@@ -367,5 +367,5 @@
 
         protected void updateEnabledState() {
-            setEnabled(Main.getLayerManager().getEditLayer() != null);
+            setEnabled(MainApplication.getLayerManager().getEditLayer() != null);
         }
 
@@ -696,5 +696,5 @@
     @Override
     public void dataChanged(DataChangedEvent event) {
-        initFromLayer(Main.getLayerManager().getEditLayer());
+        initFromLayer(MainApplication.getLayerManager().getEditLayer());
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java	(revision 12636)
@@ -172,7 +172,7 @@
         SelectionEventManager.getInstance().addSelectionListener(model, FireMode.IN_EDT_CONSOLIDATED);
         DatasetEventManager.getInstance().addDatasetListener(model, FireMode.IN_EDT);
-        Main.getLayerManager().addActiveLayerChangeListener(actSearch);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(actSearch);
         // editLayerChanged also gets the selection history of the level. Listener calls setJOSMSelection when fired.
-        Main.getLayerManager().addAndFireActiveLayerChangeListener(model);
+        MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(model);
         actSearch.updateEnabledState();
     }
@@ -180,6 +180,6 @@
     @Override
     public void hideNotify() {
-        Main.getLayerManager().removeActiveLayerChangeListener(actSearch);
-        Main.getLayerManager().removeActiveLayerChangeListener(model);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(actSearch);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(model);
         SelectionEventManager.getInstance().removeSelectionListener(actShowHistory);
         SelectionEventManager.getInstance().removeSelectionListener(model);
@@ -203,5 +203,5 @@
             if (idx < 0) return;
             if (isDoubleClick(e)) {
-                OsmDataLayer layer = Main.getLayerManager().getEditLayer();
+                OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
                 if (layer == null) return;
                 OsmPrimitive osm = model.getElementAt(idx);
@@ -299,5 +299,5 @@
 
         protected void updateEnabledState() {
-            setEnabled(Main.getLayerManager().getEditLayer() != null);
+            setEnabled(MainApplication.getLayerManager().getEditLayer() != null);
         }
 
@@ -324,5 +324,5 @@
             Collection<OsmPrimitive> sel = model.getSelected();
             if (sel.isEmpty()) return;
-            OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+            OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
             if (editLayer == null) return;
             editLayer.data.setSelected(sel);
@@ -845,5 +845,5 @@
         @Override
         public void actionPerformed(ActionEvent e) {
-            Main.getLayerManager().getEditDataSet().setSelected(sel);
+            MainApplication.getLayerManager().getEditDataSet().setSelected(sel);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java	(revision 12636)
@@ -54,4 +54,5 @@
 import org.openstreetmap.josm.data.preferences.BooleanProperty;
 import org.openstreetmap.josm.data.preferences.ParametrizedEnumProperty;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MainMenu;
 import org.openstreetmap.josm.gui.ShowHideButtonListener;
@@ -255,5 +256,5 @@
         setBorder(BorderFactory.createEtchedBorder());
 
-        Main.redirectToMainContentPane(this);
+        MainApplication.redirectToMainContentPane(this);
         Main.pref.addPreferenceChangeListener(this);
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java	(revision 12636)
@@ -35,4 +35,5 @@
 import org.openstreetmap.josm.data.osm.User;
 import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.SideButton;
 import org.openstreetmap.josm.gui.layer.Layer;
@@ -73,10 +74,10 @@
     public void showNotify() {
         SelectionEventManager.getInstance().addSelectionListenerForEdt(this);
-        Main.getLayerManager().addActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
     }
 
     @Override
     public void hideNotify() {
-        Main.getLayerManager().removeActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
         SelectionEventManager.getInstance().removeSelectionListener(this);
     }
@@ -141,5 +142,5 @@
     public void showDialog() {
         super.showDialog();
-        refreshForActiveLayer(Main.getLayerManager().getActiveLayer());
+        refreshForActiveLayer(MainApplication.getLayerManager().getActiveLayer());
     }
 
@@ -346,5 +347,5 @@
                 users.add(data.get(index).user);
             }
-            Collection<OsmPrimitive> selected = Main.getLayerManager().getEditDataSet().getAllSelected();
+            Collection<OsmPrimitive> selected = MainApplication.getLayerManager().getEditDataSet().getAllSelected();
             Collection<OsmPrimitive> byUser = new LinkedList<>();
             for (OsmPrimitive p : selected) {
@@ -353,5 +354,5 @@
                 }
             }
-            Main.getLayerManager().getEditDataSet().setSelected(byUser);
+            MainApplication.getLayerManager().getEditDataSet().setSelected(byUser);
         }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java	(revision 12636)
@@ -131,5 +131,5 @@
             @Override
             public void actionPerformed(ActionEvent e) {
-                final DataSet ds = Main.getLayerManager().getEditDataSet();
+                final DataSet ds = MainApplication.getLayerManager().getEditDataSet();
                 if (ds == null) {
                     return;
@@ -180,14 +180,14 @@
     public void showNotify() {
         DataSet.addSelectionListener(this);
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         if (ds != null) {
             updateSelection(ds.getAllSelected());
         }
-        Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this);
     }
 
     @Override
     public void hideNotify() {
-        Main.getLayerManager().removeActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
         DataSet.removeSelectionListener(this);
     }
@@ -349,5 +349,5 @@
             }
         }
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         if (ds != null) {
             ds.setSelected(sel);
@@ -488,5 +488,5 @@
 
             if (isDblClick) {
-                DataSet ds = Main.getLayerManager().getEditDataSet();
+                DataSet ds = MainApplication.getLayerManager().getEditDataSet();
                 if (ds != null) {
                     ds.setSelected(sel);
@@ -627,5 +627,5 @@
             try {
                 monitor.setTicksCount(testErrors.size());
-                final DataSet ds = Main.getLayerManager().getEditDataSet();
+                final DataSet ds = MainApplication.getLayerManager().getEditDataSet();
                 int i = 0;
                 SwingUtilities.invokeAndWait(ds::beginUpdate);
@@ -645,5 +645,5 @@
                 SwingUtilities.invokeAndWait(() -> {
                     Main.main.undoRedo.afterAdd();
-                    Main.getLayerManager().getLayersOfType(ValidatorLayer.class).forEach(ValidatorLayer::invalidate);
+                    MainApplication.getLayerManager().getLayersOfType(ValidatorLayer.class).forEach(ValidatorLayer::invalidate);
                     tree.resetErrors();
                 });
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java	(revision 12636)
@@ -33,5 +33,4 @@
 import javax.swing.event.ListSelectionListener;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.AutoScaleAction;
 import org.openstreetmap.josm.actions.downloadtasks.ChangesetContentDownloadTask;
@@ -93,9 +92,9 @@
         actSelectInCurrentLayerAction = new SelectInCurrentLayerAction();
         model.getSelectionModel().addListSelectionListener(actSelectInCurrentLayerAction);
-        Main.getLayerManager().addActiveLayerChangeListener(actSelectInCurrentLayerAction);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(actSelectInCurrentLayerAction);
 
         actZoomInCurrentLayerAction = new ZoomInCurrentLayerAction();
         model.getSelectionModel().addListSelectionListener(actZoomInCurrentLayerAction);
-        Main.getLayerManager().addActiveLayerChangeListener(actZoomInCurrentLayerAction);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(actZoomInCurrentLayerAction);
 
         addComponentListener(
@@ -103,6 +102,6 @@
                     @Override
                     public void componentShown(ComponentEvent e) {
-                        Main.getLayerManager().addAndFireActiveLayerChangeListener(actSelectInCurrentLayerAction);
-                        Main.getLayerManager().addAndFireActiveLayerChangeListener(actZoomInCurrentLayerAction);
+                        MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(actSelectInCurrentLayerAction);
+                        MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(actZoomInCurrentLayerAction);
                     }
 
@@ -110,6 +109,6 @@
                     public void componentHidden(ComponentEvent e) {
                         // make sure the listener is unregistered when the panel becomes invisible
-                        Main.getLayerManager().removeActiveLayerChangeListener(actSelectInCurrentLayerAction);
-                        Main.getLayerManager().removeActiveLayerChangeListener(actZoomInCurrentLayerAction);
+                        MainApplication.getLayerManager().removeActiveLayerChangeListener(actSelectInCurrentLayerAction);
+                        MainApplication.getLayerManager().removeActiveLayerChangeListener(actZoomInCurrentLayerAction);
                     }
                 }
@@ -201,5 +200,5 @@
                         + "edit layer ''{0}''.</html>",
                         primitives.size(),
-                        Utils.escapeReservedCharactersHTML(Main.getLayerManager().getEditLayer().getName())
+                        Utils.escapeReservedCharactersHTML(MainApplication.getLayerManager().getEditLayer().getName())
                 ),
                 title, JOptionPane.WARNING_MESSAGE, helpTopic
@@ -324,5 +323,5 @@
                 return null;
             }
-            OsmDataLayer layer = Main.getLayerManager().getEditLayer();
+            OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
             if (layer == null) {
                 return null;
@@ -339,5 +338,5 @@
 
         public final void updateEnabledState() {
-            setEnabled(Main.getLayerManager().getEditLayer() != null && model.hasSelectedPrimitives());
+            setEnabled(MainApplication.getLayerManager().getEditLayer() != null && model.hasSelectedPrimitives());
         }
 
@@ -373,5 +372,5 @@
                 return;
             }
-            Main.getLayerManager().getEditLayer().data.setSelected(target);
+            MainApplication.getLayerManager().getEditLayer().data.setSelected(target);
         }
     }
@@ -396,5 +395,5 @@
                 return;
             }
-            Main.getLayerManager().getEditLayer().data.setSelected(target);
+            MainApplication.getLayerManager().getEditLayer().data.setSelected(target);
             AutoScaleAction.zoomToSelection();
         }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java	(revision 12636)
@@ -91,8 +91,8 @@
 
         tb.add(actSelectInCurrentLayer);
-        Main.getLayerManager().addActiveLayerChangeListener(actSelectInCurrentLayer);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(actSelectInCurrentLayer);
 
         tb.add(actZoomInCurrentLayerAction);
-        Main.getLayerManager().addActiveLayerChangeListener(actZoomInCurrentLayerAction);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(actZoomInCurrentLayerAction);
 
         addComponentListener(
@@ -100,6 +100,6 @@
                     @Override
                     public void componentShown(ComponentEvent e) {
-                        Main.getLayerManager().addAndFireActiveLayerChangeListener(actSelectInCurrentLayer);
-                        Main.getLayerManager().addAndFireActiveLayerChangeListener(actZoomInCurrentLayerAction);
+                        MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(actSelectInCurrentLayer);
+                        MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(actZoomInCurrentLayerAction);
                     }
 
@@ -107,6 +107,6 @@
                     public void componentHidden(ComponentEvent e) {
                         // make sure the listener is unregistered when the panel becomes invisible
-                        Main.getLayerManager().removeActiveLayerChangeListener(actSelectInCurrentLayer);
-                        Main.getLayerManager().removeActiveLayerChangeListener(actZoomInCurrentLayerAction);
+                        MainApplication.getLayerManager().removeActiveLayerChangeListener(actSelectInCurrentLayer);
+                        MainApplication.getLayerManager().removeActiveLayerChangeListener(actZoomInCurrentLayerAction);
                     }
                 }
@@ -344,5 +344,5 @@
                             + "edit layer ''{1}''.</html>",
                             currentChangeset.getId(),
-                            Utils.escapeReservedCharactersHTML(Main.getLayerManager().getEditLayer().getName())
+                            Utils.escapeReservedCharactersHTML(MainApplication.getLayerManager().getEditLayer().getName())
                     ),
                     tr("Nothing to select"),
@@ -356,5 +356,5 @@
             if (!isEnabled())
                 return;
-            OsmDataLayer layer = Main.getLayerManager().getEditLayer();
+            OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
             if (layer == null) {
                 return;
@@ -374,5 +374,5 @@
 
         public void updateEnabledState() {
-            setEnabled(Main.getLayerManager().getEditLayer() != null && currentChangeset != null);
+            setEnabled(MainApplication.getLayerManager().getEditLayer() != null && currentChangeset != null);
         }
 
@@ -403,5 +403,5 @@
                             + "edit layer ''{1}''.</html>",
                             currentChangeset.getId(),
-                            Main.getLayerManager().getEditLayer().getName()
+                            MainApplication.getLayerManager().getEditLayer().getName()
                     ),
                     tr("Nothing to zoom to"),
@@ -415,5 +415,5 @@
             if (!isEnabled())
                 return;
-            OsmDataLayer layer = Main.getLayerManager().getEditLayer();
+            OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
             if (layer == null) {
                 return;
@@ -434,5 +434,5 @@
 
         public void updateEnabledState() {
-            setEnabled(Main.getLayerManager().getEditLayer() != null && currentChangeset != null);
+            setEnabled(MainApplication.getLayerManager().getEditLayer() != null && currentChangeset != null);
         }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/layer/DuplicateAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/layer/DuplicateAction.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/layer/DuplicateAction.java	(revision 12636)
@@ -8,6 +8,6 @@
 import javax.swing.AbstractAction;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.dialogs.IEnabledStateUpdating;
 import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel;
@@ -53,7 +53,7 @@
     private static void duplicate(Layer layer) {
         if (layer instanceof OsmDataLayer) {
-            String newName = LayerListTransferHandler.suggestNewLayerName(layer.getName(), Main.getLayerManager().getLayers());
+            String newName = LayerListTransferHandler.suggestNewLayerName(layer.getName(), MainApplication.getLayerManager().getLayers());
             OsmDataLayer oldLayer = (OsmDataLayer) layer;
-            Main.getLayerManager().addLayer(new OsmDataLayer(new DataSet(oldLayer.data), newName, null));
+            MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(oldLayer.data), newName, null));
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java	(revision 12636)
@@ -230,5 +230,5 @@
 
     private final PreferenceChangedListener preferenceListener = e -> {
-                if (Main.getLayerManager().getEditDataSet() != null) {
+                if (MainApplication.getLayerManager().getEditDataSet() != null) {
                     // Re-load data when display preference change
                     updateSelection();
@@ -487,5 +487,5 @@
         MainApplication.getMap().relationListDialog.selectRelation(relation);
         RelationEditor.getEditor(
-                Main.getLayerManager().getEditLayer(),
+                MainApplication.getLayerManager().getEditLayer(),
                 relation,
                 ((MemberInfo) membershipData.getValueAt(row, 1)).role
@@ -513,5 +513,5 @@
         DatasetEventManager.getInstance().addDatasetListener(dataChangedAdapter, FireMode.IN_EDT_CONSOLIDATED);
         SelectionEventManager.getInstance().addSelectionListener(this, FireMode.IN_EDT_CONSOLIDATED);
-        Main.getLayerManager().addActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
         for (JosmAction action : josmActions) {
             Main.registerActionShortcut(action);
@@ -524,5 +524,5 @@
         DatasetEventManager.getInstance().removeDatasetListener(dataChangedAdapter);
         SelectionEventManager.getInstance().removeSelectionListener(this);
-        Main.getLayerManager().removeActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
         for (JosmAction action : josmActions) {
             Main.unregisterActionShortcut(action);
@@ -533,5 +533,5 @@
     public void setVisible(boolean b) {
         super.setVisible(b);
-        if (b && Main.getLayerManager().getEditDataSet() != null) {
+        if (b && MainApplication.getLayerManager().getEditDataSet() != null) {
             updateSelection();
         }
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java	(revision 12636)
@@ -77,4 +77,5 @@
 import org.openstreetmap.josm.gui.ExtendedDialog;
 import org.openstreetmap.josm.gui.IExtendedDialog;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
@@ -443,5 +444,5 @@
             mainPanel.add(p, BorderLayout.CENTER);
 
-            AutoCompletionManager autocomplete = Main.getLayerManager().getEditLayer().data.getAutoCompletionManager();
+            AutoCompletionManager autocomplete = MainApplication.getLayerManager().getEditLayer().data.getAutoCompletionManager();
             List<AutoCompletionListItem> keyList = autocomplete.getKeys();
             keyList.sort(DEFAULT_AC_ITEM_COMPARATOR);
@@ -689,5 +690,5 @@
 
             cacheRecentTags();
-            AutoCompletionManager autocomplete = Main.getLayerManager().getEditLayer().data.getAutoCompletionManager();
+            AutoCompletionManager autocomplete = MainApplication.getLayerManager().getEditLayer().data.getAutoCompletionManager();
             List<AutoCompletionListItem> keyList = autocomplete.getKeys();
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java	(revision 12636)
@@ -137,6 +137,6 @@
     @Override
     public void registerListeners() {
-        Main.getLayerManager().addLayerChangeListener(zoomToGap);
-        Main.getLayerManager().addActiveLayerChangeListener(zoomToGap);
+        MainApplication.getLayerManager().addLayerChangeListener(zoomToGap);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(zoomToGap);
         super.registerListeners();
     }
@@ -145,6 +145,6 @@
     public void unregisterListeners() {
         super.unregisterListeners();
-        Main.getLayerManager().removeLayerChangeListener(zoomToGap);
-        Main.getLayerManager().removeActiveLayerChangeListener(zoomToGap);
+        MainApplication.getLayerManager().removeLayerChangeListener(zoomToGap);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(zoomToGap);
     }
 
@@ -239,5 +239,5 @@
         private void updateEnabledState() {
             setEnabled(Main.main != null
-                    && Main.getLayerManager().getEditLayer() == getLayer()
+                    && MainApplication.getLayerManager().getEditLayer() == getLayer()
                     && getSelectedRowCount() == 1
                     && hasGap());
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java	(revision 12636)
@@ -21,5 +21,4 @@
 import javax.swing.table.AbstractTableModel;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.SelectionChangedListener;
 import org.openstreetmap.josm.data.osm.DataSet;
@@ -36,4 +35,5 @@
 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter;
 import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType;
@@ -111,5 +111,5 @@
     @Override
     public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
-        if (Main.getLayerManager().getEditLayer() != this.layer) return;
+        if (MainApplication.getLayerManager().getEditLayer() != this.layer) return;
         // just trigger a repaint
         Collection<RelationMember> sel = getSelectedMembers();
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java	(revision 12636)
@@ -33,5 +33,5 @@
  *  final ParentRelationLoadingTask task = new ParentRelationLoadingTask(
  *                   child,   // the child relation
- *                   Main.getLayerManager().getEditLayer(), // the edit layer
+ *                   MainApplication.getLayerManager().getEditLayer(), // the edit layer
  *                   true,  // load fully
  *                   new PleaseWaitProgressMonitor()  // a progress monitor
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java	(revision 12636)
@@ -13,6 +13,6 @@
 import java.util.Optional;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
@@ -39,5 +39,5 @@
         if (RelationDialogManager.relationDialogManager == null) {
             RelationDialogManager.relationDialogManager = new RelationDialogManager();
-            Main.getLayerManager().addLayerChangeListener(RelationDialogManager.relationDialogManager);
+            MainApplication.getLayerManager().addLayerChangeListener(RelationDialogManager.relationDialogManager);
         }
         return RelationDialogManager.relationDialogManager;
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationTree.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationTree.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationTree.java	(revision 12636)
@@ -15,5 +15,4 @@
 import javax.swing.tree.TreePath;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.DataSetMerger;
@@ -137,8 +136,8 @@
                 return;
             }
-            DataSetMerger visitor = new DataSetMerger(Main.getLayerManager().getEditLayer().data, ds);
+            DataSetMerger visitor = new DataSetMerger(MainApplication.getLayerManager().getEditLayer().data, ds);
             visitor.merge();
             if (!visitor.getConflicts().isEmpty()) {
-                Main.getLayerManager().getEditLayer().getConflicts().add(visitor.getConflicts());
+                MainApplication.getLayerManager().getEditLayer().getConflicts().add(visitor.getConflicts());
             }
             final RelationTreeModel model = (RelationTreeModel) getModel();
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java	(revision 12636)
@@ -7,8 +7,8 @@
 import javax.swing.table.AbstractTableModel;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.SelectionChangedListener;
 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.layer.LayerManager.LayerAddEvent;
 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
@@ -44,5 +44,5 @@
     public void register() {
         DataSet.addSelectionListener(this);
-        Main.getLayerManager().addActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
     }
 
@@ -52,5 +52,5 @@
     public void unregister() {
         DataSet.removeSelectionListener(this);
-        Main.getLayerManager().removeActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
     }
 
@@ -62,5 +62,5 @@
     @Override
     public int getRowCount() {
-        if (Main.getLayerManager().getEditLayer() != layer)
+        if (MainApplication.getLayerManager().getEditLayer() != layer)
             return 0;
         return cache.size();
@@ -104,5 +104,5 @@
     @Override
     public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
-        if (layer == Main.getLayerManager().getEditLayer()) {
+        if (layer == MainApplication.getLayerManager().getEditLayer()) {
             cache.clear();
             cache.addAll(newSelection);
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java	(revision 12636)
@@ -27,5 +27,4 @@
 import javax.swing.tree.TreeSelectionModel;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -43,4 +42,5 @@
 import org.openstreetmap.josm.data.validation.TestError;
 import org.openstreetmap.josm.data.validation.util.MultipleNameVisitor;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.preferences.validator.ValidatorPreference;
 import org.openstreetmap.josm.gui.util.GuiHelper;
@@ -425,5 +425,5 @@
     @Override
     public void destroy() {
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         if (ds != null) {
             ds.removeDataSetListener(this);
Index: trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java	(revision 12636)
@@ -66,5 +66,5 @@
     protected HistoryBrowserDialogManager() {
         dialogs = new HashMap<>();
-        Main.getLayerManager().addLayerChangeListener(this);
+        MainApplication.getLayerManager().addLayerChangeListener(this);
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java	(revision 12636)
@@ -36,4 +36,5 @@
 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
 import org.openstreetmap.josm.gui.JosmUserIdentityManager;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
@@ -101,10 +102,10 @@
 
         if (Main.main != null) {
-            OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+            OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
             if (editLayer != null) {
                 editLayer.data.addDataSetListener(this);
             }
         }
-        Main.getLayerManager().addActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
     }
 
@@ -170,5 +171,5 @@
         if (history.getNumVersions() > 0) {
             HistoryOsmPrimitive newLatest = null;
-            OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+            OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
             if (editLayer != null) {
                 OsmPrimitive p = editLayer.data.getPrimitiveById(history.getId(), history.getType());
@@ -531,9 +532,9 @@
      */
     public void unlinkAsListener() {
-        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
         if (editLayer != null) {
             editLayer.data.removeDataSetListener(this);
         }
-        Main.getLayerManager().removeActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java	(revision 12636)
@@ -21,5 +21,4 @@
 import javax.swing.event.TableModelListener;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.AutoScaleAction;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -250,5 +249,5 @@
             OsmPrimitive p = getPrimitiveToZoom();
             if (p != null) {
-                OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+                OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
                 if (editLayer != null) {
                     editLayer.data.setSelected(p.getPrimitiveId());
@@ -266,5 +265,5 @@
             if (primitiveId == null)
                 return null;
-            OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+            OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
             if (editLayer == null)
                 return null;
@@ -273,5 +272,5 @@
 
         public void updateEnabledState() {
-            setEnabled(Main.getLayerManager().getEditLayer() != null && getPrimitiveToZoom() != null);
+            setEnabled(MainApplication.getLayerManager().getEditLayer() != null && getPrimitiveToZoom() != null);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java	(revision 12636)
@@ -30,4 +30,5 @@
 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
 import org.openstreetmap.josm.gui.JosmUserIdentityManager;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.dialogs.ChangesetDialog;
 import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetCacheManager;
@@ -155,5 +156,5 @@
         String text;
         if (isLatest) {
-            OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
+            OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
             text = tr("<html>Version <strong>{0}</strong> currently edited in layer ''{1}''</html>",
                     Long.toString(version),
Index: trunk/src/org/openstreetmap/josm/gui/io/AbstractUploadTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/io/AbstractUploadTask.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/io/AbstractUploadTask.java	(revision 12636)
@@ -86,5 +86,5 @@
         // FIXME: should now about the layer this task is running for. might
         // be different from the current edit layer
-        OsmDataLayer layer = Main.getLayerManager().getEditLayer();
+        OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
         if (layer == null)
             throw new IllegalStateException(tr("Failed to update primitive with id {0} because current edit layer is null", id));
@@ -275,5 +275,5 @@
         );
         if (ret == 0) {
-            DownloadReferrersAction.downloadReferrers(Main.getLayerManager().getEditLayer(), Arrays.asList(conflict.a));
+            DownloadReferrersAction.downloadReferrers(MainApplication.getLayerManager().getEditLayer(), Arrays.asList(conflict.a));
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/io/DownloadPrimitivesWithReferrersTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/io/DownloadPrimitivesWithReferrersTask.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/io/DownloadPrimitivesWithReferrersTask.java	(revision 12636)
@@ -24,4 +24,5 @@
 import org.openstreetmap.josm.data.osm.PrimitiveId;
 import org.openstreetmap.josm.gui.ExtendedDialog;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
@@ -129,7 +130,7 @@
 
         // Append downloaded data to JOSM
-        OsmDataLayer layer = Main.getLayerManager().getEditLayer();
+        OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
         if (layer == null || this.newLayer)
-            Main.getLayerManager().addLayer(tmpLayer);
+            MainApplication.getLayerManager().addLayer(tmpLayer);
         else
             layer.mergeFrom(tmpLayer);
@@ -152,5 +153,5 @@
         // Warm about deleted primitives
         final Set<PrimitiveId> del = new HashSet<>();
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         for (PrimitiveId id : ids) {
             OsmPrimitive osm = ds.getPrimitiveById(id);
Index: trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java	(revision 12636)
@@ -12,6 +12,6 @@
 import javax.swing.event.TableModelListener;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.Changeset;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
 import org.openstreetmap.josm.gui.tagging.TagModel;
@@ -99,5 +99,5 @@
      */
     public void startUserInput() {
-        pnlTagEditor.initAutoCompletion(Main.getLayerManager().getEditLayer());
+        pnlTagEditor.initAutoCompletion(MainApplication.getLayerManager().getEditLayer());
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/layer/AutosaveTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/AutosaveTask.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/AutosaveTask.java	(revision 12636)
@@ -151,5 +151,5 @@
 
             new Timer(true).schedule(this, TimeUnit.SECONDS.toMillis(1), TimeUnit.SECONDS.toMillis(PROP_INTERVAL.get()));
-            Main.getLayerManager().addAndFireLayerChangeListener(this);
+            MainApplication.getLayerManager().addAndFireLayerChangeListener(this);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 12636)
@@ -889,9 +889,9 @@
                 gpxLayer.setAssociatedFile(new File(getAssociatedFile().getParentFile(), filename));
             }
-            Main.getLayerManager().addLayer(gpxLayer);
+            MainApplication.getLayerManager().addLayer(gpxLayer);
             if (Main.pref.getBoolean("marker.makeautomarkers", true) && !gpxData.waypoints.isEmpty()) {
-                Main.getLayerManager().addLayer(new MarkerLayer(gpxData, tr("Converted from: {0}", getName()), null, gpxLayer));
-            }
-            Main.getLayerManager().removeLayer(OsmDataLayer.this);
+                MainApplication.getLayerManager().addLayer(new MarkerLayer(gpxData, tr("Converted from: {0}", getName()), null, gpxLayer));
+            }
+            MainApplication.getLayerManager().removeLayer(OsmDataLayer.this);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java	(revision 12636)
@@ -14,5 +14,4 @@
 import javax.swing.tree.TreeNode;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.RenameLayerAction;
 import org.openstreetmap.josm.data.Bounds;
@@ -49,5 +48,5 @@
     public ValidatorLayer() {
         super(tr("Validation errors"));
-        Main.getLayerManager().addLayerChangeListener(this);
+        MainApplication.getLayerManager().addLayerChangeListener(this);
         MainApplication.getMap().validatorDialog.tree.addInvalidationListener(invalidator);
     }
@@ -175,5 +174,5 @@
     public synchronized void destroy() {
         MainApplication.getMap().validatorDialog.tree.removeInvalidationListener(invalidator);
-        Main.getLayerManager().removeLayerChangeListener(this);
+        MainApplication.getLayerManager().removeLayerChangeListener(this);
         super.destroy();
     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java	(revision 12636)
@@ -182,5 +182,5 @@
                 // If none, we'll zoom to the bounding box of the layer with the photos.
                 boolean boundingBoxedLayerFound = false;
-                for (Layer l: Main.getLayerManager().getLayers()) {
+                for (Layer l: MainApplication.getLayerManager().getLayers()) {
                     if (l != yLayer) {
                         BoundingXYVisitor bbox = new BoundingXYVisitor();
@@ -544,5 +544,5 @@
     public void actionPerformed(ActionEvent ae) {
         // Construct the list of loaded GPX tracks
-        Collection<Layer> layerLst = Main.getLayerManager().getLayers();
+        Collection<Layer> layerLst = MainApplication.getLayerManager().getLayers();
         GpxDataWrapper defaultItem = null;
         for (Layer cur : layerLst) {
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java	(revision 12636)
@@ -294,5 +294,5 @@
             }
             if (layer != null) {
-                Main.getLayerManager().addLayer(layer);
+                MainApplication.getLayerManager().addLayer(layer);
 
                 if (!canceled && layer.data != null && !layer.data.isEmpty()) {
@@ -888,5 +888,5 @@
     private void clearOtherCurrentPhotos() {
         for (GeoImageLayer layer:
-                 Main.getLayerManager().getLayersOfType(GeoImageLayer.class)) {
+                 MainApplication.getLayerManager().getLayersOfType(GeoImageLayer.class)) {
             if (layer != this) {
                 layer.clearCurrentPhoto(false);
@@ -992,6 +992,6 @@
         mapModeListener.mapModeChange(null, MainApplication.getMap().mapMode);
 
-        Main.getLayerManager().addActiveLayerChangeListener(e -> {
-            if (Main.getLayerManager().getActiveLayer() == this) {
+        MainApplication.getLayerManager().addActiveLayerChangeListener(e -> {
+            if (MainApplication.getLayerManager().getActiveLayer() == this) {
                 // only in select mode it is possible to click the images
                 MainApplication.getMap().selectSelectTool(false);
@@ -999,5 +999,5 @@
         });
 
-        Main.getLayerManager().addLayerChangeListener(new LayerChangeListener() {
+        MainApplication.getLayerManager().addLayerChangeListener(new LayerChangeListener() {
             @Override
             public void layerAdded(LayerAddEvent e) {
@@ -1019,5 +1019,5 @@
                     data = null;
                     // stop listening to layer change events
-                    Main.getLayerManager().removeLayerChangeListener(this);
+                    MainApplication.getLayerManager().removeLayerChangeListener(this);
                 }
             }
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 12636)
@@ -84,6 +84,6 @@
         tr("Tool: {0}", tr("Display geotagged images")), KeyEvent.VK_Y, Shortcut.DIRECT), 200);
         build();
-        Main.getLayerManager().addActiveLayerChangeListener(this);
-        Main.getLayerManager().addLayerChangeListener(this);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().addLayerChangeListener(this);
     }
 
@@ -205,6 +205,6 @@
     @Override
     public void destroy() {
-        Main.getLayerManager().removeActiveLayerChangeListener(this);
-        Main.getLayerManager().removeLayerChangeListener(this);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().removeLayerChangeListener(this);
         super.destroy();
     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerAction.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerAction.java	(revision 12636)
@@ -29,4 +29,5 @@
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.GpxLayer;
 import org.openstreetmap.josm.gui.layer.Layer;
@@ -166,6 +167,6 @@
         }
         osmLayer.setUploadDiscouraged(true);
-        Main.getLayerManager().addLayer(osmLayer);
-        Main.getLayerManager().removeLayer(layer);
+        MainApplication.getLayerManager().addLayer(osmLayer);
+        MainApplication.getLayerManager().removeLayer(layer);
     }
 }
Index: trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackAction.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackAction.java	(revision 12636)
@@ -116,5 +116,5 @@
     @SuppressWarnings({ "rawtypes", "unchecked" })
     protected AbstractTileSourceLayer<? extends AbstractTMSTileSource> askedLayer() {
-        List<AbstractTileSourceLayer> targetLayers = Main.getLayerManager().getLayersOfType(AbstractTileSourceLayer.class);
+        List<AbstractTileSourceLayer> targetLayers = MainApplication.getLayerManager().getLayersOfType(AbstractTileSourceLayer.class);
         if (targetLayers.isEmpty()) {
             if (!GraphicsEnvironment.isHeadless()) {
Index: trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java	(revision 12636)
@@ -115,5 +115,5 @@
                 importAudio(file, ml, firstStartTime, m);
             }
-            Main.getLayerManager().addLayer(ml);
+            MainApplication.getLayerManager().addLayer(ml);
             MainApplication.getMap().repaint();
         }
Index: trunk/src/org/openstreetmap/josm/gui/layer/gpx/MarkersFromNamedPointsAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/gpx/MarkersFromNamedPointsAction.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/gpx/MarkersFromNamedPointsAction.java	(revision 12636)
@@ -9,6 +9,6 @@
 import javax.swing.AbstractAction;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.gpx.GpxData;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.GpxLayer;
 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
@@ -39,5 +39,5 @@
         MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", layer.getName()), layer.getAssociatedFile(), layer);
         if (!ml.data.isEmpty()) {
-            Main.getLayerManager().addLayer(ml);
+            MainApplication.getLayerManager().addLayer(ml);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java	(revision 12636)
@@ -417,10 +417,10 @@
             return;
         Marker m = null;
-        Layer l = Main.getLayerManager().getActiveLayer();
+        Layer l = MainApplication.getLayerManager().getActiveLayer();
         if (l != null) {
             m = getAdjacentMarker(startMarker, next, l);
         }
         if (m == null) {
-            for (Layer layer : Main.getLayerManager().getLayers()) {
+            for (Layer layer : MainApplication.getLayerManager().getLayers()) {
                 m = getAdjacentMarker(startMarker, next, layer);
                 if (m != null) {
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java	(revision 12636)
@@ -12,5 +12,4 @@
 import javax.swing.JMenu;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.gui.MainApplication;
@@ -67,9 +66,10 @@
         @Override
         public void updateEnabledState() {
-            setEnabled(MainApplication.isDisplayingMapView() && (Main.getLayerManager().getEditLayer() != null || mapHasGpxorMarkerLayer()));
+            setEnabled(MainApplication.isDisplayingMapView()
+                    && (MainApplication.getLayerManager().getEditLayer() != null || mapHasGpxorMarkerLayer()));
         }
 
         private static boolean mapHasGpxorMarkerLayer() {
-            for (Layer layer : Main.getLayerManager().getLayers()) {
+            for (Layer layer : MainApplication.getLayerManager().getLayers()) {
                 if (layer instanceof GpxLayer || layer instanceof MarkerLayer) {
                     return true;
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java	(revision 12636)
@@ -426,5 +426,5 @@
 
             // Trigger a repaint of all data layers
-            Main.getLayerManager().getLayers()
+            MainApplication.getLayerManager().getLayers()
                 .stream()
                 .filter(layer -> layer instanceof OsmDataLayer)
Index: trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java	(revision 12636)
@@ -45,4 +45,5 @@
 import org.openstreetmap.josm.data.osm.Tag;
 import org.openstreetmap.josm.gui.ExtendedDialog;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.Notification;
 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
@@ -128,5 +129,5 @@
      */
     public TaggingPreset() {
-        Main.getLayerManager().addActiveLayerChangeListener(this);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
         updateEnabledState();
     }
@@ -380,5 +381,5 @@
             return;
         }
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         Collection<OsmPrimitive> participants = Collections.emptyList();
         if (Main.main != null && ds != null) {
@@ -411,5 +412,6 @@
                 members.add(rm);
             }
-            SwingUtilities.invokeLater(() -> RelationEditor.getEditor(Main.getLayerManager().getEditLayer(), r, members).setVisible(true));
+            SwingUtilities.invokeLater(() -> RelationEditor.getEditor(
+                    MainApplication.getLayerManager().getEditLayer(), r, members).setVisible(true));
         }
         ds.setSelected(ds.getSelected()); // force update
@@ -553,5 +555,5 @@
 
     protected final void updateEnabledState() {
-        setEnabled(Main.main != null && Main.getLayerManager().getEditDataSet() != null);
+        setEnabled(Main.main != null && MainApplication.getLayerManager().getEditDataSet() != null);
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItem.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItem.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItem.java	(revision 12636)
@@ -20,4 +20,5 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Tag;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
@@ -42,5 +43,5 @@
     protected void initAutoCompletionField(AutoCompletingTextField field, List<String> keys) {
         if (Main.main == null) return;
-        OsmDataLayer layer = Main.getLayerManager().getEditLayer();
+        OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
         if (layer == null) {
             return;
Index: trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchAction.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchAction.java	(revision 12636)
@@ -9,4 +9,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.tools.Shortcut;
 
@@ -30,5 +31,5 @@
     public void actionPerformed(ActionEvent e) {
 
-        if (Main.getLayerManager().getEditLayer() == null)
+        if (MainApplication.getLayerManager().getEditLayer() == null)
             return;
 
Index: trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java	(revision 12636)
@@ -13,4 +13,5 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.gui.ExtendedDialog;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.tools.Shortcut;
 
@@ -43,5 +44,5 @@
         @Override
         public void actionPerformed(ActionEvent e) {
-            if (Main.getLayerManager().getEditLayer() != null) {
+            if (MainApplication.getLayerManager().getEditLayer() != null) {
                 TaggingPresetSearchPrimitiveDialog.getInstance().showDialog();
             }
@@ -86,6 +87,6 @@
             TaggingPreset preset = selector.getSelectedPresetAndUpdateClassification();
             if (preset != null) {
-                final Set<OsmPrimitive> matching = new HashSet<>(Main.getLayerManager().getEditDataSet().getPrimitives(preset));
-                Main.getLayerManager().getEditDataSet().setSelected(matching);
+                final Set<OsmPrimitive> matching = new HashSet<>(MainApplication.getLayerManager().getEditDataSet().getPrimitives(preset));
+                MainApplication.getLayerManager().getEditDataSet().setSelected(matching);
             }
         }
Index: trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java	(revision 12636)
@@ -38,4 +38,5 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.preferences.BooleanProperty;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.tagging.presets.items.ComboMultiSelect;
 import org.openstreetmap.josm.gui.tagging.presets.items.Key;
@@ -235,5 +236,5 @@
         boolean inTags = ckSearchInTags != null && ckSearchInTags.isSelected();
 
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         Collection<OsmPrimitive> selected = (ds == null) ? Collections.<OsmPrimitive>emptyList() : ds.getSelected();
         final List<PresetClassification> result = classifications.getMatchingPresets(
@@ -355,6 +356,6 @@
                 typesInSelectionDirty = false;
                 typesInSelection.clear();
-                if (Main.main == null || Main.getLayerManager().getEditDataSet() == null) return typesInSelection;
-                for (OsmPrimitive primitive : Main.getLayerManager().getEditDataSet().getSelected()) {
+                if (Main.main == null || MainApplication.getLayerManager().getEditDataSet() == null) return typesInSelection;
+                for (OsmPrimitive primitive : MainApplication.getLayerManager().getEditDataSet().getSelected()) {
                     typesInSelection.add(TaggingPresetType.forPrimitive(primitive));
                 }
Index: trunk/src/org/openstreetmap/josm/gui/util/HighlightHelper.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/util/HighlightHelper.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/util/HighlightHelper.java	(revision 12636)
@@ -8,8 +8,8 @@
 import java.util.Set;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.gui.MainApplication;
 
 /**
@@ -122,5 +122,5 @@
      */
     public void findAllHighlighted() {
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         if (ds != null) {
             highlightedPrimitives.addAll(ds.allNonDeletedPrimitives());
@@ -132,5 +132,5 @@
      */
     public static void clearAllHighlighted() {
-        DataSet ds = Main.getLayerManager().getEditDataSet();
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         if (ds != null) {
             for (OsmPrimitive p: ds.allNonDeletedPrimitives()) {
Index: trunk/src/org/openstreetmap/josm/gui/widgets/OsmPrimitivesTable.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/widgets/OsmPrimitivesTable.java	(revision 12634)
+++ trunk/src/org/openstreetmap/josm/gui/widgets/OsmPrimitivesTable.java	(revision 12636)
@@ -10,7 +10,7 @@
 import javax.swing.table.TableColumnModel;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.ZoomToAction;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 
@@ -94,6 +94,6 @@
      */
     public void registerListeners() {
-        Main.getLayerManager().addLayerChangeListener(zoomToAction);
-        Main.getLayerManager().addActiveLayerChangeListener(zoomToAction);
+        MainApplication.getLayerManager().addLayerChangeListener(zoomToAction);
+        MainApplication.getLayerManager().addActiveLayerChangeListener(zoomToAction);
     }
 
@@ -103,6 +103,6 @@
      */
     public void unregisterListeners() {
-        Main.getLayerManager().removeLayerChangeListener(zoomToAction);
-        Main.getLayerManager().removeActiveLayerChangeListener(zoomToAction);
+        MainApplication.getLayerManager().removeLayerChangeListener(zoomToAction);
+        MainApplication.getLayerManager().removeActiveLayerChangeListener(zoomToAction);
     }
 
