JAL-3048 JalviewJS compliant use of LineartOptions dialog
[jalview.git] / src / jalview / io / HTMLOutput.java
index bebfd28..86da67a 100644 (file)
@@ -20,7 +20,8 @@
  */
 package jalview.io;
 
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
+import jalview.datamodel.AlignExportSettingsAdapter;
 import jalview.datamodel.AlignmentExportData;
 import jalview.exceptions.NoFileSelectedException;
 import jalview.gui.AlignmentPanel;
@@ -44,76 +45,44 @@ public abstract class HTMLOutput implements Runnable
 
   protected File generatedFile;
 
+  String _bioJson = null;
+
+  /**
+   * Constructor given an alignment panel (which should not be null)
+   * 
+   * @param ap
+   */
   public HTMLOutput(AlignmentPanel ap)
   {
-    if (ap != null)
-    {
-      this.ap = ap;
-      this.pIndicator = ap.alignFrame;
-    }
+    this.ap = ap;
+    this.pIndicator = ap.alignFrame;
   }
 
+  /**
+   * Gets the BioJSON data as a string, with lazy evaluation (first time called
+   * only). If the output format is configured not to embed BioJSON, returns
+   * null.
+   * 
+   * @return
+   */
   public String getBioJSONData()
   {
-    return getBioJSONData(null);
-  }
-
-  public String getBioJSONData(AlignExportSettingI exportSettings)
-  {
     if (!isEmbedData())
     {
       return null;
     }
-    if (exportSettings == null)
+    if (_bioJson == null)
     {
-      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;
-        }
-      };
+      AlignExportSettingsI options = new AlignExportSettingsAdapter(true);
+      AlignmentExportData exportData = ap.getAlignViewport()
+              .getAlignExportData(options);
+      _bioJson = new FormatAdapter(ap, options).formatSequences(
+              FileFormat.Json, exportData.getAlignment(),
+              exportData.getOmitHidden(), exportData.getStartEndPostions(),
+              ap.getAlignViewport().getAlignment().getHiddenColumns());
     }
-    AlignmentExportData exportData = jalview.gui.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()
-                            .getAlignment().getHiddenColumns());
-    return bioJSON;
+
+    return _bioJson;
   }
 
   /**
@@ -228,6 +197,8 @@ public abstract class HTMLOutput implements Runnable
               pSessionId);
     }
 
+    // TODO: JAL-3048 generate html rendered view (requires SvgGraphics and/or
+    // Jalview HTML rendering system- probably not required for Jalview-JS)
     JalviewFileChooser jvFileChooser = new JalviewFileChooser("html",
             "HTML files");
     jvFileChooser.setFileView(new JalviewFileView());