JAL-1807 explicit imports (jalview.structure)
[jalview.git] / src / jalview / io / BioJsHTMLOutput.java
index b49c2e0..e8e993b 100644 (file)
@@ -1,11 +1,13 @@
 package jalview.io;
 
+import jalview.api.AlignmentViewPanel;
+import jalview.bin.Cache;
+import jalview.datamodel.AlignmentExportData;
 import jalview.exceptions.NoFileSelectedException;
-import jalview.gui.AlignViewport;
-import jalview.gui.AlignmentPanel;
-import jalview.gui.FeatureRenderer;
+import jalview.gui.AlignFrame;
 import jalview.json.binding.v1.BioJSReleasePojo;
 import jalview.json.binding.v1.BioJSRepositoryPojo;
+import jalview.util.BrowserLauncher;
 import jalview.util.MessageManager;
 
 import java.io.BufferedInputStream;
@@ -23,7 +25,7 @@ import java.util.TreeMap;
 
 public class BioJsHTMLOutput
 {
-  private AlignViewport av;
+  private AlignmentViewPanel ap;
 
   private static File currentBJSTemplateFile;
 
@@ -32,20 +34,19 @@ public class BioJsHTMLOutput
   public static final String DEFAULT_DIR = System.getProperty("user.home")
           + File.separatorChar + ".biojs_templates" + File.separatorChar;
 
-  public static final String BJS_TEMPLATES_LOCAL_DIRECTORY = jalview.bin.Cache
+  public static final String BJS_TEMPLATES_LOCAL_DIRECTORY = Cache
           .getDefault("biojs_template_directory", DEFAULT_DIR);
 
-  public static final String BJS_TEMPLATE_GIT_REPO = jalview.bin.Cache
+  public static final String BJS_TEMPLATE_GIT_REPO = Cache
           .getDefault(
                   "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 +55,20 @@ public class BioJsHTMLOutput
     try
     {
       String outputFile = getOutputFile();
-      String jalviewAlignmentJson = JSONFile.getJSONData(av);
+      // String jalviewAlignmentJson = JSONFile.getJSONData(ap);
+      AlignmentExportData exportData = 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(
@@ -66,7 +80,7 @@ public class BioJsHTMLOutput
       out.print(generatedBioJsWithJalviewAlignmentAsJson);
       out.flush();
       out.close();
-      jalview.util.BrowserLauncher.openURL("file:///" + outputFile);
+      BrowserLauncher.openURL("file:///" + outputFile);
     } catch (NoFileSelectedException ex)
     {
       // do noting if no file was selected
@@ -80,12 +94,11 @@ public class BioJsHTMLOutput
   {
     String selectedFile = null;
     JalviewFileChooser jvFileChooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
+            Cache.getProperty("LAST_DIRECTORY"), new String[]
             { "html" }, new String[]
             { "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");
@@ -94,7 +107,7 @@ public class BioJsHTMLOutput
     int fileChooserOpt = jvFileChooser.showSaveDialog(null);
     if (fileChooserOpt == JalviewFileChooser.APPROVE_OPTION)
     {
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", jvFileChooser
+      Cache.setProperty("LAST_DIRECTORY", jvFileChooser
               .getSelectedFile().getParent());
       selectedFile = jvFileChooser.getSelectedFile().getPath();
     }
@@ -148,7 +161,7 @@ public class BioJsHTMLOutput
     return sb.toString();
   }
 
-  public void refreshBioJSVersionsInfo(String dirName)
+  public static void refreshBioJSVersionsInfo(String dirName)
           throws URISyntaxException
   {
     File directory = new File(BJS_TEMPLATES_LOCAL_DIRECTORY);
@@ -181,7 +194,7 @@ public class BioJsHTMLOutput
     setBioJsMSAVersions(versionFileMap);
   }
 
-  public void updateBioJS()
+  public static void updateBioJS()
   {
     Thread updateThread = new Thread()
     {
@@ -190,10 +203,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();
@@ -205,7 +221,7 @@ public class BioJsHTMLOutput
   }
 
 
-  public void syncUpdates(String localDir, BioJSRepositoryPojo repo)
+  public static void syncUpdates(String localDir, BioJSRepositoryPojo repo)
   {
     for (BioJSReleasePojo bjsRelease : repo.getReleases())
     {