MenuItem repGroup = new MenuItem();\r
MenuItem sequenceName = new MenuItem("Edit Name/Description");\r
MenuItem sequenceFeature = new MenuItem("Create Sequence Feature");\r
+ MenuItem editSequence = new MenuItem("Edit Sequence");\r
\r
Sequence seq;\r
MenuItem revealAll = new MenuItem();\r
\r
if (dialog.accept)\r
{\r
-\r
getGroup().setName(dialog.getName().replace(' ', '_'));\r
getGroup().setDescription(dialog.getDescription());\r
}\r
{\r
ap.alignFrame.cut_actionPerformed();\r
}\r
+ else if(source == editSequence)\r
+ {\r
+ SequenceGroup sg = ap.av.getSelectionGroup();\r
+\r
+ if(sg!=null)\r
+ {\r
+ if (seq == null)\r
+ seq = (Sequence) sg.getSequenceAt(0);\r
+\r
+ EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(\r
+ sg.getStartRes(),\r
+ sg.getEndRes() + 1),\r
+ null,\r
+ "Edit Sequence ",\r
+ null,\r
+\r
+ ap.alignFrame,\r
+ "Edit Sequence",\r
+ 500, 100);\r
+\r
+ if (dialog.accept)\r
+ {\r
+ EditCommand editCommand = new EditCommand(\r
+ "Edit Sequences", EditCommand.REPLACE,\r
+ dialog.getName(),\r
+ sg.getSequencesAsArray(ap.av.hiddenRepSequences),\r
+ sg.getStartRes(), sg.getEndRes()+1, ap.av.alignment\r
+ );\r
+\r
+ ap.alignFrame.addHistoryItem(editCommand);\r
+\r
+ ap.av.firePropertyChange("alignment", null,\r
+ ap.av.getAlignment().getSequences());\r
+ }\r
+ }\r
+ }\r
else if (source == toUpper || source == toLower || source == toggleCase)\r
{\r
SequenceGroup sg = ap.av.getSelectionGroup();\r
copy.addActionListener(this);\r
editMenu.add(cut);\r
cut.addActionListener(this);\r
+\r
+ editMenu.add(editSequence);\r
+ editSequence.addActionListener(this);\r
+\r
editMenu.add(toUpper);\r
toUpper.addActionListener(this);\r
editMenu.add(toLower);\r
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;
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;
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;
}
}
}
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;
}
}
}
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)
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);
+ }
}
}