2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.datamodel;
\r
28 * @version $Revision$
\r
30 public class HistoryItem
\r
32 /** DOCUMENT ME!! */
\r
33 public static final int EDIT = 0;
\r
35 /** DOCUMENT ME!! */
\r
36 public static final int SORT = 1;
\r
38 /** DOCUMENT ME!! */
\r
39 public static final int HIDE = 2;
\r
41 /** DOCUMENT ME!! */
\r
42 public static final int PASTE = 3;
\r
46 AlignmentI alignment;
\r
54 Vector hiddenSeqsAsString;
\r
58 * Creates a new HistoryItem object.
\r
60 * @param description DOCUMENT ME!
\r
61 * @param al DOCUMENT ME!
\r
62 * @param type DOCUMENT ME!
\r
64 public HistoryItem(String description, AlignmentI al, int type)
\r
68 this.description = description;
\r
69 sequences = new Vector();
\r
70 alignIndex = new Vector();
\r
71 seqAsString = new Vector();
\r
73 for (int i = 0; i < al.getHeight(); i++)
\r
75 SequenceI seq = al.getSequenceAt(i);
\r
76 sequences.addElement(seq);
\r
77 alignIndex.addElement(i + "");
\r
78 seqAsString.addElement(seq.getStart()
\r
80 +" "+seq.getSequence().toString());
\r
83 if(alignment.getHiddenSequences()!=null
\r
84 && alignment.getHiddenSequences().getSize()>0)
\r
86 hiddenSeqs = new Vector();
\r
87 hiddenSeqsAsString = new Vector();
\r
88 Enumeration en = alignment.getHiddenSequences().hiddenSequences.elements();
\r
89 while (en.hasMoreElements())
\r
91 SequenceI key = (SequenceI) en.nextElement();
\r
92 hiddenSeqs.addElement(key);
\r
93 hiddenSeqsAsString.addElement(key.getSequence().toString());
\r
101 * @return DOCUMENT ME!
\r
103 public String getDescription()
\r
105 return description;
\r
109 public void restore()
\r
111 if (type == HistoryItem.SORT)
\r
113 for (int i = 0; i < sequences.size(); i++)
\r
115 alignment.getSequences().setElementAt(sequences.elementAt(i), i);
\r
120 StringTokenizer st;
\r
121 for (int i = 0; i < sequences.size(); i++)
\r
123 SequenceI restore = (SequenceI) sequences.elementAt(i);
\r
126 if (restore.getLength() == 0)
\r
128 //This is for edits which remove all residues in a sequence
\r
129 alignment.getSequences().insertElementAt(restore,
\r
130 Integer.parseInt(alignIndex.elementAt(i).toString()));
\r
133 st = new StringTokenizer(seqAsString.elementAt(i).toString());
\r
134 restore.setStart(Integer.parseInt(st.nextToken()));
\r
135 restore.setEnd(Integer.parseInt(st.nextToken()));
\r
136 restore.setSequence(st.nextToken());
\r
139 if(hiddenSeqs!=null)
\r
141 for(int hs=0; hs<hiddenSeqs.size(); hs++)
\r
143 SequenceI key = (SequenceI) hiddenSeqs.elementAt(hs);
\r
144 key.setSequence(hiddenSeqsAsString.elementAt(hs).toString());
\r
148 if (type == HistoryItem.PASTE)
\r
150 for (int i = alignment.getHeight() - 1;
\r
151 i > (sequences.size() - 1); i--)
\r
153 alignment.deleteSequence(i);
\r