From f3e508a23709b6737c0233d739a78a5097c84569 Mon Sep 17 00:00:00 2001 From: kiramt Date: Thu, 17 Aug 2017 11:23:51 +0100 Subject: [PATCH] JAL-2665 partial fix for selection running over 2 wrapped panels --- src/jalview/gui/SeqCanvas.java | 94 +++++++++++++++++++++++++++++++++------- src/jalview/gui/SeqPanel.java | 2 - 2 files changed, 79 insertions(+), 17 deletions(-) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 0b0166b..bd214f5 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -683,6 +683,52 @@ public class SeqCanvas extends JComponent implements ViewportListenerI } } + public void drawWrappedSelection(Graphics2D g, SequenceGroup group, + int canvasWidth, + int canvasHeight, int startRes) + { + int hgap = charHeight; + if (av.getScaleAboveWrapped()) + { + hgap += charHeight; + } + + int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / charWidth; + int cHeight = av.getAlignment().getHeight() * charHeight; + + int endx; + int ypos = hgap; + int maxwidth = av.getAlignment().getWidth(); + + if (av.hasHiddenColumns()) + { + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth); + } + + while ((ypos <= canvasHeight) && (startRes < maxwidth)) + { + endx = startRes + cWidth - 1; + + if (endx > maxwidth) + { + endx = maxwidth; + } + + g.translate(LABEL_WEST, 0); + + drawUnwrappedSelection(g, group, startRes, endx, 0, + av.getAlignment().getHeight() - 1, + ypos); + + g.translate(-LABEL_WEST, 0); + + ypos += cHeight + getAnnotationHeight() + hgap; + + startRes += cWidth; + } + } + AnnotationPanel annotations; int getAnnotationHeight() @@ -1053,15 +1099,15 @@ public class SeqCanvas extends JComponent implements ViewportListenerI return null; } - if (!av.getWrapAlignment()) + /*if (!av.getWrapAlignment()) { LABEL_EAST = 0; LABEL_WEST = 0; - } + }*/ // set up drawing colour Graphics2D g = (Graphics2D) selectionImage.getGraphics(); - g.translate(LABEL_WEST, 0); + // g.translate(LABEL_WEST, 0); // set background to transparent g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f)); g.fillRect(0, 0, selectionImage.getWidth(), selectionImage.getHeight()); @@ -1072,9 +1118,28 @@ public class SeqCanvas extends JComponent implements ViewportListenerI { 5f, 3f }, 0f)); g.setColor(Color.RED); + if (!av.getWrapAlignment()) + { + drawUnwrappedSelection(g, group, startRes, endRes, startSeq, endSeq, + 0); + } + else + { + drawWrappedSelection(g, group, getWidth(), getHeight(), + av.getRanges().getStartRes()); + } + + g.dispose(); + return selectionImage; + } + + private void drawUnwrappedSelection(Graphics2D g, SequenceGroup group, + int startRes, int endRes, int startSeq, int endSeq, int offset) + { if (!av.hasHiddenColumns()) { - drawSelectionGroupPart(g, group, startRes, endRes, startSeq, endSeq); + drawSelectionGroupPart(g, group, startRes, endRes, startSeq, endSeq, + offset); } else { @@ -1100,7 +1165,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI g.translate(screenY * charWidth, 0); drawSelectionGroupPart(g, group, - blockStart, blockEnd, startSeq, endSeq); + blockStart, blockEnd, startSeq, endSeq, offset); g.translate(-screenY * charWidth, 0); screenY += blockEnd - blockStart + 1; @@ -1119,24 +1184,23 @@ public class SeqCanvas extends JComponent implements ViewportListenerI blockEnd = blockStart + (endRes - startRes) - screenY; g.translate(screenY * charWidth, 0); drawSelectionGroupPart(g, group, - blockStart, blockEnd, startSeq, endSeq); + blockStart, blockEnd, startSeq, endSeq, offset); g.translate(-screenY * charWidth, 0); } } - g.translate(-LABEL_WEST, 0); - g.dispose(); - return selectionImage; + // g.translate(-LABEL_WEST, 0); } /* * Draw the selection group as a separate image and overlay */ private void drawSelectionGroupPart(Graphics2D g, SequenceGroup group, - int startRes, int endRes, int startSeq, int endSeq) + int startRes, int endRes, int startSeq, int endSeq, + int verticalOffset) { // set up values in case the alignment is wrapped - int verticalOffset = 0; + /*int verticalOffset = 0; int horizontalOffset = 0; if (av.getWrapAlignment()) { @@ -1155,11 +1219,11 @@ public class SeqCanvas extends JComponent implements ViewportListenerI // 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); - } + }*/ int visWidth = (endRes - startRes + 1) * charWidth; @@ -1174,10 +1238,10 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int ex = -1; // position of start residue of group relative to startRes, in pixels - sx = (group.getStartRes() - startRes - horizontalOffset) * charWidth; + sx = (group.getStartRes() - startRes) * charWidth; // width of group in pixels - ex = (((group.getEndRes() + 1) - group.getStartRes() - horizontalOffset) + ex = (((group.getEndRes() + 1) - group.getStartRes()) * charWidth) - 1; for (i = startSeq; i <= endSeq; i++) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 25fce62..5dbd778 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1947,8 +1947,6 @@ public class SeqPanel extends JPanel implements MouseListener, { scrollThread.setEvent(evt); } - - // seqCanvas.repaint(); } void scrollCanvas(MouseEvent evt) -- 1.7.10.2