2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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 extends EditCommand
28 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, String command,
45 SequenceI[] seqs, int column, AlignmentI al,
46 ColumnSelection colSel, SequenceGroup selectedRegion)
48 this.description = description;
49 this.selectionGroup = selectedRegion;
51 if (command.equalsIgnoreCase(TRIM_LEFT))
58 columnsDeleted = column;
61 { new Edit(CUT, seqs, 0, column, al) };
63 else if (command.equalsIgnoreCase(TRIM_RIGHT))
65 int width = al.getWidth() - column - 1;
71 columnsDeleted = width - 1;
74 { new Edit(CUT, seqs, column + 1, width, al) };
77 // We need to keep a record of the sequence start
78 // in order to restore the state after a redo
79 int i, isize = edits[0].seqs.length;
80 start = new int[isize];
81 for (i = 0; i < isize; i++)
83 start[i] = edits[0].seqs[i].getStart();
89 void cut(Edit command)
91 int column, j, jSize = command.seqs.length;
92 for (j = 0; j < jSize; j++)
94 if (command.position == 0)
96 // This is a TRIM_LEFT command
97 column = command.seqs[j].findPosition(command.number);
98 command.seqs[j].setStart(column);
102 // This is a TRIM_RIGHT command
103 column = command.seqs[j].findPosition(command.position) - 1;
104 command.seqs[j].setEnd(column);
108 super.cut(command, null);
110 if (command.position == 0)
112 deletedHiddenColumns = colSel.compensateForEdit(0, command.number);
113 if (selectionGroup != null)
115 selectionGroup.adjustForRemoveLeft(command.number);
120 deletedHiddenColumns = colSel.compensateForEdit(command.position,
122 if (selectionGroup != null)
124 selectionGroup.adjustForRemoveRight(command.position);
129 void paste(Edit command)
131 super.paste(command, null);
132 int column, j, jSize = command.seqs.length;
133 for (j = 0; j < jSize; j++)
135 if (command.position == 0)
137 command.seqs[j].setStart(start[j]);
141 column = command.seqs[j].findPosition(command.number
142 + command.position) - 1;
143 command.seqs[j].setEnd(column);
147 if (command.position == 0)
149 colSel.compensateForEdit(0, -command.number);
150 if (selectionGroup != null)
152 selectionGroup.adjustForRemoveLeft(-command.number);
156 if (deletedHiddenColumns != null)
159 for (int i = 0; i < deletedHiddenColumns.size(); i++)
161 region = (int[]) deletedHiddenColumns.elementAt(i);
162 colSel.hideColumns(region[0], region[1]);
169 return columnsDeleted;