Sequence colour moved to viewport
[jalview.git] / src / jalview / datamodel / CigarArray.java
index b8cdf52..9b60e56 100644 (file)
@@ -1,3 +1,21 @@
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
 package jalview.datamodel;\r
 \r
 public class CigarArray extends CigarBase\r
@@ -118,7 +136,7 @@ public class CigarArray extends CigarBase
    * applyDeletions\r
    * edits underlying refCigars to propagate deleted regions, and removes deletion\r
    * operations from CigarArray operation list.\r
-   * @return int[] position where deletion occured in cigarArray or null if none occured\r
+   * @return int[] position after deletion occured and range of deletion in cigarArray or null if none occured\r
    */\r
   public int[] applyDeletions()\r
   {\r
@@ -127,31 +145,45 @@ public class CigarArray extends CigarBase
       return null;\r
     int cursor=0; // range counter for deletions\r
     int vcursor=0; // visible column index\r
-    for (int i=0; i<length; i++) {\r
+    int offset=0; // shift in visible column index as deletions are made\r
+    int i=0;\r
+    while (i<length) {\r
       if (operation[i]!=D) {\r
         if (operation[i]==M)\r
           cursor+=range[i];\r
-        vcursor+=range[i];\r
+        vcursor+=range[i++];\r
       }\r
       else\r
       {\r
         if (delpos==null)\r
           delpos=new java.util.Vector();\r
         int delstart=cursor, delend=cursor+range[i]-1; // inclusive\r
-        delpos.addElement(new Integer(vcursor-1)); // index of left hand column of hidden region boundary\r
+        delpos.addElement(new int[] { vcursor+offset, range[i]}); // index of right hand column after hidden region boundary\r
+        offset+=range[i]-1; // shift in visible column coordinates\r
         System.arraycopy(operation, i+1, operation, i, length-i);\r
         System.arraycopy(range, i+1, range, i, length-i);\r
         length--;\r
+        /*        int dmax=0;\r
+         for (int s=0; s<refCigars.length; s++) {\r
+           int d = refCigars[s].deleteRange(delstart, delend);\r
+           if (d>dmax)\r
+             dmax=d;\r
+         }\r
+         offset+=dmax; // shift in visible column coordinates\r
+         */\r
         for (int s=0; s<refCigars.length; s++) {\r
-          refCigars[s].deleteRange(delstart, delend);\r
+          int d = refCigars[s].deleteRange(delstart, delend);\r
         }\r
+\r
       }\r
     }\r
     if (delpos!=null)\r
     {\r
-      int[] pos=new int[delpos.size()];\r
+      int[] pos=new int[delpos.size()*2];\r
       for (int k = 0, l = delpos.size(); k < l; k++) {\r
-        pos[k] = ((Integer) delpos.elementAt(k)).intValue();\r
+        int[] dr = ((int[]) delpos.elementAt(k));\r
+        pos[k*2] = dr[0];\r
+        pos[k*2+1] = dr[1];\r
         delpos.setElementAt(null,k);\r
       }\r
       delpos=null;\r