2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.commands;
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.ColumnSelection;
25 import jalview.datamodel.SequenceGroup;
26 import jalview.datamodel.SequenceI;
27 import jalview.util.ShiftList;
29 import java.util.List;
31 public class TrimRegionCommand extends EditCommand
33 public static String TRIM_LEFT = "TrimLeft";
35 public static String TRIM_RIGHT = "TrimRight";
37 public ColumnSelection colSel = null;
43 SequenceGroup selectionGroup;
45 List<int[]> deletedHiddenColumns;
49 public TrimRegionCommand(String description, String command,
50 SequenceI[] seqs, int column, AlignmentI al,
51 ColumnSelection colSel, SequenceGroup selectedRegion)
53 this.description = description;
54 this.selectionGroup = selectedRegion;
56 if (command.equalsIgnoreCase(TRIM_LEFT))
63 columnsDeleted = column;
65 setEdit(new Edit(Action.CUT, seqs, 0, column, al));
67 else if (command.equalsIgnoreCase(TRIM_RIGHT))
69 int width = al.getWidth() - column - 1;
75 columnsDeleted = width - 1;
77 setEdit(new Edit(Action.CUT, seqs, column + 1, width, al));
80 // We need to keep a record of the sequence start
81 // in order to restore the state after a redo
82 int i, isize = getEdit(0).seqs.length;
83 start = new int[isize];
84 for (i = 0; i < isize; i++)
86 start[i] = getEdit(0).seqs[i].getStart();
92 void cut(Edit command)
94 int column, j, jSize = command.seqs.length;
95 for (j = 0; j < jSize; j++)
97 if (command.position == 0)
99 // This is a TRIM_LEFT command
100 column = command.seqs[j].findPosition(command.number);
101 command.seqs[j].setStart(column);
105 // This is a TRIM_RIGHT command
106 column = command.seqs[j].findPosition(command.position) - 1;
107 command.seqs[j].setEnd(column);
111 super.cut(command, null);
113 if (command.position == 0)
115 deletedHiddenColumns = colSel.compensateForEdit(0, command.number);
116 if (selectionGroup != null)
118 selectionGroup.adjustForRemoveLeft(command.number);
123 deletedHiddenColumns = colSel.compensateForEdit(command.position,
125 if (selectionGroup != null)
127 selectionGroup.adjustForRemoveRight(command.position);
132 void paste(Edit command)
134 super.paste(command, null);
135 int column, j, jSize = command.seqs.length;
136 for (j = 0; j < jSize; j++)
138 if (command.position == 0)
140 command.seqs[j].setStart(start[j]);
144 column = command.seqs[j].findPosition(command.number
145 + command.position) - 1;
146 command.seqs[j].setEnd(column);
150 if (command.position == 0)
152 colSel.compensateForEdit(0, -command.number);
153 if (selectionGroup != null)
155 selectionGroup.adjustForRemoveLeft(-command.number);
159 if (deletedHiddenColumns != null)
162 for (int i = 0; i < deletedHiddenColumns.size(); i++)
164 region = deletedHiddenColumns.get(i);
165 colSel.hideColumns(region[0], region[1]);
172 return columnsDeleted;