From 2fd908578cc00b0315504af557adf1366e4ac34a Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 4 Oct 2007 16:32:06 +0000 Subject: [PATCH] refactored invertColumnSelection as an object method --- src/jalview/datamodel/ColumnSelection.java | 38 +++++++++++++++++++++++++--- src/jalview/gui/AlignViewport.java | 18 +++---------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 73b7899..6cba6b3 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -962,10 +962,15 @@ public class ColumnSelection blockEnd = end; } - if (end > blockStart) + if (end >= blockStart) { - annels.addElement(els = new Annotation[end-blockStart]); - System.arraycopy(alignmentAnnotation.annotations, blockStart, els, 0, els.length); + annels.addElement(els = new Annotation[end-blockStart+1]); + if (end-blockStart+1<=alignmentAnnotation.annotations.length) + { + System.arraycopy(alignmentAnnotation.annotations, blockStart, els, 0, els.length); + } else { + System.arraycopy(alignmentAnnotation.annotations, blockStart, els, 0, (end-blockStart+1)); + } w+=els.length; } if (w==0) @@ -979,6 +984,33 @@ public class ColumnSelection System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w, chnk.length); w+=chnk.length; } + } else { + alignmentAnnotation.restrict(start, end); + } + } + + /** + * Invert the column selection from first to end-1. + * leaves hiddenColumns untouched (and unselected) + * @param first + * @param end + */ + public void invertColumnSelection(int first, int width) + { + boolean hasHidden = hiddenColumns!=null && hiddenColumns.size()>0; + for(int i=first; i