From 2918e12657faeb91f3ca91da13f23adc914d0860 Mon Sep 17 00:00:00 2001 From: kiramt Date: Wed, 16 Aug 2017 11:40:54 +0100 Subject: [PATCH] JAL-2556 Code tidy --- src/jalview/gui/SeqCanvas.java | 54 +++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 9d11976..3626383 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -352,6 +352,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI @Override public void paintComponent(Graphics g) { + super.paintComponent(g); + updateViewport(); // img is a cached version of the last view we drew @@ -366,33 +368,13 @@ public class SeqCanvas extends JComponent implements ViewportListenerI { return; } - BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(), - img.getType()); - Graphics2D g2d = lcimg.createGraphics(); - g2d.drawImage(img, 0, 0, null); - g2d.dispose(); - - - // BufferedImage lcimg = img; // take reference since other threads may null - // img and call later. - super.paintComponent(g); BufferedImage selectImage = drawSelectionGroup(); - if (lcimg != null - && (fastPaint - || (getVisibleRect().width != g.getClipBounds().width) || (getVisibleRect().height != g - .getClipBounds().height))) + if (fastPaint || (getVisibleRect().width != g.getClipBounds().width) + || (getVisibleRect().height != g.getClipBounds().height)) { - Graphics2D g2 = (Graphics2D) lcimg.getGraphics(); - - // overlay selection group on lcimg - if (selectImage != null) - { - g2.setComposite( - AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); - g2.drawImage(selectImage, 0, 0, this); - } + BufferedImage lcimg = buildLocalImage(selectImage); g.drawImage(lcimg, 0, 0, this); fastPaint = false; @@ -419,22 +401,32 @@ public class SeqCanvas extends JComponent implements ViewportListenerI ranges.getStartSeq(), ranges.getEndSeq(), 0); } - lcimg = new BufferedImage(img.getWidth(), img.getHeight(), + BufferedImage lcimg = buildLocalImage(selectImage); + g.drawImage(lcimg, 0, 0, this); + } + + /* + * Make a local image by combining the cached image img + * with any selection + */ + private BufferedImage buildLocalImage(BufferedImage selectImage) + { + // clone the cached image + BufferedImage lcimg = new BufferedImage(img.getWidth(), img.getHeight(), img.getType()); - g2d = lcimg.createGraphics(); + Graphics2D g2d = lcimg.createGraphics(); g2d.drawImage(img, 0, 0, null); - g2d.dispose(); - - Graphics2D g2 = (Graphics2D) lcimg.getGraphics(); // overlay selection group on lcimg if (selectImage != null) { - g2.setComposite( + g2d.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); - g2.drawImage(selectImage, 0, 0, this); + g2d.drawImage(selectImage, 0, 0, this); } - g.drawImage(lcimg, 0, 0, this); + g2d.dispose(); + + return lcimg; } private void paintSeqGroup() -- 1.7.10.2