From: kiramt Date: Wed, 16 Aug 2017 10:40:54 +0000 (+0100) Subject: JAL-2556 Code tidy X-Git-Tag: Release_2_10_3b1~140^2~19 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2918e12657faeb91f3ca91da13f23adc914d0860;p=jalview.git JAL-2556 Code tidy --- 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()