import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.security.AllPermission;
import java.security.CodeSource;
File imageFile = new File(file);
imageName = imageFile.getName();
HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
- htmlSVG.generateHtmlSvgOutput(new File(file));
+ htmlSVG.exportHTML(file);
System.out.println("Creating HTML image: " + file);
continue;
}
else if (format.equalsIgnoreCase("biojsmsa"))
{
- BioJsHTMLOutput.updateBioJS();
+ if (file == null)
+ {
+ System.err.println("The output html file must not be null");
+ return;
+ }
try
{
- Thread.sleep(1500);
- } catch (InterruptedException e)
+ BioJsHTMLOutput
+ .refreshVersionInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
+ } catch (URISyntaxException e)
{
e.printStackTrace();
}
- BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel, af);
- bjs.exportJalviewAlignmentAsBioJsHtmlFile(file);
+ BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
+ bjs.exportHTML(file);
System.out.println("Creating BioJS MSA Viwer HTML file: "
+ file);
continue;
protected void htmlMenuItem_actionPerformed(ActionEvent e)
{
HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
- htmlSVG.generateHtmlSvgOutput(null);
+ htmlSVG.exportHTML(null);
}
@Override
public void bioJSMenuItem_actionPerformed(ActionEvent e)
{
- BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel, this);
- bjs.exportJalviewAlignmentAsBioJsHtmlFile(null);
+ BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
+ bjs.exportHTML(null);
}
public void createImageMap(File file, String image)
*/
package jalview.io;
-import jalview.api.AlignExportSettingI;
-import jalview.api.AlignmentViewPanel;
-import jalview.datamodel.AlignmentExportData;
import jalview.exceptions.NoFileSelectedException;
-import jalview.gui.IProgressIndicator;
+import jalview.gui.AlignmentPanel;
import jalview.gui.OOMWarning;
import jalview.json.binding.biojs.BioJSReleasePojo;
import jalview.json.binding.biojs.BioJSRepositoryPojo;
import java.util.Objects;
import java.util.TreeMap;
-public class BioJsHTMLOutput
+public class BioJsHTMLOutput extends HTMLOutput
{
- private AlignmentViewPanel ap;
-
- private long pSessionId;
-
- private IProgressIndicator pIndicator;
-
- private boolean headless;
private static File currentBJSTemplateFile;
"biojs_template_git_repo",
"https://raw.githubusercontent.com/jalview/exporter-templates/master/biojs/package.json");
- public BioJsHTMLOutput(AlignmentViewPanel ap,
- IProgressIndicator pIndicator)
+ public BioJsHTMLOutput(AlignmentPanel ap)
{
- if (ap != null)
- {
- this.ap = ap;
- this.pSessionId = System.currentTimeMillis();
- this.pIndicator = pIndicator;
- this.headless = (System.getProperty("java.awt.headless") != null && System
- .getProperty("java.awt.headless").equals("true"));
- }
+ super(ap);
}
- public void exportJalviewAlignmentAsBioJsHtmlFile(String outputFile)
+ @Override
+ public void exportHTML(String outputFile)
{
- // String outputFile = null;
+ exportStarted();
try
{
+
if (outputFile == null)
{
outputFile = getOutputFile();
}
- AlignExportSettingI exportSettings = new AlignExportSettingI()
- {
- @Override
- public boolean isExportHiddenSequences()
- {
- return true;
- }
-
- @Override
- public boolean isExportHiddenColumns()
- {
- return true;
- }
+ generatedFile = new File(outputFile);
- @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,
- ap.getAlignViewport(), exportSettings);
- String bioJSON = new FormatAdapter(ap, exportData.getSettings())
- .formatSequences(JSONFile.FILE_DESC, exportData
- .getAlignment(), exportData.getOmitHidden(),
- exportData.getStartEndPostions(), ap
- .getAlignViewport().getColumnSelection());
-
- String bioJSTemplateString = HtmlFile.readFileAsString(getCurrentBJSTemplateFile());
+ String bioJSON = getBioJSONData();
+ String bioJSTemplateString = HTMLOutput.readFileAsString(getCurrentBJSTemplateFile());
String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString
.replaceAll("#sequenceData#", bioJSON).toString();
PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
- outputFile));
+ generatedFile));
out.print(generatedBioJsWithJalviewAlignmentAsJson);
out.flush();
out.close();
- jalview.util.BrowserLauncher.openURL("file:///" + outputFile);
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "status.export_complete", "BioJS"), pSessionId);
- }
+ exportCompleted();
+ setProgressMessage(MessageManager.formatMessage(
+ "status.export_complete", "BioJS"));
+
} catch (NoFileSelectedException ex)
{
// do noting if no file was selected
new OOMWarning("Creating Image for " + outputFile, err);
} catch (Exception e)
{
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "info.error_creating_file", "HTML"), pSessionId);
- }
+ setProgressMessage(MessageManager.formatMessage(
+ "info.error_creating_file", "HTML"));
e.printStackTrace();
}
}
- public String getOutputFile() throws NoFileSelectedException
- {
- String selectedFile = null;
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "status.waiting_for_user_to_select_output_file", "HTML"),
- pSessionId);
- }
-
- JalviewFileChooser jvFileChooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
- new String[] { "html" }, new String[] { "HTML files" },
- "HTML files");
- jvFileChooser.setFileView(new JalviewFileView());
-
- jvFileChooser.setDialogTitle(MessageManager
- .getString("label.save_as_biojs_html"));
- jvFileChooser.setToolTipText(MessageManager.getString("action.save"));
-
- int fileChooserOpt = jvFileChooser.showSaveDialog(null);
- if (fileChooserOpt == JalviewFileChooser.APPROVE_OPTION)
- {
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", jvFileChooser
- .getSelectedFile().getParent());
- selectedFile = jvFileChooser.getSelectedFile().getPath();
- }
- else
- {
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "status.cancelled_image_export_operation", "BioJS"),
- pSessionId);
- throw new NoFileSelectedException("No file was selected.");
- }
- return selectedFile;
- }
- public static void refreshBioJSVersionsInfo(String dirName)
+ public static void refreshVersionInfo(String dirName)
throws URISyntaxException
{
File directory = new File(BJS_TEMPLATES_LOCAL_DIRECTORY);
BioJSRepositoryPojo release = new BioJSRepositoryPojo(
gitRepoPkgJson);
syncUpdates(BJS_TEMPLATES_LOCAL_DIRECTORY, release);
- refreshBioJSVersionsInfo(BJS_TEMPLATES_LOCAL_DIRECTORY);
+ refreshVersionInfo(BJS_TEMPLATES_LOCAL_DIRECTORY);
}
} catch (URISyntaxException e)
{
BioJsHTMLOutput.bioJsMSAVersions = bioJsMSAVersions;
}
+ @Override
+ public boolean isEmbedData()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isLaunchInBrowserAfterExport()
+ {
+ return true;
+ }
+
+ @Override
+ public File getExportedFile()
+ {
+ return generatedFile;
+ }
+
}
*/
package jalview.io;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.SequenceI;
-import jalview.gui.AlignViewport;
+import jalview.api.AlignExportSettingI;
+import jalview.datamodel.AlignmentExportData;
+import jalview.exceptions.NoFileSelectedException;
import jalview.gui.AlignmentPanel;
-import jalview.gui.FeatureRenderer;
-import jalview.gui.SequenceRenderer;
+import jalview.gui.IProgressIndicator;
import jalview.util.MessageManager;
-import java.awt.Color;
-import java.awt.Font;
-import java.io.PrintWriter;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Objects;
-public class HTMLOutput
-{
- AlignViewport av;
-
- SequenceRenderer sr;
-
- jalview.renderer.seqfeatures.FeatureRenderer fr;
- Color color;
-
- public HTMLOutput(AlignmentPanel ap, SequenceRenderer sr,
- FeatureRenderer fr1)
- {
- this.av = ap.av;
- this.sr = sr;
+public abstract class HTMLOutput
+{
+ protected AlignmentPanel ap;
- fr = new FeatureRenderer(ap);
- fr.transferSettings(fr1);
+ protected long pSessionId;
- JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
- new String[] { "html" }, new String[] { "HTML files" },
- "HTML files");
+ protected IProgressIndicator pIndicator;
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle(MessageManager.getString("label.save_as_html"));
- chooser.setToolTipText(MessageManager.getString("action.save"));
+ private boolean headless;
- int value = chooser.showSaveDialog(null);
+ protected File generatedFile;
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ public HTMLOutput(AlignmentPanel ap)
+ {
+ if (ap != null)
{
- String choice = chooser.getSelectedFile().getPath();
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
- .getSelectedFile().getParent());
-
- try
- {
- PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
- choice));
- out.println("<HTML>");
- out.println("<style type=\"text/css\">");
- out.println("<!--");
- out.print("td {font-family: \"" + av.getFont().getFamily()
- + "\", \"" + av.getFont().getName() + "\", mono; "
- + "font-size: " + av.getFont().getSize() + "px; ");
-
- if (av.getFont().getStyle() == Font.BOLD)
- {
- out.print("font-weight: BOLD; ");
- }
-
- if (av.getFont().getStyle() == Font.ITALIC)
- {
- out.print("font-style: italic; ");
- }
-
- out.println("text-align: center; }");
-
- out.println("-->");
- out.println("</style>");
- out.println("<BODY>");
-
- if (av.getWrapAlignment())
- {
- drawWrappedAlignment(out);
- }
- else
- {
- drawUnwrappedAlignment(out);
- }
-
- out.println("\n</body>\n</html>");
- out.close();
- jalview.util.BrowserLauncher.openURL("file:///" + choice);
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
+ this.ap = ap;
+ this.pIndicator = ap.alignFrame;
}
}
- void drawUnwrappedAlignment(PrintWriter out)
- {
- out.println("<table border=\"1\"><tr><td>\n");
- out.println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
-
- // ////////////
- SequenceI seq;
- AlignmentI alignment = av.getAlignment();
- // draws the top row, the measure rule
- out.println("<tr><td colspan=\"6\"></td>");
-
- int i = 0;
-
- for (i = 10; i < (alignment.getWidth() - 10); i += 10)
+ public String getBioJSONData()
+ {
+ if (!isEmbedData())
{
- out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
+ return null;
}
-
- out.println("<td colspan=\"3\"></td><td colspan=\"3\">" + i
- + "<br>|</td>");
- out.println("</tr>");
-
- for (i = 0; i < alignment.getHeight(); i++)
+ AlignExportSettingI exportSettings = new AlignExportSettingI()
{
- seq = alignment.getSequenceAt(i);
-
- String id = seq.getDisplayId(av.getShowJVSuffix());
-
- out.println("<tr><td nowrap>" + id + " </td>");
-
- for (int res = 0; res < seq.getLength(); res++)
+ @Override
+ public boolean isExportHiddenSequences()
{
- if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
- {
- color = sr.getResidueBoxColour(seq, res);
-
- color = fr.findFeatureColour(color, seq, res);
- }
- else
- {
- color = Color.white;
- }
-
- if (color.getRGB() < -1)
- {
- out.println("<td bgcolor=\"#"
- + jalview.util.Format.getHexString(color) + "\">"
- + seq.getCharAt(res) + "</td>");
- }
- else
- {
- out.println("<td>" + seq.getCharAt(res) + "</td>");
- }
+ return true;
}
- out.println("</tr>");
- }
-
- // ////////////
- out.println("</table>");
- out.println("</td></tr></table>");
- }
-
- void drawWrappedAlignment(PrintWriter out)
- {
- // //////////////////////////////////
- // / How many sequences and residues can we fit on a printable page?
- AlignmentI al = av.getAlignment();
- SequenceI seq;
- String r;
- String g;
- String b;
-
- out.println("<table border=\"1\"><tr><td>\n");
- out.println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
-
- for (int startRes = 0; startRes < al.getWidth(); startRes += av
- .getWrappedWidth())
- {
- int endRes = startRes + av.getWrappedWidth();
-
- if (endRes > al.getWidth())
+ @Override
+ public boolean isExportHiddenColumns()
{
- endRes = al.getWidth();
+ return true;
}
- if (av.getScaleAboveWrapped())
+ @Override
+ public boolean isExportAnnotations()
{
- out.println("<tr>");
-
- if (av.getScaleLeftWrapped())
- {
- out.println("<td colspan=\"7\"> </td>");
- }
- else
- {
- out.println("<td colspan=\"6\"> </td>");
- }
-
- for (int i = startRes + 10; i < endRes; i += 10)
- {
- out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
- }
-
- out.println("</tr>");
+ return true;
}
- int startPos, endPos;
- for (int s = 0; s < al.getHeight(); s++)
+ @Override
+ public boolean isExportFeatures()
{
- out.println("<tr>");
- seq = al.getSequenceAt(s);
-
- startPos = seq.findPosition(startRes);
- endPos = seq.findPosition(endRes) - 1;
+ return true;
+ }
- String id = seq.getDisplayId(av.getShowJVSuffix());
+ @Override
+ public boolean isExportGroups()
+ {
+ return true;
+ }
- out.println("<td nowrap>" + id + " </td>");
+ @Override
+ public boolean isCancelled()
+ {
+ return false;
+ }
- if (av.getScaleLeftWrapped())
- {
- if (startPos > seq.getEnd() || endPos == 0)
- {
- out.println("<td nowrap> </td>");
- }
- else
- {
- out.println("<td nowrap>" + startPos + " </td>");
- }
- }
+ };
+ AlignmentExportData exportData = jalview.gui.AlignFrame
+ .getAlignmentForExport(JSONFile.FILE_DESC,
+ ap.getAlignViewport(), exportSettings);
+ String bioJSON = new FormatAdapter(ap, exportData.getSettings())
+ .formatSequences(JSONFile.FILE_DESC, exportData.getAlignment(),
+ exportData.getOmitHidden(), exportData
+ .getStartEndPostions(), ap.getAlignViewport()
+ .getColumnSelection());
+ return bioJSON;
+ }
- for (int res = startRes; res < endRes; res++)
+ /**
+ * Read a template file content as string
+ *
+ * @param file
+ * - the file to be read
+ * @return File content as String
+ * @throws IOException
+ */
+ public static String readFileAsString(File file) throws IOException
+ {
+ InputStreamReader isReader = null;
+ BufferedReader buffReader = null;
+ StringBuilder sb = new StringBuilder();
+ Objects.requireNonNull(file, "File must not be null!");
+ @SuppressWarnings("deprecation")
+ URL url = file.toURL();
+ if (url != null)
+ {
+ try
+ {
+ isReader = new InputStreamReader(url.openStream());
+ buffReader = new BufferedReader(isReader);
+ String line;
+ String lineSeparator = System.getProperty("line.separator");
+ while ((line = buffReader.readLine()) != null)
{
- if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
- {
- color = sr.getResidueBoxColour(seq, res);
-
- color = fr.findFeatureColour(color, seq, res);
- }
- else
- {
- color = Color.white;
- }
-
- if (color.getRGB() < -1)
- {
- out.println("<td bgcolor=\"#"
- + jalview.util.Format.getHexString(color) + "\">"
- + seq.getCharAt(res) + "</td>");
- }
- else
- {
- out.println("<td>" + seq.getCharAt(res) + "</td>");
- }
-
+ sb.append(line).append(lineSeparator);
}
-
- if (av.getScaleRightWrapped()
- && endRes < startRes + av.getWrappedWidth())
+
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ } finally
+ {
+ if (isReader != null)
{
- out.println("<td colspan=\""
- + (startRes + av.getWrappedWidth() - endRes) + "\">"
- + " </td>");
+ isReader.close();
}
-
- if (av.getScaleRightWrapped() && startPos < endPos)
+
+ if (buffReader != null)
{
- out.println("<td nowrap> " + endPos + " </td>");
+ buffReader.close();
}
-
- out.println("</tr>");
- }
-
- if (endRes < al.getWidth())
- {
- out.println("<tr><td height=\"5\"></td></tr>");
}
}
-
- out.println("</table>");
- out.println("</table>");
+ return sb.toString();
}
public static String getImageMapHTML()
+ "initToolTips(); //--></script>\n");
}
+
+ public String getOutputFile() throws NoFileSelectedException
+ {
+ String selectedFile = null;
+ if (pIndicator != null && !headless)
+ {
+ pIndicator.setProgressBar(MessageManager.formatMessage(
+ "status.waiting_for_user_to_select_output_file", "HTML"),
+ pSessionId);
+ }
+
+ JalviewFileChooser jvFileChooser = new JalviewFileChooser(
+ jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
+ new String[] { "html" }, new String[] { "HTML files" },
+ "HTML files");
+ jvFileChooser.setFileView(new JalviewFileView());
+
+ jvFileChooser.setDialogTitle(MessageManager
+ .getString("label.save_as_biojs_html"));
+ jvFileChooser.setToolTipText(MessageManager.getString("action.save"));
+
+ int fileChooserOpt = jvFileChooser.showSaveDialog(null);
+ if (fileChooserOpt == JalviewFileChooser.APPROVE_OPTION)
+ {
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", jvFileChooser
+ .getSelectedFile().getParent());
+ selectedFile = jvFileChooser.getSelectedFile().getPath();
+ }
+ else
+ {
+ pIndicator.setProgressBar(MessageManager.formatMessage(
+ "status.cancelled_image_export_operation", "BioJS"),
+ pSessionId);
+ throw new NoFileSelectedException("No file was selected.");
+ }
+ return selectedFile;
+ }
+
+ protected void setProgressMessage(String message)
+ {
+ if (pIndicator != null && !headless)
+ {
+ pIndicator.setProgressBar(message, pSessionId);
+ }
+ else
+ {
+ System.out.println(message);
+ }
+ }
+
+ /**
+ * Answers true if HTML export is invoke in headless mode or false otherwise
+ *
+ * @return
+ */
+ protected boolean isHeadless()
+ {
+ return System.getProperty("java.awt.headless") != null
+ && System.getProperty("java.awt.headless").equals("true");
+ }
+
+ /**
+ * This method provides implementation of consistent behaviour which should
+ * occur before a HTML file export. It MUST be called at the start of the
+ * exportHTML() method implementation.
+ */
+ protected void exportStarted()
+ {
+ pSessionId = System.currentTimeMillis();
+ }
+
+ /**
+ * This method provides implementation of consistent behaviour which should
+ * occur after a HTML file export. It MUST be called at the end of the
+ * exportHTML() method implementation.
+ */
+ protected void exportCompleted()
+ {
+ if (isLaunchInBrowserAfterExport() && !isHeadless())
+ {
+ try
+ {
+ jalview.util.BrowserLauncher
+ .openURL("file:///" + getExportedFile());
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * if this answers true then BioJSON data will be embedded to the exported
+ * HTML file otherwise it won't be embedded.
+ *
+ * @return
+ */
+ public abstract boolean isEmbedData();
+
+ /**
+ * if this answers true then the generated HTML file is opened for viewing in
+ * a browser after its generation otherwise it won't be opened in a browser
+ *
+ * @return
+ */
+ public abstract boolean isLaunchInBrowserAfterExport();
+
+ /**
+ * handle to the generated HTML file
+ *
+ * @return
+ */
+ public abstract File getExportedFile();
+
+ /**
+ * This is the main method to handle the HTML generation.
+ *
+ * @param outputFile
+ * the file path of the generated HTML
+ */
+ public abstract void exportHTML(String outputFile);
}
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SequenceI;
-import java.io.BufferedReader;
-import java.io.File;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.StringReader;
-import java.net.URL;
-import java.util.Objects;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
return new PDBFeatureSettings();
}
- /**
- * Read a template file content as string
- *
- * @param file
- * - the file to be read
- * @return File content as String
- * @throws IOException
- */
- public static String readFileAsString(File file) throws IOException
- {
- InputStreamReader isReader = null;
- BufferedReader buffReader = null;
- StringBuilder sb = new StringBuilder();
- Objects.requireNonNull(file, "File must not be null!");
- @SuppressWarnings("deprecation")
- URL url = file.toURL();
- if (url != null)
- {
- try
- {
- isReader = new InputStreamReader(url.openStream());
- buffReader = new BufferedReader(isReader);
- String line;
- String lineSeparator = System.getProperty("line.separator");
- while ((line = buffReader.readLine()) != null)
- {
- sb.append(line).append(lineSeparator);
- }
-
- } catch (Exception ex)
- {
- ex.printStackTrace();
- } finally
- {
- if (isReader != null)
- {
- isReader.close();
- }
-
- if (buffReader != null)
- {
- buffReader.close();
- }
- }
- }
- return sb.toString();
- }
-
}
*/
package jalview.io;
-import jalview.api.AlignExportSettingI;
-import jalview.api.FeatureRenderer;
-import jalview.datamodel.AlignmentExportData;
-import jalview.gui.AlignViewport;
import jalview.gui.AlignmentPanel;
import jalview.gui.HTMLOptions;
-import jalview.gui.IProgressIndicator;
import jalview.gui.OOMWarning;
import jalview.math.AlignmentDimension;
import jalview.util.MessageManager;
import org.jfree.graphics2d.svg.SVGGraphics2D;
import org.jfree.graphics2d.svg.SVGHints;
-public class HtmlSvgOutput
+public class HtmlSvgOutput extends HTMLOutput
{
- AlignViewport av;
- FeatureRenderer fr;
-
- AlignmentPanel ap;
-
- private IProgressIndicator pIndicator;
-
- private long pSessionId;
-
- private boolean headless;
+ private File generatedFile;
public HtmlSvgOutput(AlignmentPanel ap)
{
- this.av = ap.av;
- this.ap = ap;
- fr = ap.cloneFeatureRenderer();
+ super(ap);
}
- public void generateHtmlSvgOutput(File file)
+ @Override
+ public void exportHTML(String file)
{
- pIndicator = ap.alignFrame;
- pSessionId = System.currentTimeMillis();
+ exportStarted();
try
{
- headless = (System.getProperty("java.awt.headless") != null && System
- .getProperty("java.awt.headless").equals("true"));
if (file == null)
{
- 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());
- chooser.setToolTipText(MessageManager.getString("action.save"));
- int value = chooser.showSaveDialog(ap.alignFrame);
-
- if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
- {
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
- .getSelectedFile().getParent());
- file = chooser.getSelectedFile();
- ap.alignFrame.repaint();
- }
- else
- {
- setProgressMessage(MessageManager.formatMessage(
- "status.cancelled_image_export_operation", "HTML"));
- return;
- }
+ file = getOutputFile();
}
+ generatedFile = new File(file);
} catch (Exception e)
{
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "info.error_creating_file", "HTML"), pSessionId);
+ setProgressMessage(MessageManager.formatMessage(
+ "info.error_creating_file", "HTML"));
e.printStackTrace();
return;
}
- final File fileX = file;
new Thread()
{
@Override
// 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")))
+ && !isHeadless())
{
HTMLOptions svgOption = new HTMLOptions();
renderStyle = svgOption.getValue();
SVGHints.KEY_DRAW_STRING_TYPE,
SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR);
}
- if (av.getWrapAlignment())
+ if (ap.av.getWrapAlignment())
{
printWrapped(aDimension.getWidth(), aDimension.getHeight(), 0,
alignPanelGraphics);
String idPanelSvgData = idPanelGraphics.getSVGDocument();
String alignPanelSvgData = alignPanelGraphics.getSVGDocument();
- String jsonData = null;
- boolean isEmbbedBioJSON = Boolean.valueOf(jalview.bin.Cache
- .getDefault("EXPORT_EMBBED_BIOJSON", "true"));
- if (isEmbbedBioJSON)
- {
- 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());
- }
+ String jsonData = getBioJSONData();
String htmlData = getHtml(idPanelSvgData, alignPanelSvgData, jsonData,
- av.getWrapAlignment());
- FileOutputStream out = new FileOutputStream(fileX);
+ ap.av.getWrapAlignment());
+ FileOutputStream out = new FileOutputStream(generatedFile);
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:///" + fileX);
- }
+ exportCompleted();
} catch (OutOfMemoryError err)
{
System.out.println("########################\n"
- + "OUT OF MEMORY " + fileX + "\n"
+ + "OUT OF MEMORY " + generatedFile + "\n"
+ "########################");
- new OOMWarning("Creating Image for " + fileX, err);
+ new OOMWarning("Creating Image for " + generatedFile, err);
} catch (Exception e)
{
e.printStackTrace();
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "info.error_creating_file", "HTML"), pSessionId);
+ setProgressMessage(MessageManager.formatMessage(
+ "info.error_creating_file", "HTML"));
}
setProgressMessage(MessageManager.formatMessage(
"status.export_complete", "HTML"));
}
- private void setProgressMessage(String message)
- {
- if (pIndicator != null && !headless)
- {
- pIndicator.setProgressBar(message, pSessionId);
- }
- else
- {
- System.out.println(message);
- }
- }
static JalviewFileChooser getHTMLChooser()
{
File faceBoxJsFile = new File("examples/javascript/facebox-1.3.js");
try
{
- htmlSvg.append(HtmlFile.readFileAsString(faceBoxJsFile));
+ htmlSvg.append(HTMLOutput.readFileAsString(faceBoxJsFile));
} catch (IOException e)
{
e.printStackTrace();
htmlSvg.append("</html>");
return htmlSvg.toString();
}
+
+ @Override
+ public boolean isEmbedData()
+ {
+ return Boolean.valueOf(jalview.bin.Cache.getDefault(
+ "EXPORT_EMBBED_BIOJSON", "true"));
+ }
+
+ @Override
+ public boolean isLaunchInBrowserAfterExport()
+ {
+ return true;
+ }
+
+ @Override
+ public File getExportedFile()
+ {
+ return generatedFile;
+ }
}
{
e.printStackTrace();
}
- bjsTemplate = HtmlFile.readFileAsString(BioJsHTMLOutput
+ bjsTemplate = HTMLOutput.readFileAsString(BioJsHTMLOutput
.getCurrentBJSTemplateFile());
// System.out.println(bjsTemplate);
} catch (IOException e)
{
try
{
- BioJsHTMLOutput.refreshBioJSVersionsInfo(null);
+ BioJsHTMLOutput.refreshVersionInfo(null);
} catch (URISyntaxException e)
{
AssertJUnit.fail("Expception occured while testing!");
try
{
BioJsHTMLOutput
- .refreshBioJSVersionsInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
+ .refreshVersionInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
versions = BioJsHTMLOutput.getBioJsMSAVersions();
} catch (URISyntaxException e)
{