From 5eec5a0f366f2a00c7064e175ec86e1acb4afc6a Mon Sep 17 00:00:00 2001 From: hansonr Date: Thu, 18 Apr 2019 09:32:42 -0500 Subject: [PATCH] hack for fastpaint Java bug upshifting one line after a sequence selection paste. Covered in Java by a full paint by ConsensusThread. --- src/jalview/appletgui/AlignmentPanel.java | 1 + src/jalview/gui/AlignmentPanel.java | 7 +- src/jalview/gui/SeqCanvas.java | 142 +++++++++++++++++------------ 3 files changed, 90 insertions(+), 60 deletions(-) diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index 58569cd..edb9522 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -916,6 +916,7 @@ public class AlignmentPanel extends Panel av.isShowAutocalculatedAbove()); sorter.sort(getAlignment().getAlignmentAnnotation(), av.getSortAnnotationsBy()); + this.seqPanel.seqCanvas.clearFastPaint(); repaint(); if (updateStructures) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index f27b9b7..4e5e72b 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -731,7 +731,6 @@ public class AlignmentPanel extends GAlignmentPanel implements } ranges.setViewportStartAndHeight(y, height); } - seqPanel.seqCanvas.clearFastPaint(); repaint(); } @@ -811,6 +810,12 @@ public class AlignmentPanel extends GAlignmentPanel implements av.isShowAutocalculatedAbove()); sorter.sort(getAlignment().getAlignmentAnnotation(), av.getSortAnnotationsBy()); + // BH 2019.04.18 this should not be necessary, but + // there is something wrong with the fast painting + // in that there is a -1 shift that should not be there. + // It is being covered in Java by the Consensus and Conservation + // threads forcing a full repaint after pasting. + seqPanel.seqCanvas.clearFastPaint(); repaint(); if (updateStructures) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 1851200..ad00e1e 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -38,6 +38,7 @@ import java.awt.Color; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.beans.PropertyChangeEvent; @@ -276,6 +277,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI *
  • scrolling by trackpad, middle mouse button, or other device
  • *
  • by moving the box in the Overview window
  • *
  • programmatically to make a highlighted position visible
  • + *
  • pasting a block of sequences
  • * * * @param horizontal @@ -285,7 +287,12 @@ public class SeqCanvas extends JPanel implements ViewportListenerI */ public void fastPaint(int horizontal, int vertical) { - if (fastpainting || img == null) + // System.err.println("< 0) // scrollbar pulled right, image to the left { @@ -342,11 +344,23 @@ public class SeqCanvas extends JPanel implements ViewportListenerI } } + + // System.err.println(">>> FastPaint to " + transX + " " + transY + " " + // + horizontal + " " + vertical + " " + startRes + " " + endRes + // + " " + startSeq + " " + endSeq); + + Graphics gg = img.getGraphics(); + gg.copyArea(horizontal * charWidth, vertical * charHeight, + img.getWidth(), img.getHeight(), -horizontal * charWidth, + -vertical * charHeight); + + /** @j2sNative xxi = this.img */ + gg.translate(transX, transY); drawPanel(gg, startRes, endRes, startSeq, endSeq, 0); gg.translate(-transX, -transY); gg.dispose(); - + // Call repaint on alignment panel so that repaints from other alignment // panel components can be aggregated. Otherwise performance of the // overview window and others may be adversely affected. @@ -360,35 +374,50 @@ public class SeqCanvas extends JPanel implements ViewportListenerI @Override public void paintComponent(Graphics g) { - //super.paintComponent(g); // BH 2019 - int charHeight = av.getCharHeight(); int charWidth = av.getCharWidth(); - ViewportRanges ranges = av.getRanges(); - int width = getWidth(); int height = getHeight(); width -= (width % charWidth); height -= (height % charHeight); - if ((img != null) && (fastPaint - || (getVisibleRect().width != g.getClipBounds().width) - || (getVisibleRect().height != g.getClipBounds().height))) + // BH 2019 can't possibly fastPaint if width and height are 0 + if (width == 0 || height == 0) { - g.drawImage(img, 0, 0, this); - - drawSelectionGroup((Graphics2D) g, ranges.getStartRes(), - ranges.getEndRes(), ranges.getStartSeq(), ranges.getEndSeq()); + return; + } + ViewportRanges ranges = av.getRanges(); + int startRes = ranges.getStartRes(); + int startSeq = ranges.getStartSeq(); + int endRes = ranges.getEndRes(); + int endSeq = ranges.getEndSeq(); + + // System.err.println(">>SeqCanvas paintComponent " + fastPaint + "\n" + // + getVisibleRect() + "\n" + g.getClipBounds()); + // System.err.println(">>>>>>>>>>>>>>>>SeqCanvas paintComponent " + // + startRes + " " + endRes + " " + startSeq + " " + endSeq); + Rectangle vis, clip; + if (img != null + && (fastPaint + || (vis = getVisibleRect()).width != (clip = g + .getClipBounds()).width + || vis.height != clip.height)) + { + g.drawImage(img, 0, 0, this); + // System.err.println(">>>>>>>>>>>>>>>>SeqCanvas paintComponent FAST"); + drawSelectionGroup((Graphics2D) g, startRes, endRes, startSeq, + endSeq); fastPaint = false; } - else if (width > 0 && height > 0) + else { + /* - * img is a cached version of the last view we drew, if any - * if we have no img or the size has changed, make a new one + * img is a cached version of the last view we drew. + * If we have no img or the size has changed, make a new one */ if (img == null || width != img.getWidth() || height != img.getHeight()) @@ -410,16 +439,14 @@ public class SeqCanvas extends JPanel implements ViewportListenerI if (av.getWrapAlignment()) { - drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes()); + drawWrappedPanel(gg, width, height, ranges.getStartRes()); } else { - drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(), - ranges.getStartSeq(), ranges.getEndSeq(), 0); + drawPanel(gg, startRes, endRes, startSeq, endSeq, 0); } - drawSelectionGroup(gg, ranges.getStartRes(), - ranges.getEndRes(), ranges.getStartSeq(), ranges.getEndSeq()); + drawSelectionGroup(gg, startRes, endRes, startSeq, endSeq); g.drawImage(img, 0, 0, this); gg.dispose(); @@ -427,8 +454,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI if (av.cursorMode) { - drawCursor(g, ranges.getStartRes(), ranges.getEndRes(), - ranges.getStartSeq(), ranges.getEndSeq()); + drawCursor(g, startRes, endRes, startSeq, endSeq); } } @@ -1636,7 +1662,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI public void propertyChange(PropertyChangeEvent evt) { String eventName = evt.getPropertyName(); - + // System.err.println(">>SeqCanvas propertyChange " + eventName); if (eventName.equals(SequenceGroup.SEQ_GROUP_CHANGED)) { fastPaint = true; @@ -1646,6 +1672,7 @@ public class SeqCanvas extends JPanel implements ViewportListenerI else if (eventName.equals(ViewportRanges.MOVE_VIEWPORT)) { fastPaint = false; + // System.err.println("!!!! fastPaint false from MOVE_VIEWPORT"); repaint(); return; } @@ -1677,37 +1704,37 @@ public class SeqCanvas extends JPanel implements ViewportListenerI scrollX = -range; } } - // Both scrolling and resizing change viewport ranges: scrolling changes - // both start and end points, but resize only changes end values. - // Here we only want to fastpaint on a scroll, with resize using a normal - // paint, so scroll events are identified as changes to the horizontal or - // vertical start value. - if (eventName.equals(ViewportRanges.STARTRES)) + // Both scrolling and resizing change viewport ranges: scrolling changes + // both start and end points, but resize only changes end values. + // Here we only want to fastpaint on a scroll, with resize using a normal + // paint, so scroll events are identified as changes to the horizontal or + // vertical start value. + if (eventName.equals(ViewportRanges.STARTRES)) + { + if (av.getWrapAlignment()) { - if (av.getWrapAlignment()) - { - fastPaintWrapped(scrollX); - } - else - { - fastPaint(scrollX, 0); - } + fastPaintWrapped(scrollX); + } + else + { + fastPaint(scrollX, 0); } - else if (eventName.equals(ViewportRanges.STARTSEQ)) + } + else if (eventName.equals(ViewportRanges.STARTSEQ)) + { + // scroll + fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue()); + } + else if (eventName.equals(ViewportRanges.STARTRESANDSEQ)) + { + if (av.getWrapAlignment()) { - // scroll - fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue()); + fastPaintWrapped(scrollX); } - else if (eventName.equals(ViewportRanges.STARTRESANDSEQ)) + else { - if (av.getWrapAlignment()) - { - fastPaintWrapped(scrollX); - } - else - { - fastPaint(scrollX, 0); - } + fastPaint(scrollX, 0); + } } else if (eventName.equals(ViewportRanges.STARTSEQ)) { @@ -1754,9 +1781,6 @@ public class SeqCanvas extends JPanel implements ViewportListenerI fastPaint = true; fastpainting = true; - System.out - .println("fastpaintwrapped fastpainting true; fastPaint=" - + fastPaint); try { -- 1.7.10.2