X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;h=e51afd041569e75f35083707253061e153e672b9;hb=4d2e0d36506302cc00677527725bcccbdf27d766;hp=ad6689488792191e953f429f752a7c1ca742912c;hpb=af8696684758d73680cb775f35b05c5eda879353;p=jalview.git diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index ad66894..e51afd0 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * 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 @@ -18,6 +18,8 @@ */ package jalview.datamodel; +import jalview.util.ShiftList; + import java.util.*; /** @@ -25,427 +27,770 @@ import java.util.*; */ public class ColumnSelection { - Vector selected = new Vector(); - - //Vector of int [] {startCol, endCol} - Vector hiddenColumns; - - /** - * DOCUMENT ME! - * - * @param col DOCUMENT ME! - */ - public void addElement(int col) + 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)) { - if (!selected.contains(new Integer(col))) - { - selected.addElement(new Integer(col)); - } + selected.addElement(column); } - - /** - * DOCUMENT ME! - */ - public void clear() + } + + /** + * 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.removeAllElements(); + selected.removeElement(colInt); } - - /** - * DOCUMENT ME! - * - * @param col DOCUMENT ME! - */ - public void removeElement(int col) + } + + /** + * 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) { - colInt = new Integer(i); - if (selected.contains(colInt)) - { - selected.removeElement(colInt); - } + max = columnAt(i); } } - public Vector getSelected() - { - return selected; - } + return max; + } - /** - * DOCUMENT ME! - * - * @param col DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public boolean contains(int col) - { - return selected.contains(new Integer(col)); - } + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public int getMin() + { + int min = 1000000000; - /** - * DOCUMENT ME! - * - * @param i DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int columnAt(int i) + for (int i = 0; i < selected.size(); i++) { - return ((Integer) selected.elementAt(i)).intValue(); + if (columnAt(i) < min) + { + min = columnAt(i); + } } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int size() + 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 Vector compensateForEdit(int start, int change) + { + Vector deletedHiddenColumns = null; + for (int i = 0; i < size(); i++) { - return selected.size(); + int temp = columnAt(i); + + if (temp >= start) + { + selected.setElementAt(new Integer(temp - change), i); + } } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getMax() + if(hiddenColumns!=null) { - int max = -1; + deletedHiddenColumns = new Vector(); + int hSize = hiddenColumns.size(); + for(int i=0; istart && start+change>region[1] ) + { + deletedHiddenColumns.addElement( + hiddenColumns.elementAt(i)); - for (int i = 0; i < selected.size(); i++) + hiddenColumns.removeElementAt(i); + i--; + hSize--; + continue; + } + + if(region[0]>start) { - if (columnAt(i) > max) - { - max = columnAt(i); - } + region[0] -= change; + region[1] -= change; } - return max; + if(region[0]<0) + region[0] = 0; + + } + + this.revealHiddenColumns(0); } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getMin() + 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) + */ + private void compensateForDelEdits(int start, int change) + { + for (int i = 0; i < size(); i++) { - int min = 1000000000; + int temp = columnAt(i); - for (int i = 0; i < selected.size(); i++) - { - if (columnAt(i) < min) - { - min = columnAt(i); - } - } - - return min; + if (temp >= start) + { + selected.setElementAt(new Integer(temp - change), i); + } } - - /** - * DOCUMENT ME! - * - * @param start DOCUMENT ME! - * @param change DOCUMENT ME! - */ - public void compensateForEdit(int start, int change) + if(hiddenColumns!=null) { - for (int i = 0; i < size(); i++) + for(int i=0; i= start) { - int temp = columnAt(i); - - if (temp >= start) - { - selected.setElementAt(new Integer(temp - change), i); - } + region[0] -= change; + } + if (region[1]>= start) { + region[1] -=change; + } + if (region[1] start) - { - region[0] -= change; - region[1] -= change; - } - if(region[0]<0) - region[0] = 0; - if(region[1] <0) - region[1] = 0; + if(region[0]<0) + region[0] = 0; + if(region[1] <0) + region[1] = 0; + } + } + } + /** + * Adjust hidden column boundaries based on a series of column + * additions or deletions in visible regions. + * @param shiftrecord + * @return + */ + public ShiftList compensateForEdits(ShiftList shiftrecord) { + if (shiftrecord!=null) { + Vector shifts = shiftrecord.shifts; + if (shifts!=null && shifts.size()>0) { + int shifted=0; + for (int i=0,j=shifts.size(); i=sr[0]; + if (!trailinghn) { + if (i=sr[0]; + boolean leadinghc=hr[0]