JAL-1486 JAL-1543 pushed alignment viewport->view->flat file logic into jalview.io...
authorj.procter@dundee.ac.uk <jprocter@carderbee.dyn.lifesci.dundee.ac.uk>
Fri, 12 Sep 2014 16:27:47 +0000 (17:27 +0100)
committerj.procter@dundee.ac.uk <jprocter@carderbee.dyn.lifesci.dundee.ac.uk>
Fri, 12 Sep 2014 16:27:47 +0000 (17:27 +0100)
src/jalview/appletgui/APopupMenu.java
src/jalview/gui/PopupMenu.java
src/jalview/io/AppletFormatAdapter.java
src/jalview/io/FormatAdapter.java

index d98e2aa..58c7703 100644 (file)
@@ -672,9 +672,8 @@ public class APopupMenu extends java.awt.PopupMenu implements
     // TODO consider using getSequenceSelection instead here
 
     cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
-            e.getActionCommand(),
-            new Alignment(ap.av.getSelectionAsNewSequence()),
-            ap.av.showJVSuffix));
+            e.getActionCommand(), 
+            ap.av.showJVSuffix, ap.av, true));
 
   }
 
index e84a799..0957d28 100644 (file)
@@ -2109,20 +2109,7 @@ public class PopupMenu extends JPopupMenu
     // or we simply trust the user wants
     // wysiwig behaviour
 
-    AlignmentView selvew = ap.av.getAlignmentView(true, false);
-    AlignmentI aselview = selvew.getVisibleAlignment(ap.av
-            .getGapCharacter());
-    List<AlignmentAnnotation> ala = (ap.av
-            .getVisibleAlignmentAnnotation(true));
-    if (ala != null)
-    {
-      for (AlignmentAnnotation aa : ala)
-      {
-        aselview.addAnnotation(aa);
-      }
-    }
-    cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
-            aselview, null, null, null));
+    cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(), ap.av, true));
   }
 
   public void pdbFromFile_actionPerformed()
index 26fa854..3f9a425 100755 (executable)
@@ -22,7 +22,9 @@ package jalview.io;
 
 import java.io.File;
 import java.io.InputStream;
+import java.util.List;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.*;
 
 /**
@@ -405,6 +407,35 @@ public class AppletFormatAdapter
     }
   }
 
+
+  /**
+   * create an alignment flatfile from a Jalview alignment view 
+   * @param format
+   * @param jvsuffix
+   * @param av
+   * @param selectedOnly
+   * @return flatfile in a string
+   */
+  public String formatSequences(String format, boolean jvsuffix,
+          AlignViewportI av, boolean selectedOnly)
+  {
+
+    AlignmentView selvew = av.getAlignmentView(selectedOnly, false);
+    AlignmentI aselview = selvew.getVisibleAlignment(av
+            .getGapCharacter());
+    List<AlignmentAnnotation> ala = (av
+            .getVisibleAlignmentAnnotation(selectedOnly));
+    if (ala != null)
+    {
+      for (AlignmentAnnotation aa : ala)
+      {
+        aselview.addAnnotation(aa);
+      }
+    }
+    
+    return formatSequences(format, aselview, jvsuffix);
+  }
+  
   /**
    * Construct an output class for an alignment in a particular filetype TODO:
    * allow caller to detect errors and warnings encountered when generating
index 9913428..c2a317a 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.io;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.*;
 
 /**
@@ -247,4 +248,16 @@ public class FormatAdapter extends AppletFormatAdapter
     }
     return AppletFormatAdapter.isValidFormat(format, forwriting);
   }
+
+  /**
+   * Create a flat file representation of a given view or selected region of a view
+   * @param format
+   * @param av
+   * @return String containing flat file
+   */
+  public String formatSequences(String format, AlignViewportI av, boolean selectedOnly)
+  {
+    return formatSequences(format, getCacheSuffixDefault(format), av, selectedOnly);
+  }
+
 }