From 1e968e44cb033e74e9f81d7140b5393f8ad6e305 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Mon, 5 Feb 2007 14:40:03 +0000 Subject: [PATCH] Fixed bug in trim right annotation adjust --- src/jalview/commands/EditCommand.java | 58 +++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index 7effdfb..1d4880a 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -366,6 +366,8 @@ public class EditCommand implements CommandI continue; } + int tSize = 0; + aSize = annotations[a].annotations.length; if(insert) temp = new Annotation[aSize + command.number]; @@ -373,13 +375,19 @@ public class EditCommand implements CommandI { if(command.position 0) - temp = new Annotation[aSize - command.number + command.position]; + if(command.position+command.number>aSize) + tSize = aSize; else - temp = new Annotation[aSize]; + tSize = aSize - command.number + command.position; } else - temp = new Annotation[aSize]; + tSize = aSize; + + if(tSize<0) + tSize = aSize; + + temp = new Annotation[tSize]; + } if(insert) @@ -410,11 +418,28 @@ public class EditCommand implements CommandI aSize - command.position); } else - temp = annotations[a].annotations; + { + if (command.deletedAnnotations != null + && + command.deletedAnnotations.containsKey(annotations[a].annotationId)) + { + Annotation[] restore = (Annotation[]) + command.deletedAnnotations.get(annotations[a].annotationId); + + temp = new Annotation[annotations[a].annotations.length+ + restore.length]; + System.arraycopy(annotations[a].annotations, + 0,temp,0, + annotations[a].annotations.length); + System.arraycopy(restore,0,temp,annotations[a].annotations.length,restore.length); + } + else + temp = annotations[a].annotations; + } } else { - if(command.position < aSize && aSize - command.number+command.position>0) + if(tSize!=aSize) { System.arraycopy(annotations[a].annotations, 0, temp, 0, command.position); @@ -432,7 +457,26 @@ public class EditCommand implements CommandI aSize - command.position - command.number); } else - temp = annotations[a].annotations; + { + int dSize = aSize - command.position; + + if(dSize>0) + { + Annotation[] deleted = new Annotation[command.number]; + System.arraycopy(annotations[a].annotations, + command.position, deleted, 0, dSize); + + command.deletedAnnotations.put(annotations[a].annotationId, + deleted); + + tSize = Math.min(annotations[a].annotations.length, command.position); + temp = new Annotation[tSize]; + System.arraycopy(annotations[a].annotations, + 0, temp, 0, tSize); + } + else + temp = annotations[a].annotations; + } } annotations[a].annotations = temp; -- 1.7.10.2