X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fcommands%2FTrimRegionCommand.java;h=655657e9aec76574971ee98fc867ade01dd57b34;hb=HEAD;hp=37518bcadb09f4d25e76ee7c28ae3345267abbef;hpb=e9759a4932c7ee68d52e3b8a55188c3688fe0529;p=jalview.git diff --git a/src/jalview/commands/TrimRegionCommand.java b/src/jalview/commands/TrimRegionCommand.java index 37518bc..655657e 100644 --- a/src/jalview/commands/TrimRegionCommand.java +++ b/src/jalview/commands/TrimRegionCommand.java @@ -1,163 +1,80 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * - * This program 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 2 - * of the License, or (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ -package jalview.commands; - -import jalview.util.ShiftList; -import jalview.datamodel.*; -import java.util.Vector; - -public class TrimRegionCommand - extends EditCommand -{ - public static String TRIM_LEFT = "TrimLeft"; - public static String TRIM_RIGHT = "TrimRight"; - - public ColumnSelection colSel = null; - - int [] start; - - ShiftList shiftList; - - SequenceGroup selectionGroup; - - Vector deletedHiddenColumns; - - int columnsDeleted; - - public TrimRegionCommand(String description, - String command, - SequenceI[] seqs, - int column, - AlignmentI al, - 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)}; - } - else if (command.equalsIgnoreCase(TRIM_RIGHT)) - { - int width = al.getWidth()-column-1; - if(width<2) - { - return; - } - - columnsDeleted = width-1; - - edits = new Edit[] - { new Edit(CUT, seqs, column+1, width, al)}; - } - - //We need to keep a record of the sequence start - //in order to restore the state after a redo - int i, isize = edits[0].seqs.length; - start = new int[isize]; - for(i=0; i. + * 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; + } + +}