+ /*
+ * Work backwards through the edit list, deriving the sequences before each
+ * was applied. The final result is the sequence set before any edits.
+ */
+ Iterator<Edit> editList = new ReverseListIterator<Edit>(getEdits());
+ while (editList.hasNext())
+ {
+ Edit oldEdit = editList.next();
+ Action action = oldEdit.getAction();
+ int position = oldEdit.getPosition();
+ int number = oldEdit.getNumber();
+ final char gap = oldEdit.getGapCharacter();
+ for (SequenceI seq : oldEdit.getSequences())
+ {
+ SequenceI ds = seq.getDatasetSequence();
+ SequenceI preEdit = result.get(ds);
+ if (preEdit == null)
+ {
+ preEdit = new Sequence("", seq.getSequenceAsString(),
+ seq.getStart(), seq.getEnd());
+ preEdit.setDatasetSequence(ds);
+ result.put(ds, preEdit);
+ }
+ /*
+ * 'Undo' this edit action on the sequence (updating the value in the
+ * map).
+ */
+ if (ds != null)
+ {
+ if (action == Action.DELETE_GAP)
+ {
+ preEdit.setSequence(new String(StringUtils.insertCharAt(
+ preEdit.getSequence(), position, number, gap)));
+ }
+ else if (action == Action.INSERT_GAP)
+ {
+ preEdit.setSequence(new String(StringUtils.deleteChars(
+ preEdit.getSequence(), position, position + number)));
+ }
+ else
+ {
+ System.err.println("Can't undo edit action " + action);
+ // throw new IllegalStateException("Can't undo edit action " +
+ // action);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ public class Edit
+ {
+ public SequenceI[] oldds;
+
+ boolean fullAlignmentHeight = false;
+
+ Map<SequenceI, AlignmentAnnotation[]> deletedAnnotationRows;
+
+ Map<String, Annotation[]> deletedAnnotations;
+
+ /*
+ * features deleted by the cut (re-add on Undo)
+ * (including the original of any shortened features)
+ */
+ Map<SequenceI, List<SequenceFeature>> deletedFeatures;
+
+ /*
+ * shortened features added by the cut (delete on Undo)
+ */
+ Map<SequenceI, List<SequenceFeature>> truncatedFeatures;
+
+ AlignmentI al;
+
+ Action command;
+
+ char[][] string;
+
+ SequenceI[] seqs;
+
+ int[] alIndex;
+
+ int position, number;