From 12816bbe5d1b492ac183fc2b2a25e7d988a09ef6 Mon Sep 17 00:00:00 2001 From: BobHanson Date: Fri, 20 Mar 2020 00:12:33 -0500 Subject: [PATCH] JAL-3560 avoiding Graphics.setClip Now that Graphics.setClip is supported, it is important to avoid it whenever possible. It requires a full run back through the graphics stack and return twice in order to clear the clip and reset it with all other characteristics of the graphics state intact. This was particularly notable in JViewport, creating very sluggish handling of FeatureSettings, particularly in Firefox. --- src/jalview/appletgui/SeqCanvas.java | 8 +++++--- src/jalview/gui/AlignmentPanel.java | 7 ++++++- src/jalview/gui/TreeCanvas.java | 11 ++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index f055776..ecb0888 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -492,15 +492,17 @@ public class SeqCanvas extends Panel implements ViewportListenerI { ypos - (avcharHeight / 2), ypos - (avcharHeight / 2), ypos - (avcharHeight / 2) + 8 }, 3); } } - + // BH 2020.03.19 avoiding g.setClip at all costs + g = g.create(); if (g.getClip() == null) { - g.setClip(0, 0, cWidth * avcharWidth, canvasHeight); + g.clipRect(0, 0, cWidth * avcharWidth, canvasHeight); } drawPanel(g, startRes, endx, 0, al.getHeight() - 1, ypos); - g.setClip(null); + // g.setClip(null); + g.dispose(); if (av.isShowAnnotation()) { g.translate(0, cHeight + ypos + 4); diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 72a074d..d8035bb 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -1079,6 +1079,7 @@ public class AlignmentPanel extends GAlignmentPanel implements public int printWrappedAlignment(int pageWidth, int pageHeight, int pageNumber, Graphics g) throws PrinterException { + int annotationHeight = 0; if (av.isShowAnnotation()) { @@ -1103,6 +1104,8 @@ public class AlignmentPanel extends GAlignmentPanel implements int totalHeight = cHeight * (maxwidth / resWidth + 1); + g = g.create(); + g.setColor(Color.white); g.fillRect(0, 0, pageWidth, pageHeight); g.setFont(av.getFont()); @@ -1116,7 +1119,8 @@ public class AlignmentPanel extends GAlignmentPanel implements */ g.translate(0, -pageNumber * pageHeight); - g.setClip(0, pageNumber * pageHeight, pageWidth, pageHeight); + // BH 2020.03.19 avoiding g.setClip + g.clipRect(0, pageNumber * pageHeight, pageWidth, pageHeight); /* * draw sequence ids and annotation labels (if shown) @@ -1129,6 +1133,7 @@ public class AlignmentPanel extends GAlignmentPanel implements getSeqPanel().seqCanvas.drawWrappedPanelForPrinting(g, pageWidth - idWidth, totalHeight, 0); + g.dispose(); if ((pageNumber * pageHeight) < totalHeight) { return Printable.PAGE_EXISTS; diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 29ba52b..0c09b71 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -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; } -- 1.7.10.2