JAL-1976 added an intermediate message between a user selecting an export file and...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 17 Jun 2016 11:35:52 +0000 (12:35 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 17 Jun 2016 11:35:52 +0000 (12:35 +0100)
resources/lang/Messages.properties
src/jalview/io/HtmlSvgOutput.java
src/jalview/util/ImageMaker.java

index 62e1a6e..b130842 100644 (file)
@@ -1308,3 +1308,4 @@ status.fetching_dbrefs_for_sequences_without_valid_refs = Fetching db refs for {
 status.fetching_3d_structures_for = Fetching 3D Structure for {0}
 status.obtaining_mapping_with_sifts = Obtaining mapping with SIFTS
 status.obtaining_mapping_with_nw_alignment = Obtaining mapping with NW alignment
+status.exporting_alignment_as_x_file = Exporting alignment as {0} file
index 00af242..c9deb85 100644 (file)
@@ -51,6 +51,13 @@ public class HtmlSvgOutput
 
   AlignmentPanel ap;
 
+  private IProgressIndicator pIndicator;
+
+  private long pSessionId;
+
+  private boolean headless;
+
+
   public HtmlSvgOutput(File file, AlignmentPanel ap)
   {
     this.av = ap.av;
@@ -61,20 +68,16 @@ public class HtmlSvgOutput
 
   public void generateHtmlSvgOutput(File file)
   {
-    IProgressIndicator pIndicator = ap.alignFrame;
-    long pSessionId = System.currentTimeMillis();
+    pIndicator = ap.alignFrame;
+    pSessionId = System.currentTimeMillis();
     try
     {
-      boolean headless = (System.getProperty("java.awt.headless") != null && System
+      headless = (System.getProperty("java.awt.headless") != null && System
               .getProperty("java.awt.headless").equals("true"));
       if (file == null)
       {
-        if (pIndicator != null && !headless)
-        {
-          pIndicator.setProgressBar(MessageManager.formatMessage(
-                  "status.waiting_for_user_to_select_output_file", "HTML"),
-                  pSessionId);
-        }
+        setProgressMessage(MessageManager.formatMessage(
+                "status.waiting_for_user_to_select_output_file", "HTML"));
         JalviewFileChooser chooser = getHTMLChooser();
         chooser.setFileView(new jalview.io.JalviewFileView());
         chooser.setDialogTitle(ap.alignFrame.getTitle());
@@ -86,135 +89,159 @@ public class HtmlSvgOutput
           jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
                   .getSelectedFile().getParent());
           file = chooser.getSelectedFile();
+          ap.alignFrame.repaint();
         }
         else
         {
-
-          if (pIndicator != null && !headless)
-        {
-            pIndicator.setProgressBar(MessageManager.formatMessage(
-                    "status.cancelled_image_export_operation", "HTML"),
-                    pSessionId);
-          }
-          return;
-        }
-      }
-
-      AlignmentDimension aDimension = ap.getAlignmentDimension();
-      SVGGraphics2D g1 = new SVGGraphics2D(aDimension.getWidth(),
-              aDimension.getHeight());
-      SVGGraphics2D g2 = new SVGGraphics2D(aDimension.getWidth(),
-              aDimension.getHeight());
-
-      String renderStyle = jalview.bin.Cache.getDefault("HTML_RENDERING",
-              "Prompt each time");
-
-      // If we need to prompt, and if the GUI is visible then
-      // Prompt for rendering style
-      if (renderStyle.equalsIgnoreCase("Prompt each time")
-              && !(System.getProperty("java.awt.headless") != null && System
-                      .getProperty("java.awt.headless").equals("true")))
-      {
-        HTMLOptions svgOption = new HTMLOptions();
-        renderStyle = svgOption.getValue();
-
-        if (renderStyle == null || svgOption.cancelled)
-        {
+          setProgressMessage(MessageManager.formatMessage(
+                  "status.cancelled_image_export_operation", "HTML"));
           return;
         }
       }
-
-      if (renderStyle.equalsIgnoreCase("Lineart"))
-      {
-        g1.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE,
-                SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR);
-        g2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE,
-                SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR);
-      }
-      printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), 0, g1,
-              g2);
-
-      String titleSvgData = g1.getSVGDocument();
-      String alignSvgData = g2.getSVGDocument();
-      String jsonData = null;
-      boolean isEmbbedBioJSON = Boolean.valueOf(jalview.bin.Cache
-              .getDefault("EXPORT_EMBBED_BIOJSON", "true"));
-      if (isEmbbedBioJSON)
+    } catch (Exception e)
+    {
+      e.printStackTrace();
+    }
+    final File fileX = file;
+    new Thread()
+    {
+      @Override
+      public void run()
       {
-        AlignExportSettingI exportSettings = new AlignExportSettingI()
+        try
         {
-          @Override
-          public boolean isExportHiddenSequences()
+          setProgressMessage(null);
+          setProgressMessage(MessageManager
+.formatMessage(
+                  "status.exporting_alignment_as_x_file", "HTML"));
+          AlignmentDimension aDimension = ap.getAlignmentDimension();
+          SVGGraphics2D g1 = new SVGGraphics2D(aDimension.getWidth(),
+                  aDimension.getHeight());
+          SVGGraphics2D g2 = new SVGGraphics2D(aDimension.getWidth(),
+                  aDimension.getHeight());
+
+          String renderStyle = jalview.bin.Cache.getDefault(
+                  "HTML_RENDERING", "Prompt each time");
+
+          // If we need to prompt, and if the GUI is visible then
+          // Prompt for rendering style
+          if (renderStyle.equalsIgnoreCase("Prompt each time")
+                  && !(System.getProperty("java.awt.headless") != null && System
+                          .getProperty("java.awt.headless").equals("true")))
           {
-            return true;
-          }
+            HTMLOptions svgOption = new HTMLOptions();
+            renderStyle = svgOption.getValue();
 
-          @Override
-          public boolean isExportHiddenColumns()
-          {
-            return true;
+            if (renderStyle == null || svgOption.cancelled)
+            {
+              return;
+            }
           }
 
-          @Override
-          public boolean isExportAnnotations()
+          if (renderStyle.equalsIgnoreCase("Lineart"))
           {
-            return true;
+            g1.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE,
+                    SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR);
+            g2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE,
+                    SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR);
           }
-
-          @Override
-          public boolean isExportFeatures()
+          printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), 0,
+                  g1, g2);
+
+          String titleSvgData = g1.getSVGDocument();
+          String alignSvgData = g2.getSVGDocument();
+          String jsonData = null;
+          boolean isEmbbedBioJSON = Boolean.valueOf(jalview.bin.Cache
+                  .getDefault("EXPORT_EMBBED_BIOJSON", "true"));
+          if (isEmbbedBioJSON)
           {
-            return true;
+            AlignExportSettingI exportSettings = new AlignExportSettingI()
+            {
+              @Override
+              public boolean isExportHiddenSequences()
+              {
+                return true;
+              }
+
+              @Override
+              public boolean isExportHiddenColumns()
+              {
+                return true;
+              }
+
+              @Override
+              public boolean isExportAnnotations()
+              {
+                return true;
+              }
+
+              @Override
+              public boolean isExportFeatures()
+              {
+                return true;
+              }
+
+              @Override
+              public boolean isExportGroups()
+              {
+                return true;
+              }
+
+              @Override
+              public boolean isCancelled()
+              {
+                return false;
+              }
+
+            };
+            AlignmentExportData exportData = jalview.gui.AlignFrame
+                    .getAlignmentForExport(JSONFile.FILE_DESC, av,
+                            exportSettings);
+            jsonData = new FormatAdapter(ap, exportData.getSettings())
+                    .formatSequences(JSONFile.FILE_DESC,
+                            exportData.getAlignment(),
+                            exportData.getOmitHidden(),
+                            exportData.getStartEndPostions(),
+                            av.getColumnSelection());
           }
