JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / io / HtmlSvgOutput.java
index 30c40a9..d4a4651 100644 (file)
 package jalview.io;
 
 import jalview.bin.Cache;
-import jalview.exceptions.NoFileSelectedException;
+import jalview.bin.Jalview;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.LineartOptions;
 import jalview.gui.OOMWarning;
 import jalview.math.AlignmentDimension;
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.Graphics;
 import java.awt.print.PrinterException;
@@ -36,43 +35,14 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import javax.swing.JOptionPane;
-
 import org.jfree.graphics2d.svg.SVGGraphics2D;
 import org.jfree.graphics2d.svg.SVGHints;
 
 public class HtmlSvgOutput extends HTMLOutput
 {
-
   public HtmlSvgOutput(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", "HTML"));
-      return;
-    } catch (Exception e)
-    {
-      setProgressMessage(MessageManager
-              .formatMessage("info.error_creating_file", "HTML"));
-      e.printStackTrace();
-      return;
-    }
-    new Thread(this).start();
+    super(ap, "HTML");
   }
 
   public int printUnwrapped(int pwidth, int pheight, int pi,
@@ -230,20 +200,10 @@ public class HtmlSvgOutput extends HTMLOutput
   }
 
   @Override
-  public File getExportedFile()
-  {
-    return generatedFile;
-  }
-
-  @Override
   public void run()
   {
     try
     {
-      setProgressMessage(null);
-      setProgressMessage(MessageManager.formatMessage(
-              "status.exporting_alignment_as_x_file", "HTML"));
-
       String renderStyle = Cache.getDefault("HTML_RENDERING",
               "Prompt each time");
       AtomicBoolean textOption = new AtomicBoolean(
@@ -252,7 +212,7 @@ public class HtmlSvgOutput extends HTMLOutput
       /*
        * configure the action to run on OK in the dialog
        */
-      RunResponse okAction = new RunResponse(JOptionPane.OK_OPTION)
+      Runnable okAction = new Runnable()
       {
         @Override
         public void run()
@@ -264,20 +224,21 @@ public class HtmlSvgOutput extends HTMLOutput
       /*
        * Prompt for character rendering style if preference is not set
        */
-      if (renderStyle.equalsIgnoreCase("Prompt each time") && !isHeadless())
+      if (renderStyle.equalsIgnoreCase("Prompt each time")
+              && !Jalview.isHeadlessMode())
       {
-        LineartOptions svgOption = new LineartOptions("HTML_RENDERING",
-                "HTML", textOption);
-        svgOption.setResponseAction(new RunResponse(JOptionPane.NO_OPTION)
+        LineartOptions svgOption = new LineartOptions("HTML", textOption);
+        svgOption.setResponseAction(1, new Runnable()
         {
           @Override
           public void run()
           {
             setProgressMessage(MessageManager.formatMessage(
-                    "status.cancelled_image_export_operation", "HTML"));
+                    "status.cancelled_image_export_operation",
+                    getDescription()));
           }
         });
-        svgOption.setResponseAction(okAction);
+        svgOption.setResponseAction(0, okAction);
         svgOption.showDialog();
         /* no code here - JalviewJS cannot execute it */
       }
@@ -297,7 +258,7 @@ public class HtmlSvgOutput extends HTMLOutput
     {
       e.printStackTrace();
       setProgressMessage(MessageManager
-              .formatMessage("info.error_creating_file", "HTML"));
+              .formatMessage("info.error_creating_file", getDescription()));
     }
   }
 
@@ -347,13 +308,13 @@ public class HtmlSvgOutput extends HTMLOutput
       out.flush();
       out.close();
       setProgressMessage(MessageManager
-              .formatMessage("status.export_complete", "HTML"));
+              .formatMessage("status.export_complete", getDescription()));
       exportCompleted();
     } catch (Exception e)
     {
       e.printStackTrace();
       setProgressMessage(MessageManager
-              .formatMessage("info.error_creating_file", "HTML"));
+              .formatMessage("info.error_creating_file", getDescription()));
     }
   }
 }