Index: src/org/openstreetmap/josm/plugins/print/PrintDialog.java
===================================================================
--- src/org/openstreetmap/josm/plugins/print/PrintDialog.java	(revision 35337)
+++ src/org/openstreetmap/josm/plugins/print/PrintDialog.java	(working copy)
@@ -20,12 +20,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
+import java.util.*;
 
 import javax.print.PrintService;
 import javax.print.PrintServiceLookup;
@@ -223,24 +218,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 +239,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 +262,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();
                 });
             }
 
@@ -469,7 +445,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: src/org/openstreetmap/josm/plugins/print/PrintPlugin.java
===================================================================
--- src/org/openstreetmap/josm/plugins/print/PrintPlugin.java	(revision 35337)
+++ src/org/openstreetmap/josm/plugins/print/PrintPlugin.java	(working copy)
@@ -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();
@@ -107,7 +107,7 @@
      * Saves the existing value for later restorePref.
      *
      * @param key the preference key
-     * @param the temporary new int value
+     * @param value the temporary new int value
      */
     protected static void adjustPref(String key, int value) {
         if (!Config.getPref().get(key).isEmpty()) {
@@ -122,7 +122,7 @@
      * Saves the existing value for later restorePref.
      *
      * @param key the preference key
-     * @param the temporary new boolean value
+     * @param value the temporary new boolean value
      */
     protected static void adjustPref(String key, boolean value) {
         if (!Config.getPref().get(key).isEmpty()) {
@@ -137,7 +137,7 @@
      * Saves the existing value for later restorePref.
      *
      * @param key the preference key
-     * @param the temporary new String value
+     * @param value the temporary new String value
      */
     protected static void adjustPref(String key, String value) {
         if (!Config.getPref().get(key).isEmpty()) {
Index: src/org/openstreetmap/josm/plugins/print/PrintableLayerManager.java
===================================================================
--- src/org/openstreetmap/josm/plugins/print/PrintableLayerManager.java	(revision 35337)
+++ src/org/openstreetmap/josm/plugins/print/PrintableLayerManager.java	(working copy)
@@ -1,10 +1,9 @@
 // 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 java.util.stream.Collectors;
 
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.gui.MainApplication;
@@ -14,8 +13,12 @@
 
 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) {
         layerManager.removeActiveLayerChangeListener(listener);
@@ -43,29 +46,18 @@
 
     @Override
     public synchronized List<Layer> getVisibleLayersInZOrder() {
-        ArrayList<Layer> layers = new ArrayList<>();
-        for (Layer l: layerManager.getLayers()) {
-            if (l.isVisible()) {
-                layers.add(l);
+        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;
             }
-        }
-        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));
-                }
-            }
-        );
-        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: src/org/openstreetmap/josm/plugins/print/PrintableMapView.java
===================================================================
--- src/org/openstreetmap/josm/plugins/print/PrintableMapView.java	(revision 35337)
+++ src/org/openstreetmap/josm/plugins/print/PrintableMapView.java	(working copy)
@@ -11,7 +11,6 @@
 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;
@@ -18,7 +17,7 @@
 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;
@@ -30,10 +29,12 @@
 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
 import org.openstreetmap.josm.spi.preferences.Config;
+import org.openstreetmap.josm.tools.Logging;
 
 /**
  * The PrintableMapView class implements a "Printable" perspective on
  * the main MapView.
+ *
  * @author Kai Pastor
  */
 public class PrintableMapView extends MapView implements Printable {
@@ -58,14 +59,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 +79,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.
      */
@@ -106,12 +105,12 @@
      * Initialize the PrintableMapView for a particular combination of
      * main MapView, PageFormat and target resolution
      *
-     * @param pageformat the size and orientation of the page being drawn
+     * @param pageFormat the size and orientation of the page being drawn
      */
     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));
     }
 
     /**
@@ -154,31 +153,28 @@
 
     /**
      * 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 PAGE_EXISTS for page==0 or NO_SUCH_PAGE for 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;
         }
 
+        Logging.info("Page format " + pageFormat.getImageableX() + ", " + pageFormat.getImageableY() + ", width " + pageFormat.getWidth() +" height " + pageFormat.getHeight());
+
         initialize(pageFormat);
 
         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;
     }
@@ -185,19 +181,19 @@
 
     /**
      * 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);
 
-        Bounds box = getRealBounds();
+        Bounds box = MainApplication.getMap().mapView.getRealBounds();
         for (Layer l : getLayerManager().getVisibleLayersInZOrder()) {
+            paintLayer(l, g2d);
             if (l.getOpacity() < 1) {
                 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) l.getOpacity()));
             }
@@ -205,19 +201,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;
@@ -243,32 +238,32 @@
 
         /* 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);
@@ -287,7 +282,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) {
@@ -308,7 +303,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);
 
@@ -320,13 +315,13 @@
 
     /**
      * Paint a text.
-     *
+     * <p>
      * This method will not only draw the letters but also a background which improves redability.
      *
-     * @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();
