import jalview.datamodel.*;\r
import jalview.analysis.*;\r
import jalview.io.*;\r
+import jalview.commands.*;\r
import java.awt.*;\r
import java.awt.event.*;\r
import java.util.*;\r
\r
void updateEditMenuBar()\r
{\r
- if (historyList.size() > 0)\r
- {\r
- undoMenuItem.setEnabled(true);\r
- HistoryItem hi = (HistoryItem) historyList.peek();\r
- undoMenuItem.setLabel("Undo " + hi.getDescription());\r
- }\r
- else\r
- {\r
- undoMenuItem.setEnabled(false);\r
- undoMenuItem.setLabel("Undo");\r
- }\r
-\r
- if (redoList.size() > 0)\r
- {\r
- redoMenuItem.setEnabled(true);\r
- HistoryItem hi = (HistoryItem) redoList.peek();\r
- redoMenuItem.setLabel("Redo " + hi.getDescription());\r
- }\r
- else\r
- {\r
- redoMenuItem.setEnabled(false);\r
- redoMenuItem.setLabel("Redo");\r
- }\r
}\r
\r
- public void addHistoryItem(HistoryItem hi)\r
- {\r
- historyList.push(hi);\r
- redoList.removeAllElements();\r
- updateEditMenuBar();\r
- }\r
\r
protected void undoMenuItem_actionPerformed()\r
{\r
- HistoryItem nh,hi = (HistoryItem) historyList.pop();\r
- redoList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,\r
- HistoryItem.HIDE));\r
- if (hi.alColumnChanges!=null)\r
- nh.alColumnChanges=hi.alColumnChanges.getInverse();\r
- restoreHistoryItem(hi);\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
}\r
\r
protected void redoMenuItem_actionPerformed()\r
{\r
- HistoryItem nh,hi = (HistoryItem) redoList.pop();\r
- historyList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,\r
- HistoryItem.HIDE));\r
- if (hi.alColumnChanges!=null)\r
- nh.alColumnChanges=hi.alColumnChanges.getInverse();\r
- restoreHistoryItem(hi);\r
- updateEditMenuBar();\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
+\r
}\r
\r
// used by undo and redo\r
- void restoreHistoryItem(HistoryItem hi)\r
+ void restoreHistoryItem(CommandI command)\r
{\r
- hi.restore(viewport.getColumnSelection());\r
- updateEditMenuBar();\r
-\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
}\r
\r
public void moveSelectedSequences(boolean up)\r
\r
protected void pasteThis_actionPerformed()\r
{\r
- addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,\r
- HistoryItem.PASTE));\r
+ // addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,\r
+ // HistoryItem.PASTE));\r
paste(false);\r
}\r
\r
\r
protected void delete_actionPerformed()\r
{\r
- addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,\r
- HistoryItem.HIDE));\r
+ //addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,\r
+ // HistoryItem.HIDE));\r
if (viewport.getSelectionGroup() == null)\r
{\r
return;\r
\r
public void remove2LeftMenuItem_actionPerformed()\r
{\r
- ColumnSelection colSel = viewport.getColumnSelection();\r
- if (colSel.size() > 0)\r
- {\r
- HistoryItem edit;\r
- addHistoryItem(edit=new HistoryItem("Remove Left", viewport.alignment,\r
- HistoryItem.HIDE));\r
- int min = colSel.getMin();\r
- viewport.getAlignment().trimLeft(min);\r
- colSel.compensateForEdit(0, min);\r
- edit.addShift(0, min);\r
- if (viewport.getSelectionGroup() != null)\r
- {\r
- viewport.getSelectionGroup().adjustForRemoveLeft(min);\r
- }\r
-\r
- Vector groups = viewport.alignment.getGroups();\r
- for (int i = 0; i < groups.size(); i++)\r
- {\r
- SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
- if (!sg.adjustForRemoveLeft(min))\r
- {\r
- viewport.alignment.deleteGroup(sg);\r
- }\r
- }\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
- }\r
}\r
\r
public void remove2RightMenuItem_actionPerformed()\r
{\r
- ColumnSelection colSel = viewport.getColumnSelection();\r
- if (colSel.size() > 0)\r
- {\r
- addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,\r
- HistoryItem.HIDE));\r
- int max = colSel.getMax();\r
- viewport.getAlignment().trimRight(max);\r
-\r
- if (viewport.getSelectionGroup() != null)\r
- {\r
- viewport.getSelectionGroup().adjustForRemoveRight(max);\r
- }\r
-\r
- Vector groups = viewport.alignment.getGroups();\r
- for (int i = 0; i < groups.size(); i++)\r
- {\r
- SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
- if (!sg.adjustForRemoveRight(max))\r
- {\r
- viewport.alignment.deleteGroup(sg);\r
- }\r
- }\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
- }\r
-\r
}\r
\r
public void removeGappedColumnMenuItem_actionPerformed()\r
{\r
- HistoryItem edit;\r
- addHistoryItem(edit=new HistoryItem("Remove Gapped Columns",\r
- viewport.alignment,\r
- HistoryItem.HIDE));\r
-\r
- //This is to maintain viewport position on first residue\r
- //of first sequence\r
- SequenceI seq = viewport.alignment.getSequenceAt(0);\r
- int startRes = seq.findPosition(viewport.startRes);\r
-\r
- viewport.getAlignment().removeGaps();\r
-\r
- viewport.setStartRes(seq.findIndex(startRes)-1);\r
-\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
}\r
\r
public void removeAllGapsMenuItem_actionPerformed()\r
{\r
- // TODO: hidden regions should not be touched by removeAllGaps - a minimal number of gaps will remain in alignment segments containing uneven length subsequences\r
- // TODO: columnSelection.compensateforedits should be called (and passed to history item)\r
- HistoryItem editgaps;\r
- addHistoryItem(editgaps=new HistoryItem("Remove Gaps", viewport.alignment,\r
- HistoryItem.HIDE));\r
-\r
- //This is to maintain viewport position on first residue\r
- //of first sequence\r
- SequenceI seq = viewport.alignment.getSequenceAt(0);\r
- int startRes = seq.findPosition(viewport.startRes);\r
-\r
- SequenceI current;\r
- Vector seqs=null;\r
-\r
- int start=0, end = viewport.alignment.getWidth();\r
-\r
- if (viewport.getSelectionGroup() != null\r
- && viewport.getSelectionGroup().getSequences(false) != null\r
- && viewport.getSelectionGroup().getSize(false)>0)\r
- {\r
- seqs = viewport.getSelectionGroup().getSequences(true);\r
- start = viewport.getSelectionGroup().getStartRes();\r
- end = viewport.getSelectionGroup().getEndRes()+1;\r
- }\r
- else\r
- seqs = viewport.alignment.getSequences();\r
-\r
- /* Commented out regions below are partial implementation of todo above.\r
- * divide start,end into visible chunks, and for each:\r
- int diff=end-start+1;\r
- int diffmax=0;\r
- int dr[] = new int[seqs.size()];\r
- */\r
- for (int i = 0; i < seqs.size(); i++)\r
- {\r
- current = (SequenceI) seqs.elementAt(i);\r
- //dr[i]=\r
- current.removeGaps(start, end);\r
- /*if (d<diff) // can only shift\r
- diff=d;\r
- if (diffmax<d)\r
- diffmax=d;\r
- */\r
- }\r
- /* // after the end of each chunk -\r
- * if (diff>0) {\r
- // record shift for history.\r
- editgaps.addShift(start, diff);\r
- if (viewport.hasHiddenColumns && diffmax>diff) {\r
- // pad sequence\r
- StringBuffer gaps=new StringBuffer(diffmax);\r
- for (int i=0,j=diffmax-diff; i<j; i++)\r
- gaps.append(viewport.getGapCharacter());\r
- for (int i=0, j=seqs.size(); i<j; i++) {\r
- current = (SequenceI) seqs.elementAt(i);\r
- if (dr[i]-diff>0) {\r
- String sq = current.getSequence();\r
- current.setSequence(sq.substring(0, hcend-dr[i])+gaps.substring(0, dr[i]-diff)+sq.substring());\r
- }\r
- }\r
- }\r
- }*/\r
-\r
- viewport.setStartRes(seq.findIndex(startRes)-1);\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
}\r
\r
public void alignmentChanged()\r
\r
public void sortPairwiseMenuItem_actionPerformed()\r
{\r
- addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment,\r
- HistoryItem.SORT));\r
+ // addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment,\r
+ // HistoryItem.SORT));\r
AlignmentSorter.sortByPID(viewport.getAlignment(),\r
viewport.getAlignment().getSequenceAt(0));\r
alignPanel.repaint();\r
\r
public void sortIDMenuItem_actionPerformed()\r
{\r
- addHistoryItem(new HistoryItem("ID Sort", viewport.alignment,\r
- HistoryItem.SORT));\r
+ // addHistoryItem(new HistoryItem("ID Sort", viewport.alignment,\r
+ // HistoryItem.SORT));\r
AlignmentSorter.sortByID(viewport.getAlignment());\r
alignPanel.repaint();\r
}\r
\r
public void sortGroupMenuItem_actionPerformed()\r
{\r
- addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,\r
- HistoryItem.SORT));\r
+ // addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,\r
+ // HistoryItem.SORT));\r
AlignmentSorter.sortByGroup(viewport.getAlignment());\r
alignPanel.repaint();\r
\r
{\r
public void actionPerformed(ActionEvent evt)\r
{\r
- addHistoryItem(new HistoryItem("Sort", viewport.alignment,\r
- HistoryItem.SORT));\r
+ // addHistoryItem(new HistoryItem("Sort", viewport.alignment,\r
+ // HistoryItem.SORT));\r
AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree());\r
alignPanel.repaint();\r
}\r