X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;h=d651c0bfb7e67dfecbbac0d1161b25998b7b51d6;hb=37de9310bec3501cbc6381e0c3dcb282fcaad812;hp=bd06ca363467c2f9bc8d351efcdb3dddab2ff91c;hpb=b2d54d33d6313efd9da96bd7586dfaa7a0d7a182;p=jalview.git diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index bd06ca3..d651c0b 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -1,666 +1,1014 @@ /* - * 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 + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview 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 3 * 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. - * + * + * Jalview 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 + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.datamodel; +import jalview.util.Comparison; import jalview.util.ShiftList; +import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; +import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField; -import java.util.*; +import java.util.ArrayList; +import java.util.BitSet; +import java.util.Collections; +import java.util.List; +import java.util.Vector; /** - * NOTE: Columns are zero based. + * Data class holding the selected columns and hidden column ranges for a view. + * Ranges are base 1. */ public class ColumnSelection { - Vector selected = new Vector(); + /** + * A class to hold an efficient representation of selected columns + */ + private class IntList + { + /* + * list of selected columns (ordered by selection order, not column order) + */ + private List order; - //Vector of int [] {startCol, endCol} - Vector hiddenColumns; + /* + * an unmodifiable view of the selected columns list + */ + private List _uorder; /** - * Add a column to the selection - * - * @param col index of column + * bitfield for column selection - allows quick lookup */ - public void addElement(int col) - { - Integer column = new Integer(col); - if (!selected.contains(column)) - { - selected.addElement(column); - } - } + private BitSet selected; /** - * clears column selection + * Constructor */ - public void clear() + IntList() { - selected.removeAllElements(); + order = new ArrayList(); + _uorder = Collections.unmodifiableList(order); + selected = new BitSet(); } /** - * removes col from selection - * - * @param col index of column to be removed + * Copy constructor + * + * @param other */ - public void removeElement(int col) + IntList(IntList other) { - Integer colInt = new Integer(col); - - if (selected.contains(colInt)) + this(); + if (other != null) + { + int j = other.size(); + for (int i = 0; i < j; i++) { - selected.removeElement(colInt); + add(other.elementAt(i)); } + } } /** - * removes a range of columns from the selection - * @param start int - first column in range to be removed - * @param end int - last col + * adds a new column i to the selection - only if i is not already selected + * + * @param i */ - public void removeElements(int start, int end) + void add(int i) { - Integer colInt; - for(int i=start; i getList() { - int max = -1; - - for (int i = 0; i < selected.size(); i++) - { - if (columnAt(i) > max) - { - max = columnAt(i); - } - } - - return max; + return _uorder; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getMin() + int size() { - int min = 1000000000; - - for (int i = 0; i < selected.size(); i++) - { - if (columnAt(i) < min) - { - min = columnAt(i); - } - } - - return min; + return order.size(); } - /** - * 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) + * gets the column that was selected first, second or i'th + * + * @param i + * @return */ - public void compensateForEdit(int start, int change) + int elementAt(int i) { - 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; - } - } + return order.get(i); } - /** - * 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) + protected boolean pruneColumnList(final List shifts) + { + int s = 0, t = shifts.size(); + int[] sr = shifts.get(s++); + boolean pruned = false; + int i = 0, j = order.size(); + while (i < j && s <= t) + { + int c = order.get(i++).intValue(); + if (sr[0] <= c) { - for(int i=0; i= c) + { // sr[1] -ve means inseriton. + order.remove(--i); + selected.clear(c); + j--; + } + else { - int[] region = (int[]) hiddenColumns.elementAt(i); - if(region[0] >= start) + if (s < t) { - region[0] -= change; - } - if (region[1]>= start) { - region[1] -=change; - } - if (region[1]