convert space to gapchar
[jalview.git] / src / jalview / gui / AlignFrame.java
index 71581f6..3c74f43 100755 (executable)
@@ -142,7 +142,7 @@ public class AlignFrame
    }
 
    setMenusFromViewport(viewport);
-
+   buildSortByAnnotationScoresMenu();
    if (viewport.wrapAlignment)
    {
      wrapMenuItem_actionPerformed(null);
@@ -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,18 +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");
@@ -2321,7 +2368,8 @@ public class AlignFrame
     }
     editPane.setText(contents.toString()+"</html>");
     JInternalFrame frame = new JInternalFrame();
-    frame.getContentPane().add(editPane);
+    frame.getContentPane().add(new JScrollPane(editPane));
+
     Desktop.instance.addInternalFrame(frame,"Alignment Properties: "+getTitle(),500,400);
   }
 
@@ -3086,12 +3134,17 @@ public class AlignFrame
       sortByAnnotScore.removeAll();
       // almost certainly a quicker way to do this - but we keep it simple
       Hashtable scoreSorts=new Hashtable();
-      AlignmentAnnotation aann[] = viewport.alignment.getAlignmentAnnotation();
-      for (int i=0;i<aann.length; i++)
+      AlignmentAnnotation aann[];
+      Enumeration sq = viewport.alignment.getSequences().elements();
+      while (sq.hasMoreElements())
       {
-        if (aann[i].hasScore() && aann[i].sequenceRef!=null)
+        aann = ((SequenceI) sq.nextElement()).getAnnotation();
+        for (int i=0;aann!=null && i<aann.length; i++)
         {
-          scoreSorts.put(aann[i].label, aann[i].label);
+          if (aann[i].hasScore() && aann[i].sequenceRef!=null)
+          {
+            scoreSorts.put(aann[i].label, aann[i].label);
+          }
         }
       }
       Enumeration labels = scoreSorts.keys();
@@ -3673,6 +3726,7 @@ public void drop(DropTargetDropEvent evt)
       {
         // (isAnnotation)
         alignPanel.adjustAnnotationHeight();
+        buildSortByAnnotationScoresMenu();
       }
 
     }