From 04c49245650f804b89b88b6818fd8add2ef9343e Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 19 Apr 2007 14:42:24 +0000 Subject: [PATCH] REPLACE added to edit command --- src/jalview/appletgui/APopupMenu.java | 42 +++++++++++- src/jalview/commands/EditCommand.java | 122 +++++++++++++++++++++++++-------- 2 files changed, 134 insertions(+), 30 deletions(-) diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index b281fcd..8af2759 100755 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -70,6 +70,7 @@ public class APopupMenu MenuItem repGroup = new MenuItem(); MenuItem sequenceName = new MenuItem("Edit Name/Description"); MenuItem sequenceFeature = new MenuItem("Create Sequence Feature"); + MenuItem editSequence = new MenuItem("Edit Sequence"); Sequence seq; MenuItem revealAll = new MenuItem(); @@ -310,7 +311,6 @@ public class APopupMenu if (dialog.accept) { - getGroup().setName(dialog.getName().replace(' ', '_')); getGroup().setDescription(dialog.getDescription()); } @@ -324,6 +324,42 @@ public class APopupMenu { ap.alignFrame.cut_actionPerformed(); } + else if(source == editSequence) + { + SequenceGroup sg = ap.av.getSelectionGroup(); + + if(sg!=null) + { + if (seq == null) + seq = (Sequence) sg.getSequenceAt(0); + + EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString( + sg.getStartRes(), + sg.getEndRes() + 1), + null, + "Edit Sequence ", + null, + + ap.alignFrame, + "Edit Sequence", + 500, 100); + + if (dialog.accept) + { + EditCommand editCommand = new EditCommand( + "Edit Sequences", EditCommand.REPLACE, + dialog.getName(), + sg.getSequencesAsArray(ap.av.hiddenRepSequences), + sg.getStartRes(), sg.getEndRes()+1, ap.av.alignment + ); + + ap.alignFrame.addHistoryItem(editCommand); + + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); + } + } + } else if (source == toUpper || source == toLower || source == toggleCase) { SequenceGroup sg = ap.av.getSelectionGroup(); @@ -597,6 +633,10 @@ public class APopupMenu copy.addActionListener(this); editMenu.add(cut); cut.addActionListener(this); + + editMenu.add(editSequence); + editSequence.addActionListener(this); + editMenu.add(toUpper); toUpper.addActionListener(this); editMenu.add(toLower); diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index 45b19af..ccc6a81 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) - { - insertGap(edits[e]); - } - else if (edits[e].command == DELETE_GAP) - { - deleteGap(edits[e]); - } - else if (edits[e].command == CUT) - { - cut(edits[e]); - } - else if (edits[e].command == PASTE) + switch(edits[e].command) { - paste(edits[e]); + case INSERT_GAP: + insertGap(edits[e]); + break; + case DELETE_GAP: + deleteGap(edits[e]); + break; + case CUT: + cut(edits[e]); + 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) - { - deleteGap(edits[e]); - } - else if (edits[e].command == DELETE_GAP) - { - insertGap(edits[e]); - } - else if (edits[e].command == CUT) - { - paste(edits[e]); - } - else if (edits[e].command == PASTE) + switch (edits[e].command) { - cut(edits[e]); + case INSERT_GAP: + deleteGap(edits[e]); + break; + case DELETE_GAP: + insertGap(edits[e]); + break; + case CUT: + paste(edits[e]); + break; + case PASTE: + cut(edits[e]); + break; + case REPLACE: + replace(edits[e]); + break; } } } @@ -327,9 +350,29 @@ public class EditCommand command.string = null; } - final void adjustAnnotations(Edit command, boolean insert, boolean modifyVisibility) + 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) + { AlignmentAnnotation[] annotations = null; if (modifyVisibility && !insert) @@ -704,6 +747,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; + string = new char[seqs.length][]; + for (int i = 0; i < seqs.length; i++) + { + string[i] = replace.toCharArray(); + } + + fullAlignmentHeight = (al.getHeight() == seqs.length); + } } } -- 1.7.10.2