X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FHistoryItem.java;h=37e4ce0f42da94ef4ecd23a9317eb6fdcc92fdc2;hb=174230b4233d9ce80f94527768d2cd2f76da11ab;hp=0520bc004cbc39164ddcbc76b2211d791ec1da0a;hpb=19e35813ebb5102a69682857bd25f46955f17cbb;p=jalview.git diff --git a/src/jalview/datamodel/HistoryItem.java b/src/jalview/datamodel/HistoryItem.java index 0520bc0..37e4ce0 100755 --- a/src/jalview/datamodel/HistoryItem.java +++ b/src/jalview/datamodel/HistoryItem.java @@ -1,156 +1,180 @@ -/* -* 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 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; - - - /** - * 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.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; - } - - - public void restore() - { - if (type == HistoryItem.SORT) - { - for (int i = 0; i < sequences.size(); i++) - { - alignment.getSequences().setElementAt(sequences.elementAt(i), i); - } - } - else - { - - 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 - restore.setSequence(seqAsString.elementAt(i).toString()); - alignment.getSequences().insertElementAt(restore, - Integer.parseInt(alignIndex.elementAt(i).toString())); - } - else - { - restore.setSequence(seqAsString.elementAt(i).toString()); - } - } - - if(hiddenSeqs!=null) - { - for(int hs=0; hs (sequences.size() - 1); i--) - { - alignment.deleteSequence(i); - } - } - } - - } -} +/* +* Jalview - A Sequence Alignment Editor and Viewer +* Copyright (C) 2006 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 inverse 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 (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); + } +}