From b836aae53d015cbbac0da38920299d075c874a95 Mon Sep 17 00:00:00 2001 From: kiramt Date: Wed, 16 Aug 2017 12:20:16 +0100 Subject: [PATCH] JAL-2665 fix resize --- src/jalview/gui/SeqCanvas.java | 60 +++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 3626383..6f63dd6 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -296,8 +296,9 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int transX = 0; int transY = 0; - gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth, - imgHeight, -horizontal * charWidth, -vertical * charHeight); + gg.copyArea(horizontal * charWidth, vertical * charHeight, + img.getWidth(), img.getHeight(), -horizontal * charWidth, + -vertical * charHeight); if (horizontal > 0) // scrollbar pulled right, image to the left { @@ -318,7 +319,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI } else { - transY = imgHeight - ((vertical + 1) * charHeight); + transY = img.getHeight() - ((vertical + 1) * charHeight); } } else if (vertical < 0) @@ -360,15 +361,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI // selectImage will hold any selection we have // lcimg is a local *copy* of img which we'll draw selectImage on top of - if (img == null) - { - setupImage(); - } - if (img == null) - { - return; - } - BufferedImage selectImage = drawSelectionGroup(); if (fastPaint || (getVisibleRect().width != g.getClipBounds().width) @@ -380,6 +372,29 @@ public class SeqCanvas extends JComponent implements ViewportListenerI fastPaint = false; return; } + + int width = getWidth(); + int height = getHeight(); + + width -= (width % charWidth); + height -= (height % charHeight); + + if ((width < 1) || (height < 1)) + { + return; + } + + if (img == null || width != img.getWidth() || height != img.getHeight()) + { + img = setupImage(); + gg = (Graphics2D) img.getGraphics(); + gg.setFont(av.getFont()); + } + if (img == null) + { + return; + } + if (av.antiAlias) { @@ -388,7 +403,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI } gg.setColor(Color.white); - gg.fillRect(0, 0, imgWidth, imgHeight); + gg.fillRect(0, 0, img.getWidth(), img.getHeight()); ViewportRanges ranges = av.getRanges(); if (av.getWrapAlignment()) @@ -435,21 +450,20 @@ public class SeqCanvas extends JComponent implements ViewportListenerI repaint(); } - private void setupImage() + /*private void setupImage() { // this draws the whole of the alignment imgWidth = getWidth(); imgHeight = getHeight(); - + imgWidth -= (imgWidth % charWidth); imgHeight -= (imgHeight % charHeight); - + if ((imgWidth < 1) || (imgHeight < 1)) { return; } - - + try { img = new BufferedImage(imgWidth, imgHeight, @@ -461,13 +475,13 @@ public class SeqCanvas extends JComponent implements ViewportListenerI System.gc(); System.err.println("SeqCanvas OutOfMemory Redraw Error.\n" + er); new OOMWarning("Creating alignment image for display", er); - + return; } + + }*/ - } - - private BufferedImage setupSelectionImage() + private BufferedImage setupImage() { BufferedImage lcimg = null; @@ -1056,7 +1070,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI private BufferedImage drawSelectionGroup() { // get a new image of the correct size - BufferedImage selectionImage = setupSelectionImage(); + BufferedImage selectionImage = setupImage(); if (selectionImage == null) { -- 1.7.10.2