Check for all gapped seqs
[jalview.git] / src / jalview / datamodel / HistoryItem.java
index 3a5b180..09e87f3 100755 (executable)
+/*\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
 package jalview.datamodel;\r
 \r
 import java.util.*;\r
 \r
+\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
 public class HistoryItem\r
 {\r
+  /** DOCUMENT ME!! */\r
   public static final int EDIT = 0;\r
+\r
+  /** DOCUMENT ME!! */\r
   public static final int SORT = 1;\r
+\r
+  /** DOCUMENT ME!! */\r
   public static final int HIDE = 2;\r
-  public static final int PASTE= 3;\r
+\r
+  /** DOCUMENT ME!! */\r
+  public static final int PASTE = 3;\r
 \r
   final int type;\r
+\r
+  AlignmentI alignment;\r
+  String description;\r
+\r
   Vector sequences;\r
+  Vector seqAsString;\r
   Vector alignIndex;\r
-  String description;\r
+\r
   Vector hiddenSeqs;\r
+  Vector hiddenSeqsAsString;\r
 \r
+\r
+  /**\r
+   * Creates a new HistoryItem object.\r
+   *\r
+   * @param description DOCUMENT ME!\r
+   * @param al DOCUMENT ME!\r
+   * @param type DOCUMENT ME!\r
+   */\r
   public HistoryItem(String description, AlignmentI al, int type)\r
   {\r
+    alignment = al;\r
     this.type = type;\r
     this.description = description;\r
     sequences = new Vector();\r
     alignIndex = new Vector();\r
-    hiddenSeqs = new Vector();\r
+    seqAsString = new Vector();\r
 \r
     for (int i = 0; i < al.getHeight(); i++)\r
     {\r
       SequenceI seq = al.getSequenceAt(i);\r
       sequences.addElement(seq);\r
       alignIndex.addElement(i + "");\r
-      hiddenSeqs.addElement(seq.getSequence().toString());\r
+      seqAsString.addElement(seq.getStart()\r
+                             +" "+seq.getEnd()\r
+                             +" "+seq.getSequence().toString());\r
     }\r
-  }\r
 \r
-  public int getType()\r
-  {return type;}\r
-\r
-  public Vector getSequences()\r
-  {return sequences;}\r
+    if(alignment.getHiddenSequences()!=null\r
+       && alignment.getHiddenSequences().getSize()>0)\r
+    {\r
+      hiddenSeqs = new Vector();\r
+      hiddenSeqsAsString = new Vector();\r
+      Enumeration en = alignment.getHiddenSequences().hiddenSequences.elements();\r
+      while (en.hasMoreElements())\r
+      {\r
+        SequenceI key = (SequenceI) en.nextElement();\r
+        hiddenSeqs.addElement(key);\r
+        hiddenSeqsAsString.addElement(key.getSequence().toString());\r
+      }\r
+    }\r
+  }\r
 \r
+  /**\r
+   * DOCUMENT ME!\r
+   *\r
+   * @return DOCUMENT ME!\r
+   */\r
   public String getDescription()\r
-  {return description; }\r
+  {\r
+    return description;\r
+  }\r
 \r
-  public Vector getHidden()\r
-  { return hiddenSeqs; }\r
 \r
-  public int getAlignIndex(int seq)\r
+  public void restore()\r
   {\r
-    return Integer.parseInt(alignIndex.elementAt(seq).toString());\r
-  }\r
+    if (type == HistoryItem.SORT)\r
+    {\r
+      for (int i = 0; i < sequences.size(); i++)\r
+      {\r
+        alignment.getSequences().setElementAt(sequences.elementAt(i), i);\r
+      }\r
+    }\r
+    else\r
+    {\r
+      StringTokenizer st;\r
+      for (int i = 0; i < sequences.size(); i++)\r
+      {\r
+        SequenceI restore = (SequenceI) sequences.elementAt(i);\r
 \r
+\r
+        if (restore.getLength() == 0)\r
+        {\r
+          //This is for edits which remove all residues in a sequence\r
+          alignment.getSequences().insertElementAt(restore,\r
+              Integer.parseInt(alignIndex.elementAt(i).toString()));\r
+        }\r
+\r
+        st = new StringTokenizer(seqAsString.elementAt(i).toString());\r
+        restore.setStart(Integer.parseInt(st.nextToken()));\r
+        restore.setEnd(Integer.parseInt(st.nextToken()));\r
+        restore.setSequence(st.nextToken());\r
+      }\r
+\r
+      if(hiddenSeqs!=null)\r
+      {\r
+        for(int hs=0; hs<hiddenSeqs.size(); hs++)\r
+        {\r
+          SequenceI key = (SequenceI) hiddenSeqs.elementAt(hs);\r
+          key.setSequence(hiddenSeqsAsString.elementAt(hs).toString());\r
+        }\r
+      }\r
+\r
+      if (type == HistoryItem.PASTE)\r
+      {\r
+        for (int i = alignment.getHeight() - 1;\r
+             i > (sequences.size() - 1); i--)\r
+        {\r
+          alignment.deleteSequence(i);\r
+        }\r
+      }\r
+    }\r
+\r
+  }\r
 }\r