2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.datamodel;
21 import jalview.util.ShiftList;
32 public class HistoryItem
35 public static final int EDIT = 0;
38 public static final int SORT = 1;
41 public static final int HIDE = 2;
44 public static final int PASTE = 3;
56 Vector hiddenSeqsAsString;
58 * public field - set directly if history involves a frame shift
59 * should contain the <em>inverse</em> frame shift operations.
61 public ShiftList alColumnChanges=null;
64 * Creates a new HistoryItem object.
66 * @param description DOCUMENT ME!
67 * @param al DOCUMENT ME!
68 * @param type DOCUMENT ME!
70 public HistoryItem(String description, AlignmentI al, int type)
74 this.description = description;
75 sequences = new Vector();
76 alignIndex = new Vector();
77 seqAsString = new Vector();
79 for (int i = 0; i < al.getHeight(); i++)
81 SequenceI seq = al.getSequenceAt(i);
82 sequences.addElement(seq);
83 alignIndex.addElement(i + "");
84 seqAsString.addElement(seq.getStart()
86 +" "+seq.getSequence().toString());
89 if(alignment.getHiddenSequences()!=null
90 && alignment.getHiddenSequences().getSize()>0)
92 hiddenSeqs = new Vector();
93 hiddenSeqsAsString = new Vector();
94 Enumeration en = alignment.getHiddenSequences().hiddenSequences.elements();
95 while (en.hasMoreElements())
97 SequenceI key = (SequenceI) en.nextElement();
98 hiddenSeqs.addElement(key);
99 hiddenSeqsAsString.addElement(key.getSequence().toString());
106 * @return DOCUMENT ME!
108 public String getDescription()
114 * restore state - adjusting gui hiddenColumn view as necessary
115 * @param columnSelection
117 public void restore(ColumnSelection columnSelection)
119 if (type == HistoryItem.SORT)
121 for (int i = 0; i < sequences.size(); i++)
123 alignment.getSequences().setElementAt(sequences.elementAt(i), i);
129 for (int i = 0; i < sequences.size(); i++)
131 SequenceI restore = (SequenceI) sequences.elementAt(i);
134 if (restore.getLength() == 0)
136 //This is for edits which remove all residues in a sequence
137 alignment.getSequences().insertElementAt(restore,
138 Integer.parseInt(alignIndex.elementAt(i).toString()));
141 st = new StringTokenizer(seqAsString.elementAt(i).toString());
142 restore.setStart(Integer.parseInt(st.nextToken()));
143 restore.setEnd(Integer.parseInt(st.nextToken()));
144 restore.setSequence(st.nextToken());
149 for(int hs=0; hs<hiddenSeqs.size(); hs++)
151 SequenceI key = (SequenceI) hiddenSeqs.elementAt(hs);
152 key.setSequence(hiddenSeqsAsString.elementAt(hs).toString());
156 if (type == HistoryItem.PASTE)
158 for (int i = alignment.getHeight() - 1;
159 i > (sequences.size() - 1); i--)
161 alignment.deleteSequence(i);
164 if (alColumnChanges!=null) {
165 columnSelection.compensateForEdits(alColumnChanges);
171 * note a frame shift that must be compensated for
172 * @param pos start position for shift (in original reference frame)
173 * @param shift length of shift
175 public void addShift(int pos, int shift) {
176 if (alColumnChanges==null)
177 alColumnChanges = new ShiftList();
178 alColumnChanges.addShift(pos, -shift);