Index: trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java	(revision 12122)
+++ trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java	(revision 12125)
@@ -198,5 +198,5 @@
         JMenu subMenu = Main.main.menu.imagerySubMenu;
         int heightUnrolled = 30*(getItemCount()+subMenu.getItemCount());
-        if (heightUnrolled < Main.panel.getHeight()) {
+        if (heightUnrolled < Main.main.panel.getHeight()) {
             // add all items of submenu if they will fit on screen
             int n = subMenu.getItemCount();
Index: trunk/src/org/openstreetmap/josm/gui/MainApplication.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 12122)
+++ trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 12125)
@@ -88,5 +88,5 @@
     private static final List<String> COMMAND_LINE_ARGS = new ArrayList<>();
 
-    private MainFrame mainFrame;
+    private final MainFrame mainFrame;
 
     /**
@@ -109,13 +109,16 @@
     @Override
     protected void initializeMainWindow() {
-        mainPanel.reAddListeners();
         if (mainFrame != null) {
+            mainFrame.preInitialize();
+            panel = mainFrame.getPanel();
             mainFrame.initialize();
-
             menu = mainFrame.getMenu();
         } else {
             // required for running some tests.
+            panel = new MainPanel(Main.getLayerManager());
             menu = new MainMenu();
         }
+        panel.addMapFrameListener((o, n) -> redoUndoListener.commandChanged(0, 0));
+        panel.reAddListeners();
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/MainFrame.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MainFrame.java	(revision 12122)
+++ trunk/src/org/openstreetmap/josm/gui/MainFrame.java	(revision 12125)
@@ -49,4 +49,5 @@
     protected transient WindowGeometry geometry;
     protected int windowState = JFrame.NORMAL;
+    private MainPanel panel;
     private MainMenu menu;
 
@@ -71,5 +72,14 @@
 
     /**
+     * Performs pre-initialization required before the call to {@link #initialize()}.
+     * @since 12125
+     */
+    public void preInitialize() {
+        panel = new MainPanel(Main.getLayerManager());
+    }
+
+    /**
      * Initializes the content of the window and get the current status panel.
+     * {@link #preInitialize()} must have been previously called.
      */
     public void initialize() {
@@ -98,5 +108,5 @@
         refreshTitle();
 
-        getContentPane().add(Main.panel, BorderLayout.CENTER);
+        getContentPane().add(panel, BorderLayout.CENTER);
         menu.initialize();
     }
@@ -115,4 +125,6 @@
      * Gets the main menu used for this window.
      * @return The main menu.
+     * @throws IllegalStateException if the main frame has not been initialized yet
+     * @see #initialize
      */
     public MainMenu getMenu() {
@@ -121,4 +133,18 @@
         }
         return menu;
+    }
+
+    /**
+     * Gets the main panel.
+     * @return The main panel.
+     * @throws IllegalStateException if the main frame has not been initialized yet
+     * @see #initialize
+     * @since 12125
+     */
+    public MainPanel getPanel() {
+        if (panel == null) {
+            throw new IllegalStateException("Not initialized.");
+        }
+        return panel;
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandler.java	(revision 12122)
+++ trunk/src/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandler.java	(revision 12125)
@@ -71,5 +71,5 @@
      */
     public void pasteOn(OsmDataLayer editLayer, EastNorth mPosition, Transferable transferable) {
-        importData(new TransferSupport(Main.panel, transferable), editLayer, mPosition);
+        importData(new TransferSupport(Main.main.panel, transferable), editLayer, mPosition);
     }
 
@@ -80,5 +80,5 @@
     public void pasteTags(Collection<? extends OsmPrimitive> primitives) {
         Transferable transferable = ClipboardUtils.getClipboardContent();
-        importTags(new TransferSupport(Main.panel, transferable), primitives);
+        importTags(new TransferSupport(Main.main.panel, transferable), primitives);
     }
 
