X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FHtmlSvgOutput.java;h=4ea3000b05ed4ab7a69d388d5566120305b9e189;hb=refs%2Fheads%2Fimprovement%2FJAL-4381_dynamic_value_colouring_of_annotations;hp=30c40a909113e1983fe18055e34ba739e6d5afc0;hpb=fe8a4b9cb2b7242c902259aab79ecc0637c6c370;p=jalview.git diff --git a/src/jalview/io/HtmlSvgOutput.java b/src/jalview/io/HtmlSvgOutput.java index 30c40a9..4ea3000 100644 --- a/src/jalview/io/HtmlSvgOutput.java +++ b/src/jalview/io/HtmlSvgOutput.java @@ -20,59 +20,29 @@ */ package jalview.io; -import jalview.bin.Cache; -import jalview.exceptions.NoFileSelectedException; -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; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Locale; import java.util.concurrent.atomic.AtomicBoolean; -import javax.swing.JOptionPane; - import org.jfree.graphics2d.svg.SVGGraphics2D; import org.jfree.graphics2d.svg.SVGHints; +import jalview.bin.Cache; +import jalview.gui.AlignmentPanel; +import jalview.gui.LineartOptions; +import jalview.gui.OOMWarning; +import jalview.math.AlignmentDimension; +import jalview.util.MessageManager; + 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, @@ -89,8 +59,8 @@ public class HtmlSvgOutput extends HTMLOutput return ap.printWrappedAlignment(pwidth, pheight, pi, pg[0]); } - String getHtml(String titleSvg, String alignmentSvg, - String jsonData, boolean wrapped) + String getHtml(String titleSvg, String alignmentSvg, String jsonData, + boolean wrapped) { StringBuilder htmlSvg = new StringBuilder(); htmlSvg.append("\n"); @@ -219,8 +189,8 @@ public class HtmlSvgOutput extends HTMLOutput @Override public boolean isEmbedData() { - return Boolean.valueOf( - jalview.bin.Cache.getDefault("EXPORT_EMBBED_BIOJSON", "true")); + return Boolean + .valueOf(Cache.getDefault("EXPORT_EMBBED_BIOJSON", "true")); } @Override @@ -230,54 +200,43 @@ public class HtmlSvgOutput extends HTMLOutput } @Override - public File getExportedFile() + public void run() { - return generatedFile; + run(null); } @Override - public void run() + public void run(String renderer) { try { - setProgressMessage(null); - setProgressMessage(MessageManager.formatMessage( - "status.exporting_alignment_as_x_file", "HTML")); - - String renderStyle = Cache.getDefault("HTML_RENDERING", - "Prompt each time"); + String renderStyle = renderer == null + ? Cache.getDefault("HTML_RENDERING", + LineartOptions.PROMPT_EACH_TIME) + : renderer; AtomicBoolean textOption = new AtomicBoolean( - !"Lineart".equals(renderStyle)); + !"lineart".equals(renderStyle.toLowerCase(Locale.ROOT))); /* * configure the action to run on OK in the dialog */ - RunResponse okAction = new RunResponse(JOptionPane.OK_OPTION) - { - @Override - public void run() - { - doOutput(textOption.get()); - } + Runnable okAction = () -> { + doOutput(textOption.get()); }; /* * Prompt for character rendering style if preference is not set */ - if (renderStyle.equalsIgnoreCase("Prompt each time") && !isHeadless()) + if (renderStyle.equalsIgnoreCase(LineartOptions.PROMPT_EACH_TIME) + && !isHeadless()) { - LineartOptions svgOption = new LineartOptions("HTML_RENDERING", - "HTML", textOption); - svgOption.setResponseAction(new RunResponse(JOptionPane.NO_OPTION) - { - @Override - public void run() - { - setProgressMessage(MessageManager.formatMessage( - "status.cancelled_image_export_operation", "HTML")); - } + LineartOptions svgOption = new LineartOptions("HTML", textOption); + svgOption.setResponseAction(1, () -> { + setProgressMessage(MessageManager.formatMessage( + "status.cancelled_image_export_operation", + getDescription())); }); - svgOption.setResponseAction(okAction); + svgOption.setResponseAction(0, okAction); svgOption.showDialog(); /* no code here - JalviewJS cannot execute it */ } @@ -290,14 +249,15 @@ public class HtmlSvgOutput extends HTMLOutput } } 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) { e.printStackTrace(); setProgressMessage(MessageManager - .formatMessage("info.error_creating_file", "HTML")); + .formatMessage("info.error_creating_file", getDescription())); } } @@ -319,11 +279,9 @@ public class HtmlSvgOutput extends HTMLOutput aDimension.getWidth(), aDimension.getHeight()); if (!textCharacters) // Lineart selected { - idPanelGraphics.setRenderingHint( - SVGHints.KEY_DRAW_STRING_TYPE, + idPanelGraphics.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); - alignPanelGraphics.setRenderingHint( - SVGHints.KEY_DRAW_STRING_TYPE, + alignPanelGraphics.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); } if (ap.av.getWrapAlignment()) @@ -333,27 +291,27 @@ public class HtmlSvgOutput extends HTMLOutput } else { - printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), - 0, idPanelGraphics, alignPanelGraphics); + 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()); + String htmlData = getHtml(idPanelSvgData, alignPanelSvgData, jsonData, + ap.av.getWrapAlignment()); FileOutputStream out = new FileOutputStream(generatedFile); out.write(htmlData.getBytes()); 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())); } } }