- public static final String BJS_TEMPLATE_GIT_REPO = jalview.bin.Cache
- .getDefault(
- "biojs_template_git_repo",
- "https://raw.githubusercontent.com/jalview/exporter-templates/master/biojs/package.json");
-
- public BioJsHTMLOutput(AlignmentViewPanel ap,
- IProgressIndicator pIndicator)
- {
- 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"));
- }
- }
-
- public void exportJalviewAlignmentAsBioJsHtmlFile()
- {
- try
- {
- String outputFile = getOutputFile();
- // String jalviewAlignmentJson = JSONFile.getJSONData(ap);
- 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,
- 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 = getBioJsTemplateAsString();
- String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString
- .replaceAll("#sequenceData#", bioJSON).toString();
-
- PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
- outputFile));
- 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);
- }
- } catch (NoFileSelectedException ex)
- {
- // do noting if no file was selected
- } catch (Exception e)
- {
- pIndicator.setProgressBar(MessageManager.formatMessage(
- "info.error_creating_file", "HTML"), pSessionId);
- 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"));