2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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;
25 import jalview.datamodel.*;
26 import jalview.util.*;
28 public class TrimRegionCommand extends EditCommand
30 public static String TRIM_LEFT = "TrimLeft";
32 public static String TRIM_RIGHT = "TrimRight";
34 public ColumnSelection colSel = null;
40 SequenceGroup selectionGroup;
42 Vector deletedHiddenColumns;
46 public TrimRegionCommand(String description, String command,
47 SequenceI[] seqs, int column, AlignmentI al,
48 ColumnSelection colSel, SequenceGroup selectedRegion)
50 this.description = description;
51 this.selectionGroup = selectedRegion;
53 if (command.equalsIgnoreCase(TRIM_LEFT))
60 columnsDeleted = column;
63 { new Edit(CUT, seqs, 0, column, al) };
65 else if (command.equalsIgnoreCase(TRIM_RIGHT))
67 int width = al.getWidth() - column - 1;
73 columnsDeleted = width - 1;
76 { new Edit(CUT, seqs, column + 1, width, al) };
79 // We need to keep a record of the sequence start
80 // in order to restore the state after a redo
81 int i, isize = edits[0].seqs.length;
82 start = new int[isize];
83 for (i = 0; i < isize; i++)
85 start[i] = edits[0].seqs[i].getStart();
91 void cut(Edit command)
93 int column, j, jSize = command.seqs.length;
94 for (j = 0; j < jSize; j++)
96 if (command.position == 0)
98 // This is a TRIM_LEFT command
99 column = command.seqs[j].findPosition(command.number);
100 command.seqs[j].setStart(column);
104 // This is a TRIM_RIGHT command
105 column = command.seqs[j].findPosition(command.position) - 1;
106 command.seqs[j].setEnd(column);
110 super.cut(command, null);
112 if (command.position == 0)
114 deletedHiddenColumns = colSel.compensateForEdit(0, command.number);
115 if (selectionGroup != null)
117 selectionGroup.adjustForRemoveLeft(command.number);
122 deletedHiddenColumns = colSel.compensateForEdit(command.position,
124 if (selectionGroup != null)
126 selectionGroup.adjustForRemoveRight(command.position);
131 void paste(Edit command)
133 super.paste(command, null);
134 int column, j, jSize = command.seqs.length;
135 for (j = 0; j < jSize; j++)
137 if (command.position == 0)
139 command.seqs[j].setStart(start[j]);
143 column = command.seqs[j].findPosition(command.number
144 + command.position) - 1;
145 command.seqs[j].setEnd(column);
149 if (command.position == 0)
151 colSel.compensateForEdit(0, -command.number);
152 if (selectionGroup != null)
154 selectionGroup.adjustForRemoveLeft(-command.number);
158 if (deletedHiddenColumns != null)
161 for (int i = 0; i < deletedHiddenColumns.size(); i++)
163 region = (int[]) deletedHiddenColumns.elementAt(i);
164 colSel.hideColumns(region[0], region[1]);
171 return columnsDeleted;