*/
package jalview.io;
-import jalview.bin.Cache;
-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();
- if (outputFile == null)
- {
- setProgressMessage(MessageManager.formatMessage(
- "status.cancelled_image_export_operation", "HTML"));
- return;
- }
- }
- generatedFile = new File(outputFile);
- } 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,
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("<html>\n");
@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
@Override
public void run()
{
+ run(null);
+ }
+
+ @Override
+ public void run(String renderer)
+ {
try
{
- setProgressMessage(null);
- setProgressMessage(MessageManager.formatMessage(
- "status.exporting_alignment_as_x_file", getDescription()));
-
- 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", textOption);
- svgOption.setResponseAction(new RunResponse(JOptionPane.NO_OPTION)
- {
- @Override
- public void run()
- {
- setProgressMessage(MessageManager.formatMessage(
- "status.cancelled_image_export_operation",
- getDescription()));
- }
+ 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 */
}
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())
}
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();
.formatMessage("info.error_creating_file", getDescription()));
}
}
-
- @Override
- protected String getDescription()
- {
- return "HTML";
- }
}