Fixed bug in trim right annotation adjust
authoramwaterhouse <Andrew Waterhouse>
Mon, 5 Feb 2007 14:40:03 +0000 (14:40 +0000)
committeramwaterhouse <Andrew Waterhouse>
Mon, 5 Feb 2007 14:40:03 +0000 (14:40 +0000)
src/jalview/commands/EditCommand.java

index 7effdfb..1d4880a 100644 (file)
@@ -366,6 +366,8 @@ public class EditCommand implements CommandI
           continue;\r
         }\r
 \r
+        int tSize = 0;\r
+\r
         aSize = annotations[a].annotations.length;\r
         if(insert)\r
           temp = new Annotation[aSize + command.number];\r
@@ -373,13 +375,19 @@ public class EditCommand implements CommandI
         {\r
           if(command.position<aSize)\r
           {\r
-            if (aSize - command.number + command.position > 0)\r
-              temp = new Annotation[aSize - command.number + command.position];\r
+            if(command.position+command.number>aSize)\r
+              tSize = aSize;\r
             else\r
-              temp = new Annotation[aSize];\r
+            tSize = aSize - command.number + command.position;\r
           }\r
           else\r
-            temp = new Annotation[aSize];\r
+            tSize = aSize;\r
+\r
+          if(tSize<0)\r
+            tSize = aSize;\r
+\r
+          temp = new Annotation[tSize];\r
+\r
         }\r
 \r
         if(insert)\r
@@ -410,11 +418,28 @@ public class EditCommand implements CommandI
                              aSize - command.position);\r
           }\r
           else\r
-            temp = annotations[a].annotations;\r
+          {\r
+            if (command.deletedAnnotations != null\r
+                           &&\r
+                           command.deletedAnnotations.containsKey(annotations[a].annotationId))\r
+            {\r
+              Annotation[] restore = (Annotation[])\r
+                  command.deletedAnnotations.get(annotations[a].annotationId);\r
+\r
+              temp = new Annotation[annotations[a].annotations.length+\r
+                  restore.length];\r
+              System.arraycopy(annotations[a].annotations,\r
+                               0,temp,0,\r
+                               annotations[a].annotations.length);\r
+              System.arraycopy(restore,0,temp,annotations[a].annotations.length,restore.length);\r
+            }\r
+            else\r
+              temp = annotations[a].annotations;\r
+          }\r
         }\r
         else\r
         {\r
-          if(command.position < aSize &&  aSize - command.number+command.position>0)\r
+          if(tSize!=aSize)\r
           {\r
             System.arraycopy(annotations[a].annotations,\r
                              0, temp, 0, command.position);\r
@@ -432,7 +457,26 @@ public class EditCommand implements CommandI
                              aSize - command.position - command.number);\r
           }\r
           else\r
-            temp = annotations[a].annotations;\r
+          {\r
+            int dSize = aSize - command.position;\r
+\r
+            if(dSize>0)\r
+            {\r
+              Annotation[] deleted = new Annotation[command.number];\r
+              System.arraycopy(annotations[a].annotations,\r
+                               command.position, deleted, 0, dSize);\r
+\r
+              command.deletedAnnotations.put(annotations[a].annotationId,\r
+                                             deleted);\r
+\r
+              tSize = Math.min(annotations[a].annotations.length, command.position);\r
+              temp = new Annotation[tSize];\r
+              System.arraycopy(annotations[a].annotations,\r
+                  0, temp, 0, tSize);\r
+            }\r
+            else\r
+              temp = annotations[a].annotations;\r
+          }\r
         }\r
 \r
         annotations[a].annotations = temp;\r