-
-          @Override
-          public boolean isExportGroups()
+          String htmlData = getHtml(titleSvgData, alignSvgData, jsonData);
+          FileOutputStream out = new FileOutputStream(fileX);
+          out.write(htmlData.getBytes());
+          out.flush();
+          out.close();
+          if (!(System.getProperty("java.awt.headless") != null && System
+                  .getProperty("java.awt.headless").equals("true")))
           {
-            return true;
+            jalview.util.BrowserLauncher.openURL("file:///" + fileX);
           }
+        } catch (OutOfMemoryError err)
+        {
+          System.out.println("########################\n"
+                  + "OUT OF MEMORY " + fileX + "\n"
+                  + "########################");
+          new OOMWarning("Creating Image for " + fileX, err);
+        } catch (Exception e)
+        {
+          e.printStackTrace();
+          pIndicator.setProgressBar(MessageManager.formatMessage(
+                  "info.error_creating_file", "HTML"), pSessionId);
+        }
+        setProgressMessage(MessageManager.formatMessage(
+                "status.export_complete", "HTML"));
+      }
+    }.start();
 
-          @Override
-          public boolean isCancelled()
-          {
-            return false;
-          }
+  }
 
-        };
-        AlignmentExportData exportData = jalview.gui.AlignFrame
-                .getAlignmentForExport(JSONFile.FILE_DESC, av,
-                        exportSettings);
-        jsonData = new FormatAdapter(ap, exportData.getSettings())
-                .formatSequences(JSONFile.FILE_DESC,
-                        exportData.getAlignment(),
-                        exportData.getOmitHidden(),
-                        exportData.getStartEndPostions(),
-                        av.getColumnSelection());
-      }
-      String htmlData = getHtml(titleSvgData, alignSvgData, jsonData);
-      FileOutputStream out = new FileOutputStream(file);
-      out.write(htmlData.getBytes());
-      out.flush();
-      out.close();
-      if (!(System.getProperty("java.awt.headless") != null && System
-              .getProperty("java.awt.headless").equals("true")))
-      {
-        jalview.util.BrowserLauncher.openURL("file:///" + file);
-      }
-      if (pIndicator != null && !headless)
-      {
-        pIndicator.setProgressBar(MessageManager.formatMessage(
-                "status.export_complete", "HTML"), pSessionId);
-      }
-    } catch (OutOfMemoryError err)
+  private void setProgressMessage(String message)
+  {
+    if (pIndicator != null && !headless)
     {
-      System.out.println("########################\n" + "OUT OF MEMORY "
-              + file + "\n" + "########################");
-      new OOMWarning("Creating Image for " + file, err);
-    } catch (Exception e)
+      pIndicator.setProgressBar(message, pSessionId);
+    }
+    else
     {
-      e.printStackTrace();
-      pIndicator.setProgressBar(MessageManager.formatMessage(
-              "info.error_creating_file", "HTML"), pSessionId);
+      System.out.println(message);
     }
   }
 
index 72fa605..10ea153 100755 (executable)
@@ -134,6 +134,10 @@ public class ImageMaker
       try
       {
         out = new FileOutputStream(file);
+        pIndicator.setProgressBar(null, pSessionId);
+        pIndicator.setProgressBar(MessageManager.formatMessage(
+                "status.exporting_alignment_as_x_file", type.getName()),
+                pSessionId);
         if (type == TYPE.SVG)
         {
           setupSVG(width, height, fileTitle);