fixed redundancy Undo and allowed it to work on UNALIGNED SEQUENCES
authorjprocter <Jim Procter>
Thu, 26 May 2005 17:19:40 +0000 (17:19 +0000)
committerjprocter <Jim Procter>
Thu, 26 May 2005 17:19:40 +0000 (17:19 +0000)
(ho ho)

src/jalview/gui/AlignFrame.java
src/jalview/gui/RedundancyPanel.java

index 1183cd8..6447005 100755 (executable)
@@ -419,11 +419,12 @@ public class AlignFrame extends GAlignFrame
   protected void delete_actionPerformed(ActionEvent e)
   {
     boolean seqsdeleted=false;
-    addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, HistoryItem.HIDE));
 
     if (viewport.getSelectionGroup() == null)
       return;
 
+    addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, HistoryItem.HIDE));
+
      SequenceGroup sg = viewport.getSelectionGroup();
      for (int i=0;i < sg.sequences.size(); i++)
      {
@@ -996,7 +997,7 @@ public class AlignFrame extends GAlignFrame
 
   public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
   {
-    RedundancyPanel sp = new RedundancyPanel(alignPanel);
+    RedundancyPanel sp = new RedundancyPanel(alignPanel, this);
     JInternalFrame frame = new JInternalFrame();
     frame.setContentPane(sp);
     Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, 100, false);
index 93ffd9c..f91f75d 100755 (executable)
@@ -6,98 +6,113 @@ import java.awt.event.*;
 import java.util.*;\r
 import javax.swing.event.*;\r
 \r
-public class RedundancyPanel extends GSliderPanel\r
+public class RedundancyPanel\r
+    extends GSliderPanel\r
 {\r
+  AlignFrame af;\r
   AlignmentPanel ap;\r
+  Stack historyList = new Stack(); // simpler than synching with alignFrame.\r
 \r
-  SequenceI[] oldAlignment;\r
-\r
-\r
-  public RedundancyPanel(AlignmentPanel ap)\r
+  public RedundancyPanel(AlignmentPanel ap, AlignFrame af)\r
   {\r
     this.ap = ap;\r
-\r
+    this.af = af;\r
     label.setText("Enter the redundancy threshold");\r
 \r
     slider.addChangeListener(new ChangeListener()\r
     {\r
       public void stateChanged(ChangeEvent evt)\r
       {\r
-        valueField.setText( slider.getValue()+"" );\r
+        valueField.setText(slider.getValue() + "");\r
       }\r
     });\r
 \r
     slider.setMinimum(0);\r
     slider.setMaximum(100);\r
-    slider.setValue(100 );\r
+    slider.setValue(100);\r
 \r
   }\r
 \r
   public void applyButton_actionPerformed(ActionEvent e)\r
   {\r
-       float threshold = slider.getValue();\r
-       Vector del;\r
+    float threshold = slider.getValue();\r
+    Vector del;\r
+    historyList.push(new HistoryItem("Remove redundancy (" + threshold + "%)",\r
+                                      ap.av.alignment, HistoryItem.HIDE));\r
+\r
+    undoButton.setEnabled(true);\r
+    SequenceGroup sg = ap.av.getSelectionGroup();\r
+    if (sg != null && sg.getSize() >= 1)\r
+    {\r
 \r
-       oldAlignment = new SequenceI[ap.av.alignment.getHeight()];\r
-        for (int i = 0; i < ap.av.alignment.getHeight(); i++)\r
+      del = ap.av.alignment.removeRedundancy(threshold, sg.sequences);\r
+      for (int i = 0; i < del.size(); i++)\r
+      {\r
+        if (sg.sequences.contains( (SequenceI) del.elementAt(i)))\r
         {\r
-           oldAlignment[i] = new Sequence(ap.av.alignment.getSequenceAt(i).getName(),\r
-                                ap.av.alignment.getSequenceAt(i).\r
-                                getSequence());\r
+          sg.deleteSequence( (SequenceI) del.elementAt(i));\r
         }\r
+      }\r
 \r
-        undoButton.setEnabled(true);\r
-\r
-        SequenceGroup sg = ap.av.getSelectionGroup();\r
-       if (sg != null && sg.getSize() > 1)\r
-       {\r
-\r
-         del = ap.av.alignment.removeRedundancy(threshold, sg.sequences);\r
-         for (int i = 0; i < del.size(); i++)\r
-           if (sg.sequences.contains( (SequenceI) del.elementAt(i)))\r
-             sg.deleteSequence( (SequenceI) del.elementAt(i));\r
-\r
-         }\r
-         else\r
-         {\r
-           Vector s = new Vector();\r
-           int i=0;\r
-           while(i < ap.av.alignment.getHeight())\r
-           {\r
-             s.addElement( ap.av.alignment.getSequenceAt(i) );\r
-             i++;\r
-           }\r
-            del = ap.av.alignment.removeRedundancy(threshold,s);\r
-           for (int j=0; j < del.size(); j++)\r
-           {\r
-               if (sg.sequences.contains((SequenceI)del.elementAt(j)))\r
-               sg.deleteSequence((SequenceI)del.elementAt(j));\r
-\r
-           }\r
-         }\r
-\r
-         ap.repaint();\r
+    }\r
+    else\r
+    {\r
+      Vector s = new Vector();\r
+      int i = 0;\r
+      while (i < ap.av.alignment.getHeight())\r
+      {\r
+        s.addElement(ap.av.alignment.getSequenceAt(i));\r
+        i++;\r
+      }\r
+      del = ap.av.alignment.removeRedundancy(threshold, s);\r
+    }\r
+\r
+    // This has to be done before the restoreHistoryItem method of alignFrame will\r
+    // actually restore these sequences.\r
+\r
+    if (del.size()>0)\r
+      for (int i=0,j=del.size(); i<j; i++) {\r
+        SequenceI sq = (SequenceI) del.elementAt(i);\r
+        sq.deleteChars(0,sq.getLength());\r
+      }\r
+\r
+    ap.av.firePropertyChange("alignment", null,\r
+                             ap.av.getAlignment().getSequences());\r
+    ap.av.resetSeqLimits(ap.seqPanel.seqCanvas.getHeight());\r
+    if (ap.av.getAlignment().getHeight() < 1)\r
+    {\r
+      try\r
+      {\r
+        af.setClosed(true);\r
+      }\r
+      catch (Exception ex)\r
+      {}\r
+    }\r
+    ap.av.updateConservation();\r
+    ap.av.updateConsensus();\r
+    af.updateEditMenuBar();\r
+    ap.repaint();\r
 \r
   }\r
 \r
   public void undoButton_actionPerformed(ActionEvent e)\r
   {\r
+    HistoryItem hi = (HistoryItem)historyList.pop();\r
+    af.restoreHistoryItem(hi);\r
+    if (historyList.size()==0)\r
       undoButton.setEnabled(false);\r
-      ap.av.setAlignment( new Alignment(oldAlignment) );\r
-      oldAlignment = null;\r
-      ap.repaint();\r
   }\r
 \r
-\r
   public void valueField_actionPerformed(ActionEvent e)\r
   {\r
-    try{\r
+    try\r
+    {\r
       int i = Integer.parseInt(valueField.getText());\r
       slider.setValue(i);\r
     }\r
-    catch(Exception ex)\r
+    catch (Exception ex)\r
     {\r
-      valueField.setText( slider.getValue()+"" );\r
+      valueField.setText(slider.getValue() + "");\r
     }\r
   }\r
 }\r