undo stackempty error fix, refactored do and undo() method to take array of alignment...
authorjprocter <Jim Procter>
Wed, 2 May 2007 12:25:44 +0000 (12:25 +0000)
committerjprocter <Jim Procter>
Wed, 2 May 2007 12:25:44 +0000 (12:25 +0000)
src/jalview/gui/AlignFrame.java

index 58650cb..3c74f43 100755 (executable)
@@ -1049,8 +1049,28 @@ public class AlignFrame
     }
   }
 
-
-
+  /**
+   * 
+   * @return alignment objects for all views
+   */
+  AlignmentI[] getViewAlignments()
+  {
+    if (alignPanels!=null)
+    {
+      Enumeration e = alignPanels.elements();
+      AlignmentI[] als = new AlignmentI[alignPanels.size()];
+      for (int i=0; e.hasMoreElements(); i++)
+      {
+        als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
+      }
+      return als;
+    }
+    if (viewport!=null)
+    {
+      return new AlignmentI[] { viewport.alignment };
+    }
+    return null;
+  }
   /**
    * DOCUMENT ME!
    *
@@ -1058,9 +1078,11 @@ public class AlignFrame
    */
   protected void undoMenuItem_actionPerformed(ActionEvent e)
   {
+    if (viewport.historyList.empty())
+      return;
     CommandI command = (CommandI)viewport.historyList.pop();
     viewport.redoList.push(command);
-    command.undoCommand();
+    command.undoCommand(getViewAlignments());
 
     AlignViewport originalSource = getOriginatingSource(command);
     updateEditMenuBar();
@@ -1088,7 +1110,7 @@ public class AlignFrame
 
     CommandI command = (CommandI) viewport.redoList.pop();
     viewport.historyList.push(command);
-    command.doCommand();
+    command.doCommand(getViewAlignments());
 
     AlignViewport originalSource = getOriginatingSource(command);
     updateEditMenuBar();
@@ -1582,19 +1604,43 @@ public class AlignFrame
            alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier
            alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a);
          }
-
-
        }
      }
      if (!newAlignment) {
+       
        // propagate alignment changed.
        viewport.setEndSeq(alignment.getHeight());
        if (annotationAdded)
        {
-         alignPanel.annotationPanel.adjustPanelHeight();
+         // Duplicate sequence annotation in all views.
+         AlignmentI[] alview = this.getViewAlignments();
+         for (int avnum=0;avnum<alview.length; avnum++)
+         {
+           if (alview[avnum]!=alignment)
+           {
+             // duplicate in a view other than the one with input focus
+             int avwidth = alview[avnum].getWidth()+1;
+             for (int i=0; i < sequences.length; i++)
+             {
+               AlignmentAnnotation sann[] = sequences[i].getAnnotation();
+               if (sann==null)
+                 continue;
+               // this relies on sann being preserved after we modify the sequence's annotation array
+               for (int a=0; a<sann.length; a++)
+               {
+                 AlignmentAnnotation newann = new AlignmentAnnotation(sann[a]);
+                 sequences[i].addAlignmentAnnotation(newann);
+                 newann.padAnnotation(avwidth);
+                 alview[avnum].addAnnotation(newann); // annotation was duplicated earlier
+                 alview[avnum].setAnnotationIndex(newann, a);
+               }
+             }
+           }
+         }
          buildSortByAnnotationScoresMenu();
        }
        viewport.firePropertyChange("alignment", null, alignment.getSequences());
+      
      } else {
        AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
        String newtitle = new String("Copied sequences");