JAL-2418 source formatting
[jalview.git] / src / jalview / io / BioJsHTMLOutput.java
index 1be97f5..52ce845 100644 (file)
@@ -53,8 +53,7 @@ public class BioJsHTMLOutput extends HTMLOutput
           .getDefault("biojs_template_directory", DEFAULT_DIR);
 
   public static final String BJS_TEMPLATE_GIT_REPO = jalview.bin.Cache
-          .getDefault(
-                  "biojs_template_git_repo",
+          .getDefault("biojs_template_git_repo",
                   "https://raw.githubusercontent.com/jalview/exporter-templates/master/biojs/package.json");
 
   public BioJsHTMLOutput(AlignmentPanel ap)
@@ -68,44 +67,26 @@ public class BioJsHTMLOutput extends HTMLOutput
     exportStarted();
     try
     {
-
       if (outputFile == null)
       {
         outputFile = getOutputFile();
       }
       generatedFile = new File(outputFile);
-
-      String bioJSON = getBioJSONData();
-      String bioJSTemplateString = HTMLOutput.readFileAsString(getCurrentBJSTemplateFile());
-      String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString
-              .replaceAll("#sequenceData#", bioJSON).toString();
-
-      PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
-              generatedFile));
-      out.print(generatedBioJsWithJalviewAlignmentAsJson);
-      out.flush();
-      out.close();
-      exportCompleted();
-      setProgressMessage(MessageManager.formatMessage(
-              "status.export_complete", "BioJS"));
-
-    } catch (NoFileSelectedException ex)
-    {
-      // do noting if no file was selected
-    } catch (OutOfMemoryError err)
+    } catch (NoFileSelectedException e)
     {
-      System.out.println("########################\n" + "OUT OF MEMORY "
-              + outputFile + "\n" + "########################");
-      new OOMWarning("Creating Image for " + outputFile, err);
+      setProgressMessage(MessageManager.formatMessage(
+              "status.cancelled_image_export_operation", "BioJS MSA"));
+      return;
     } catch (Exception e)
     {
-      setProgressMessage(MessageManager.formatMessage(
-              "info.error_creating_file", "HTML"));
+      setProgressMessage(MessageManager
+              .formatMessage("info.error_creating_file", "BioJS MSA"));
       e.printStackTrace();
+      return;
     }
-  }
-
+    new Thread(this).start();
 
+  }
 
   public static void refreshVersionInfo(String dirName)
           throws URISyntaxException
@@ -149,7 +130,8 @@ public class BioJsHTMLOutput extends HTMLOutput
       {
         try
         {
-          String gitRepoPkgJson = getURLContentAsString(BJS_TEMPLATE_GIT_REPO);
+          String gitRepoPkgJson = getURLContentAsString(
+                  BJS_TEMPLATE_GIT_REPO);
           if (gitRepoPkgJson != null)
           {
             BioJSRepositoryPojo release = new BioJSRepositoryPojo(
@@ -251,8 +233,8 @@ public class BioJsHTMLOutput extends HTMLOutput
         }
       }
     }
-    return responseStrBuilder == null ? null : responseStrBuilder
-            .toString();
+    return responseStrBuilder == null ? null
+            : responseStrBuilder.toString();
   }
 
   public static File getCurrentBJSTemplateFile()
@@ -294,4 +276,38 @@ public class BioJsHTMLOutput extends HTMLOutput
     return generatedFile;
   }
 
+  @Override
+  public void run()
+  {
+    try
+    {
+      String bioJSON = getBioJSONData();
+      String bioJSTemplateString = HTMLOutput
+              .readFileAsString(getCurrentBJSTemplateFile());
+      String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString
+              .replaceAll("#sequenceData#", bioJSON).toString();
+
+      PrintWriter out = new java.io.PrintWriter(
+              new java.io.FileWriter(generatedFile));
+      out.print(generatedBioJsWithJalviewAlignmentAsJson);
+      out.flush();
+      out.close();
+      setProgressMessage(MessageManager
+              .formatMessage("status.export_complete", "BioJS"));
+      exportCompleted();
+
+    } catch (OutOfMemoryError err)
+    {
+      System.out.println("########################\n" + "OUT OF MEMORY "
+              + generatedFile + "\n" + "########################");
+      new OOMWarning("Creating Image for " + generatedFile, err);
+    } catch (Exception e)
+    {
+      setProgressMessage(MessageManager
+              .formatMessage("info.error_creating_file", "HTML"));
+      e.printStackTrace();
+    }
+
+  }
+
 }