2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.commands;
\r
21 import jalview.util.ShiftList;
\r
23 import jalview.datamodel.*;
\r
25 public class TrimRegionCommand
\r
28 public static String TRIM_LEFT = "TrimLeft";
\r
29 public static String TRIM_RIGHT = "TrimRight";
\r
31 public ColumnSelection colSel = null;
\r
35 public TrimRegionCommand(String description,
\r
40 ColumnSelection colSel)
\r
42 this.description = description;
\r
43 if (command.equalsIgnoreCase(TRIM_LEFT))
\r
45 edits = new Edit[] { new Edit(CUT, seqs, 0, column, al)};
\r
46 this.colSel = colSel;
\r
48 else if (command.equalsIgnoreCase(TRIM_RIGHT))
\r
51 { new Edit(CUT, seqs, column+1, al.getWidth() - column, al)};
\r
54 //We need to keep a record of the sequence start
\r
55 //in order to restore the state after a redo
\r
56 int i, isize = edits[0].seqs.length;
\r
57 start = new int[isize];
\r
58 for(i=0; i<isize; i++)
\r
59 start[i] = edits[0].seqs[i].getStart();
\r
64 void cut(Edit command)
\r
66 int column, j, jSize = command.seqs.length;
\r
67 for (j = 0; j < jSize; j++)
\r
69 if(command.position==0)
\r
71 column = command.seqs[j].findPosition(command.number);
\r
72 command.seqs[j].setStart(column);
\r
76 column = command.seqs[j].findPosition(command.position)-1;
\r
77 command.seqs[j].setEnd(column);
\r
83 void paste(Edit command)
\r
85 super.paste(command);
\r
86 int column, j, jSize = command.seqs.length;
\r
87 for (j = 0; j < jSize; j++)
\r
89 if(command.position==0)
\r
91 command.seqs[j].setStart(start[j]);
\r
95 column = command.seqs[j]
\r
96 .findPosition(command.number+command.position)-1;
\r
97 command.seqs[j].setEnd(column);
\r
101 if(command.position==0)
\r
103 ShiftList slist = new ShiftList();
\r
104 slist.addShift(0, -command.number);
\r
105 colSel.compensateForEdits(slist);
\r