JAL-3048 JalviewJS compliant use of LineartOptions dialog
[jalview.git] / src / jalview / io / HTMLOutput.java
old mode 100755 (executable)
new mode 100644 (file)
index 81cdd3c..86da67a
@@ -1,6 +1,27 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 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;
@@ -24,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;
   }
 
   /**
@@ -208,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());