X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;h=546ba1a7dbe4443e0e40da5929f4d07585b6dea5;hb=153dd62dc91da13ae732600e6ea55ddbe15eab39;hp=4904495ee9ad8b919fecee944b3a8668900b6148;hpb=a706a0f1f86af677c05c12713e791b78320003e6;p=jalview.git diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 4904495..546ba1a 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 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 + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * 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. + * + * 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 Jalview. If not, see . */ package jalview.datamodel; @@ -29,13 +28,14 @@ public class ColumnSelection { Vector selected = new Vector(); - //Vector of int [] {startCol, endCol} + // 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) { @@ -56,8 +56,9 @@ public class ColumnSelection /** * removes col from selection - * - * @param col index of column to be removed + * + * @param col + * index of column to be removed */ public void removeElement(int col) { @@ -71,8 +72,11 @@ public class ColumnSelection /** * 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) { @@ -88,7 +92,7 @@ public class ColumnSelection } /** - * + * * @return Vector containing selected columns as Integers */ public Vector getSelected() @@ -97,9 +101,10 @@ public class ColumnSelection } /** - * - * @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) @@ -108,20 +113,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 ((Integer) selected.elementAt(i)).intValue(); } /** * DOCUMENT ME! - * + * * @return DOCUMENT ME! */ public int size() @@ -130,9 +136,9 @@ public class ColumnSelection } /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! + * rightmost selected column + * + * @return rightmost column in alignment that is selected */ public int getMax() { @@ -150,9 +156,9 @@ public class ColumnSelection } /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! + * Leftmost column in selection + * + * @return column index of leftmost column in selection */ public int getMin() { @@ -171,9 +177,11 @@ public class ColumnSelection /** * 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 Vector compensateForEdit(int start, int change) { @@ -197,8 +205,7 @@ public class ColumnSelection int[] region = (int[]) hiddenColumns.elementAt(i); if (region[0] > start && start + change > region[1]) { - deletedHiddenColumns.addElement( - hiddenColumns.elementAt(i)); + deletedHiddenColumns.addElement(hiddenColumns.elementAt(i)); hiddenColumns.removeElementAt(i); i--; @@ -226,10 +233,13 @@ public class ColumnSelection } /** - * 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) { @@ -274,8 +284,9 @@ public class ColumnSelection } /** - * Adjust hidden column boundaries based on a series of column - * additions or deletions in visible regions. + * Adjust hidden column boundaries based on a series of column additions or + * deletions in visible regions. + * * @param shiftrecord * @return */ @@ -290,7 +301,7 @@ public class ColumnSelection for (int i = 0, j = shifts.size(); i < j; i++) { int[] sh = (int[]) shifts.elementAt(i); - //compensateForEdit(shifted+sh[0], sh[1]); + // compensateForEdit(shifted+sh[0], sh[1]); compensateForDelEdits(shifted + sh[0], sh[1]); shifted -= sh[1]; } @@ -301,8 +312,9 @@ public class ColumnSelection } /** - * removes intersection of position,length ranges in deletions - * from the start,end regions marked in intervals. + * removes intersection of position,length ranges in deletions from the + * start,end regions marked in intervals. + * * @param deletions * @param intervals * @return @@ -389,7 +401,8 @@ public class ColumnSelection } } } - return pruned; // true if any interval was removed or modified by operations. + return pruned; // true if any interval was removed or modified by + // operations. } private boolean pruneColumnList(Vector deletion, Vector list) @@ -400,7 +413,7 @@ public class ColumnSelection int i = 0, j = list.size(); while (i < j && s <= t) { - int c = ( (Integer) list.elementAt(i++)).intValue(); + int c = ((Integer) list.elementAt(i++)).intValue(); if (sr[0] <= c) { if (sr[1] + sr[0] >= c) @@ -422,8 +435,9 @@ public class ColumnSelection } /** - * remove any hiddenColumns or selected columns and shift remaining - * based on a series of position, range deletions. + * remove any hiddenColumns or selected columns and shift remaining based on a + * series of position, range deletions. + * * @param deletions */ public void pruneDeletions(ShiftList deletions) @@ -457,9 +471,11 @@ public class ColumnSelection } /** - * This Method is used to return all the HiddenColumn regions - * less than the given index. - * @param end int + * This Method is used to return all the HiddenColumn regions less than the + * given index. + * + * @param end + * int * @return Vector */ public Vector getHiddenColumns() @@ -469,7 +485,9 @@ public class ColumnSelection /** * Return absolute column index for a visible column index - * @param column int column index in alignment view + * + * @param column + * int column index in alignment view * @return alignment column index for column */ public int adjustForHiddenColumns(int column) @@ -490,9 +508,11 @@ public class ColumnSelection } /** - * Use this method to find out where a visible column is in the alignment - * when hidden columns exist - * @param hiddenColumn int + * Use this method to find out where a column will appear in the visible alignment when + * hidden columns exist. If the column is not visible, then the left-most visible column will always be returned. + * + * @param hiddenColumn + * int * @return int */ public int findColumnPosition(int hiddenColumn) @@ -501,22 +521,21 @@ public class ColumnSelection if (hiddenColumns != null) { int index = 0; - int gaps = 0; + int[] region; do { - int[] region = (int[]) hiddenColumns.elementAt(index); + region = (int[]) hiddenColumns.elementAt(index++); if (hiddenColumn > region[1]) { result -= region[1] + 1 - region[0]; } - index++; + } while ((hiddenColumn > region[1]) && (index < hiddenColumns.size())); + if (hiddenColumn>region[0] && hiddenColumn