X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fio%2FHtmlSvgOutput.java;h=1f828538b2fe13f1c7fb339658f88dd5d3943d20;hb=1e28a196997a1e0b8b74d468bfd3df8ec74c1337;hp=e60824a6e668112f4c8367b9933f930d48c62c9a;hpb=e60cacff9260c47c12cf34a7e191678cfc97d265;p=jalview.git diff --git a/src/jalview/io/HtmlSvgOutput.java b/src/jalview/io/HtmlSvgOutput.java index e60824a..1f82853 100644 --- a/src/jalview/io/HtmlSvgOutput.java +++ b/src/jalview/io/HtmlSvgOutput.java @@ -20,148 +20,66 @@ */ package jalview.io; +import jalview.bin.Cache; import jalview.gui.AlignmentPanel; -import jalview.gui.HTMLOptions; +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; import java.io.File; 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 { - - private File generatedFile; - public HtmlSvgOutput(AlignmentPanel ap) { super(ap); } @Override - public void exportHTML(String file) + public void exportHTML(String outputFile) { exportStarted(); try { - if (file == null) + if (outputFile == null) { - file = getOutputFile(); + outputFile = getOutputFile(); + if (outputFile == null) + { + setProgressMessage(MessageManager.formatMessage( + "status.cancelled_image_export_operation", "HTML")); + return; + } } - generatedFile = new File(file); + generatedFile = new File(outputFile); } catch (Exception e) { - setProgressMessage(MessageManager.formatMessage( - "info.error_creating_file", "HTML")); + setProgressMessage(MessageManager + .formatMessage("info.error_creating_file", "HTML")); e.printStackTrace(); return; } - new Thread() - { - @Override - public void run() - { - try - { - setProgressMessage(null); - setProgressMessage(MessageManager.formatMessage( - "status.exporting_alignment_as_x_file", "HTML")); - AlignmentDimension aDimension = ap.getAlignmentDimension(); - SVGGraphics2D idPanelGraphics = new SVGGraphics2D( - aDimension.getWidth(), - aDimension.getHeight()); - SVGGraphics2D alignPanelGraphics = 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") - && !isHeadless()) - { - 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")) - { - idPanelGraphics.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, - SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); - alignPanelGraphics.setRenderingHint( - SVGHints.KEY_DRAW_STRING_TYPE, - SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); - } - if (ap.av.getWrapAlignment()) - { - printWrapped(aDimension.getWidth(), aDimension.getHeight(), 0, - alignPanelGraphics); - } - else - { - printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), 0, - idPanelGraphics, alignPanelGraphics); - } - - String idPanelSvgData = idPanelGraphics.getSVGDocument(); - String alignPanelSvgData = alignPanelGraphics.getSVGDocument(); - String jsonData = getBioJSONData(); - String htmlData = getHtml(idPanelSvgData, alignPanelSvgData, jsonData, - ap.av.getWrapAlignment()); - FileOutputStream out = new FileOutputStream(generatedFile); - out.write(htmlData.getBytes()); - out.flush(); - out.close(); - exportCompleted(); - } catch (OutOfMemoryError err) - { - System.out.println("########################\n" - + "OUT OF MEMORY " + generatedFile + "\n" - + "########################"); - new OOMWarning("Creating Image for " + generatedFile, err); - } catch (Exception e) - { - e.printStackTrace(); - setProgressMessage(MessageManager.formatMessage( - "info.error_creating_file", "HTML")); - } - setProgressMessage(MessageManager.formatMessage( - "status.export_complete", "HTML")); - } - }.start(); - + new Thread(this).start(); } - - static JalviewFileChooser getHTMLChooser() - { - return new jalview.io.JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - new String[] { "html" }, - new String[] { "Hypertext Markup Language" }, - "Hypertext Markup Language"); - } - - public int printUnwrapped(int pwidth, int pheight, int pi, Graphics... pg) + public int printUnwrapped(int pwidth, int pheight, int pi, + Graphics idGraphics, Graphics alignmentGraphics) throws PrinterException { - return ap.printUnwrapped(pwidth, pheight, pi, pg); + return ap.printUnwrapped(pwidth, pheight, pi, idGraphics, + alignmentGraphics); } public int printWrapped(int pwidth, int pheight, int pi, Graphics... pg) @@ -170,17 +88,20 @@ public class HtmlSvgOutput extends HTMLOutput return ap.printWrappedAlignment(pwidth, pheight, pi, pg[0]); } - private String getHtml(String titleSvg, String alignmentSvg, + String getHtml(String titleSvg, String alignmentSvg, String jsonData, boolean wrapped) { StringBuilder htmlSvg = new StringBuilder(); htmlSvg.append("\n"); if (jsonData != null) { - htmlSvg.append("  "); - htmlSvg.append(""); - htmlSvg.append("
" - + jsonData + "
"); + htmlSvg.append( + "  "); + htmlSvg.append( + ""); + htmlSvg.append( + "
" + + jsonData + "
"); htmlSvg.append("
 "); } htmlSvg.append("\n"); if (!wrapped) { - htmlSvg.append("
"); - htmlSvg.append("
\n"); - htmlSvg.append("
\n"); - htmlSvg.append(titleSvg); - htmlSvg.append("
"); - htmlSvg.append("
\n\n\n\n"); - htmlSvg.append("
"); - htmlSvg.append( - "
") - .append(alignmentSvg).append("
").append("
"); - htmlSvg.append("
"); + htmlSvg.append("
"); + htmlSvg.append("
\n"); + htmlSvg.append("
\n"); + htmlSvg.append(titleSvg); + htmlSvg.append("
"); + htmlSvg.append( + "
\n\n\n\n"); + htmlSvg.append("
"); + htmlSvg.append( + "
") + .append(alignmentSvg).append("
").append("
"); + htmlSvg.append("
"); - htmlSvg.append("\n" - + "\n" - + "\n" + + "\n" + + "\n"); + htmlSvg.append("\n"); } else { - htmlSvg.append("
\n") - .append(alignmentSvg).append("
"); - htmlSvg.append("\n" - + "\n"); - + htmlSvg.append("
\n").append(alignmentSvg).append("
"); + htmlSvg.append( + "\n" + + "\n"); } // javascript for launching file in Jalview - htmlSvg.append("