JAL-3253 temporary branch SwingJS upgrade with testNG fixes Java 8
[jalview.git] / src / jalview / gui / TreeCanvas.java
index 29ba52b..0c09b71 100755 (executable)
@@ -584,8 +584,6 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
   public int print(Graphics pg, PageFormat pf, int pi)
           throws PrinterException
   {
-    pg.setFont(font);
-    pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
 
     int pwidth = (int) pf.getImageableWidth();
     int pheight = (int) pf.getImageableHeight();
@@ -602,6 +600,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       pwidth = getWidth();
     }
 
+    pg = pg.create();
+    pg.setFont(font);
+    pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
+
     if (fitToWindow)
     {
       if (pheight > getHeight())
@@ -616,7 +618,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       FontMetrics fm = pg.getFontMetrics(font);
       int height = fm.getHeight() * nameHash.size();
       pg.translate(0, -pi * pheight);
-      pg.setClip(0, pi * pheight, pwidth, (pi * pheight) + pheight);
+      // BH 2020.03.19 avoiding setClip here
+      pg.clipRect(0, pi * pheight, pwidth, (pi * pheight) + pheight);
 
       // translate number of pages,
       // height is screen size as this is the
@@ -626,6 +629,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
 
     draw(pg, pwidth, pheight);
 
+    pg.dispose();
+
     return Printable.PAGE_EXISTS;
   }