X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;h=57db830447bec3d1ca24d77ce1dd64d956d77bfa;hb=4d7f98a6dd54d9863ba449ec79dcd95d25ed863d;hp=c895b2f3c8b2a1c604f416bf585dbac5ff09e9d8;hpb=5655997c202bfcb4ab2778999d785490d3a7dbae;p=jalview.git diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index c895b2f..57db830 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -1,41 +1,49 @@ /* - * 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.ShiftList; +import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; +import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Vector; /** * NOTE: Columns are zero based. */ public class ColumnSelection { - Vector selected = new Vector(); + Vector selected = new Vector(); - //Vector of int [] {startCol, endCol} - Vector hiddenColumns; + // Vector of int [] {startCol, endCol} + Vector hiddenColumns; /** * Add a column to the selection - * - * @param col index of column + * + * @param col + * index of column */ public void addElement(int col) { @@ -55,9 +63,10 @@ public class ColumnSelection } /** - * removes col from selection - * - * @param col index of column to be removed + * Removes value 'col' from the selection (not the col'th item) + * + * @param col + * index of column to be removed */ public void removeElement(int col) { @@ -65,19 +74,24 @@ public class ColumnSelection if (selected.contains(colInt)) { + // if this ever changes to List.remove(), ensure Integer not int argument + // as List.remove(int i) removes the i'th item which is wrong 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 + * + * @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 getSelected() { return selected; } /** - * - * @param col index to search for in column selection - * + * + * @param col + * index to search for in column selection + * * @return true if Integer(col) is in selection. */ public boolean contains(int col) @@ -107,20 +123,21 @@ public class ColumnSelection } /** - * DOCUMENT ME! - * - * @param i DOCUMENT ME! - * - * @return DOCUMENT ME! + * Column number at position i in selection + * + * @param i + * index into selected columns + * + * @return column number in alignment */ public int columnAt(int i) { - return ((Integer) selected.elementAt(i)).intValue(); + return selected.elementAt(i).intValue(); } /** * DOCUMENT ME! - * + * * @return DOCUMENT ME! */ public int size() @@ -129,9 +146,9 @@ public class ColumnSelection } /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! + * rightmost selected column + * + * @return rightmost column in alignment that is selected */ public int getMax() { @@ -149,9 +166,9 @@ public class ColumnSelection } /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! + * Leftmost column in selection + * + * @return column index of leftmost column in selection */ public int getMin() { @@ -168,47 +185,72 @@ public class ColumnSelection 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) + * + * @param start + * beginning of edit + * @param left + * shift in edit (+ve for removal, or -ve for inserts) */ - public void compensateForEdit(int start, int change) + public List compensateForEdit(int start, int change) { + List deletedHiddenColumns = null; for (int i = 0; i < size(); i++) { int temp = columnAt(i); if (temp >= start) { + // if this ever changes to List.set(), swap parameter order!! selected.setElementAt(new Integer(temp - change), i); } } - if(hiddenColumns!=null) + if (hiddenColumns != null) { - for(int i=0; i(); + int hSize = hiddenColumns.size(); + for (int i = 0; i < hSize; i++) { - int[] region = (int[]) hiddenColumns.elementAt(i); - if(region[0] > start) + int[] region = hiddenColumns.elementAt(i); + if (region[0] > start && start + change > region[1]) + { + deletedHiddenColumns.add(region); + + hiddenColumns.removeElementAt(i); + i--; + hSize--; + continue; + } + + if (region[0] > start) { region[0] -= change; region[1] -= change; } - if(region[0]<0) + + if (region[0] < 0) + { region[0] = 0; - if(region[1] <0) - region[1] = 0; + } + } + + this.revealHiddenColumns(0); } + + return deletedHiddenColumns; } + /** - * 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) + * 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) { @@ -218,179 +260,246 @@ public class ColumnSelection if (temp >= start) { + // if this ever changes to List.set(), swap parameter order!! selected.setElementAt(new Integer(temp - change), i); } } - if(hiddenColumns!=null) + if (hiddenColumns != null) { - for(int i=0; i= start) + int[] region = hiddenColumns.elementAt(i); + if (region[0] >= start) { region[0] -= change; } - if (region[1]>= start) { - region[1] -=change; + if (region[1] >= start) + { + region[1] -= change; } - if (region[1]