refactored invertColumnSelection as an object method
authorjprocter <Jim Procter>
Thu, 4 Oct 2007 16:32:06 +0000 (16:32 +0000)
committerjprocter <Jim Procter>
Thu, 4 Oct 2007 16:32:06 +0000 (16:32 +0000)
src/jalview/datamodel/ColumnSelection.java
src/jalview/gui/AlignViewport.java

index 73b7899..6cba6b3 100644 (file)
@@ -962,10 +962,15 @@ public class ColumnSelection
           blockEnd = end;\r
         }\r
 \r
-        if (end > blockStart)\r
+        if (end >= blockStart)\r
         {\r
-          annels.addElement(els = new Annotation[end-blockStart]);\r
-          System.arraycopy(alignmentAnnotation.annotations, blockStart, els, 0, els.length);\r
+          annels.addElement(els = new Annotation[end-blockStart+1]);\r
+          if (end-blockStart+1<=alignmentAnnotation.annotations.length)\r
+          {\r
+            System.arraycopy(alignmentAnnotation.annotations, blockStart, els, 0, els.length);\r
+          } else {\r
+            System.arraycopy(alignmentAnnotation.annotations, blockStart, els, 0, (end-blockStart+1));\r
+          }\r
           w+=els.length;\r
         }\r
         if (w==0)\r
@@ -979,6 +984,33 @@ public class ColumnSelection
           System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w, chnk.length);\r
           w+=chnk.length;\r
         }\r
+    } else {\r
+      alignmentAnnotation.restrict(start, end);\r
+    }\r
+  }\r
+\r
+  /**\r
+   * Invert the column selection from first to end-1.\r
+   * leaves hiddenColumns untouched (and unselected)\r
+   * @param first\r
+   * @param end\r
+   */\r
+  public void invertColumnSelection(int first, int width)\r
+  {\r
+    boolean hasHidden = hiddenColumns!=null && hiddenColumns.size()>0;\r
+    for(int i=first; i<width; i++)\r
+    {\r
+      if(contains(i))\r
+    {\r
+        removeElement(i);\r
     }\r
+      else\r
+      {\r
+        if (!hasHidden || isVisible(i))\r
+        {\r
+          addElement(i);\r
+        }\r
+      }\r
+    }    \r
   }\r
 }\r
index 41341d0..afdfd69 100755 (executable)
@@ -1453,20 +1453,7 @@ public class AlignViewport
 
     public void invertColumnSelection()
     {
-      for(int i=0; i<alignment.getWidth(); i++)
-      {
-        if(colSel.contains(i))
-      {
-          colSel.removeElement(i);
-      }
-        else
-        {
-          if (!hasHiddenColumns || colSel.isVisible(i))
-          {
-            colSel.addElement(i);
-          }
-        }
-      }
+      colSel.invertColumnSelection(0,alignment.getWidth());
     }
 
     public int adjustForHiddenSeqs(int alignmentIndex)
@@ -1479,7 +1466,7 @@ public class AlignViewport
      * derived from the whole alignment or just the current
      * selection with start and end points adjusted
      * @note if you need references to the actual SequenceI objects in the alignment or currently selected then use getSequenceSelection()
-     * @return String[]
+     * @return selection as new sequenceI objects
      */
     public SequenceI[] getSelectionAsNewSequence()
     {
@@ -1501,6 +1488,7 @@ public class AlignViewport
 
       return sequences;
     }
+    
     /**
      * get the currently selected sequence objects or all the sequences in the alignment.
      * @return array of references to sequence objects