- 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()
- {
- String outputFile = null;
- try
- {
- outputFile = getOutputFile();
- 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 = AlignFrame
- .getAlignmentForExport(FileFormat.Json,
- ap.getAlignViewport(), exportSettings);
- String bioJSON = new FormatAdapter(ap, exportData.getSettings())
- .formatSequences(FileFormat.Json, 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 (OutOfMemoryError err)
- {
- System.out.println("########################\n" + "OUT OF MEMORY "
- + outputFile + "\n" + "########################");
- new OOMWarning("Creating Image for " + outputFile, err);
- } 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"));
-
- 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 String getBioJsTemplateAsString() throws IOException