X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FHistoryItem.java;h=0520bc004cbc39164ddcbc76b2211d791ec1da0a;hb=476d13d644d3bf2886519b13bc7f02d1ae9729f9;hp=eb4979d6c8ba2d8ea978cb2596fa3fcc016c2c4f;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/datamodel/HistoryItem.java b/src/jalview/datamodel/HistoryItem.java index eb4979d..0520bc0 100755 --- a/src/jalview/datamodel/HistoryItem.java +++ b/src/jalview/datamodel/HistoryItem.java @@ -29,96 +29,128 @@ import java.util.*; */ 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; - Vector sequences; - Vector alignIndex; - String description; - Vector hiddenSeqs; - - /** - * 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) - { - this.type = type; - this.description = description; - sequences = new Vector(); - alignIndex = new Vector(); - hiddenSeqs = new Vector(); + /** DOCUMENT ME!! */ + public static final int EDIT = 0; - for (int i = 0; i < al.getHeight(); i++) - { - SequenceI seq = al.getSequenceAt(i); - sequences.addElement(seq); - alignIndex.addElement(i + ""); - hiddenSeqs.addElement(seq.getSequence().toString()); - } - } + /** DOCUMENT ME!! */ + public static final int SORT = 1; - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getType() - { - return type; - } + /** DOCUMENT ME!! */ + public static final int HIDE = 2; + + /** DOCUMENT ME!! */ + public static final int PASTE = 3; + + final int type; - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Vector getSequences() + 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++) { - return sequences; + SequenceI seq = al.getSequenceAt(i); + sequences.addElement(seq); + alignIndex.addElement(i + ""); + seqAsString.addElement(seq.getSequence().toString()); } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public String getDescription() + if(alignment.getHiddenSequences()!=null + && alignment.getHiddenSequences().getSize()>0) { - return description; + 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; + } + - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Vector getHidden() + public void restore() + { + if (type == HistoryItem.SORT) { - return hiddenSeqs; + for (int i = 0; i < sequences.size(); i++) + { + alignment.getSequences().setElementAt(sequences.elementAt(i), i); + } } - - /** - * DOCUMENT ME! - * - * @param seq DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getAlignIndex(int seq) + else { - return Integer.parseInt(alignIndex.elementAt(seq).toString()); + + 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); + } + } } + + } }