From 3dfe7249d7b369536e3e151c7e7b44c0d4d1458e Mon Sep 17 00:00:00 2001 From: kiramt Date: Wed, 16 Aug 2017 15:51:55 +0100 Subject: [PATCH] JAL-2665 Selecting on wrapped alignments --- src/jalview/gui/SeqCanvas.java | 44 ++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 558c1ca..9b6c298 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -1034,17 +1034,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI */ private BufferedImage drawSelectionGroup() { - int verticalOffset = 0; - if (av.getWrapAlignment()) - { - verticalOffset = charHeight; - if (av.getScaleAboveWrapped()) - { - verticalOffset += charHeight; - } - } - - // get a new image of the correct size + // get a new image of the correct size BufferedImage selectionImage = setupImage(); if (selectionImage == null) @@ -1058,6 +1048,32 @@ public class SeqCanvas extends JComponent implements ViewportListenerI // nothing to draw return null; } + + // set up values in case the alignment is wrapped + int verticalOffset = 0; + int horizontalOffset = 0; + if (av.getWrapAlignment()) + { + int hgap = charHeight; + if (av.getScaleAboveWrapped()) + { + hgap += charHeight; + } + + // get the start res of the group and work out the offsets for it in the wrapped alignment + int groupstart = group.getStartRes(); + int cWidth = (getWidth() - LABEL_EAST - LABEL_WEST) / charWidth; + + // group is in which slice of alignment? res position / width in residues + int slice = groupstart / cWidth; + // vertical offset is increased by slice number * number of sequences * height of each sequence + verticalOffset = slice * (av.getAlignment().getHeight() * charHeight + + getAnnotationHeight() + hgap) + hgap; + + // horizontal offset is number of residues to subtract from group residue + // position + horizontalOffset = (slice * cWidth); + } // set up drawing colour Graphics2D g = (Graphics2D) selectionImage.getGraphics(); @@ -1077,8 +1093,10 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int startRes = av.getRanges().getStartRes(); // set x start and end positions of group - int startx = (group.getStartRes() - startRes) * charWidth; - int endx = (group.getEndRes() - startRes + 1) * charWidth; + int startx = (group.getStartRes() - startRes - horizontalOffset) + * charWidth; + int endx = (group.getEndRes() - startRes + 1 - horizontalOffset) + * charWidth; int oldY = -1; int i = 0; -- 1.7.10.2