From 4bc692b7e0ccca12c362bcb6ee9b4c88f431bd22 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 6 Nov 2009 16:29:54 +0000 Subject: [PATCH] setting and merging selected columns from another selection object --- src/jalview/datamodel/ColumnSelection.java | 97 +++++++++++++++++++++------- 1 file changed, 72 insertions(+), 25 deletions(-) diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 6bba5d2..afa2e07 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -36,7 +36,7 @@ public class ColumnSelection * Add a column to the selection * * @param col - * index of column + * index of column */ public void addElement(int col) { @@ -59,7 +59,7 @@ public class ColumnSelection * removes col from selection * * @param col - * index of column to be removed + * index of column to be removed */ public void removeElement(int col) { @@ -75,9 +75,9 @@ public class ColumnSelection * removes a range of columns from the selection * * @param start - * int - first column in range to be removed + * int - first column in range to be removed * @param end - * int - last col + * int - last col */ public void removeElements(int start, int end) { @@ -104,7 +104,7 @@ public class ColumnSelection /** * * @param col - * index to search for in column selection + * index to search for in column selection * * @return true if Integer(col) is in selection. */ @@ -117,7 +117,7 @@ public class ColumnSelection * Column number at position i in selection * * @param i - * index into selected columns + * index into selected columns * * @return column number in alignment */ @@ -180,9 +180,9 @@ public class ColumnSelection * propagate shift in alignment columns to column selection * * @param start - * beginning of edit + * beginning of edit * @param left - * shift in edit (+ve for removal, or -ve for inserts) + * shift in edit (+ve for removal, or -ve for inserts) */ public Vector compensateForEdit(int start, int change) { @@ -238,9 +238,9 @@ public class ColumnSelection * compensateForEdit - allowing for edits within hidden regions * * @param start - * beginning of edit + * beginning of edit * @param left - * shift in edit (+ve for removal, or -ve for inserts) + * shift in edit (+ve for removal, or -ve for inserts) */ private void compensateForDelEdits(int start, int change) { @@ -403,7 +403,7 @@ public class ColumnSelection } } return pruned; // true if any interval was removed or modified by - // operations. + // operations. } private boolean pruneColumnList(Vector deletion, Vector list) @@ -476,7 +476,7 @@ public class ColumnSelection * given index. * * @param end - * int + * int * @return Vector */ public Vector getHiddenColumns() @@ -488,7 +488,7 @@ public class ColumnSelection * Return absolute column index for a visible column index * * @param column - * int column index in alignment view + * int column index in alignment view * @return alignment column index for column */ public int adjustForHiddenColumns(int column) @@ -513,7 +513,7 @@ public class ColumnSelection * hidden columns exist * * @param hiddenColumn - * int + * int * @return int */ public int findColumnPosition(int hiddenColumn) @@ -573,7 +573,7 @@ public class ColumnSelection * hidden columns. In otherwords, the next hidden column. * * @param index - * int + * int */ public int getHiddenBoundaryRight(int alPos) { @@ -601,7 +601,7 @@ public class ColumnSelection * hidden columns. In otherwords, the previous hidden column. * * @param index - * int + * int */ public int getHiddenBoundaryLeft(int alPos) { @@ -679,7 +679,7 @@ public class ColumnSelection * specified * * @param res - * int + * int */ public void hideColumns(int col) { @@ -867,10 +867,11 @@ public class ColumnSelection * return all visible segments between the given start and end boundaries * * @param start - * (first column inclusive from 0) + * (first column inclusive from 0) * @param end - * (last column - not inclusive) - * @return int[] {i_start, i_end, ..} where intervals lie in start<=i_start<=i_end blockStart) { annels.addElement(els = new Annotation[end - blockStart + 1]); - if ((els.length+blockStart)<= alignmentAnnotation.annotations.length) + if ((els.length + blockStart) <= alignmentAnnotation.annotations.length) { // copy just the visible segment of the annotation row System.arraycopy(alignmentAnnotation.annotations, blockStart, @@ -1008,7 +1009,8 @@ public class ColumnSelection { // copy to the end of the annotation row System.arraycopy(alignmentAnnotation.annotations, blockStart, - els, 0, (alignmentAnnotation.annotations.length - blockStart)); + els, 0, + (alignmentAnnotation.annotations.length - blockStart)); } w += els.length; } @@ -1056,4 +1058,49 @@ public class ColumnSelection } } } + + /** + * add in any unselected columns from the given column selection, excluding any that are hidden. + * @param colsel + */ + public void addElementsFrom(ColumnSelection colsel) + { + if (colsel != null && colsel.size() > 0) + { + Enumeration e = colsel.getSelected().elements(); + while (e.hasMoreElements()) + { + Object eo = e.nextElement(); + if (hiddenColumns!=null && isVisible(((Integer) eo).intValue())) { + if (!selected.contains(eo)) + { + selected.addElement(eo); + } + } + } + } + } +/** + * set the selected columns the given column selection, excluding any columns that are hidden. + * @param colsel + */ + public void setElementsFrom(ColumnSelection colsel) + { + if (colsel.selected != null && colsel.selected.size() > 0) + { + if (hiddenColumns!=null && hiddenColumns.size()>0) + { + // only select visible columns in this columns selection + selected = new Vector(); + addElementsFrom(colsel); + } else { + // be quick + selected = new Vector(colsel.selected); + } + } + else + { + selected = new Vector(); + } + } } -- 1.7.10.2