From 68401761687b7d2ebe7d56eb5a607770ae742c9b Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 27 Jun 2017 07:47:55 +0100 Subject: [PATCH] JAL-2600 fast painting on resize --- src/jalview/gui/AnnotationPanel.java | 47 ++++++++++++++++----- src/jalview/gui/SeqCanvas.java | 75 ++++++++++++++++++++++------------ 2 files changed, 86 insertions(+), 36 deletions(-) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index c688789..e98b79e 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -971,7 +971,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, * @param horizontal * repaint with horizontal shift in alignment */ - public void fastPaint(int horizontal) + public void fastPaint(int horizontal, boolean isresize) { if ((horizontal == 0) || gg == null || av.getAlignment().getAlignmentAnnotation() == null @@ -981,22 +981,46 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, repaint(); return; } - long stime = System.currentTimeMillis(); - gg.copyArea(0, 0, imgWidth, getHeight(), - -horizontal * av.getCharWidth(), 0); - long mtime = System.currentTimeMillis(); + int sr = av.getRanges().getStartRes(); int er = av.getRanges().getEndRes() + 1; int transX = 0; + long stime; + long mtime; - if (horizontal > 0) // scrollbar pulled right, image to the left + if (isresize) { - transX = (er - sr - horizontal) * av.getCharWidth(); - sr = er - horizontal; + imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes() + + 1) * av.getCharWidth(); + + BufferedImage newimage = new BufferedImage(imgWidth, + ap.getAnnotationPanel().getHeight(), + BufferedImage.TYPE_INT_ARGB); + + gg = (Graphics2D) newimage.getGraphics(); + gg.setFont(av.getFont()); + gg.drawImage(image, null, 0, 0); + image = newimage; + + transX = (er - horizontal - sr) * av.getCharWidth(); + sr = er - horizontal - sr; } - else if (horizontal < 0) + else { - er = sr - horizontal; + stime = System.currentTimeMillis(); + gg.copyArea(0, 0, imgWidth, getHeight(), + -horizontal * av.getCharWidth(), 0); + mtime = System.currentTimeMillis(); + + if (horizontal > 0) // scrollbar pulled right, image to the left + { + transX = (er - sr - horizontal) * av.getCharWidth(); + sr = er - horizontal; + } + else if (horizontal < 0) + { + er = sr - horizontal; + } } gg.translate(transX, 0); @@ -1170,11 +1194,12 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, // Respond to viewport range changes (e.g. alignment panel was scrolled) if (evt.getPropertyName().equals("startres")) { - fastPaint((int) evt.getNewValue() - (int) evt.getOldValue()); + fastPaint((int) evt.getNewValue() - (int) evt.getOldValue(), false); } else if (evt.getPropertyName().equals("endres")) { // resize + fastPaint((int) evt.getNewValue() - (int) evt.getOldValue(), true); } } } diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index d3ba304..e8f9c5b 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -277,7 +277,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI * @param vertical * shift up or down in repaint */ - public void fastPaint(int horizontal, int vertical) + public void fastPaint(int horizontal, int vertical, boolean isresize) { if (fastpainting || gg == null) { @@ -286,8 +286,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI fastpainting = true; fastPaint = true; updateViewport(); - gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth, - imgHeight, -horizontal * charWidth, -vertical * charHeight); ViewportRanges ranges = av.getRanges(); int sr = ranges.getStartRes(); @@ -297,35 +295,60 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int transX = 0; int transY = 0; - if (horizontal > 0) // scrollbar pulled right, image to the left + if (isresize) { - transX = (er - sr - horizontal) * charWidth; - sr = er - horizontal; - } - else if (horizontal < 0) - { - er = sr - horizontal; + imgWidth = getWidth(); + imgHeight = getHeight(); + + imgWidth -= (imgWidth % charWidth); + imgHeight -= (imgHeight % charHeight); + + BufferedImage newimg = new BufferedImage(imgWidth, imgHeight, + BufferedImage.TYPE_INT_ARGB); + + gg = (Graphics2D) newimg.getGraphics(); + gg.setFont(av.getFont()); + gg.drawImage(img, null, 0, 0); + img = newimg; + + transX = (er - horizontal - sr) * charWidth; + sr = er - horizontal - sr; } - else if (vertical > 0) // scroll down + else { - ss = es - vertical; + gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth, + imgHeight, -horizontal * charWidth, -vertical * charHeight); - if (ss < ranges.getStartSeq()) - { // ie scrolling too fast, more than a page at a time - ss = ranges.getStartSeq(); + if (horizontal > 0) // scrollbar pulled right, image to the left + { + transX = (er - sr - horizontal) * charWidth; + sr = er - horizontal; } - else + else if (horizontal < 0) { - transY = imgHeight - ((vertical + 1) * charHeight); + er = sr - horizontal; } - } - else if (vertical < 0) - { - es = ss - vertical; + else if (vertical > 0) // scroll down + { + ss = es - vertical; - if (es > ranges.getEndSeq()) + if (ss < ranges.getStartSeq()) + { // ie scrolling too fast, more than a page at a time + ss = ranges.getStartSeq(); + } + else + { + transY = imgHeight - ((vertical + 1) * charHeight); + } + } + else if (vertical < 0) { - es = ranges.getEndSeq(); + es = ss - vertical; + + if (es > ranges.getEndSeq()) + { + es = ranges.getEndSeq(); + } } } @@ -1005,16 +1028,18 @@ public class SeqCanvas extends JComponent implements ViewportListenerI { scrollX = vpRanges.getStartRes() - vpRanges.getEndRes(); } - fastPaint(scrollX, 0); + fastPaint(scrollX, 0, false); } else if (evt.getPropertyName().equals("endres")) { // resize - only endres changes + int scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); + fastPaint(scrollX, 0, true); } else if (evt.getPropertyName().equals("startseq")) { // scroll - fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue()); + fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue(), false); } else if (evt.getPropertyName().equals("endseq")) { -- 1.7.10.2