2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.commands;
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.Annotation;
26 import jalview.datamodel.Sequence;
27 import jalview.datamodel.SequenceFeature;
28 import jalview.datamodel.SequenceI;
29 import jalview.util.ReverseListIterator;
30 import jalview.util.StringUtils;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.Hashtable;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.ListIterator;
47 * Description: Essential information for performing undo and redo for cut/paste
48 * insert/delete gap which can be stored in the HistoryList
52 * Copyright: Copyright (c) 2006
56 * Company: Dundee University
59 * @author not attributable
62 public class EditCommand implements CommandI
66 INSERT_GAP, DELETE_GAP, CUT, PASTE, REPLACE, INSERT_NUC
69 private List<Edit> edits = new ArrayList<Edit>();
77 public EditCommand(String description)
79 this.description = description;
82 public EditCommand(String description, Action command, SequenceI[] seqs,
83 int position, int number, AlignmentI al)
85 this.description = description;
86 if (command == Action.CUT || command == Action.PASTE)
88 setEdit(new Edit(command, seqs, position, number, al));
94 public EditCommand(String description, Action command, String replace,
95 SequenceI[] seqs, int position, int number, AlignmentI al)
97 this.description = description;
98 if (command == Action.REPLACE)
100 setEdit(new Edit(command, seqs, position, number, al, replace));
103 performEdit(0, null);
107 * Set the list of edits to the specified item (only).
111 protected void setEdit(Edit e)
118 * Add the given edit command to the stored list of commands. If simply
119 * expanding the range of the last command added, then modify it instead of
120 * adding a new command.
124 public void addEdit(Edit e)
126 if (!expandEdit(edits, e))
133 * Returns true if the new edit is incorporated by updating (expanding the
134 * range of) the last edit on the list, else false. We can 'expand' the last
135 * edit if the new one is the same action, on the same sequences, and acts on
136 * a contiguous range. This is the case where a mouse drag generates a series
137 * of contiguous gap insertions or deletions.
143 protected static boolean expandEdit(List<Edit> edits, Edit e)
145 if (edits == null || edits.isEmpty())
149 Edit lastEdit = edits.get(edits.size() - 1);
150 Action action = e.command;
151 if (lastEdit.command != action)
157 * Both commands must act on the same sequences - compare the underlying
158 * dataset sequences, rather than the aligned sequences, which change as
161 if (lastEdit.seqs.length != e.seqs.length)
165 for (int i = 0; i < e.seqs.length; i++)
167 if (lastEdit.seqs[i].getDatasetSequence() != e.seqs[i]
168 .getDatasetSequence())
175 * Check a contiguous edit; either
177 * <li>a new Insert <n> positions to the right of the last <insert n>, or</li>
178 * <li>a new Delete <n> gaps which is <n> positions to the left of the last
182 boolean contiguous = (action == Action.INSERT_GAP && e.position == lastEdit.position
184 || (action == Action.DELETE_GAP && e.position + e.number == lastEdit.position);
188 * We are just expanding the range of the last edit. For delete gap, also
189 * moving the start position left.
191 lastEdit.number += e.number;
192 lastEdit.seqs = e.seqs;
193 if (action == Action.DELETE_GAP)
203 * Clear the list of stored edit commands.
206 protected void clearEdits()
212 * Returns the i'th stored Edit command.
217 protected Edit getEdit(int i)
219 if (i >= 0 && i < edits.size())
227 final public String getDescription()
239 * Return the alignment for the first edit (or null if no edit).
243 final public AlignmentI getAlignment()
245 return (edits.isEmpty() ? null : edits.get(0).al);
249 * append a new editCommand Note. this shouldn't be called if the edit is an
250 * operation affects more alignment objects than the one referenced in al (for
251 * example, cut or pasting whole sequences). Use the form with an additional
252 * AlignmentI[] views parameter.
261 final public void appendEdit(Action command, SequenceI[] seqs,
263 int number, AlignmentI al, boolean performEdit)
265 appendEdit(command, seqs, position, number, al, performEdit, null);
269 * append a new edit command with a set of alignment views that may be
280 final public void appendEdit(Action command, SequenceI[] seqs,
282 int number, AlignmentI al, boolean performEdit, AlignmentI[] views)
284 Edit edit = new Edit(command, seqs, position, number,
285 al.getGapCharacter());
286 if (al.getHeight() == seqs.length)
289 edit.fullAlignmentHeight = true;
296 performEdit(edit, views);
301 * Overloaded method that accepts an Edit object with additional parameters.
308 final public void appendEdit(Edit edit, AlignmentI al,
309 boolean performEdit, AlignmentI[] views)
311 if (al.getHeight() == edit.seqs.length)
314 edit.fullAlignmentHeight = true;
321 performEdit(edit, views);
326 * Execute all the edit commands, starting at the given commandIndex
328 * @param commandIndex
331 public final void performEdit(int commandIndex, AlignmentI[] views)
333 ListIterator<Edit> iterator = edits.listIterator(commandIndex);
334 while (iterator.hasNext())
336 Edit edit = iterator.next();
337 performEdit(edit, views);
342 * Execute one edit command in all the specified alignment views
347 protected static void performEdit(Edit edit, AlignmentI[] views)
349 switch (edit.command)
367 // TODO:add deleteNuc for UNDO
369 // insertNuc(edits[e]);
377 final public void doCommand(AlignmentI[] views)
379 performEdit(0, views);
383 * Undo the stored list of commands, in reverse order.
386 final public void undoCommand(AlignmentI[] views)
388 ListIterator<Edit> iterator = edits.listIterator(edits.size());
389 while (iterator.hasPrevious())
391 Edit e = iterator.previous();
419 * Insert gap(s) in sequences as specified by the command, and adjust
424 final private static void insertGap(Edit command)
427 for (int s = 0; s < command.seqs.length; s++)
429 command.seqs[s].insertCharAt(command.position,
430 command.number, command.gapChar);
431 // System.out.println("pos: "+command.position+" number: "+command.number);
434 adjustAnnotations(command, true, false, null);
438 // final void insertNuc(Edit command)
441 // for (int s = 0; s < command.seqs.length; s++)
443 // System.out.println("pos: "+command.position+" number: "+command.number);
444 // command.seqs[s].insertCharAt(command.position, command.number,'A');
447 // adjustAnnotations(command, true, false, null);
451 * Delete gap(s) in sequences as specified by the command, and adjust
456 final static private void deleteGap(Edit command)
458 for (int s = 0; s < command.seqs.length; s++)
460 command.seqs[s].deleteChars(command.position, command.position
464 adjustAnnotations(command, false, false, null);
468 * Carry out a Cut action. The cut characters are saved in case Undo is
474 static void cut(Edit command, AlignmentI[] views)
476 boolean seqDeleted = false;
477 command.string = new char[command.seqs.length][];
479 for (int i = 0; i < command.seqs.length; i++)
481 final SequenceI sequence = command.seqs[i];
482 if (sequence.getLength() > command.position)
484 command.string[i] = sequence.getSequence(command.position,
485 command.position + command.number);
486 SequenceI oldds = sequence.getDatasetSequence();
487 if (command.oldds != null && command.oldds[i] != null)
489 // we are redoing an undone cut.
490 sequence.setDatasetSequence(null);
492 sequence.deleteChars(command.position, command.position
494 if (command.oldds != null && command.oldds[i] != null)
496 // oldds entry contains the cut dataset sequence.
497 sequence.setDatasetSequence(command.oldds[i]);
498 command.oldds[i] = oldds;
502 // modify the oldds if necessary
503 if (oldds != sequence.getDatasetSequence()
504 || sequence.getSequenceFeatures() != null)
506 if (command.oldds == null)
508 command.oldds = new SequenceI[command.seqs.length];
510 command.oldds[i] = oldds;
514 sequence.findPosition(command.position),
515 sequence.findPosition(command.position
516 + command.number), false);
521 if (sequence.getLength() < 1)
523 command.al.deleteSequence(sequence);
528 adjustAnnotations(command, false, seqDeleted, views);
532 * Perform the given Paste command. This may be to add cut or copied sequences
533 * to an alignment, or to undo a 'Cut' action on a region of the alignment.
538 static void paste(Edit command, AlignmentI[] views)
542 boolean newDSWasNeeded;
543 int newstart, newend;
544 boolean seqWasDeleted = false;
545 int start = 0, end = 0;
547 for (int i = 0; i < command.seqs.length; i++)
550 newDSWasNeeded = command.oldds != null && command.oldds[i] != null;
551 if (command.seqs[i].getLength() < 1)
553 // ie this sequence was deleted, we need to
554 // read it to the alignment
555 if (command.alIndex[i] < command.al.getHeight())
557 List<SequenceI> sequences;
558 synchronized (sequences = command.al.getSequences())
560 if (!(command.alIndex[i] < 0))
562 sequences.add(command.alIndex[i], command.seqs[i]);
568 command.al.addSequence(command.seqs[i]);
570 seqWasDeleted = true;
572 newstart = command.seqs[i].getStart();
573 newend = command.seqs[i].getEnd();
575 tmp = new StringBuffer();
576 tmp.append(command.seqs[i].getSequence());
577 // Undo of a delete does not replace original dataset sequence on to
578 // alignment sequence.
580 if (command.string != null && command.string[i] != null)
582 if (command.position >= tmp.length())
584 // This occurs if padding is on, and residues
585 // are removed from end of alignment
586 int length = command.position - tmp.length();
589 tmp.append(command.gapChar);
593 tmp.insert(command.position, command.string[i]);
594 for (int s = 0; s < command.string[i].length; s++)
596 if (jalview.schemes.ResidueProperties.aaIndex[command.string[i][s]] != 23)
601 start = command.seqs[i].findPosition(command.position);
602 end = command.seqs[i].findPosition(command.position
605 if (command.seqs[i].getStart() == start)
615 command.string[i] = null;
618 command.seqs[i].setSequence(tmp.toString());
619 command.seqs[i].setStart(newstart);
620 command.seqs[i].setEnd(newend);
623 if (command.seqs[i].getDatasetSequence() != null)
628 ds = command.oldds[i];
632 // make a new DS sequence
633 // use new ds mechanism here
634 ds = new Sequence(command.seqs[i].getName(),
635 jalview.analysis.AlignSeq.extractGaps(
636 jalview.util.Comparison.GapChars,
637 command.seqs[i].getSequenceAsString()),
638 command.seqs[i].getStart(), command.seqs[i].getEnd());
639 ds.setDescription(command.seqs[i].getDescription());
641 if (command.oldds == null)
643 command.oldds = new SequenceI[command.seqs.length];
645 command.oldds[i] = command.seqs[i].getDatasetSequence();
646 command.seqs[i].setDatasetSequence(ds);
648 adjustFeatures(command, i, start, end, true);
651 adjustAnnotations(command, true, seqWasDeleted, views);
653 command.string = null;
656 static void replace(Edit command)
660 int start = command.position;
661 int end = command.number;
662 // TODO TUTORIAL - Fix for replacement with different length of sequence (or
664 // TODO Jalview 2.4 bugfix change to an aggregate command - original
665 // sequence string is cut, new string is pasted in.
666 command.number = start + command.string[0].length;
667 for (int i = 0; i < command.seqs.length; i++)
669 boolean newDSWasNeeded = command.oldds != null
670 && command.oldds[i] != null;
673 * cut addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT,
674 * cut, sg.getStartRes(), sg.getEndRes()-sg.getStartRes()+1,
675 * viewport.alignment));
679 * then addHistoryItem(new EditCommand( "Add sequences",
680 * EditCommand.PASTE, sequences, 0, alignment.getWidth(), alignment) );
683 oldstring = command.seqs[i].getSequenceAsString();
684 tmp = new StringBuffer(oldstring.substring(0, start));
685 tmp.append(command.string[i]);
686 String nogaprep = jalview.analysis.AlignSeq.extractGaps(
687 jalview.util.Comparison.GapChars, new String(
689 int ipos = command.seqs[i].findPosition(start)
690 - command.seqs[i].getStart();
691 tmp.append(oldstring.substring(end));
692 command.seqs[i].setSequence(tmp.toString());
693 command.string[i] = oldstring.substring(start, end).toCharArray();
694 String nogapold = jalview.analysis.AlignSeq.extractGaps(
695 jalview.util.Comparison.GapChars, new String(
697 if (!nogaprep.toLowerCase().equals(nogapold.toLowerCase()))
701 SequenceI oldds = command.seqs[i].getDatasetSequence();
702 command.seqs[i].setDatasetSequence(command.oldds[i]);
703 command.oldds[i] = oldds;
707 if (command.oldds == null)
709 command.oldds = new SequenceI[command.seqs.length];
711 command.oldds[i] = command.seqs[i].getDatasetSequence();
712 SequenceI newds = new Sequence(
713 command.seqs[i].getDatasetSequence());
714 String fullseq, osp = newds.getSequenceAsString();
715 fullseq = osp.substring(0, ipos) + nogaprep
716 + osp.substring(ipos + nogaprep.length());
717 newds.setSequence(fullseq.toUpperCase());
718 // TODO: JAL-1131 ensure newly created dataset sequence is added to
720 // dataset sequences associated with the alignment.
721 // TODO: JAL-1131 fix up any annotation associated with new dataset
722 // sequence to ensure that original sequence/annotation relationships
724 command.seqs[i].setDatasetSequence(newds);
733 final static void adjustAnnotations(Edit command, boolean insert,
734 boolean modifyVisibility, AlignmentI[] views)
736 AlignmentAnnotation[] annotations = null;
738 if (modifyVisibility && !insert)
740 // only occurs if a sequence was added or deleted.
741 command.deletedAnnotationRows = new Hashtable<SequenceI, AlignmentAnnotation[]>();
743 if (command.fullAlignmentHeight)
745 annotations = command.al.getAlignmentAnnotation();
750 AlignmentAnnotation[] tmp;
751 for (int s = 0; s < command.seqs.length; s++)
753 if (modifyVisibility)
755 // Rows are only removed or added to sequence object.
759 tmp = command.seqs[s].getAnnotation();
762 int alen = tmp.length;
763 for (int aa = 0; aa < tmp.length; aa++)
765 if (!command.al.deleteAnnotation(tmp[aa]))
767 // strip out annotation not in the current al (will be put
768 // back on insert in all views)
773 command.seqs[s].setAlignmentAnnotation(null);
774 if (alen != tmp.length)
776 // save the non-null annotation references only
777 AlignmentAnnotation[] saved = new AlignmentAnnotation[alen];
778 for (int aa = 0, aapos = 0; aa < tmp.length; aa++)
782 saved[aapos++] = tmp[aa];
787 command.deletedAnnotationRows.put(command.seqs[s], saved);
788 // and then remove any annotation in the other views
789 for (int alview = 0; views != null && alview < views.length; alview++)
791 if (views[alview] != command.al)
793 AlignmentAnnotation[] toremove = views[alview]
794 .getAlignmentAnnotation();
795 if (toremove == null || toremove.length == 0)
799 // remove any alignment annotation on this sequence that's
800 // on that alignment view.
801 for (int aa = 0; aa < toremove.length; aa++)
803 if (toremove[aa].sequenceRef == command.seqs[s])
805 views[alview].deleteAnnotation(toremove[aa]);
813 // save all the annotation
814 command.deletedAnnotationRows.put(command.seqs[s], tmp);
821 if (command.deletedAnnotationRows != null
822 && command.deletedAnnotationRows
823 .containsKey(command.seqs[s]))
825 AlignmentAnnotation[] revealed = command.deletedAnnotationRows
826 .get(command.seqs[s]);
827 command.seqs[s].setAlignmentAnnotation(revealed);
828 if (revealed != null)
830 for (int aa = 0; aa < revealed.length; aa++)
832 // iterate through al adding original annotation
833 command.al.addAnnotation(revealed[aa]);
835 for (int aa = 0; aa < revealed.length; aa++)
837 command.al.setAnnotationIndex(revealed[aa], aa);
839 // and then duplicate added annotation on every other alignment
841 for (int vnum = 0; views != null && vnum < views.length; vnum++)
843 if (views[vnum] != command.al)
845 int avwidth = views[vnum].getWidth() + 1;
846 // duplicate in this view
847 for (int a = 0; a < revealed.length; a++)
849 AlignmentAnnotation newann = new AlignmentAnnotation(
851 command.seqs[s].addAlignmentAnnotation(newann);
852 newann.padAnnotation(avwidth);
853 views[vnum].addAnnotation(newann);
854 views[vnum].setAnnotationIndex(newann, a);
864 if (command.seqs[s].getAnnotation() == null)
871 annotations = command.seqs[s].getAnnotation();
875 tmp = new AlignmentAnnotation[aSize
876 + command.seqs[s].getAnnotation().length];
878 System.arraycopy(annotations, 0, tmp, 0, aSize);
880 System.arraycopy(command.seqs[s].getAnnotation(), 0, tmp, aSize,
881 command.seqs[s].getAnnotation().length);
885 aSize = annotations.length;
889 if (annotations == null)
896 command.deletedAnnotations = new Hashtable<String, Annotation[]>();
901 for (int a = 0; a < annotations.length; a++)
903 if (annotations[a].autoCalculated
904 || annotations[a].annotations == null)
911 aSize = annotations[a].annotations.length;
914 temp = new Annotation[aSize + command.number];
915 if (annotations[a].padGaps)
917 for (int aa = 0; aa < temp.length; aa++)
919 temp[aa] = new Annotation(command.gapChar + "", null, ' ', 0);
925 if (command.position < aSize)
927 if (command.position + command.number >= aSize)
933 tSize = aSize - command.number;
945 temp = new Annotation[tSize];
950 if (command.position < annotations[a].annotations.length)
952 System.arraycopy(annotations[a].annotations, 0, temp, 0,
955 if (command.deletedAnnotations != null
956 && command.deletedAnnotations
957 .containsKey(annotations[a].annotationId))
959 Annotation[] restore = command.deletedAnnotations
960 .get(annotations[a].annotationId);
962 System.arraycopy(restore, 0, temp, command.position,
967 System.arraycopy(annotations[a].annotations, command.position,
968 temp, command.position + command.number, aSize
973 if (command.deletedAnnotations != null
974 && command.deletedAnnotations
975 .containsKey(annotations[a].annotationId))
977 Annotation[] restore = command.deletedAnnotations
978 .get(annotations[a].annotationId);
980 temp = new Annotation[annotations[a].annotations.length
982 System.arraycopy(annotations[a].annotations, 0, temp, 0,
983 annotations[a].annotations.length);
984 System.arraycopy(restore, 0, temp,
985 annotations[a].annotations.length, restore.length);
989 temp = annotations[a].annotations;
995 if (tSize != aSize || command.position < 2)
997 int copylen = Math.min(command.position,
998 annotations[a].annotations.length);
1001 System.arraycopy(annotations[a].annotations, 0, temp, 0,
1002 copylen); // command.position);
1005 Annotation[] deleted = new Annotation[command.number];
1006 if (copylen >= command.position)
1008 copylen = Math.min(command.number,
1009 annotations[a].annotations.length - command.position);
1012 System.arraycopy(annotations[a].annotations,
1013 command.position, deleted, 0, copylen); // command.number);
1017 command.deletedAnnotations.put(annotations[a].annotationId,
1019 if (annotations[a].annotations.length > command.position
1022 System.arraycopy(annotations[a].annotations, command.position
1023 + command.number, temp, command.position,
1024 annotations[a].annotations.length - command.position
1025 - command.number); // aSize
1030 int dSize = aSize - command.position;
1034 Annotation[] deleted = new Annotation[command.number];
1035 System.arraycopy(annotations[a].annotations, command.position,
1038 command.deletedAnnotations.put(annotations[a].annotationId,
1041 tSize = Math.min(annotations[a].annotations.length,
1043 temp = new Annotation[tSize];
1044 System.arraycopy(annotations[a].annotations, 0, temp, 0, tSize);
1048 temp = annotations[a].annotations;
1053 annotations[a].annotations = temp;
1057 final static void adjustFeatures(Edit command, int index, int i, int j,
1060 SequenceI seq = command.seqs[index];
1061 SequenceI sequence = seq.getDatasetSequence();
1062 if (sequence == null)
1069 if (command.editedFeatures != null
1070 && command.editedFeatures.containsKey(seq))
1072 sequence.setSequenceFeatures(command.editedFeatures
1079 SequenceFeature[] sf = sequence.getSequenceFeatures();
1086 SequenceFeature[] oldsf = new SequenceFeature[sf.length];
1090 for (int s = 0; s < sf.length; s++)
1092 SequenceFeature copy = new SequenceFeature(sf[s]);
1096 if (sf[s].getEnd() < i)
1101 if (sf[s].getBegin() > j)
1103 sf[s].setBegin(copy.getBegin() - cSize);
1104 sf[s].setEnd(copy.getEnd() - cSize);
1108 if (sf[s].getBegin() >= i)
1113 if (sf[s].getEnd() < j)
1115 sf[s].setEnd(j - 1);
1118 sf[s].setEnd(sf[s].getEnd() - (cSize));
1120 if (sf[s].getBegin() > sf[s].getEnd())
1122 sequence.deleteFeature(sf[s]);
1126 if (command.editedFeatures == null)
1128 command.editedFeatures = new Hashtable<SequenceI, SequenceFeature[]>();
1131 command.editedFeatures.put(seq, oldsf);
1136 * Returns the list of edit commands wrapped by this object.
1140 public List<Edit> getEdits()
1146 * Returns a map whose keys are the dataset sequences, and values their
1147 * aligned sequences before the command edit list was applied. The aligned
1148 * sequences are copies, which may be updated without affecting the originals.
1150 * The command holds references to the aligned sequences (after editing). If
1151 * the command is an 'undo',then the prior state is simply the aligned state.
1152 * Otherwise, we have to derive the prior state by working backwards through
1153 * the edit list to infer the aligned sequences before editing.
1155 * Note: an alternative solution would be to cache the 'before' state of each
1156 * edit, but this would be expensive in space in the common case that the
1157 * original is never needed (edits are not mirrored).
1160 * @throws IllegalStateException
1161 * on detecting an edit command of a type that can't be unwound
1163 public Map<SequenceI, SequenceI> priorState(boolean forUndo)
1165 Map<SequenceI, SequenceI> result = new HashMap<SequenceI, SequenceI>();
1166 if (getEdits() == null)
1172 for (Edit e : getEdits())
1174 for (SequenceI seq : e.getSequences())
1176 SequenceI ds = seq.getDatasetSequence();
1177 SequenceI preEdit = result.get(ds);
1178 if (preEdit == null)
1180 preEdit = new Sequence("", seq.getSequenceAsString());
1181 preEdit.setDatasetSequence(ds);
1182 result.put(ds, preEdit);
1190 * Work backwards through the edit list, deriving the sequences before each
1191 * was applied. The final result is the sequence set before any edits.
1193 Iterator<Edit> edits = new ReverseListIterator<Edit>(getEdits());
1194 while (edits.hasNext())
1196 Edit oldEdit = edits.next();
1197 Action action = oldEdit.getAction();
1198 int position = oldEdit.getPosition();
1199 int number = oldEdit.getNumber();
1200 final char gap = oldEdit.getGapCharacter();
1201 for (SequenceI seq : oldEdit.getSequences())
1203 SequenceI ds = seq.getDatasetSequence();
1204 SequenceI preEdit = result.get(ds);
1205 if (preEdit == null)
1207 preEdit = new Sequence("", seq.getSequenceAsString());
1208 preEdit.setDatasetSequence(ds);
1209 result.put(ds, preEdit);
1212 * 'Undo' this edit action on the sequence (updating the value in the
1217 if (action == Action.DELETE_GAP)
1219 preEdit.setSequence(new String(StringUtils.insertCharAt(
1220 preEdit.getSequence(), position,
1223 else if (action == Action.INSERT_GAP)
1225 preEdit.setSequence(new String(StringUtils.deleteChars(
1226 preEdit.getSequence(), position, position + number)));
1230 throw new IllegalStateException("Can't undo edit action " + action);
1240 public SequenceI[] oldds;
1242 boolean fullAlignmentHeight = false;
1244 Hashtable<SequenceI, AlignmentAnnotation[]> deletedAnnotationRows;
1246 Hashtable<String, Annotation[]> deletedAnnotations;
1248 Hashtable<SequenceI, SequenceFeature[]> editedFeatures;
1260 int position, number;
1264 public Edit(Action command, SequenceI[] seqs, int position, int number,
1267 this.command = command;
1269 this.position = position;
1270 this.number = number;
1271 this.gapChar = gapChar;
1274 Edit(Action command, SequenceI[] seqs, int position, int number,
1277 this.gapChar = al.getGapCharacter();
1278 this.command = command;
1280 this.position = position;
1281 this.number = number;
1284 alIndex = new int[seqs.length];
1285 for (int i = 0; i < seqs.length; i++)
1287 alIndex[i] = al.findIndex(seqs[i]);
1290 fullAlignmentHeight = (al.getHeight() == seqs.length);
1293 Edit(Action command, SequenceI[] seqs, int position, int number,
1294 AlignmentI al, String replace)
1296 this.command = command;
1298 this.position = position;
1299 this.number = number;
1301 this.gapChar = al.getGapCharacter();
1302 string = new char[seqs.length][];
1303 for (int i = 0; i < seqs.length; i++)
1305 string[i] = replace.toCharArray();
1308 fullAlignmentHeight = (al.getHeight() == seqs.length);
1311 public SequenceI[] getSequences()
1316 public int getPosition()
1321 public Action getAction()
1326 public int getNumber()
1331 public char getGapCharacter()
1338 * Returns an iterator over the list of edit commands which traverses the list
1339 * either forwards or backwards.
1344 public Iterator<Edit> getEditIterator(boolean forwards)
1348 return getEdits().iterator();
1352 return new ReverseListIterator<Edit>(getEdits());