Index: plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableLayerManager.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableLayerManager.java	(revision 35495)
+++ plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableLayerManager.java	(date 1593361748025)
@@ -1,20 +1,22 @@
 // License: GPL. For details, see LICENSE file.
 package org.openstreetmap.josm.plugins.print;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
 import org.openstreetmap.josm.data.osm.DataSet;
-import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.MainLayerManager;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+
 public class PrintableLayerManager extends MainLayerManager {
 
-    private static final MainLayerManager layerManager = MainApplication.getLayerManager();
+    private final MainLayerManager layerManager;
+
+    PrintableLayerManager(MainLayerManager delegate) {
+        this.layerManager = delegate;
+    }
 
     @Override
     public synchronized void removeActiveLayerChangeListener(ActiveLayerChangeListener listener) {
@@ -43,29 +45,18 @@
 
     @Override
     public synchronized List<Layer> getVisibleLayersInZOrder() {
-        ArrayList<Layer> layers = new ArrayList<>();
-        for (Layer l: layerManager.getLayers()) {
-            if (l.isVisible()) {
-                layers.add(l);
-            }
-        }
-        Collections.sort(
-            layers,
-            new Comparator<Layer>() {
-                @Override
-                public int compare(Layer l2, Layer l1) { // l1 and l2 swapped!
-                    if (l1 instanceof OsmDataLayer && l2 instanceof OsmDataLayer) {
-                        if (l1 == layerManager.getActiveLayer()) return -1;
-                        if (l2 == layerManager.getActiveLayer()) return 1;
-                        return Integer.valueOf(layerManager.getLayers().indexOf(l1)).
-                                     compareTo(layerManager.getLayers().indexOf(l2));
-                    } else
-                        return Integer.valueOf(layerManager.getLayers().indexOf(l1)).
-                                     compareTo(layerManager.getLayers().indexOf(l2));
-                }
+        final Comparator<Layer> layerComparator = (l2, l1) -> { // l1 and l2 swapped!
+            if (l1 instanceof OsmDataLayer && l2 instanceof OsmDataLayer) {
+                if (l1 == layerManager.getActiveLayer()) return -1;
+                if (l2 == layerManager.getActiveLayer()) return 1;
             }
-        );
-        return layers;
+            return Integer.compare(layerManager.getLayers().indexOf(l1), layerManager.getLayers().indexOf(l2));
+        };
+
+        return layerManager.getLayers().stream()
+                .filter(Layer::isVisible)
+                .sorted(layerComparator)
+                .collect(Collectors.toList());
     }
 
     @Override
Index: plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableMapView.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableMapView.java	(revision 35495)
+++ plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableMapView.java	(date 1593361549320)
@@ -11,14 +11,13 @@
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Shape;
-import java.awt.event.ComponentListener;
 import java.awt.font.FontRenderContext;
 import java.awt.font.GlyphVector;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.awt.print.PageFormat;
 import java.awt.print.Printable;
-import java.awt.print.PrinterException;
+import java.util.Arrays;
 
 import org.openstreetmap.gui.jmapviewer.tilesources.AbstractOsmTileSource;
 import org.openstreetmap.josm.data.Bounds;
@@ -34,6 +33,7 @@
 /**
  * The PrintableMapView class implements a "Printable" perspective on
  * the main MapView.
+ *
  * @author Kai Pastor
  */
 public class PrintableMapView extends MapView implements Printable {
@@ -58,14 +58,12 @@
      */
     public PrintableMapView() {
         /* Initialize MapView with a dummy parent */
-        super(new PrintableLayerManager(), null);
+        super(new PrintableLayerManager(MainApplication.getLayerManager()), null);
 
         /* Disable MapView's ComponentLister,
          * as it will interfere with the main MapView. */
-        ComponentListener[] listeners = getComponentListeners();
-        for (int i = 0; i < listeners.length; i++) {
-            removeComponentListener(listeners[i]);
-        }
+        Arrays.stream(getComponentListeners())
+                .forEach(this::removeComponentListener);
     }
 
     /**
@@ -80,7 +78,7 @@
 
     /**
      * Unset the fixed map scale
-     *
+     * <p>
      * The map scaling will be chosen automatically such that the
      * main windows map view fits on the page format.
      */
@@ -93,13 +91,13 @@
      * Get the map scale that will be used for rendering
      * @return the map scale that will be used for rendering
      */
-    public int getMapScale() {
+    public double getMapScale() {
         if (fixedMapScale > 0 || g2dFactor == 0.0) {
             return fixedMapScale;
         }
 
         double dist100px = getDist100Pixel() / g2dFactor;
-        int mapScale = (int) (dist100px * 72.0 / 2.54);
+        double mapScale = (dist100px * 72.0 / 2.54);
         return mapScale;
     }
 
@@ -111,8 +109,8 @@
      */
     public void initialize(PageFormat pageFormat) {
         int resolution = Config.getPref().getInt("print.resolution.dpi", PrintPlugin.DEF_RESOLUTION_DPI);
-        g2dFactor = 72.0/resolution;
-        setSize((int) (pageFormat.getImageableWidth()/g2dFactor), (int) (pageFormat.getImageableHeight()/g2dFactor));
+        g2dFactor = 72.0 / resolution;
+        setSize((int) (pageFormat.getImageableWidth() / g2dFactor), (int) (pageFormat.getImageableHeight() / g2dFactor));
     }
 
     /**
@@ -123,7 +121,7 @@
         Dimension dim = getSize();
         if (dim.width != width || dim.height != height) {
             super.setSize(width, height);
-            zoomTo(MainApplication.getMap().mapView.getRealBounds());
+            zoomTo(MainApplication.getMap().mapView.getCenter());
             rezoomToFixedScale();
         }
     }
@@ -136,7 +134,7 @@
         Dimension dim = getSize();
         if (dim.width != newSize.width || dim.height != newSize.height) {
             super.setSize(newSize);
-            zoomTo(MainApplication.getMap().mapView.getRealBounds());
+            zoomTo(MainApplication.getMap().mapView.getCenter());
             rezoomToFixedScale();
         }
     }
@@ -155,21 +153,16 @@
 
     /**
      * Render a page for the printer
-     *
+     * <p>
      * Implements java.awt.print.Printable.
      *
-     * @param g the context into which the page is drawn
+     * @param g          the context into which the page is drawn
      * @param pageFormat the size and orientation of the page being drawn
-     * @param page the zero based index of the page to be drawn
-     *
+     * @param page       the zero based index of the page to be drawn
      * @return {@code PAGE_EXISTS} for {@code page=0} or {@code NO_SUCH_PAGE} for {@code page>0}
-     *
-     * @throws PrinterException thrown when the print job is terminated
-     *
      */
     @Override
-    public int print(Graphics g, PageFormat pageFormat, int page) throws
-                                                    PrinterException {
+    public int print(Graphics g, PageFormat pageFormat, int page) {
         if (page > 0) { /* stop after first page */
             return NO_SUCH_PAGE;
         }
@@ -178,26 +171,26 @@
 
         Graphics2D g2d = (Graphics2D) g;
         g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
-        paintMap(g2d, pageFormat);
-        paintMapScale(g2d, pageFormat);
+        paintMap(g2d);
+        paintMapScale(g2d);
         paintMapAttribution(g2d, pageFormat);
         return PAGE_EXISTS;
     }
 
     /**
      * Paint the map
-     *
+     * <p>
      * This implementation is derived from MapView's paint and
      * from other JOSM core components.
      *
      * @param g2d the graphics context to use for painting
-     * @param pageFormat the size and orientation of the page being drawn
      */
-    public void paintMap(Graphics2D g2d, PageFormat pageFormat) {
-        AffineTransform at = g2d.getTransform();
+    public void paintMap(Graphics2D g2d) {
+        AffineTransform originalTransform = g2d.getTransform();
         g2d.scale(g2dFactor, g2dFactor);
+        g2d.translate(getWidth() / 2, getHeight() / 2);
 
-        Bounds box = getRealBounds();
+        Bounds box = MainApplication.getMap().mapView.getRealBounds();
         for (Layer l : getLayerManager().getVisibleLayersInZOrder()) {
             if (l.getOpacity() < 1) {
                 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) l.getOpacity()));
@@ -206,19 +199,18 @@
             g2d.setPaintMode();
         }
 
-        g2d.setTransform(at);
+        g2d.setTransform(originalTransform);
     }
 
     /**
      * Paint a linear scale and a lexical scale
-     *
+     * <p>
      * This implementation is derived from JOSM's MapScaler,
      * NavigatableComponent and SystemOfMeasurement.
      *
      * @param g2d the graphics context to use for painting
-     * @param pageFormat the size and orientation of the page being drawn
      */
-    public void paintMapScale(Graphics2D g2d, PageFormat pageFormat) {
+    public void paintMapScale(Graphics2D g2d) {
         SystemOfMeasurement som = SystemOfMeasurement.getSystemOfMeasurement();
         double dist100px = getDist100Pixel() / g2dFactor;
         double dist = dist100px / som.aValue;
@@ -244,38 +236,38 @@
 
         /* offset from the left paper border to the left end of the bar */
         Rectangle2D bound = g2d.getFontMetrics().getStringBounds("0", g2d);
-        int xLeft = (int) (bound.getWidth()/2);
+        int xLeft = (int) (bound.getWidth() / 2);
 
         /* offset from the left paper border to the right label */
         String rightLabel = som.getDistText(dist100px * distScale);
         bound = g2d.getFontMetrics().getStringBounds(rightLabel, g2d);
-        int xRight = xLeft+(int) Math.max(0.95*x, x-bound.getWidth()/2);
+        int xRight = xLeft + (int) Math.max(0.95 * x, x - bound.getWidth() / 2);
 
         // CHECKSTYLE.OFF: SingleSpaceSeparator
-        int h        = FONT_SIZE / 2; // raster, height of the bar
-        int yLexical = 3 * h;         // baseline of the lexical scale
-        int yBar     = 4 * h;         // top of the bar
-        int yLabel   = 8 * h;         // baseline of the labels
-        int w  = (int) (distScale * 100.0);  // length of the bar
-        int ws = (int) (distScale * 20.0);   // length of a segment
+        int h = FONT_SIZE / 2;             // raster, height of the bar
+        int yLexical = 3 * h;              // baseline of the lexical scale
+        int yBar = 4 * h;                  // top of the bar
+        int yLabel = 8 * h;                // baseline of the labels
+        int w = (int) (distScale * 100.0); // length of the bar
+        int ws = (int) (distScale * 20.0); // length of a segment
         // CHECKSTYLE.ON: SingleSpaceSeparator
 
         /* white background */
         g2d.setColor(Color.WHITE);
-        g2d.fillRect(xLeft-1, yBar-1, w+2, h+2);
+        g2d.fillRect(xLeft - 1, yBar - 1, w + 2, h + 2);
 
         /* black foreground */
         g2d.setColor(Color.BLACK);
         g2d.drawRect(xLeft, yBar, w, h);
         g2d.fillRect(xLeft, yBar, ws, h);
-        g2d.fillRect(xLeft+(int) (distScale * 40.0), yBar, ws, h);
-        g2d.fillRect(xLeft+w-ws, yBar, ws, h);
+        g2d.fillRect(xLeft + (int) (distScale * 40.0), yBar, ws, h);
+        g2d.fillRect(xLeft + w - ws, yBar, ws, h);
         g2d.setFont(labelFont);
         paintText(g2d, "0", 0, yLabel);
         paintText(g2d, rightLabel, xRight, yLabel);
 
         /* lexical scale */
-        int mapScale = getMapScale();
+        int mapScale = (int) getMapScale();
         String lexicalScale = tr("Scale") + " 1 : " + mapScale;
 
         Font scaleFront = new Font("Arial", Font.BOLD, FONT_SIZE);
@@ -288,7 +280,7 @@
     /**
      * Paint an attribution text
      *
-     * @param g2d the graphics context to use for painting
+     * @param g2d        the graphics context to use for painting
      * @param pageFormat the size and orientation of the page being drawn
      */
     public void paintMapAttribution(Graphics2D g2d, PageFormat pageFormat) {
@@ -309,7 +301,7 @@
             String line = text.substring(from, to);
 
             Rectangle2D bound = g2d.getFontMetrics().getStringBounds(line, g2d);
-            int x = (int) ((pageFormat.getImageableWidth() - bound.getWidth()) - FONT_SIZE/2);
+            int x = (int) ((pageFormat.getImageableWidth() - bound.getWidth()) - FONT_SIZE / 2);
 
             paintText(g2d, line, x, y);
 
@@ -321,13 +313,13 @@
 
     /**
      * Paint a text.
-     *
-     * This method will not only draw the letters but also a background which improves redability.
+     * <p>
+     * This method will not only draw the letters but also a background which improves readability.
      *
-     * @param g2d the graphics context to use for painting
+     * @param g2d  the graphics context to use for painting
      * @param text the text to be drawn
-     * @param x the x coordinate
-     * @param y the y coordinate
+     * @param x    the x coordinate
+     * @param y    the y coordinate
      */
     public void paintText(Graphics2D g2d, String text, int x, int y) {
         AffineTransform ax = g2d.getTransform();
Index: plugins/print/src/org/openstreetmap/josm/plugins/print/PrintDialog.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- plugins/print/src/org/openstreetmap/josm/plugins/print/PrintDialog.java	(revision 35495)
+++ plugins/print/src/org/openstreetmap/josm/plugins/print/PrintDialog.java	(date 1593361748033)
@@ -223,24 +223,16 @@
         mapView.setFixedMapScale(mapScale);
         scaleModel = new SpinnerNumberModel(mapScale, 250, 5000000, 250);
         final JSpinner scaleField = new JSpinner(scaleModel);
-        scaleField.addChangeListener(new ChangeListener() {
-            @Override
-            public void stateChanged(ChangeEvent evt) {
-                SwingUtilities.invokeLater(new Runnable() {
-                    @Override
-                    public void run() {
-                        try {
-                            scaleField.commitEdit();
-                            Config.getPref().put("print.map-scale", scaleModel.getNumber().toString());
-                            mapView.setFixedMapScale(scaleModel.getNumber().intValue());
-                            printPreview.repaint();
-                        } catch (ParseException e) {
-                            Logging.error(e);
-                        }
-                    }
-                });
+        scaleField.addChangeListener(evt -> SwingUtilities.invokeLater(() -> {
+            try {
+                scaleField.commitEdit();
+                Config.getPref().put("print.map-scale", scaleModel.getNumber().toString());
+                mapView.setFixedMapScale(scaleModel.getNumber().intValue());
+                printPreview.repaint();
+            } catch (ParseException e) {
+                Logging.error(e);
             }
-        });
+        }));
         add(scaleField, std.grid(GBC.RELATIVE, row));
 
         row++;
@@ -252,23 +244,15 @@
           Config.getPref().getInt("print.resolution.dpi", PrintPlugin.DEF_RESOLUTION_DPI),
           30, 1200, 10);
         final JSpinner resolutionField = new JSpinner(resolutionModel);
-        resolutionField.addChangeListener(new ChangeListener() {
-            @Override
-            public void stateChanged(ChangeEvent evt) {
-                SwingUtilities.invokeLater(new Runnable() {
-                    @Override
-                    public void run() {
-                        try {
-                            resolutionField.commitEdit();
-                            Config.getPref().put("print.resolution.dpi", resolutionModel.getNumber().toString());
-                            printPreview.repaint();
-                        } catch (ParseException e) {
-                            Logging.error(e);
-                        }
-                    }
-                });
+        resolutionField.addChangeListener(evt -> SwingUtilities.invokeLater(() -> {
+            try {
+                resolutionField.commitEdit();
+                Config.getPref().put("print.resolution.dpi", resolutionModel.getNumber().toString());
+                printPreview.repaint();
+            } catch (ParseException e) {
+                Logging.error(e);
             }
-        });
+        }));
         add(resolutionField, std.grid(GBC.RELATIVE, row));
 
         row++;
@@ -283,12 +267,9 @@
         attributionText.getDocument().addDocumentListener(new DocumentListener() {
             @Override
             public void insertUpdate(DocumentEvent evt) {
-                SwingUtilities.invokeLater(new Runnable() {
-                    @Override
-                    public void run() {
-                        Config.getPref().put("print.attribution", attributionText.getText());
-                        printPreview.repaint();
-                    }
+                SwingUtilities.invokeLater(() -> {
+                    Config.getPref().put("print.attribution", attributionText.getText());
+                    printPreview.repaint();
                 });
             }
 
@@ -455,6 +436,12 @@
         }
     }
 
+//    @Override
+//    public void dispose() {
+//        mapView.destroy();
+//        super.dispose();
+//    }
+
     protected void savePrintSettings() {
         // Save only one printer service attribute: printer name
         PrintService service = job.getPrintService();
@@ -469,7 +456,7 @@
         }
 
         // Save all request attributes
-        List<String> ignoredAttributes = Arrays.asList("media-printable-area");
+        List<String> ignoredAttributes = Collections.singletonList("media-printable-area");
         List<List<String>> requestAttributes = new ArrayList<>();
         for (Attribute a : attrs.toArray()) {
             List<String> setting = null;
Index: plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPlugin.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPlugin.java	(revision 35495)
+++ plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPlugin.java	(date 1582386010912)
@@ -45,7 +45,7 @@
         int pos = fileMenu.getItemCount();
         do {
             pos--;
-        } while (fileMenu != null && pos > 2 && fileMenu.getItem(pos) != null);
+        } while (pos > 2 && fileMenu.getItem(pos) != null);
 
         if (pos > 0) {
             PrintAction printAction = new PrintAction();
Index: plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPreview.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPreview.java	(revision 35495)
+++ plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPreview.java	(date 1593350349826)
@@ -258,8 +258,7 @@
         AffineTransform at = g2d.getTransform();
 
         Dimension out = getZoomedPageDimension();
-        double scale = Math.min(
-          out.getHeight()/format.getHeight(), out.getWidth()/format.getWidth());
+        double scale = Math.min(out.getHeight()/format.getHeight(), out.getWidth()/format.getWidth());
         double left = 0.5 * (getWidth() - scale * format.getWidth());
         double top = 0.5 * (getHeight() - scale * format.getHeight());
 
