-/*\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
-\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
-\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
- SequenceI seq = al.getSequenceAt(i);\r
- sequences.addElement(seq);\r
- alignIndex.addElement(i + "");\r
- seqAsString.addElement(seq.getStart()\r
- +" "+seq.getEnd()\r
- +" "+seq.getSequence().toString());\r
- }\r
-\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
- {\r
- return description;\r
- }\r
-\r
-\r
- public void restore()\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
+/*
+* 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.datamodel;
+
+import jalview.util.ShiftList;
+
+import java.util.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class HistoryItem
+{
+ /** DOCUMENT ME!! */
+ public static final int EDIT = 0;
+
+ /** DOCUMENT ME!! */
+ public static final int SORT = 1;
+
+ /** DOCUMENT ME!! */
+ public static final int HIDE = 2;
+
+ /** DOCUMENT ME!! */
+ public static final int PASTE = 3;
+
+ final int type;
+
+ AlignmentI alignment;
+ String description;
+
+ Vector sequences;
+ Vector seqAsString;
+ Vector alignIndex;
+
+ Vector hiddenSeqs;
+ Vector hiddenSeqsAsString;
+ /**
+ * public field - set directly if history involves a frame shift
+ * should contain the <em>inverse</em> frame shift operations.
+ */
+ public ShiftList alColumnChanges=null;
+
+ /**
+ * Creates a new HistoryItem object.
+ *
+ * @param description DOCUMENT ME!
+ * @param al DOCUMENT ME!
+ * @param type DOCUMENT ME!
+ */
+ public HistoryItem(String description, AlignmentI al, int type)
+ {
+ alignment = al;
+ this.type = type;
+ this.description = description;
+ sequences = new Vector();
+ alignIndex = new Vector();
+ seqAsString = new Vector();
+
+ for (int i = 0; i < al.getHeight(); i++)
+ {
+ SequenceI seq = al.getSequenceAt(i);
+ sequences.addElement(seq);
+ alignIndex.addElement(i + "");
+ seqAsString.addElement(seq.getStart()
+ +" "+seq.getEnd()
+ +" "+seq.getSequence().toString());
+ }
+
+ if(alignment.getHiddenSequences()!=null
+ && alignment.getHiddenSequences().getSize()>0)
+ {
+ hiddenSeqs = new Vector();
+ hiddenSeqsAsString = new Vector();
+ Enumeration en = alignment.getHiddenSequences().hiddenSequences.elements();
+ while (en.hasMoreElements())
+ {
+ SequenceI key = (SequenceI) en.nextElement();
+ hiddenSeqs.addElement(key);
+ hiddenSeqsAsString.addElement(key.getSequence().toString());
+ }
+ }
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+
+ /**
+ * restore state - adjusting gui hiddenColumn view as necessary
+ * @param columnSelection
+ */
+ public void restore(ColumnSelection columnSelection)
+ {
+ if (type == HistoryItem.SORT)
+ {
+ for (int i = 0; i < sequences.size(); i++)
+ {
+ alignment.getSequences().setElementAt(sequences.elementAt(i), i);
+ }
+ }
+ else
+ {
+ StringTokenizer st;
+ for (int i = 0; i < sequences.size(); i++)
+ {
+ SequenceI restore = (SequenceI) sequences.elementAt(i);
+
+
+ if (restore.getLength() == 0)
+ {
+ //This is for edits which remove all residues in a sequence
+ alignment.getSequences().insertElementAt(restore,
+ Integer.parseInt(alignIndex.elementAt(i).toString()));
+ }
+
+ st = new StringTokenizer(seqAsString.elementAt(i).toString());
+ restore.setStart(Integer.parseInt(st.nextToken()));
+ restore.setEnd(Integer.parseInt(st.nextToken()));
+ restore.setSequence(st.nextToken());
+ }
+
+ if(hiddenSeqs!=null)
+ {
+ for(int hs=0; hs<hiddenSeqs.size(); hs++)
+ {
+ SequenceI key = (SequenceI) hiddenSeqs.elementAt(hs);
+ key.setSequence(hiddenSeqsAsString.elementAt(hs).toString());
+ }
+ }
+
+ if (type == HistoryItem.PASTE)
+ {
+ for (int i = alignment.getHeight() - 1;
+ i > (sequences.size() - 1); i--)
+ {
+ alignment.deleteSequence(i);
+ }
+ }
+ if (alColumnChanges!=null) {
+ columnSelection.compensateForEdits(alColumnChanges);
+ }
+ }
+
+ }
+ /**
+ * note a frame shift that must be compensated for
+ * @param pos start position for shift (in original reference frame)
+ * @param shift length of shift
+ */
+ public void addShift(int pos, int shift) {
+ if (alColumnChanges==null)
+ alColumnChanges = new ShiftList();
+ alColumnChanges.addShift(pos, -shift);
+ }
+}