This commit was manufactured by cvs2svn to create branch 'VamJalview'.
[jalview.git] / src / jalview / appletgui / ColumnSelection.java
index 4ec546a..33c4604 100755 (executable)
@@ -1,3 +1,22 @@
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
+\r
 package jalview.appletgui;\r
 \r
 import java.util.*;\r
@@ -5,70 +24,101 @@ import java.util.*;
 /**\r
  * NOTE: Columns are zero based.\r
  */\r
-public class ColumnSelection{\r
+public class ColumnSelection\r
+{\r
   Vector selected = new Vector();\r
 \r
-  public void addElement(int col) {\r
-    selected.addElement(new Integer(col));\r
+  public void addElement(int col)\r
+  {\r
+    if(!selected.contains(new Integer(col)))\r
+      selected.addElement(new Integer(col));\r
   }\r
 \r
-  public void clear() {\r
+  public void clear()\r
+  {\r
     selected.removeAllElements();\r
   }\r
 \r
-  public void removeElement(int col) {\r
+  public void removeElement(int col)\r
+  {\r
     Integer colInt = new Integer(col);\r
-    if (selected.contains(colInt)) {\r
+    if (selected.contains(colInt))\r
+    {\r
       selected.removeElement(colInt);\r
-    } else {\r
-      System.err.println("WARNING: Tried to remove Integer NOT in ColumnSelection");\r
     }\r
   }\r
 \r
-  public boolean contains(int col) {\r
+  public void removeElements(int start, int end)\r
+  {\r
+    Integer colInt;\r
+    for(int i=start; i<end; i++)\r
+    {\r
+      colInt = new Integer(i);\r
+      if (selected.contains(colInt))\r
+      {\r
+          selected.removeElement(colInt);\r
+      }\r
+    }\r
+    }\r
+\r
+  public boolean contains(int col)\r
+  {\r
     return selected.contains(new Integer(col));\r
   }\r
 \r
-  public int columnAt(int i) {\r
-    return ((Integer)selected.elementAt(i)).intValue();\r
+  public int columnAt(int i)\r
+  {\r
+    return ( (Integer) selected.elementAt(i)).intValue();\r
   }\r
 \r
-  public int size() {\r
+  public int size()\r
+  {\r
     return selected.size();\r
   }\r
 \r
-  public int getMax() {\r
+  public int getMax()\r
+  {\r
     int max = -1;\r
 \r
-    for (int i=0;i<selected.size();i++) {\r
-      if (columnAt(i) > max) {\r
+    for (int i = 0; i < selected.size(); i++)\r
+    {\r
+      if (columnAt(i) > max)\r
+      {\r
         max = columnAt(i);\r
       }\r
     }\r
     return max;\r
   }\r
 \r
-  public int getMin() {\r
+  public int getMin()\r
+  {\r
     int min = 1000000000;\r
 \r
-    for (int i=0;i<selected.size();i++) {\r
-      if (columnAt(i) < min) {\r
+    for (int i = 0; i < selected.size(); i++)\r
+    {\r
+      if (columnAt(i) < min)\r
+      {\r
         min = columnAt(i);\r
       }\r
     }\r
     return min;\r
   }\r
 \r
-  public Vector asVector() {\r
+  public Vector asVector()\r
+  {\r
     return selected;\r
   }\r
 \r
-  public void compensateForEdit(int start, int change) {\r
-    for (int i=0; i < size();i++) {\r
+  public void compensateForEdit(int start, int change)\r
+  {\r
+    for (int i = 0; i < size(); i++)\r
+    {\r
       int temp = columnAt(i);\r
 \r
       if (temp >= start)\r
-        selected.setElementAt(new Integer(temp-change),i);\r
+      {\r
+        selected.setElementAt(new Integer(temp - change), i);\r
+      }\r
     }\r
   }\r
 }\r