From 60ee9fb76ea07566ece5c3455a1abedfff467354 Mon Sep 17 00:00:00 2001 From: kiramt Date: Wed, 16 Aug 2017 16:34:32 +0100 Subject: [PATCH] JAL-2665 Added hidden columns group selection - almost working --- src/jalview/datamodel/SequenceGroup.java | 9 ++- src/jalview/gui/SeqCanvas.java | 110 +++++++++++++++++++++++------- 2 files changed, 91 insertions(+), 28 deletions(-) diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 06cdec4..8ece1e5 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -517,10 +517,9 @@ public class SequenceGroup implements AnnotatedCollectionI { if (s != null && !sequences.contains(s)) { - List before = sequences; sequences.add(s); - changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, - sequences); + changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, + sequences.size() - 1, sequences.size()); } if (recalc) @@ -715,8 +714,8 @@ public class SequenceGroup implements AnnotatedCollectionI { List before = sequences; sequences.remove(s); - changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, - sequences); + changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, + sequences.size() + 1, sequences.size()); if (recalc) { diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 9b6c298..318d74d 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -357,7 +357,10 @@ public class SeqCanvas extends JComponent implements ViewportListenerI // selectImage will hold any selection we have // lcimg is a local *copy* of img which we'll draw selectImage on top of - BufferedImage selectImage = drawSelectionGroup(); + ViewportRanges ranges = av.getRanges(); + BufferedImage selectImage = drawSelectionGroup( + av.getRanges().getStartRes(), av.getRanges().getEndRes(), + ranges.getStartSeq(), ranges.getEndSeq()); if (fastPaint || (getVisibleRect().width != g.getClipBounds().width) || (getVisibleRect().height != g.getClipBounds().height)) @@ -401,7 +404,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI gg.setColor(Color.white); gg.fillRect(0, 0, img.getWidth(), img.getHeight()); - ViewportRanges ranges = av.getRanges(); if (av.getWrapAlignment()) { drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes()); @@ -1029,12 +1031,14 @@ public class SeqCanvas extends JComponent implements ViewportListenerI } + /* * Draw the selection group as a separate image and overlay */ - private BufferedImage drawSelectionGroup() + private BufferedImage drawSelectionGroup(int startRes, int endRes, + int startSeq, int endSeq) { - // get a new image of the correct size + // get a new image of the correct size BufferedImage selectionImage = setupImage(); if (selectionImage == null) @@ -1049,6 +1053,84 @@ public class SeqCanvas extends JComponent implements ViewportListenerI return null; } + // set up drawing colour + Graphics2D g = (Graphics2D) selectionImage.getGraphics(); + 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()); + + g.setComposite(AlphaComposite.Src); + g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_ROUND, 3f, new float[] + { 5f, 3f }, 0f)); + g.setColor(Color.RED); + + if (!av.hasHiddenColumns()) + { + drawSelectionGroupPart(g, group, startRes, endRes, startSeq, endSeq); + } + 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; + + for (int[] region : av.getAlignment().getHiddenColumns() + .getHiddenColumnsCopy()) + { + int hideStart = region[0]; + int hideEnd = region[1]; + + if (hideStart <= blockStart) + { + blockStart += (hideEnd - hideStart) + 1; + continue; + } + + blockEnd = hideStart - 1; + + g.translate(screenY * charWidth, 0); + + drawSelectionGroupPart(g, group, + blockStart, blockEnd, startSeq, endSeq); + + g.translate(-screenY * charWidth, 0); + screenY += blockEnd - blockStart + 1; + blockStart = hideEnd + 1; + + if (screenY > (endRes - startRes)) + { + // already rendered last block + break; + } + } + + if (screenY <= (endRes - startRes)) + { + // remaining visible region to render + blockEnd = blockStart + (endRes - startRes) - screenY; + g.translate(screenY * charWidth, 0); + drawSelectionGroupPart(g, group, + blockStart, blockEnd, startSeq, endSeq); + + g.translate(-screenY * charWidth, 0); + } + } + g.translate(-LABEL_WEST, 0); + return selectionImage; + } + + /* + * 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) + { // set up values in case the alignment is wrapped int verticalOffset = 0; int horizontalOffset = 0; @@ -1075,23 +1157,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI horizontalOffset = (slice * cWidth); } - // set up drawing colour - Graphics2D g = (Graphics2D) selectionImage.getGraphics(); - 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()); - - g.setComposite(AlphaComposite.Src); - g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, - BasicStroke.JOIN_ROUND, 3f, new float[] - { 5f, 3f }, 0f)); - g.setColor(Color.RED); - int visWidth = av.getRanges().getViewportWidth() * charWidth; - int startRes = av.getRanges().getStartRes(); - // set x start and end positions of group int startx = (group.getStartRes() - startRes - horizontalOffset) * charWidth; @@ -1105,8 +1172,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI int bottom = -1; // get sequences to determine y positions of group - int startSeq = av.getRanges().getStartSeq(); - for (i = startSeq; i <= av.getRanges().getEndSeq(); ++i) + for (i = startSeq; i <= endSeq; ++i) { int sy = verticalOffset + (i - startSeq) * charHeight; @@ -1204,8 +1270,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI inGroup = false; } - g.translate(-LABEL_WEST, 0); - return selectionImage; } /** -- 1.7.10.2