Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / jalview / io / BioJsHTMLOutput.java
index 52ce845..13bfb8c 100644 (file)
  */
 package jalview.io;
 
-import jalview.exceptions.NoFileSelectedException;
-import jalview.gui.AlignmentPanel;
-import jalview.gui.OOMWarning;
-import jalview.json.binding.biojs.BioJSReleasePojo;
-import jalview.json.binding.biojs.BioJSRepositoryPojo;
-import jalview.util.MessageManager;
-
 import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.File;
@@ -39,9 +32,15 @@ import java.net.URL;
 import java.util.Objects;
 import java.util.TreeMap;
 
+import jalview.bin.Cache;
+import jalview.gui.AlignmentPanel;
+import jalview.gui.OOMWarning;
+import jalview.json.binding.biojs.BioJSReleasePojo;
+import jalview.json.binding.biojs.BioJSRepositoryPojo;
+import jalview.util.MessageManager;
+
 public class BioJsHTMLOutput extends HTMLOutput
 {
-
   private static File currentBJSTemplateFile;
 
   private static TreeMap<String, File> bioJsMSAVersions;
@@ -49,43 +48,16 @@ public class BioJsHTMLOutput extends HTMLOutput
   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
-          .getDefault("biojs_template_git_repo",
-                  "https://raw.githubusercontent.com/jalview/exporter-templates/master/biojs/package.json");
+  public static final String BJS_TEMPLATE_GIT_REPO = Cache.getDefault(
+          "biojs_template_git_repo",
+          "https://raw.githubusercontent.com/jalview/exporter-templates/master/biojs/package.json");
 
   public BioJsHTMLOutput(AlignmentPanel ap)
   {
-    super(ap);
-  }
-
-  @Override
-  public void exportHTML(String outputFile)
-  {
-    exportStarted();
-    try
-    {
-      if (outputFile == null)
-      {
-        outputFile = getOutputFile();
-      }
-      generatedFile = new File(outputFile);
-    } catch (NoFileSelectedException e)
-    {
-      setProgressMessage(MessageManager.formatMessage(
-              "status.cancelled_image_export_operation", "BioJS MSA"));
-      return;
-    } catch (Exception e)
-    {
-      setProgressMessage(MessageManager
-              .formatMessage("info.error_creating_file", "BioJS MSA"));
-      e.printStackTrace();
-      return;
-    }
-    new Thread(this).start();
-
+    super(ap, "BioJS MSA");
   }
 
   public static void refreshVersionInfo(String dirName)
@@ -166,8 +138,9 @@ public class BioJsHTMLOutput extends HTMLOutput
       {
         if (!biojsDirectory.mkdirs())
         {
-          System.out.println("Couldn't create local directory : "
-                  + BJS_TEMPLATES_LOCAL_DIRECTORY);
+          jalview.bin.Console
+                  .outPrintln("Couldn't create local directory : "
+                          + BJS_TEMPLATES_LOCAL_DIRECTORY);
           return;
         }
       }
@@ -271,12 +244,6 @@ public class BioJsHTMLOutput extends HTMLOutput
   }
 
   @Override
-  public File getExportedFile()
-  {
-    return generatedFile;
-  }
-
-  @Override
   public void run()
   {
     try
@@ -293,21 +260,28 @@ public class BioJsHTMLOutput extends HTMLOutput
       out.flush();
       out.close();
       setProgressMessage(MessageManager
-              .formatMessage("status.export_complete", "BioJS"));
+              .formatMessage("status.export_complete", getDescription()));
       exportCompleted();
 
     } catch (OutOfMemoryError err)
     {
-      System.out.println("########################\n" + "OUT OF MEMORY "
-              + generatedFile + "\n" + "########################");
+      jalview.bin.Console
+              .outPrintln("########################\n" + "OUT OF MEMORY "
+                      + generatedFile + "\n" + "########################");
       new OOMWarning("Creating Image for " + generatedFile, err);
     } catch (Exception e)
     {
       setProgressMessage(MessageManager
-              .formatMessage("info.error_creating_file", "HTML"));
+              .formatMessage("info.error_creating_file", getDescription()));
       e.printStackTrace();
     }
 
   }
 
+  @Override
+  public void run(String s)
+  {
+    run();
+  }
+
 }