X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;fp=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;h=2d2223111c2bb0c75b1aa104ab76ba9e98059ebf;hb=0f71bfca98457c30f1051f142c31b6aaa3e23ead;hp=0000000000000000000000000000000000000000;hpb=072fc418c393cbd2a40dfa1d3e46f90178b79572;p=jalview.git diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java new file mode 100644 index 0000000..2d22231 --- /dev/null +++ b/src/jalview/datamodel/ColumnSelection.java @@ -0,0 +1,728 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ +package jalview.datamodel; + +import jalview.util.ShiftList; + +import java.util.*; + +/** + * NOTE: Columns are zero based. + */ +public class ColumnSelection +{ + Vector selected = new Vector(); + + //Vector of int [] {startCol, endCol} + Vector hiddenColumns; + + /** + * Add a column to the selection + * + * @param col index of column + */ + public void addElement(int col) + { + Integer column = new Integer(col); + if (!selected.contains(column)) + { + selected.addElement(column); + } + } + + /** + * clears column selection + */ + public void clear() + { + selected.removeAllElements(); + } + + /** + * removes col from selection + * + * @param col index of column to be removed + */ + public void removeElement(int col) + { + Integer colInt = new Integer(col); + + if (selected.contains(colInt)) + { + selected.removeElement(colInt); + } + } + + /** + * removes a range of columns from the selection + * @param start int - first column in range to be removed + * @param end int - last col + */ + public void removeElements(int start, int end) + { + Integer colInt; + for(int i=start; i max) + { + max = columnAt(i); + } + } + + return max; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public int getMin() + { + int min = 1000000000; + + for (int i = 0; i < selected.size(); i++) + { + if (columnAt(i) < min) + { + min = columnAt(i); + } + } + + return min; + } + + + /** + * propagate shift in alignment columns to column selection + * + * @param start beginning of edit + * @param left shift in edit (+ve for removal, or -ve for inserts) + */ + public void compensateForEdit(int start, int change) + { + for (int i = 0; i < size(); i++) + { + int temp = columnAt(i); + + if (temp >= start) + { + selected.setElementAt(new Integer(temp - change), i); + } + } + + if(hiddenColumns!=null) + { + for(int i=0; i start) + { + region[0] -= change; + region[1] -= change; + } + if(region[0]<0) + region[0] = 0; + if(region[1] <0) + region[1] = 0; + } + } + } + /** + * propagate shift in alignment columns to column selection + * special version of compensateForEdit - allowing for edits within hidden regions + * @param start beginning of edit + * @param left shift in edit (+ve for removal, or -ve for inserts) + */ + private void compensateForDelEdits(int start, int change) + { + for (int i = 0; i < size(); i++) + { + int temp = columnAt(i); + + if (temp >= start) + { + selected.setElementAt(new Integer(temp - change), i); + } + } + + if(hiddenColumns!=null) + { + for(int i=0; i= start) + { + region[0] -= change; + } + if (region[1]>= start) { + region[1] -=change; + } + if (region[1]