-/*\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.commands;\r
-\r
-import jalview.util.ShiftList;\r
-import jalview.datamodel.*;\r
-import java.util.Vector;\r
-\r
-public class TrimRegionCommand\r
- extends EditCommand\r
-{\r
- public static String TRIM_LEFT = "TrimLeft";\r
- public static String TRIM_RIGHT = "TrimRight";\r
-\r
- public ColumnSelection colSel = null;\r
-\r
- int [] start;\r
-\r
- ShiftList shiftList;\r
-\r
- SequenceGroup selectionGroup;\r
-\r
- Vector deletedHiddenColumns;\r
-\r
- int columnsDeleted;\r
-\r
- public TrimRegionCommand(String description,\r
- String command,\r
- SequenceI[] seqs,\r
- int column,\r
- AlignmentI al,\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
- if(column==0)\r
- return;\r
-\r
- columnsDeleted = column;\r
-\r
- edits = new Edit[] { new Edit(CUT, seqs, 0, column, al)};\r
- }\r
- else if (command.equalsIgnoreCase(TRIM_RIGHT))\r
- {\r
- int width = al.getWidth()-column;\r
- if(width<2)\r
- {\r
- return;\r
- }\r
-\r
- columnsDeleted = width-1;\r
-\r
- edits = new Edit[]\r
- { new Edit(CUT, seqs, column+1, width, al)};\r
- }\r
-\r
- //We need to keep a record of the sequence start\r
- //in order to restore the state after a redo\r
- int i, isize = edits[0].seqs.length;\r
- start = new int[isize];\r
- for(i=0; i<isize; i++)\r
- start[i] = edits[0].seqs[i].getStart();\r
-\r
- performEdit(0);\r
- }\r
-\r
- void cut(Edit command)\r
- {\r
- int column, j, jSize = command.seqs.length;\r
- for (j = 0; j < jSize; j++)\r
- {\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
- {\r
- super.paste(command);\r
- int column, j, jSize = command.seqs.length;\r
- for (j = 0; j < jSize; j++)\r
- {\r
- if(command.position==0)\r
- {\r
- command.seqs[j].setStart(start[j]);\r
- }\r
- else\r
- {\r
- column = command.seqs[j]\r
- .findPosition(command.number+command.position)-1;\r
- command.seqs[j].setEnd(column);\r
- }\r
- }\r
-\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
- 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
- public int getSize()\r
- {\r
- return columnsDeleted;\r
- }\r
-\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.commands;
+
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+
+public class TrimRegionCommand extends EditCommand
+{
+ int columnsDeleted;
+
+ /**
+ * Constructs and performs a trim alignment command
+ *
+ * @param description
+ * (to show in Undo/Redo menu)
+ * @param trimLeft
+ * if true trim to left of column, else to right
+ * @param seqs
+ * the sequences to trim
+ * @param column
+ * the alignment column (base 0) from which to trim
+ * @param al
+ */
+ public TrimRegionCommand(String description, boolean trimLeft,
+ SequenceI[] seqs, int column, AlignmentI al)
+ {
+ this.description = description;
+ if (trimLeft)
+ {
+ if (column == 0)
+ {
+ return;
+ }
+
+ columnsDeleted = column;
+
+ setEdit(new Edit(Action.CUT, seqs, 0, column, al));
+ }
+ else
+ {
+ int width = al.getWidth() - column - 1;
+ if (width < 1)
+ {
+ return;
+ }
+
+ columnsDeleted = width;
+
+ setEdit(new Edit(Action.CUT, seqs, column + 1, width, al));
+ }
+
+ performEdit(0, null);
+ }
+
+ @Override
+ public int getSize()
+ {
+ return columnsDeleted;
+ }
+
+}