X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;h=6b448320f0aa225a53a266ab9f75bfec1203163c;hb=7b3241c464d774516c4295a5023f4aef7939298e;hp=c7e841885f22146c7a0933255a75ebfe5d58d79f;hpb=6fe4dc1cb082ea9df1c733d05e74ee1a187816cf;p=jalview.git diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index c7e8418..6b44832 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -27,645 +27,768 @@ import java.util.*; */ 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 - */ - public void addElement(int col) + /** + * 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)) { - Integer column = new Integer(col); - if (!selected.contains(column)) - { - selected.addElement(column); - } + selected.addElement(column); } + } - /** - * clears column selection - */ - public void clear() - { - selected.removeAllElements(); - } + /** + * 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); + /** + * 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); - } + 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) + /** + * 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); + } } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getMax() - { - int max = -1; + return max; + } - for (int i = 0; i < selected.size(); i++) - { - if (columnAt(i) > max) - { - max = columnAt(i); - } - } + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public int getMin() + { + int min = 1000000000; - return max; + for (int i = 0; i < selected.size(); i++) + { + if (columnAt(i) < min) + { + min = columnAt(i); + } } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getMin() - { - int min = 1000000000; + return min; + } - 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 Vector compensateForEdit(int start, int change) + { + Vector deletedHiddenColumns = null; + for (int i = 0; i < size(); i++) + { + int temp = columnAt(i); + if (temp >= start) + { + selected.setElementAt(new Integer(temp - change), i); + } + } - /** - * 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) + if(hiddenColumns!=null) { - for (int i = 0; i < size(); i++) + deletedHiddenColumns = new Vector(); + int hSize = hiddenColumns.size(); + for(int i=0; istart && start+change>region[1] ) { - int temp = columnAt(i); + deletedHiddenColumns.addElement( + hiddenColumns.elementAt(i)); - if (temp >= start) - { - selected.setElementAt(new Integer(temp - change), i); - } + hiddenColumns.removeElementAt(i); + i--; + hSize--; + continue; } - if(hiddenColumns!=null) + if(region[0]>start) { - 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; - } + region[0] -= change; + region[1] -= change; } + + if(region[0]<0) + region[0] = 0; + + } + + this.revealHiddenColumns(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) + + 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++) { - for (int i = 0; i < size(); i++) - { - int temp = columnAt(i); + int temp = columnAt(i); - if (temp >= start) - { - selected.setElementAt(new Integer(temp - change), i); - } - } + if (temp >= start) + { + selected.setElementAt(new Integer(temp - change), i); + } + } - if(hiddenColumns!=null) + if(hiddenColumns!=null) + { + for(int i=0; i= start) { - for(int i=0; i= start) - { - region[0] -= change; - } - if (region[1]>= start) { - region[1] -=change; - } - if (region[1]= start) { + region[1] -=change; } + if (region[1]