From bef980d8536bd7da240abcbf357e3ed3b064b523 Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 27 Jun 2017 09:36:37 +0100 Subject: [PATCH] JAL-2600 Add in IdCanvas and checks for 0 size images --- src/jalview/gui/AnnotationPanel.java | 21 +++++++++------- src/jalview/gui/IdCanvas.java | 46 ++++++++++++++++++++++------------ src/jalview/gui/SeqCanvas.java | 33 +++++++++++++----------- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index e98b79e..3dee5a8 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -993,17 +993,20 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes() + 1) * av.getCharWidth(); - BufferedImage newimage = new BufferedImage(imgWidth, - ap.getAnnotationPanel().getHeight(), - BufferedImage.TYPE_INT_ARGB); + if (imgWidth > 0) + { + 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; + 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; + transX = (er - horizontal - sr) * av.getCharWidth(); + sr = er - horizontal - sr; + } } else { diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 5ce36cb..cfbc403 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -153,7 +153,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI * @param vertical * DOCUMENT ME! */ - public void fastPaint(int vertical) + public void fastPaint(int vertical, boolean isresize) { if (gg == null) { @@ -171,26 +171,37 @@ public class IdCanvas extends JPanel implements ViewportListenerI int es = ranges.getEndSeq(); int transY = 0; - if (vertical > 0) // scroll down + if (isresize) { - ss = es - vertical; - - if (ss < ranges.getStartSeq()) - { // ie scrolling too fast, more than a page at a time - ss = ranges.getStartSeq(); - } - else + if (vertical != 0) { transY = imgHeight - ((vertical + 1) * av.getCharHeight()); + ss = es - vertical - ss; } } - else if (vertical < 0) // scroll up + else { - es = ss - vertical; + 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) * av.getCharHeight()); + } + } + else if (vertical < 0) // scroll up { - es = ranges.getEndSeq(); + es = ss - vertical; + + if (es > ranges.getEndSeq()) + { + es = ranges.getEndSeq(); + } } } @@ -524,10 +535,13 @@ public class IdCanvas extends JPanel implements ViewportListenerI public void propertyChange(PropertyChangeEvent evt) { // Respond to viewport range changes (e.g. alignment panel was scrolled) - if (evt.getPropertyName().equals("startseq") - || evt.getPropertyName().equals("endseq")) + if (evt.getPropertyName().equals("startseq")) + { + fastPaint((int) evt.getNewValue() - (int) evt.getOldValue(), false); + } + else if (evt.getPropertyName().equals("endseq")) { - fastPaint((int) evt.getNewValue() - (int) evt.getOldValue()); + fastPaint((int) evt.getNewValue() - (int) evt.getOldValue(), true); } } } diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index fdad32b..f1b473c 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -303,23 +303,26 @@ public class SeqCanvas extends JComponent implements ViewportListenerI imgWidth -= (imgWidth % charWidth); imgHeight -= (imgHeight % charHeight); - BufferedImage newimg = new BufferedImage(imgWidth, imgHeight, - BufferedImage.TYPE_INT_ARGB); + if ((imgWidth > 0) && (imgHeight > 0)) + { + 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; + gg = (Graphics2D) newimg.getGraphics(); + gg.setFont(av.getFont()); + gg.drawImage(img, null, 0, 0); + img = newimg; - if (horizontal != 0) - { - transX = (er - horizontal - sr) * charWidth; - sr = er - horizontal - sr; - } - else if (vertical != 0) - { - transY = imgHeight - ((vertical + 1) * charHeight); - ss = es - vertical - ss; + if (horizontal != 0) + { + transX = (er - horizontal - sr) * charWidth; + sr = er - horizontal - sr; + } + else if (vertical != 0) + { + transY = imgHeight - ((vertical + 1) * charHeight); + ss = es - vertical - ss; + } } } else -- 1.7.10.2