X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;h=4371994e0d3593a5594b07d2bd89e86895aee9a9;hb=5f7810e6c809dbc218fed92b811999807dec148a;hp=ca54570a09085a98f06ad0b90425e43b7b4ec8f9;hpb=506d60f0e188723ddc91c26824b41ac7034df3fe;p=jalview.git diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index ca54570..4371994 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Copyright (C) 2010 J Procter, AM Waterhouse, 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 file is part of Jalview. * - * 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 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. * - * 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 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; @@ -36,7 +35,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 +58,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 +74,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 +103,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 +116,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 +179,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 +237,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 +402,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 +475,7 @@ public class ColumnSelection * given index. * * @param end - * int + * int * @return Vector */ public Vector getHiddenColumns() @@ -488,7 +487,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 +512,7 @@ public class ColumnSelection * hidden columns exist * * @param hiddenColumn - * int + * int * @return int */ public int findColumnPosition(int hiddenColumn) @@ -573,7 +572,7 @@ public class ColumnSelection * hidden columns. In otherwords, the next hidden column. * * @param index - * int + * int */ public int getHiddenBoundaryRight(int alPos) { @@ -601,7 +600,7 @@ public class ColumnSelection * hidden columns. In otherwords, the previous hidden column. * * @param index - * int + * int */ public int getHiddenBoundaryLeft(int alPos) { @@ -679,7 +678,7 @@ public class ColumnSelection * specified * * @param res - * int + * int */ public void hideColumns(int col) { @@ -867,10 +866,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 (end - blockStart + 1 <= alignmentAnnotation.annotations.length) + if ((els.length + blockStart) <= alignmentAnnotation.annotations.length) { + // copy just the visible segment of the annotation row System.arraycopy(alignmentAnnotation.annotations, blockStart, els, 0, els.length); } else { + // copy to the end of the annotation row System.arraycopy(alignmentAnnotation.annotations, blockStart, - els, 0, (end - blockStart + 1)); + els, 0, + (alignmentAnnotation.annotations.length - blockStart)); } w += els.length; } @@ -1054,4 +1057,58 @@ 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) + { + selected = new Vector(); + 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 + { + // add everything regardless + Enumeration en = colsel.selected.elements(); + while (en.hasMoreElements()) + { + selected.addElement(en.nextElement()); + } + } + } + } }