2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
23 import jalview.datamodel.*;
\r
24 import jalview.util.*;
\r
26 public class TrimRegionCommand
\r
29 public static String TRIM_LEFT = "TrimLeft";
\r
30 public static String TRIM_RIGHT = "TrimRight";
\r
32 public ColumnSelection colSel = null;
\r
36 ShiftList shiftList;
\r
38 SequenceGroup selectionGroup;
\r
40 Vector deletedHiddenColumns;
\r
44 public TrimRegionCommand(String description,
\r
49 ColumnSelection colSel,
\r
50 SequenceGroup selectedRegion)
\r
52 this.description = description;
\r
53 this.selectionGroup = selectedRegion;
\r
54 this.colSel = colSel;
\r
55 if (command.equalsIgnoreCase(TRIM_LEFT))
\r
62 columnsDeleted = column;
\r
66 new Edit(CUT, seqs, 0, column, al)};
\r
68 else if (command.equalsIgnoreCase(TRIM_RIGHT))
\r
70 int width = al.getWidth() - column - 1;
\r
76 columnsDeleted = width - 1;
\r
80 new Edit(CUT, seqs, column + 1, width, al)};
\r
83 //We need to keep a record of the sequence start
\r
84 //in order to restore the state after a redo
\r
85 int i, isize = edits[0].seqs.length;
\r
86 start = new int[isize];
\r
87 for (i = 0; i < isize; i++)
\r
89 start[i] = edits[0].seqs[i].getStart();
\r
95 void cut(Edit command)
\r
97 int column, j, jSize = command.seqs.length;
\r
98 for (j = 0; j < jSize; j++)
\r
100 if (command.position == 0)
\r
102 //This is a TRIM_LEFT command
\r
103 column = command.seqs[j].findPosition(command.number);
\r
104 command.seqs[j].setStart(column);
\r
108 //This is a TRIM_RIGHT command
\r
109 column = command.seqs[j].findPosition(command.position) - 1;
\r
110 command.seqs[j].setEnd(column);
\r
114 super.cut(command);
\r
116 if (command.position == 0)
\r
118 deletedHiddenColumns = colSel.compensateForEdit(0, command.number);
\r
119 if (selectionGroup != null)
\r
121 selectionGroup.adjustForRemoveLeft(command.number);
\r
126 deletedHiddenColumns = colSel.compensateForEdit(command.position,
\r
128 if (selectionGroup != null)
\r
130 selectionGroup.adjustForRemoveRight(command.position);
\r
135 void paste(Edit command)
\r
137 super.paste(command);
\r
138 int column, j, jSize = command.seqs.length;
\r
139 for (j = 0; j < jSize; j++)
\r
141 if (command.position == 0)
\r
143 command.seqs[j].setStart(start[j]);
\r
147 column = command.seqs[j]
\r
148 .findPosition(command.number + command.position) - 1;
\r
149 command.seqs[j].setEnd(column);
\r
153 if (command.position == 0)
\r
155 colSel.compensateForEdit(0, -command.number);
\r
156 if (selectionGroup != null)
\r
158 selectionGroup.adjustForRemoveLeft( -command.number);
\r
162 if (deletedHiddenColumns != null)
\r
165 for (int i = 0; i < deletedHiddenColumns.size(); i++)
\r
167 region = (int[]) deletedHiddenColumns.elementAt(i);
\r
168 colSel.hideColumns(region[0], region[1]);
\r
173 public int getSize()
\r
175 return columnsDeleted;
\r