From: kiramt Date: Wed, 16 Aug 2017 11:20:16 +0000 (+0100) Subject: JAL-2665 fix resize X-Git-Tag: Release_2_10_3b1~140^2~18 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b836aae53d015cbbac0da38920299d075c874a95;p=jalview.git JAL-2665 fix resize --- 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) {