2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.commands;
23 import jalview.datamodel.*;
24 import jalview.util.*;
26 public class TrimRegionCommand
29 public static String TRIM_LEFT = "TrimLeft";
30 public static String TRIM_RIGHT = "TrimRight";
32 public ColumnSelection colSel = null;
38 SequenceGroup selectionGroup;
40 Vector deletedHiddenColumns;
44 public TrimRegionCommand(String description,
49 ColumnSelection colSel,
50 SequenceGroup selectedRegion)
52 this.description = description;
53 this.selectionGroup = selectedRegion;
55 if (command.equalsIgnoreCase(TRIM_LEFT))
62 columnsDeleted = column;
66 new Edit(CUT, seqs, 0, column, al)};
68 else if (command.equalsIgnoreCase(TRIM_RIGHT))
70 int width = al.getWidth() - column - 1;
76 columnsDeleted = width - 1;
80 new Edit(CUT, seqs, column + 1, width, al)};
83 //We need to keep a record of the sequence start
84 //in order to restore the state after a redo
85 int i, isize = edits[0].seqs.length;
86 start = new int[isize];
87 for (i = 0; i < isize; i++)
89 start[i] = edits[0].seqs[i].getStart();
95 void cut(Edit command)
97 int column, j, jSize = command.seqs.length;
98 for (j = 0; j < jSize; j++)
100 if (command.position == 0)
102 //This is a TRIM_LEFT command
103 column = command.seqs[j].findPosition(command.number);
104 command.seqs[j].setStart(column);
108 //This is a TRIM_RIGHT command
109 column = command.seqs[j].findPosition(command.position) - 1;
110 command.seqs[j].setEnd(column);
114 super.cut(command, null);
116 if (command.position == 0)
118 deletedHiddenColumns = colSel.compensateForEdit(0, command.number);
119 if (selectionGroup != null)
121 selectionGroup.adjustForRemoveLeft(command.number);
126 deletedHiddenColumns = colSel.compensateForEdit(command.position,
128 if (selectionGroup != null)
130 selectionGroup.adjustForRemoveRight(command.position);
135 void paste(Edit command)
137 super.paste(command, null);
138 int column, j, jSize = command.seqs.length;
139 for (j = 0; j < jSize; j++)
141 if (command.position == 0)
143 command.seqs[j].setStart(start[j]);
147 column = command.seqs[j]
148 .findPosition(command.number + command.position) - 1;
149 command.seqs[j].setEnd(column);
153 if (command.position == 0)
155 colSel.compensateForEdit(0, -command.number);
156 if (selectionGroup != null)
158 selectionGroup.adjustForRemoveLeft( -command.number);
162 if (deletedHiddenColumns != null)
165 for (int i = 0; i < deletedHiddenColumns.size(); i++)
167 region = (int[]) deletedHiddenColumns.elementAt(i);
168 colSel.hideColumns(region[0], region[1]);
175 return columnsDeleted;