X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fcommands%2FEditCommand.java;h=ce881273d13d79100884ba4e42ca30257a1b2707;hb=855f7a4bb3e8d5fcfa9059df64262fc73f0164be;hp=052b212fed256fcc2efffbc1ab9fcb7361c2c8c0;hpb=537bad6655186ae1c9daf2dbe6746c7c7168aeb0;p=jalview.git diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index 052b212..ce88127 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -44,6 +44,7 @@ public class EditCommand public static final int DELETE_GAP = 1; public static final int CUT = 2; public static final int PASTE = 3; + public static final int REPLACE = 4; Edit[] edits; @@ -75,6 +76,24 @@ public class EditCommand performEdit(0); } + public EditCommand(String description, + int command, + String replace, + SequenceI[] seqs, + int position, + int number, + AlignmentI al) + { + this.description = description; + if (command == REPLACE) + { + edits = new Edit[] + { new Edit(command, seqs, position, number, al, replace)}; + } + + performEdit(0); + } + final public String getDescription() { return description; @@ -129,21 +148,23 @@ public class EditCommand int eSize = edits.length; for (int e = commandIndex; e < eSize; e++) { - if (edits[e].command == INSERT_GAP) + switch(edits[e].command) { + case INSERT_GAP: insertGap(edits[e]); - } - else if (edits[e].command == DELETE_GAP) - { + break; + case DELETE_GAP: deleteGap(edits[e]); - } - else if (edits[e].command == CUT) - { + break; + case CUT: cut(edits[e]); - } - else if (edits[e].command == PASTE) - { + break; + case PASTE: paste(edits[e]); + break; + case REPLACE: + replace(edits[e]); + break; } } } @@ -158,21 +179,23 @@ public class EditCommand int e = 0, eSize = edits.length; for (e = eSize - 1; e > -1; e--) { - if (edits[e].command == INSERT_GAP) + switch (edits[e].command) { + case INSERT_GAP: deleteGap(edits[e]); - } - else if (edits[e].command == DELETE_GAP) - { + break; + case DELETE_GAP: insertGap(edits[e]); - } - else if (edits[e].command == CUT) - { + break; + case CUT: paste(edits[e]); - } - else if (edits[e].command == PASTE) - { + break; + case PASTE: cut(edits[e]); + break; + case REPLACE: + replace(edits[e]); + break; } } } @@ -327,6 +350,27 @@ public class EditCommand command.string = null; } + void replace(Edit command) + { + StringBuffer tmp; + String oldstring; + int start = command.position; + int end = command.number; + + command.number = start + command.string[0].length; + for (int i = 0; i < command.seqs.length; i++) + { + oldstring = command.seqs[i].getSequenceAsString(); + tmp = new StringBuffer(oldstring.substring(0, start)); + tmp.append(command.string[i]); + tmp.append(oldstring.substring(end)); + command.seqs[i].setSequence(tmp.toString()); + command.string[i] = oldstring.substring(start, end).toCharArray(); + tmp = null; + oldstring = null; + } + } + final void adjustAnnotations(Edit command, boolean insert, boolean modifyVisibility) { @@ -347,7 +391,7 @@ public class EditCommand AlignmentAnnotation[] tmp; for (int s = 0; s < command.seqs.length; s++) { - if (modifyVisibility) + if (modifyVisibility) { // Rows are only removed or added to sequence object. if (!insert) { @@ -428,11 +472,22 @@ public class EditCommand } int tSize = 0; - + if (annotations[a].annotations == null) + { + // nothing to edit here ? + continue; + } aSize = annotations[a].annotations.length; if (insert) { temp = new Annotation[aSize + command.number]; + if(annotations[a].padGaps) + for (int aa = 0; aa < temp.length; aa++) + { + temp[aa] = new Annotation( + command.gapChar+"", + null, ' ', 0); + } } else { @@ -697,6 +752,27 @@ public class EditCommand fullAlignmentHeight = (al.getHeight() == seqs.length); } - } + Edit(int command, + SequenceI[] seqs, + int position, + int number, + AlignmentI al, + String replace) + { + this.command = command; + this.seqs = seqs; + this.position = position; + this.number = number; + this.al = al; + this.gapChar = al.getGapCharacter(); + string = new char[seqs.length][]; + for (int i = 0; i < seqs.length; i++) + { + string[i] = replace.toCharArray(); + } + + fullAlignmentHeight = (al.getHeight() == seqs.length); + } + } }