Adjusts columnSelection correctly
authoramwaterhouse <Andrew Waterhouse>
Wed, 25 Oct 2006 14:00:35 +0000 (14:00 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 25 Oct 2006 14:00:35 +0000 (14:00 +0000)
src/jalview/commands/TrimRegionCommand.java

index 8ada376..5a5dcd1 100644 (file)
@@ -19,8 +19,8 @@
 package jalview.commands;\r
 \r
 import jalview.util.ShiftList;\r
-\r
 import jalview.datamodel.*;\r
+import java.util.Vector;\r
 \r
 public class TrimRegionCommand\r
     extends EditCommand\r
@@ -32,18 +32,26 @@ public class TrimRegionCommand
 \r
   int [] start;\r
 \r
+  ShiftList shiftList;\r
+\r
+  SequenceGroup selectionGroup;\r
+\r
+  Vector deletedHiddenColumns;\r
+\r
   public TrimRegionCommand(String description,\r
                      String command,\r
                      SequenceI[] seqs,\r
                      int column,\r
                      AlignmentI al,\r
-                     ColumnSelection colSel)\r
+                     ColumnSelection colSel,\r
+                     SequenceGroup selectedRegion)\r
   {\r
     this.description = description;\r
+    this.selectionGroup = selectedRegion;\r
+    this.colSel = colSel;\r
     if (command.equalsIgnoreCase(TRIM_LEFT))\r
     {\r
       edits = new Edit[] { new Edit(CUT, seqs, 0, column, al)};\r
-      this.colSel = colSel;\r
     }\r
     else if (command.equalsIgnoreCase(TRIM_RIGHT))\r
     {\r
@@ -68,16 +76,32 @@ public class TrimRegionCommand
     {\r
       if(command.position==0)\r
       {\r
+        //This is a TRIM_LEFT command\r
         column = command.seqs[j].findPosition(command.number);\r
         command.seqs[j].setStart(column);\r
       }\r
       else\r
       {\r
+        //This is a TRIM_RIGHT command\r
         column = command.seqs[j].findPosition(command.position)-1;\r
         command.seqs[j].setEnd(column);\r
       }\r
     }\r
+\r
     super.cut(command);\r
+\r
+    if (command.position == 0)\r
+    {\r
+      deletedHiddenColumns = colSel.compensateForEdit(0, command.number);\r
+      if(selectionGroup!=null)\r
+        selectionGroup.adjustForRemoveLeft(command.number);\r
+    }\r
+    else\r
+    {\r
+      deletedHiddenColumns = colSel.compensateForEdit(command.position, command.number);\r
+      if(selectionGroup!=null)\r
+        selectionGroup.adjustForRemoveRight(command.position);\r
+    }\r
   }\r
 \r
   void paste(Edit command)\r
@@ -98,12 +122,24 @@ public class TrimRegionCommand
       }\r
     }\r
 \r
-    if(command.position==0)\r
+    if (command.position == 0)\r
+    {\r
+      colSel.compensateForEdit(0, -command.number);\r
+      if(selectionGroup!=null)\r
+        selectionGroup.adjustForRemoveLeft(-command.number);\r
+    }\r
+\r
+    if (deletedHiddenColumns != null)\r
     {\r
-      ShiftList slist = new ShiftList();\r
-      slist.addShift(0, -command.number);\r
-      colSel.compensateForEdits(slist);\r
+      int[] region;\r
+      for (int i = 0; i < deletedHiddenColumns.size(); i++)\r
+      {\r
+        region = (int[]) deletedHiddenColumns.elementAt(i);\r
+        colSel.hideColumns(region[0], region[1]);\r
+      }\r
     }\r
+\r
+\r
   }\r
 \r
 }\r