- 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)
- {
- if (ap != null)
- {
- this.ap = ap;
- }
- }
-
- 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);
- if (exportData.getSettings().isCancelled())
- {
- return;
- }
- String jalviewAlignmentJson = 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#", jalviewAlignmentJson)
- .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);
- } catch (NoFileSelectedException ex)
- {
- // do noting if no file was selected
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- public String getOutputFile() throws NoFileSelectedException
- {
- String selectedFile = null;
- 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
- {
- throw new NoFileSelectedException("No file was selected.");
- }
- return selectedFile;
- }
-