*/\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
-\r
- /** DOCUMENT ME!! */\r
- public static final int PASTE = 3;\r
- final int type;\r
- Vector sequences;\r
- Vector alignIndex;\r
- String description;\r
- Vector hiddenSeqs;\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
- this.type = type;\r
- this.description = description;\r
- sequences = new Vector();\r
- alignIndex = new Vector();\r
- hiddenSeqs = new Vector();\r
+ /** DOCUMENT ME!! */\r
+ public static final int EDIT = 0;\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
- }\r
- }\r
+ /** DOCUMENT ME!! */\r
+ public static final int SORT = 1;\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getType()\r
- {\r
- return type;\r
- }\r
+ /** DOCUMENT ME!! */\r
+ public static final int HIDE = 2;\r
+\r
+ /** DOCUMENT ME!! */\r
+ public static final int PASTE = 3;\r
+\r
+ final int type;\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public Vector getSequences()\r
+ AlignmentI alignment;\r
+ String description;\r
+\r
+ Vector sequences;\r
+ Vector seqAsString;\r
+ Vector alignIndex;\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
+ seqAsString = new Vector();\r
+\r
+ for (int i = 0; i < al.getHeight(); i++)\r
{\r
- return sequences;\r
+ SequenceI seq = al.getSequenceAt(i);\r
+ sequences.addElement(seq);\r
+ alignIndex.addElement(i + "");\r
+ seqAsString.addElement(seq.getSequence().toString());\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public String getDescription()\r
+ if(alignment.getHiddenSequences()!=null\r
+ && alignment.getHiddenSequences().getSize()>0)\r
{\r
- return description;\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
+ {\r
+ return description;\r
+ }\r
+\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public Vector getHidden()\r
+ public void restore()\r
+ {\r
+ if (type == HistoryItem.SORT)\r
{\r
- return hiddenSeqs;\r
+ for (int i = 0; i < sequences.size(); i++)\r
+ {\r
+ alignment.getSequences().setElementAt(sequences.elementAt(i), i);\r
+ }\r
}\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param seq DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getAlignIndex(int seq)\r
+ else\r
{\r
- return Integer.parseInt(alignIndex.elementAt(seq).toString());\r
+\r
+ for (int i = 0; i < sequences.size(); i++)\r
+ {\r
+ SequenceI restore = (SequenceI) sequences.elementAt(i);\r
+\r
+ if (restore.getLength() == 0)\r
+ {\r
+ //This is for edits which remove all residues in a sequence\r
+ restore.setSequence(seqAsString.elementAt(i).toString());\r
+ alignment.getSequences().insertElementAt(restore,\r
+ Integer.parseInt(alignIndex.elementAt(i).toString()));\r
+ }\r
+ else\r
+ {\r
+ restore.setSequence(seqAsString.elementAt(i).toString());\r
+ }\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