X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FColumnSelection.java;h=a7fd83a211c26d4f97f96534d512ea006f421bad;hb=0149a3aec3e61c36ee788adfbd53bf560407e1e0;hp=9b255508b7282afe57b2bb1d5d91ec53a7c2078f;hpb=1e6b1fe5829b88270879ffc3dde6add3f5642b14;p=jalview.git diff --git a/src/jalview/gui/ColumnSelection.java b/src/jalview/gui/ColumnSelection.java index 9b25550..a7fd83a 100755 --- a/src/jalview/gui/ColumnSelection.java +++ b/src/jalview/gui/ColumnSelection.java @@ -1,75 +1,182 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2005 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 + */ package jalview.gui; import java.util.*; + /** * NOTE: Columns are zero based. */ -public class ColumnSelection{ - Vector selected = new Vector(); - - public void addElement(int col) { - selected.addElement(new Integer(col)); - } - - public void clear() { - selected.removeAllElements(); - } - - public void removeElement(int col) { - Integer colInt = new Integer(col); - if (selected.contains(colInt)) { - selected.removeElement(colInt); - } else { - System.err.println("WARNING: Tried to remove Integer NOT in ColumnSelection"); - } - } +public class ColumnSelection +{ + Vector selected = new Vector(); - public boolean contains(int col) { - return selected.contains(new Integer(col)); - } + /** + * DOCUMENT ME! + * + * @param col DOCUMENT ME! + */ + public void addElement(int col) + { + if (!selected.contains(new Integer(col))) + { + selected.addElement(new Integer(col)); + } + } - public int columnAt(int i) { - return ((Integer)selected.elementAt(i)).intValue(); - } + /** + * DOCUMENT ME! + */ + public void clear() + { + selected.removeAllElements(); + } - public int size() { - return selected.size(); - } + /** + * DOCUMENT ME! + * + * @param col DOCUMENT ME! + */ + public void removeElement(int col) + { + Integer colInt = new Integer(col); - public int getMax() { - int max = -1; + if (selected.contains(colInt)) + { + selected.removeElement(colInt); + } + } - for (int i=0;i max) { - max = columnAt(i); + public void removeElements(int start, int end) + { + Integer colInt; + for(int i=start; i= start) { - selected.setElementAt(new Integer(temp-change),i); - } + for (int i = 0; i < selected.size(); i++) + { + if (columnAt(i) > max) + { + max = columnAt(i); + } + } + + return max; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public int getMin() + { + int min = 1000000000; + + for (int i = 0; i < selected.size(); i++) + { + if (columnAt(i) < min) + { + min = columnAt(i); + } + } + + return min; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Vector asVector() + { + return selected; + } + + /** + * DOCUMENT ME! + * + * @param start DOCUMENT ME! + * @param change DOCUMENT ME! + */ + public void compensateForEdit(int start, int change) + { + for (int i = 0; i < size(); i++) + { + int temp = columnAt(i); + + if (temp >= start) + { + selected.setElementAt(new Integer(temp - change), i); + } + } } - } }