*/
package jalview.appletgui;
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.analysis.*;
-import jalview.commands.*;
-import jalview.datamodel.*;
-import jalview.schemes.*;
-import jalview.util.MessageManager;
-import jalview.util.UrlLink;
+import jalview.analysis.AAFrequency;
+import jalview.analysis.Conservation;
+import jalview.commands.ChangeCaseCommand;
+import jalview.commands.EditCommand;
+import jalview.commands.EditCommand.Action;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
import jalview.io.AppletFormatAdapter;
import jalview.io.SequenceAnnotationReport;
+import jalview.schemes.Blosum62ColourScheme;
+import jalview.schemes.BuriedColourScheme;
+import jalview.schemes.ClustalxColourScheme;
+import jalview.schemes.HelixColourScheme;
+import jalview.schemes.HydrophobicColourScheme;
+import jalview.schemes.NucleotideColourScheme;
+import jalview.schemes.PIDColourScheme;
+import jalview.schemes.ResidueProperties;
+import jalview.schemes.StrandColourScheme;
+import jalview.schemes.TaylorColourScheme;
+import jalview.schemes.TurnColourScheme;
+import jalview.schemes.ZappoColourScheme;
+import jalview.util.MessageManager;
+import jalview.util.UrlLink;
+
+import java.awt.CheckboxMenuItem;
+import java.awt.Frame;
+import java.awt.Menu;
+import java.awt.MenuItem;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.Vector;
public class APopupMenu extends java.awt.PopupMenu implements
ActionListener, ItemListener
if (sg != null)
{
if (seq == null)
+ {
seq = (Sequence) sg.getSequenceAt(0);
+ }
EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
sg.getStartRes(), sg.getEndRes() + 1), null,
if (dialog.accept)
{
EditCommand editCommand = new EditCommand(MessageManager.getString("label.edit_sequences"),
- EditCommand.REPLACE, dialog.getName().replace(' ',
+ Action.REPLACE, dialog.getName().replace(' ',
ap.av.getGapCharacter()),
sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
sg.getStartRes(), sg.getEndRes() + 1,
PDBEntry entry = (PDBEntry) seq.getPDBId().firstElement();
if (ap.av.applet.jmolAvailable)
+ {
new jalview.appletgui.AppletJmol(entry, new Sequence[]
{ seq }, null, ap, AppletFormatAdapter.URL);
+ }
else
+ {
new MCview.AppletPDBViewer(entry, new Sequence[]
{ seq }, null, ap, AppletFormatAdapter.URL);
+ }
}
else
import jalview.bin.JalviewLite;
import jalview.commands.CommandI;
import jalview.commands.EditCommand;
+import jalview.commands.EditCommand.Action;
import jalview.commands.OrderCommand;
import jalview.commands.RemoveGapColCommand;
import jalview.commands.RemoveGapsCommand;
}
// !newAlignment
- addHistoryItem(new EditCommand(MessageManager.getString("label.add_sequences"), EditCommand.PASTE,
+ addHistoryItem(new EditCommand(
+ MessageManager.getString("label.add_sequences"), Action.PASTE,
seqs, 0, viewport.getAlignment().getWidth(),
viewport.getAlignment()));
/*
* //ADD HISTORY ITEM
*/
- addHistoryItem(new EditCommand(MessageManager.getString("label.cut_sequences"), EditCommand.CUT, cut,
- sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
+ addHistoryItem(new EditCommand(
+ MessageManager.getString("label.cut_sequences"), Action.CUT,
+ cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
viewport.getAlignment()));
viewport.setSelectionGroup(null);
*/
package jalview.appletgui;
-import java.util.*;
-import java.util.List;
-import java.awt.*;
-import java.awt.event.*;
-
import jalview.analysis.AlignSeq;
-import jalview.commands.*;
-import jalview.datamodel.*;
+import jalview.commands.CommandI;
+import jalview.commands.EditCommand;
+import jalview.commands.EditCommand.Action;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
import jalview.util.MessageManager;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.AdjustmentListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+import java.util.Vector;
+
public class RedundancyPanel extends SliderPanel implements Runnable,
WindowListener
{
}
EditCommand cut = new EditCommand(MessageManager.getString("action.remove_redundancy"),
- EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
+ Action.CUT, deleted, 0, width, ap.av.getAlignment());
AlignmentI alignment = ap.av.getAlignment();
for (int i = 0; i < del.size(); i++)
{
*/
package jalview.appletgui;
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.commands.*;
-import jalview.datamodel.*;
-import jalview.schemes.*;
+import jalview.commands.EditCommand;
+import jalview.commands.EditCommand.Action;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.schemes.ResidueProperties;
import jalview.structure.SelectionSource;
import jalview.structure.SequenceListener;
import jalview.structure.StructureSelectionManager;
import jalview.util.MessageManager;
+import java.awt.BorderLayout;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Panel;
+import java.awt.Point;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.util.Vector;
+
public class SeqPanel extends Panel implements MouseMotionListener,
MouseListener, SequenceListener
{
void setCursorPosition()
{
- SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(
+ SequenceI sequence = av.getAlignment().getSequenceAt(
seqCanvas.cursorY);
seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
void setSelectionAreaAtCursor(boolean topLeft)
{
- SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(
+ SequenceI sequence = av.getAlignment().getSequenceAt(
seqCanvas.cursorY);
if (av.getSelectionGroup() != null)
{
String tmp = sequence.hashCode() + index + "";
if (lastMessage == null || !lastMessage.equals(tmp))
+ {
ssm.mouseOverSequence(sequence, index, pos, av);
+ }
lastMessage = tmp;
}
int respos = sequence.findPosition(res);
if (ssm != null)
+ {
mouseOverSequence(sequence, res, respos);
+ }
StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: "
+ sequence.getName());
.containsKey(features[i].featureGroup)
&& !((Boolean) seqCanvas.fr.featureGroups
.get(features[i].featureGroup)).booleanValue())
+ {
continue;
+ }
if ((features[i].getBegin() <= res)
&& (features[i].getEnd() >= res))
{
if (av.isHiddenRepSequence(seq))
{
- sg = (SequenceGroup) av.getRepresentedSequences(seq);
+ sg = av.getRepresentedSequences(seq);
groupEditing = true;
}
}
}
else
{
- editCommand.appendEdit(EditCommand.INSERT_GAP, groupSeqs,
+ editCommand.appendEdit(Action.INSERT_GAP, groupSeqs,
startres, startres - lastres, av.getAlignment(), true);
}
}
}
else
{
- editCommand.appendEdit(EditCommand.DELETE_GAP, groupSeqs,
+ editCommand.appendEdit(Action.DELETE_GAP, groupSeqs,
startres, lastres - startres, av.getAlignment(), true);
}
}
else
{
- editCommand.appendEdit(EditCommand.INSERT_GAP, new SequenceI[]
+ editCommand.appendEdit(Action.INSERT_GAP, new SequenceI[]
{ seq }, lastres, startres - lastres, av.getAlignment(), true);
}
}
if (max > 0)
{
- editCommand.appendEdit(EditCommand.DELETE_GAP, new SequenceI[]
+ editCommand.appendEdit(Action.DELETE_GAP, new SequenceI[]
{ seq }, startres, max, av.getAlignment(), true);
}
}
}
}
- editCommand.appendEdit(EditCommand.DELETE_GAP, seq, blankColumn, 1,
+ editCommand.appendEdit(Action.DELETE_GAP, seq, blankColumn, 1,
av.getAlignment(), true);
- editCommand.appendEdit(EditCommand.INSERT_GAP, seq, j, 1,
+ editCommand.appendEdit(Action.INSERT_GAP, seq, j, 1,
av.getAlignment(), true);
}
void deleteChar(int j, SequenceI[] seq, int fixedColumn)
{
- editCommand.appendEdit(EditCommand.DELETE_GAP, seq, j, 1,
+ editCommand.appendEdit(Action.DELETE_GAP, seq, j, 1,
av.getAlignment(), true);
- editCommand.appendEdit(EditCommand.INSERT_GAP, seq, fixedColumn, 1,
+ editCommand.appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1,
av.getAlignment(), true);
}
return;
}
- SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
+ SequenceI sequence = av.getAlignment().getSequenceAt(seq);
if (sequence == null || res > sequence.getLength())
{
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
+import java.util.ListIterator;
/**
*
*/
public class EditCommand implements CommandI
{
- public static final int INSERT_GAP = 0;
-
- 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;
-
- public static final int INSERT_NUC = 5;
+ public enum Action
+ {
+ INSERT_GAP, DELETE_GAP, CUT, PASTE, REPLACE, INSERT_NUC
+ };
- Edit[] edits;
+ private List<Edit> edits = new ArrayList<Edit>();
String description;
this.description = description;
}
- public EditCommand(String description, int command, SequenceI[] seqs,
+ public EditCommand(String description, Action command, SequenceI[] seqs,
int position, int number, AlignmentI al)
{
this.description = description;
- if (command == CUT || command == PASTE)
+ if (command == Action.CUT || command == Action.PASTE)
{
- edits = new Edit[]
- { new Edit(command, seqs, position, number, al) };
+ setEdit(new Edit(command, seqs, position, number, al));
}
performEdit(0, null);
}
- public EditCommand(String description, int command, String replace,
+ public EditCommand(String description, Action command, String replace,
SequenceI[] seqs, int position, int number, AlignmentI al)
{
this.description = description;
- if (command == REPLACE)
+ if (command == Action.REPLACE)
{
- edits = new Edit[]
- { new Edit(command, seqs, position, number, al, replace) };
+ setEdit(new Edit(command, seqs, position, number, al, replace));
}
performEdit(0, null);
}
+ /**
+ * Set the list of edits to the specified item (only).
+ *
+ * @param e
+ */
+ protected void setEdit(Edit e)
+ {
+ edits.clear();
+ edits.add(e);
+ }
+
+ /**
+ * Add the given edit command to the stored list of commands.
+ *
+ * @param e
+ */
+ protected void addEdit(Edit e)
+ {
+ edits.add(e);
+ }
+
+ /**
+ * Clear the list of stored edit commands.
+ *
+ */
+ protected void clearEdits()
+ {
+ edits.clear();
+ }
+
+ /**
+ * Returns the i'th stored Edit command.
+ *
+ * @param i
+ * @return
+ */
+ protected Edit getEdit(int i)
+ {
+ if (i >= 0 && i < edits.size())
+ {
+ return edits.get(i);
+ }
+ return null;
+ }
+
@Override
final public String getDescription()
{
@Override
public int getSize()
{
- return edits == null ? 0 : edits.length;
+ return edits.size();
}
+ /**
+ * Return the alignment for the first edit (or null if no edit).
+ *
+ * @return
+ */
final public AlignmentI getAlignment()
{
- return edits[0].al;
+ return (edits.isEmpty() ? null : edits.get(0).al);
}
/**
* @param al
* @param performEdit
*/
- final public void appendEdit(int command, SequenceI[] seqs, int position,
+ final public void appendEdit(Action command, SequenceI[] seqs,
+ int position,
int number, AlignmentI al, boolean performEdit)
{
appendEdit(command, seqs, position, number, al, performEdit, null);
* @param performEdit
* @param views
*/
- final public void appendEdit(int command, SequenceI[] seqs, int position,
+ final public void appendEdit(Action command, SequenceI[] seqs,
+ int position,
int number, AlignmentI al, boolean performEdit, AlignmentI[] views)
{
Edit edit = new Edit(command, seqs, position, number,
edit.fullAlignmentHeight = true;
}
- if (edits != null)
- {
- Edit[] temp = new Edit[edits.length + 1];
- System.arraycopy(edits, 0, temp, 0, edits.length);
- edits = temp;
- edits[edits.length - 1] = edit;
- }
- else
- {
- edits = new Edit[]
- { edit };
- }
+ edits.add(edit);
if (performEdit)
{
- performEdit(edits.length - 1, views);
+ performEdit(edit, views);
}
}
+ /**
+ * Execute all the edit commands, starting at the given commandIndex
+ *
+ * @param commandIndex
+ * @param views
+ */
final void performEdit(int commandIndex, AlignmentI[] views)
{
- int eSize = edits.length;
- for (int e = commandIndex; e < eSize; e++)
+ ListIterator<Edit> iterator = edits.listIterator(commandIndex);
+ while (iterator.hasNext())
{
- switch (edits[e].command)
- {
- case INSERT_GAP:
- insertGap(edits[e]);
- break;
- case DELETE_GAP:
- deleteGap(edits[e]);
- break;
- case CUT:
- cut(edits[e], views);
- break;
- case PASTE:
- paste(edits[e], views);
- break;
- case REPLACE:
- replace(edits[e]);
- break;
+ Edit edit = iterator.next();
+ performEdit(edit, views);
+ }
+ }
+
+ /**
+ * Execute one edit command in all the specified alignment views
+ *
+ * @param edit
+ * @param views
+ */
+ protected void performEdit(Edit edit, AlignmentI[] views)
+ {
+ switch (edit.command)
+ {
+ case INSERT_GAP:
+ insertGap(edit);
+ break;
+ case DELETE_GAP:
+ deleteGap(edit);
+ break;
+ case CUT:
+ cut(edit, views);
+ break;
+ case PASTE:
+ paste(edit, views);
+ break;
+ case REPLACE:
+ replace(edit);
+ break;
+ case INSERT_NUC:
// TODO:add deleteNuc for UNDO
// case INSERT_NUC:
// insertNuc(edits[e]);
- // break;
- }
+ break;
+ default:
+ break;
}
}
performEdit(0, views);
}
+ /**
+ * Undo the stored list of commands, in reverse order.
+ */
@Override
final public void undoCommand(AlignmentI[] views)
{
- for(Edit e : edits){
- switch (e.command)
- {
- case INSERT_GAP:
- deleteGap(e);
- break;
- case DELETE_GAP:
- insertGap(e);
- break;
- case CUT:
- paste(e, views);
- break;
- case PASTE:
- cut(e, views);
- break;
- case REPLACE:
- replace(e);
- break;
- }
+ ListIterator<Edit> iterator = edits.listIterator(edits.size());
+ while (iterator.hasPrevious())
+ {
+ Edit e = iterator.previous();
+ switch (e.command)
+ {
+ case INSERT_GAP:
+ deleteGap(e);
+ break;
+ case DELETE_GAP:
+ insertGap(e);
+ break;
+ case CUT:
+ paste(e, views);
+ break;
+ case PASTE:
+ cut(e, views);
+ break;
+ case REPLACE:
+ replace(e);
+ break;
+ case INSERT_NUC:
+ // not implemented
+ break;
+ default:
+ break;
+ }
}
}
- final void insertGap(Edit command)
+ /**
+ * Insert gap(s) in sequences as specified by the command, and adjust
+ * annotations.
+ *
+ * @param command
+ */
+ final private void insertGap(Edit command)
{
for (int s = 0; s < command.seqs.length; s++)
// adjustAnnotations(command, true, false, null);
// }
- final void deleteGap(Edit command)
+ /**
+ * Delete gap(s) in sequences as specified by the command, and adjust
+ * annotations.
+ *
+ * @param command
+ */
+ final private void deleteGap(Edit command)
{
for (int s = 0; s < command.seqs.length; s++)
{
adjustAnnotations(command, false, false, null);
}
+ /**
+ * Carry out a Cut action. The cut characters are saved in case Undo is
+ * requested.
+ *
+ * @param command
+ * @param views
+ */
void cut(Edit command, AlignmentI[] views)
{
boolean seqDeleted = false;
for (int i = 0; i < command.seqs.length; i++)
{
- if (command.seqs[i].getLength() > command.position)
+ final SequenceI sequence = command.seqs[i];
+ if (sequence.getLength() > command.position)
{
- command.string[i] = command.seqs[i].getSequence(command.position,
+ command.string[i] = sequence.getSequence(command.position,
command.position + command.number);
- SequenceI oldds = command.seqs[i].getDatasetSequence();
+ SequenceI oldds = sequence.getDatasetSequence();
if (command.oldds != null && command.oldds[i] != null)
{
// we are redoing an undone cut.
- command.seqs[i].setDatasetSequence(null);
+ sequence.setDatasetSequence(null);
}
- command.seqs[i].deleteChars(command.position, command.position
+ sequence.deleteChars(command.position, command.position
+ command.number);
if (command.oldds != null && command.oldds[i] != null)
{
// oldds entry contains the cut dataset sequence.
- command.seqs[i].setDatasetSequence(command.oldds[i]);
+ sequence.setDatasetSequence(command.oldds[i]);
command.oldds[i] = oldds;
}
else
{
// modify the oldds if necessary
- if (oldds != command.seqs[i].getDatasetSequence()
- || command.seqs[i].getSequenceFeatures() != null)
+ if (oldds != sequence.getDatasetSequence()
+ || sequence.getSequenceFeatures() != null)
{
if (command.oldds == null)
{
adjustFeatures(
command,
i,
- command.seqs[i].findPosition(command.position),
- command.seqs[i].findPosition(command.position
+ sequence.findPosition(command.position),
+ sequence.findPosition(command.position
+ command.number), false);
}
}
}
- if (command.seqs[i].getLength() < 1)
+ if (sequence.getLength() < 1)
{
- command.al.deleteSequence(command.seqs[i]);
+ command.al.deleteSequence(sequence);
seqDeleted = true;
}
}
adjustAnnotations(command, false, seqDeleted, views);
}
+ /**
+ * Perform the given Paste command. This may be to add cut or copied sequences
+ * to an alignment, or to undo a 'Cut' action on a region of the alignment.
+ *
+ * @param command
+ * @param views
+ */
void paste(Edit command, AlignmentI[] views)
{
StringBuffer tmp;
if (modifyVisibility && !insert)
{
// only occurs if a sequence was added or deleted.
- command.deletedAnnotationRows = new Hashtable();
+ command.deletedAnnotationRows = new Hashtable<SequenceI, AlignmentAnnotation[]>();
}
if (command.fullAlignmentHeight)
{
&& command.deletedAnnotationRows
.containsKey(command.seqs[s]))
{
- AlignmentAnnotation[] revealed = (AlignmentAnnotation[]) command.deletedAnnotationRows
+ AlignmentAnnotation[] revealed = command.deletedAnnotationRows
.get(command.seqs[s]);
command.seqs[s].setAlignmentAnnotation(revealed);
if (revealed != null)
if (!insert)
{
- command.deletedAnnotations = new Hashtable();
+ command.deletedAnnotations = new Hashtable<String, Annotation[]>();
}
int aSize;
&& command.deletedAnnotations
.containsKey(annotations[a].annotationId))
{
- Annotation[] restore = (Annotation[]) command.deletedAnnotations
+ Annotation[] restore = command.deletedAnnotations
.get(annotations[a].annotationId);
System.arraycopy(restore, 0, temp, command.position,
&& command.deletedAnnotations
.containsKey(annotations[a].annotationId))
{
- Annotation[] restore = (Annotation[]) command.deletedAnnotations
+ Annotation[] restore = command.deletedAnnotations
.get(annotations[a].annotationId);
temp = new Annotation[annotations[a].annotations.length
if (command.editedFeatures != null
&& command.editedFeatures.containsKey(seq))
{
- sequence.setSequenceFeatures((SequenceFeature[]) command.editedFeatures
+ sequence.setSequenceFeatures(command.editedFeatures
.get(seq));
}
if (command.editedFeatures == null)
{
- command.editedFeatures = new Hashtable();
+ command.editedFeatures = new Hashtable<SequenceI, SequenceFeature[]>();
}
command.editedFeatures.put(seq, oldsf);
boolean fullAlignmentHeight = false;
- Hashtable deletedAnnotationRows;
+ Hashtable<SequenceI, AlignmentAnnotation[]> deletedAnnotationRows;
- Hashtable deletedAnnotations;
+ Hashtable<String, Annotation[]> deletedAnnotations;
- Hashtable editedFeatures;
+ Hashtable<SequenceI, SequenceFeature[]> editedFeatures;
AlignmentI al;
- int command;
+ Action command;
char[][] string;
char gapChar;
- Edit(int command, SequenceI[] seqs, int position, int number,
+ Edit(Action command, SequenceI[] seqs, int position, int number,
char gapChar)
{
this.command = command;
this.gapChar = gapChar;
}
- Edit(int command, SequenceI[] seqs, int position, int number,
+ Edit(Action command, SequenceI[] seqs, int position, int number,
AlignmentI al)
{
this.gapChar = al.getGapCharacter();
fullAlignmentHeight = (al.getHeight() == seqs.length);
}
- Edit(int command, SequenceI[] seqs, int position, int number,
+ Edit(Action command, SequenceI[] seqs, int position, int number,
AlignmentI al, String replace)
{
this.command = command;
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
-import jalview.datamodel.*;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
public class RemoveGapColCommand extends EditCommand
{
int startCol = -1, endCol = -1;
columnsDeleted = 0;
- edits = new Edit[0];
+ clearEdits();
boolean delete = true;
for (int i = start; i <= end; i++)
if (!delete && startCol > -1)
{
- this.appendEdit(DELETE_GAP, seqs, startCol - columnsDeleted, endCol
+ this.appendEdit(Action.DELETE_GAP, seqs, startCol - columnsDeleted,
+ endCol
- startCol, al, false, null);
columnsDeleted += (endCol - startCol);
// This is for empty columns at the
// end of the alignment
- this.appendEdit(DELETE_GAP, seqs, startCol - columnsDeleted, end
+ this.appendEdit(Action.DELETE_GAP, seqs, startCol - columnsDeleted,
+ end
- startCol + 1, al, false, null);
columnsDeleted += (end - startCol + 1);
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
-import jalview.datamodel.*;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
public class RemoveGapsCommand extends EditCommand
{
int j, jSize;
- edits = new Edit[0];
+ clearEdits();
boolean delete = true;
char[] sequence;
if (!delete && startCol > -1)
{
- this.appendEdit(DELETE_GAP, new SequenceI[]
+ this.appendEdit(Action.DELETE_GAP, new SequenceI[]
{ seqs[s] }, start + startCol - deletedCols, endCol - startCol,
al, false, null);
}
if (delete && startCol > -1)
{
- this.appendEdit(DELETE_GAP, new SequenceI[]
+ this.appendEdit(Action.DELETE_GAP, new SequenceI[]
{ seqs[s] }, start + startCol - deletedCols, jSize - startCol, al,
false, null);
}
*/
package jalview.commands;
-import jalview.datamodel.*;
+import jalview.datamodel.SequenceI;
public class SlideSequencesCommand extends EditCommand
{
for (i = 0; i < lSize; i++)
{
for (j = 0; j < slideSize; j++)
+ {
if (!jalview.util.Comparison.isGap(seqsLeft[i].getCharAt(j)))
{
gapsInsertedBegin = true;
break;
}
+ }
}
+ Edit e = null;
+
if (!gapsInsertedBegin)
- edits = new Edit[]
- { new Edit(DELETE_GAP, seqsLeft, 0, slideSize, gapChar) };
+ {
+ e = new Edit(Action.DELETE_GAP, seqsLeft, 0, slideSize, gapChar);
+ setEdit(e);
+ }
else
- edits = new Edit[]
- { new Edit(INSERT_GAP, seqsRight, 0, slideSize, gapChar) };
+ {
+ e = new Edit(Action.INSERT_GAP, seqsRight, 0, slideSize, gapChar);
+ setEdit(e);
+ }
- performEdit(0, null);
+ performEdit(e, null);
}
public boolean getGapsInsertedBegin()
{
boolean same = false;
- if (command.edits[0].seqs.length == edits[0].seqs.length)
+ if (command.getEdit(0).seqs.length == getEdit(0).seqs.length)
{
same = true;
- for (int i = 0; i < command.edits[0].seqs.length; i++)
+ for (int i = 0; i < command.getEdit(0).seqs.length; i++)
{
- if (edits[0].seqs[i] != command.edits[0].seqs[i])
+ if (getEdit(0).seqs[i] != command.getEdit(0).seqs[i])
{
same = false;
}
if (same)
{
- Edit[] temp = new Edit[command.edits.length + 1];
- System.arraycopy(command.edits, 0, temp, 0, command.edits.length);
- command.edits = temp;
- command.edits[command.edits.length - 1] = edits[0];
+ command.addEdit(getEdit(0));
}
return same;
*/
package jalview.commands;
-import java.util.*;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.util.ShiftList;
-import jalview.datamodel.*;
-import jalview.util.*;
+import java.util.List;
public class TrimRegionCommand extends EditCommand
{
SequenceGroup selectionGroup;
- Vector deletedHiddenColumns;
+ List<int[]> deletedHiddenColumns;
int columnsDeleted;
columnsDeleted = column;
- edits = new Edit[]
- { new Edit(CUT, seqs, 0, column, al) };
+ setEdit(new Edit(Action.CUT, seqs, 0, column, al));
}
else if (command.equalsIgnoreCase(TRIM_RIGHT))
{
columnsDeleted = width - 1;
- edits = new Edit[]
- { new Edit(CUT, seqs, column + 1, width, al) };
+ setEdit(new Edit(Action.CUT, seqs, column + 1, width, al));
}
// We need to keep a record of the sequence start
// in order to restore the state after a redo
- int i, isize = edits[0].seqs.length;
+ int i, isize = getEdit(0).seqs.length;
start = new int[isize];
for (i = 0; i < isize; i++)
{
- start[i] = edits[0].seqs[i].getStart();
+ start[i] = getEdit(0).seqs[i].getStart();
}
performEdit(0, null);
int[] region;
for (int i = 0; i < deletedHiddenColumns.size(); i++)
{
- region = (int[]) deletedHiddenColumns.elementAt(i);
+ region = deletedHiddenColumns.get(i);
colSel.hideColumns(region[0], region[1]);
}
}
*/
package jalview.datamodel;
-import java.util.*;
+import jalview.util.ShiftList;
-import jalview.util.*;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Vector;
/**
* NOTE: Columns are zero based.
* @param left
* shift in edit (+ve for removal, or -ve for inserts)
*/
- public Vector compensateForEdit(int start, int change)
+ public List<int[]> compensateForEdit(int start, int change)
{
- Vector deletedHiddenColumns = null;
+ List<int[]> deletedHiddenColumns = null;
for (int i = 0; i < size(); i++)
{
int temp = columnAt(i);
if (hiddenColumns != null)
{
- deletedHiddenColumns = new Vector();
+ deletedHiddenColumns = new ArrayList<int[]>();
int hSize = hiddenColumns.size();
for (int i = 0; i < hSize; i++)
{
int[] region = (int[]) hiddenColumns.elementAt(i);
if (region[0] > start && start + change > region[1])
{
- deletedHiddenColumns.addElement(hiddenColumns.elementAt(i));
+ deletedHiddenColumns.add(region);
hiddenColumns.removeElementAt(i);
i--;
public boolean isVisible(int column)
{
if (hiddenColumns != null)
+ {
for (int i = 0; i < hiddenColumns.size(); i++)
{
int[] region = (int[]) hiddenColumns.elementAt(i);
return false;
}
}
+ }
return true;
}
w += els.length;
}
if (w == 0)
+ {
return;
+ }
Enumeration e = annels.elements();
alignmentAnnotation.annotations = new Annotation[w];
w = 0;
import jalview.bin.Cache;
import jalview.commands.CommandI;
import jalview.commands.EditCommand;
+import jalview.commands.EditCommand.Action;
import jalview.commands.OrderCommand;
import jalview.commands.RemoveGapColCommand;
import jalview.commands.RemoveGapsCommand;
if (viewport.historyList.size() > 0)
{
undoMenuItem.setEnabled(true);
- CommandI command = (CommandI) viewport.historyList.peek();
+ CommandI command = viewport.historyList.peek();
undoMenuItem.setText(MessageManager.formatMessage(
"label.undo_command", new String[]
{ command.getDescription() }));
{
redoMenuItem.setEnabled(true);
- CommandI command = (CommandI) viewport.redoList.peek();
+ CommandI command = viewport.redoList.peek();
redoMenuItem.setText(MessageManager.formatMessage(
"label.redo_command", new String[]
{ command.getDescription() }));
{
return;
}
- CommandI command = (CommandI) viewport.historyList.pop();
+ CommandI command = viewport.historyList.pop();
viewport.redoList.push(command);
command.undoCommand(getViewAlignments());
return;
}
- CommandI command = (CommandI) viewport.redoList.pop();
+ CommandI command = viewport.redoList.pop();
viewport.historyList.push(command);
command.doCommand(getViewAlignments());
// /////
// ADD HISTORY ITEM
//
- addHistoryItem(new EditCommand(MessageManager.getString("label.add_sequences"), EditCommand.PASTE,
+ addHistoryItem(new EditCommand(
+ MessageManager.getString("label.add_sequences"),
+ Action.PASTE,
sequences, 0, alignment.getWidth(), alignment));
}
// Add any annotations attached to sequences
/*
* //ADD HISTORY ITEM
*/
- addHistoryItem(new EditCommand(MessageManager.getString("label.cut_sequences"), EditCommand.CUT, cut,
- sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
+ addHistoryItem(new EditCommand(
+ MessageManager.getString("label.cut_sequences"), Action.CUT,
+ cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
viewport.getAlignment()));
viewport.setSelectionGroup(null);
import jalview.analysis.NJTree;
import jalview.api.AlignViewportI;
import jalview.bin.Cache;
+import jalview.commands.CommandI;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
boolean gatherViewsHere = false;
- Stack historyList = new Stack();
+ Stack<CommandI> historyList = new Stack<CommandI>();
- Stack redoList = new Stack();
+ Stack<CommandI> redoList = new Stack<CommandI>();
int thresholdTextColour = 0;
import jalview.analysis.Conservation;
import jalview.commands.ChangeCaseCommand;
import jalview.commands.EditCommand;
+import jalview.commands.EditCommand.Action;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.Annotation;
import jalview.datamodel.DBRefEntry;
{
EditCommand editCommand = new EditCommand(
MessageManager.getString("label.edit_sequences"),
- EditCommand.REPLACE, dialog.getName().replace(' ',
+ Action.REPLACE, dialog.getName().replace(' ',
ap.av.getGapCharacter()),
sg.getSequencesAsArray(ap.av.getHiddenRepSequences()),
sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment());
*/
package jalview.gui;
-import java.util.*;
-
-import java.awt.event.*;
-import javax.swing.*;
-import javax.swing.event.*;
-
import jalview.analysis.AlignSeq;
-import jalview.commands.*;
-import jalview.datamodel.*;
-import jalview.jbgui.*;
+import jalview.commands.CommandI;
+import jalview.commands.EditCommand;
+import jalview.commands.EditCommand.Action;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.jbgui.GSliderPanel;
import jalview.util.MessageManager;
+import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+import java.util.Vector;
+
+import javax.swing.JInternalFrame;
+import javax.swing.JProgressBar;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
+
/**
* DOCUMENT ME!
*
AlignmentPanel ap;
- Stack historyList = new Stack(); // simpler than synching with alignFrame.
+ Stack<CommandI> historyList = new Stack<CommandI>();
+
+ // simpler than synching with alignFrame.
float[] redundancy;
}
EditCommand cut = new EditCommand(MessageManager.getString("action.remove_redundancy"),
- EditCommand.CUT, deleted, 0, width, ap.av.getAlignment());
+ Action.CUT, deleted, 0, width, ap.av.getAlignment());
for (int i = 0; i < del.size(); i++)
{
return;
}
- CommandI command = (CommandI) historyList.pop();
+ CommandI command = historyList.pop();
if (ap.av.historyList.contains(command))
{
command.undoCommand(af.getViewAlignments());
package jalview.gui;
import jalview.commands.EditCommand;
+import jalview.commands.EditCommand.Action;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SearchResults;
import jalview.datamodel.Sequence;
}
else
{
- editCommand.appendEdit(EditCommand.INSERT_GAP, groupSeqs,
+ editCommand.appendEdit(Action.INSERT_GAP, groupSeqs,
startres, startres - lastres, av.getAlignment(), true);
}
}
}
else
{
- editCommand.appendEdit(EditCommand.DELETE_GAP, groupSeqs,
+ editCommand.appendEdit(Action.DELETE_GAP, groupSeqs,
startres, lastres - startres, av.getAlignment(), true);
}
}
else
{
- editCommand.appendEdit(EditCommand.INSERT_GAP, new SequenceI[]
+ editCommand.appendEdit(Action.INSERT_GAP, new SequenceI[]
{ seq }, lastres, startres - lastres, av.getAlignment(), true);
}
}
if (max > 0)
{
- editCommand.appendEdit(EditCommand.DELETE_GAP,
+ editCommand.appendEdit(Action.DELETE_GAP,
new SequenceI[]
{ seq }, startres, max, av.getAlignment(), true);
}
}
else
{
- editCommand.appendEdit(EditCommand.INSERT_NUC, new SequenceI[]
+ editCommand.appendEdit(Action.INSERT_NUC, new SequenceI[]
{ seq }, lastres, startres - lastres, av.getAlignment(), true);
}
}
}
}
- editCommand.appendEdit(EditCommand.DELETE_GAP, seq, blankColumn, 1,
+ editCommand.appendEdit(Action.DELETE_GAP, seq, blankColumn, 1,
av.getAlignment(), true);
- editCommand.appendEdit(EditCommand.INSERT_GAP, seq, j, 1,
+ editCommand.appendEdit(Action.INSERT_GAP, seq, j, 1,
av.getAlignment(), true);
}
void deleteChar(int j, SequenceI[] seq, int fixedColumn)
{
- editCommand.appendEdit(EditCommand.DELETE_GAP, seq, j, 1,
+ editCommand.appendEdit(Action.DELETE_GAP, seq, j, 1,
av.getAlignment(), true);
- editCommand.appendEdit(EditCommand.INSERT_GAP, seq, fixedColumn, 1,
+ editCommand.appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1,
av.getAlignment(), true);
}
--- /dev/null
+package jalview.commands;
+
+import static org.junit.Assert.assertEquals;
+import jalview.commands.EditCommand.Action;
+import jalview.commands.EditCommand.Edit;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Unit tests for EditCommand
+ *
+ * @author gmcarstairs
+ *
+ */
+public class EditCommandTest
+{
+
+ private EditCommand testee;
+
+ private SequenceI[] seqs;
+
+ private Alignment al;
+
+ @Before
+ public void setUp()
+ {
+ testee = new EditCommand();
+ seqs = new SequenceI[4];
+ seqs[0] = new Sequence("seq0", "abcdefghjk");
+ seqs[1] = new Sequence("seq1", "fghjklmnopq");
+ seqs[2] = new Sequence("seq2", "qrstuvwxyz");
+ seqs[3] = new Sequence("seq3", "1234567890");
+ al = new Alignment(seqs);
+ al.setGapCharacter('?');
+ }
+
+ /**
+ * Test inserting gap characters
+ */
+ @Test
+ public void testAppendEdit_insertGap()
+ {
+ // set a non-standard gap character to prove it is actually used
+ testee.appendEdit(Action.INSERT_GAP, seqs, 4, 3, al, true);
+ assertEquals("abcd???efghjk", seqs[0].getSequenceAsString());
+ assertEquals("fghj???klmnopq", seqs[1].getSequenceAsString());
+ assertEquals("qrst???uvwxyz", seqs[2].getSequenceAsString());
+ assertEquals("1234???567890", seqs[3].getSequenceAsString());
+
+ // todo: test for handling out of range positions?
+ }
+
+ /**
+ * Test deleting characters from sequences. Note the deleteGap() action does
+ * not check that only gap characters are being removed.
+ */
+ @Test
+ public void testAppendEdit_deleteGap()
+ {
+ testee.appendEdit(Action.DELETE_GAP, seqs, 4, 3, al, true);
+ assertEquals("abcdhjk", seqs[0].getSequenceAsString());
+ assertEquals("fghjnopq", seqs[1].getSequenceAsString());
+ assertEquals("qrstxyz", seqs[2].getSequenceAsString());
+ assertEquals("1234890", seqs[3].getSequenceAsString());
+ }
+
+ /**
+ * Test a cut action. The command should store the cut characters to support
+ * undo.
+ */
+ @Test
+ public void testCut()
+ {
+ Edit ec = testee.new Edit(Action.CUT, seqs, 4, 3, al);
+ testee.cut(ec, new AlignmentI[]
+ { al });
+ assertEquals("abcdhjk", seqs[0].getSequenceAsString());
+ assertEquals("fghjnopq", seqs[1].getSequenceAsString());
+ assertEquals("qrstxyz", seqs[2].getSequenceAsString());
+ assertEquals("1234890", seqs[3].getSequenceAsString());
+
+ assertEquals("efg", new String(ec.string[0]));
+ assertEquals("klm", new String(ec.string[1]));
+ assertEquals("uvw", new String(ec.string[2]));
+ assertEquals("567", new String(ec.string[3]));
+ // TODO: case where whole sequence is deleted as nothing left; etc
+ }
+
+ /**
+ * Test a Paste action, where this adds sequences to an alignment.
+ */
+ @Test
+ @Ignore
+ // TODO fix so it works
+ public void testPaste_addToAlignment()
+ {
+ SequenceI[] newSeqs = new SequenceI[2];
+ newSeqs[0] = new Sequence("newseq0", "ACEFKL");
+ newSeqs[1] = new Sequence("newseq1", "JWMPDH");
+
+ Edit ec = testee.new Edit(Action.PASTE, newSeqs, 0, al.getWidth(), al);
+ testee.paste(ec, new AlignmentI[]
+ { al });
+ assertEquals(6, al.getSequences().size());
+ assertEquals("1234567890", seqs[3].getSequenceAsString());
+ assertEquals("ACEFKL", seqs[4].getSequenceAsString());
+ assertEquals("JWMPDH", seqs[5].getSequenceAsString());
+ }
+
+ /**
+ * Test insertGap followed by undo command
+ */
+ @Test
+ public void testUndo_insertGap()
+ {
+ // Edit ec = testee.new Edit(Action.INSERT_GAP, seqs, 4, 3, '?');
+ testee.appendEdit(Action.INSERT_GAP, seqs, 4, 3, al, true);
+ // check something changed
+ assertEquals("abcd???efghjk", seqs[0].getSequenceAsString());
+ testee.undoCommand(new AlignmentI[]
+ { al });
+ assertEquals("abcdefghjk", seqs[0].getSequenceAsString());
+ assertEquals("fghjklmnopq", seqs[1].getSequenceAsString());
+ assertEquals("qrstuvwxyz", seqs[2].getSequenceAsString());
+ assertEquals("1234567890", seqs[3].getSequenceAsString());
+ }
+
+ /**
+ * Test deleteGap followed by undo command
+ */
+ @Test
+ public void testUndo_deleteGap()
+ {
+ testee.appendEdit(Action.DELETE_GAP, seqs, 4, 3, al, true);
+ // check something changed
+ assertEquals("abcdhjk", seqs[0].getSequenceAsString());
+ testee.undoCommand(new AlignmentI[]
+ { al });
+ // deleteGap doesn't 'remember' deleted characters, only gaps get put back
+ assertEquals("abcd???hjk", seqs[0].getSequenceAsString());
+ assertEquals("fghj???nopq", seqs[1].getSequenceAsString());
+ assertEquals("qrst???xyz", seqs[2].getSequenceAsString());
+ assertEquals("1234???890", seqs[3].getSequenceAsString());
+ }
+
+ /**
+ * Test several commands followed by an undo command
+ */
+ @Test
+ public void testUndo_multipleCommands()
+ {
+ // delete positions 3/4/5 (counting from 1)
+ testee.appendEdit(Action.DELETE_GAP, seqs, 2, 3, al, true);
+ assertEquals("abfghjk", seqs[0].getSequenceAsString());
+ assertEquals("1267890", seqs[3].getSequenceAsString());
+
+ // insert 2 gaps after the second residue
+ testee.appendEdit(Action.INSERT_GAP, seqs, 2, 2, al, true);
+ assertEquals("ab??fghjk", seqs[0].getSequenceAsString());
+ assertEquals("12??67890", seqs[3].getSequenceAsString());
+
+ // delete positions 4/5/6
+ testee.appendEdit(Action.DELETE_GAP, seqs, 3, 3, al, true);
+ assertEquals("ab?hjk", seqs[0].getSequenceAsString());
+ assertEquals("12?890", seqs[3].getSequenceAsString());
+
+ // undo edit commands
+ testee.undoCommand(new AlignmentI[]
+ { al });
+ assertEquals("ab?????hjk", seqs[0].getSequenceAsString());
+ assertEquals("12?????890", seqs[3].getSequenceAsString());
+ }
+
+ /**
+ * Unit test for JAL-1594 bug: click and drag sequence right to insert gaps -
+ * undo did not remove them all.
+ */
+ @Test
+ public void testUndo_multipleInsertGaps()
+ {
+ testee.appendEdit(Action.INSERT_GAP, seqs, 4, 1, al, true);
+ testee.appendEdit(Action.INSERT_GAP, seqs, 5, 1, al, true);
+ testee.appendEdit(Action.INSERT_GAP, seqs, 6, 1, al, true);
+
+ // undo edit commands
+ testee.undoCommand(new AlignmentI[]
+ { al });
+ assertEquals("abcdefghjk", seqs[0].getSequenceAsString());
+ assertEquals("1234567890", seqs[3].getSequenceAsString());
+
+ }
+
+ /**
+ * Test cut followed by undo command
+ */
+ @Test
+ public void testUndo_cut()
+ {
+ testee.appendEdit(Action.CUT, seqs, 4, 3, al, true);
+ // check something changed
+ assertEquals("abcdhjk", seqs[0].getSequenceAsString());
+ testee.undoCommand(new AlignmentI[]
+ { al });
+ assertEquals("abcdefghjk", seqs[0].getSequenceAsString());
+ assertEquals("fghjklmnopq", seqs[1].getSequenceAsString());
+ assertEquals("qrstuvwxyz", seqs[2].getSequenceAsString());
+ assertEquals("1234567890", seqs[3].getSequenceAsString());
+ }
+
+ /**
+ * Test the replace command (used to manually edit a sequence)
+ */
+ @Test
+ public void testReplace()
+ {
+ // seem to need a dataset sequence on the edited sequence here
+ seqs[1].setDatasetSequence(seqs[1]);
+ new EditCommand("", Action.REPLACE, "ZXY", new SequenceI[]
+ { seqs[1] }, 4, 8, al);
+ assertEquals("abcdefghjk", seqs[0].getSequenceAsString());
+ assertEquals("qrstuvwxyz", seqs[2].getSequenceAsString());
+ assertEquals("1234567890", seqs[3].getSequenceAsString());
+ seqs[1] = new Sequence("seq1", "fghjZXYnopq");
+
+ }
+}