From 467af4486bf57121f72a3e1d3c82dc72cbfd3a6b Mon Sep 17 00:00:00 2001 From: kiramt Date: Wed, 16 Aug 2017 20:53:45 +0100 Subject: [PATCH] JAL-2665 Working with hidden columns --- src/jalview/gui/SeqCanvas.java | 95 ++++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 33 deletions(-) diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 318d74d..9bd38c5 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -1073,9 +1073,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI else { // package into blocks of visible columns - // Graphics2D g = (Graphics2D) selectionImage.getGraphics(); - // Graphics g1 = selectionImage.getGraphics(); - int screenY = 0; int blockStart = startRes; int blockEnd = endRes; @@ -1117,7 +1114,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI g.translate(screenY * charWidth, 0); drawSelectionGroupPart(g, group, blockStart, blockEnd, startSeq, endSeq); - + g.translate(-screenY * charWidth, 0); } } @@ -1157,13 +1154,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI horizontalOffset = (slice * cWidth); } - int visWidth = av.getRanges().getViewportWidth() * charWidth; - - // set x start and end positions of group - int startx = (group.getStartRes() - startRes - horizontalOffset) - * charWidth; - int endx = (group.getEndRes() - startRes + 1 - horizontalOffset) - * charWidth; + int visWidth = (endRes - startRes + 1) * charWidth; int oldY = -1; int i = 0; @@ -1171,13 +1162,29 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int top = -1; int bottom = -1; - // get sequences to determine y positions of group - for (i = startSeq; i <= endSeq; ++i) + int sx = -1; + int sy = -1; + int ex = -1; + + // position of start residue of group relative to startRes, in pixels + sx = (group.getStartRes() - startRes - horizontalOffset) * charWidth; + + // width of group in pixels + ex = (((group.getEndRes() + 1) - group.getStartRes() - horizontalOffset) + * charWidth) - 1; + + for (i = startSeq; i <= endSeq; i++) { - int sy = verticalOffset + (i - startSeq) * charHeight; + sy = verticalOffset + (i - startSeq) * charHeight; - if (group.getSequences(null) - .contains(av.getAlignment().getSequenceAt(i))) + if (sx + ex < 0 || sx > visWidth) + { + continue; + } + + if ((sx <= (endRes - startRes) * charWidth) + && group.getSequences(null) + .contains(av.getAlignment().getSequenceAt(i))) { if ((bottom == -1) && !group.getSequences(null) .contains(av.getAlignment().getSequenceAt(i + 1))) @@ -1203,34 +1210,45 @@ public class SeqCanvas extends JComponent implements ViewportListenerI { // if start position is visible, draw vertical line to left of // group - if (startx >= 0 && startx < visWidth * charWidth) + if (sx >= 0 && sx < visWidth) { - g.drawLine(startx, oldY, startx, sy); + g.drawLine(sx, oldY, sx, sy); } // if end position is visible, draw vertical line to right of // group - if (endx <= visWidth * charWidth) + if (sx + ex < visWidth) + { + g.drawLine(sx + ex, oldY, sx + ex, sy); + } + + if (sx < 0) { - g.drawLine(endx, oldY, endx, sy); + ex += sx; + sx = 0; } - if (endx > visWidth * charWidth) + if (sx + ex > visWidth) { - endx = visWidth * charWidth; + ex = visWidth; + } + + else if (sx + ex >= (endRes - startRes + 1) * charWidth) + { + ex = (endRes - startRes + 1) * charWidth; } // draw horizontal line at top of group if (top != -1) { - g.drawLine(startx, top, endx, top); + g.drawLine(sx, top, sx + ex, top); top = -1; } // draw horizontal line at bottom of group if (bottom != -1) { - g.drawLine(startx, bottom, endx, bottom); + g.drawLine(sx, bottom, sx + ex, bottom); bottom = -1; } @@ -1238,33 +1256,44 @@ public class SeqCanvas extends JComponent implements ViewportListenerI } } } + if (inGroup) { - int sy = verticalOffset + (i - startSeq) * charHeight; - if (startx >= 0 && startx < visWidth) + sy = verticalOffset + ((i - startSeq) * charHeight); + if (sx >= 0 && sx < visWidth) { - g.drawLine(startx, oldY, startx, sy); + g.drawLine(sx, oldY, sx, sy); } - if (endx < visWidth) + if (sx + ex < visWidth) { - g.drawLine(endx, oldY, endx, sy); + g.drawLine(sx + ex, oldY, sx + ex, sy); } - if (endx > visWidth) + if (sx < 0) + { + ex += sx; + sx = 0; + } + + if (sx + ex > visWidth) + { + ex = visWidth; + } + else if (sx + ex >= (endRes - startRes + 1) * charWidth) { - endx = visWidth; + ex = (endRes - startRes + 1) * charWidth; } if (top != -1) { - g.drawLine(startx, top, endx, top); + g.drawLine(sx, top, sx + ex, top); top = -1; } if (bottom != -1) { - g.drawLine(startx, bottom - 1, endx, bottom - 1); + g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); bottom = -1; } -- 1.7.10.2