2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.commands;
22 import jalview.datamodel.*;
23 import jalview.util.*;
25 public class TrimRegionCommand extends EditCommand
27 public static String TRIM_LEFT = "TrimLeft";
29 public static String TRIM_RIGHT = "TrimRight";
31 public ColumnSelection colSel = null;
37 SequenceGroup selectionGroup;
39 Vector deletedHiddenColumns;
43 public TrimRegionCommand(String description, String command,
44 SequenceI[] seqs, int column, AlignmentI al,
45 ColumnSelection colSel, SequenceGroup selectedRegion)
47 this.description = description;
48 this.selectionGroup = selectedRegion;
50 if (command.equalsIgnoreCase(TRIM_LEFT))
57 columnsDeleted = column;
60 { new Edit(CUT, seqs, 0, column, al) };
62 else if (command.equalsIgnoreCase(TRIM_RIGHT))
64 int width = al.getWidth() - column - 1;
70 columnsDeleted = width - 1;
73 { new Edit(CUT, seqs, column + 1, width, al) };
76 // We need to keep a record of the sequence start
77 // in order to restore the state after a redo
78 int i, isize = edits[0].seqs.length;
79 start = new int[isize];
80 for (i = 0; i < isize; i++)
82 start[i] = edits[0].seqs[i].getStart();
88 void cut(Edit command)
90 int column, j, jSize = command.seqs.length;
91 for (j = 0; j < jSize; j++)
93 if (command.position == 0)
95 // This is a TRIM_LEFT command
96 column = command.seqs[j].findPosition(command.number);
97 command.seqs[j].setStart(column);
101 // This is a TRIM_RIGHT command
102 column = command.seqs[j].findPosition(command.position) - 1;
103 command.seqs[j].setEnd(column);
107 super.cut(command, null);
109 if (command.position == 0)
111 deletedHiddenColumns = colSel.compensateForEdit(0, command.number);
112 if (selectionGroup != null)
114 selectionGroup.adjustForRemoveLeft(command.number);
119 deletedHiddenColumns = colSel.compensateForEdit(command.position,
121 if (selectionGroup != null)
123 selectionGroup.adjustForRemoveRight(command.position);
128 void paste(Edit command)
130 super.paste(command, null);
131 int column, j, jSize = command.seqs.length;
132 for (j = 0; j < jSize; j++)
134 if (command.position == 0)
136 command.seqs[j].setStart(start[j]);
140 column = command.seqs[j].findPosition(command.number
141 + command.position) - 1;
142 command.seqs[j].setEnd(column);
146 if (command.position == 0)
148 colSel.compensateForEdit(0, -command.number);
149 if (selectionGroup != null)
151 selectionGroup.adjustForRemoveLeft(-command.number);
155 if (deletedHiddenColumns != null)
158 for (int i = 0; i < deletedHiddenColumns.size(); i++)
160 region = (int[]) deletedHiddenColumns.elementAt(i);
161 colSel.hideColumns(region[0], region[1]);
168 return columnsDeleted;