house keeping
[jalview.git] / src / jalview / io / BioJsHTMLOutput.java
index a026c57..73be79f 100644 (file)
@@ -1,9 +1,8 @@
 package jalview.io;
 
+import jalview.api.AlignmentViewPanel;
+import jalview.datamodel.AlignmentExportData;
 import jalview.exceptions.NoFileSelectedException;
-import jalview.gui.AlignViewport;
-import jalview.gui.AlignmentPanel;
-import jalview.gui.FeatureRenderer;
 import jalview.json.binding.v1.BioJSReleasePojo;
 import jalview.json.binding.v1.BioJSRepositoryPojo;
 import jalview.util.MessageManager;
@@ -23,7 +22,7 @@ import java.util.TreeMap;
 
 public class BioJsHTMLOutput
 {
-  private AlignViewport av;
+  private AlignmentViewPanel ap;
 
   private static File currentBJSTemplateFile;
 
@@ -40,12 +39,11 @@ public class BioJsHTMLOutput
                   "biojs_template_git_repo",
                   "https://raw.githubusercontent.com/tcofoegbu/bjs-template/master/package.json");
 
-  public BioJsHTMLOutput(AlignmentPanel ap, FeatureRenderer fr1)
+  public BioJsHTMLOutput(AlignmentViewPanel ap)
   {
     if (ap != null)
     {
-      this.av = ap.av;
-      av.setFeatureRenderer(new FeatureRenderer(ap));
+      this.ap = ap;
     }
   }
 
@@ -54,7 +52,20 @@ public class BioJsHTMLOutput
     try
     {
       String outputFile = getOutputFile();
-      String jalviewAlignmentJson = JSONFile.getJSONData(av);
+      // String jalviewAlignmentJson = JSONFile.getJSONData(ap);
+      AlignmentExportData exportData = jalview.gui.AlignFrame
+              .getAlignmentForExport(
+              JSONFile.FILE_DESC, ap.getAlignViewport());
+      if (exportData.getSettings().isCancelled())
+      {
+        return;
+      }
+      String jalviewAlignmentJson = new FormatAdapter(ap,
+              exportData.getSettings()).formatSequences(JSONFile.FILE_DESC,
+              exportData.getAlignment(), exportData.getOmitHidden(),
+              exportData.getStartEndPostions(), ap.getAlignViewport()
+                      .getColumnSelection());
+
       String bioJSTemplateString = getBioJsTemplateAsString();
       String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString
               .replaceAll(
@@ -85,7 +96,6 @@ public class BioJsHTMLOutput
             { "HTML files" }, "HTML files");
     jvFileChooser.setFileView(new JalviewFileView());
 
-    // TODO uncomment when supported by MassageManager
     jvFileChooser.setDialogTitle(MessageManager
             .getString("label.save_as_biojs_html"));
     jvFileChooser.setDialogTitle("save as BioJs HTML");
@@ -190,10 +200,13 @@ public class BioJsHTMLOutput
         try
         {
           String gitRepoPkgJson = getURLContentAsString(BJS_TEMPLATE_GIT_REPO);
-          BioJSRepositoryPojo release = new BioJSRepositoryPojo(
-                  gitRepoPkgJson);
-          syncUpdates(BJS_TEMPLATES_LOCAL_DIRECTORY, release);
-          refreshBioJSVersionsInfo(BJS_TEMPLATES_LOCAL_DIRECTORY);
+          if (gitRepoPkgJson != null)
+          {
+            BioJSRepositoryPojo release = new BioJSRepositoryPojo(
+                    gitRepoPkgJson);
+            syncUpdates(BJS_TEMPLATES_LOCAL_DIRECTORY, release);
+            refreshBioJSVersionsInfo(BJS_TEMPLATES_LOCAL_DIRECTORY);
+          }
         } catch (URISyntaxException e)
         {
           e.printStackTrace();