X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fcommands%2FTrimRegionCommand.java;h=8166ed61adf81d35446eeb25c38199c3f1fc3234;hb=4d2e0d36506302cc00677527725bcccbdf27d766;hp=8ada376dc57ce8d0119188c940e5eca9bc081d9e;hpb=ebb678af128304dc13e1b6ec9e0961489bf83d39;p=jalview.git diff --git a/src/jalview/commands/TrimRegionCommand.java b/src/jalview/commands/TrimRegionCommand.java index 8ada376..8166ed6 100644 --- a/src/jalview/commands/TrimRegionCommand.java +++ b/src/jalview/commands/TrimRegionCommand.java @@ -19,8 +19,8 @@ package jalview.commands; import jalview.util.ShiftList; - import jalview.datamodel.*; +import java.util.Vector; public class TrimRegionCommand extends EditCommand @@ -32,23 +32,46 @@ public class TrimRegionCommand int [] start; + ShiftList shiftList; + + SequenceGroup selectionGroup; + + Vector deletedHiddenColumns; + + int columnsDeleted; + public TrimRegionCommand(String description, String command, SequenceI[] seqs, int column, AlignmentI al, - ColumnSelection colSel) + ColumnSelection colSel, + SequenceGroup selectedRegion) { this.description = description; + this.selectionGroup = selectedRegion; + this.colSel = colSel; if (command.equalsIgnoreCase(TRIM_LEFT)) { + if(column==0) + return; + + columnsDeleted = column; + edits = new Edit[] { new Edit(CUT, seqs, 0, column, al)}; - this.colSel = colSel; } else if (command.equalsIgnoreCase(TRIM_RIGHT)) { + int width = al.getWidth()-column; + if(width<2) + { + return; + } + + columnsDeleted = width-1; + edits = new Edit[] - { new Edit(CUT, seqs, column+1, al.getWidth() - column, al)}; + { new Edit(CUT, seqs, column+1, width, al)}; } //We need to keep a record of the sequence start @@ -68,16 +91,32 @@ public class TrimRegionCommand { if(command.position==0) { + //This is a TRIM_LEFT command column = command.seqs[j].findPosition(command.number); command.seqs[j].setStart(column); } else { + //This is a TRIM_RIGHT command column = command.seqs[j].findPosition(command.position)-1; command.seqs[j].setEnd(column); } } + super.cut(command); + + if (command.position == 0) + { + deletedHiddenColumns = colSel.compensateForEdit(0, command.number); + if(selectionGroup!=null) + selectionGroup.adjustForRemoveLeft(command.number); + } + else + { + deletedHiddenColumns = colSel.compensateForEdit(command.position, command.number); + if(selectionGroup!=null) + selectionGroup.adjustForRemoveRight(command.position); + } } void paste(Edit command) @@ -98,12 +137,27 @@ public class TrimRegionCommand } } - if(command.position==0) + if (command.position == 0) + { + colSel.compensateForEdit(0, -command.number); + if(selectionGroup!=null) + selectionGroup.adjustForRemoveLeft(-command.number); + } + + if (deletedHiddenColumns != null) { - ShiftList slist = new ShiftList(); - slist.addShift(0, -command.number); - colSel.compensateForEdits(slist); + int[] region; + for (int i = 0; i < deletedHiddenColumns.size(); i++) + { + region = (int[]) deletedHiddenColumns.elementAt(i); + colSel.hideColumns(region[0], region[1]); + } } } + public int getSize() + { + return columnsDeleted; + } + }