X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FHtmlSvgOutput.java;h=6058cf55928fd5a0d9bc3404620e415b5d09bac3;hb=c19d2a91ca05e052e3408bf5852d88eb5d0608f1;hp=464385826989c2c469e8b14df13a86ca87f1e6a6;hpb=cca50cb3aee94f3ed1a5e504d45b8d8b665f8c5b;p=jalview.git diff --git a/src/jalview/io/HtmlSvgOutput.java b/src/jalview/io/HtmlSvgOutput.java index 4643858..6058cf5 100644 --- a/src/jalview/io/HtmlSvgOutput.java +++ b/src/jalview/io/HtmlSvgOutput.java @@ -1,10 +1,31 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2) + * Copyright (C) 2015 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 . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.io; +import jalview.api.AlignExportSettingI; +import jalview.api.FeatureRenderer; +import jalview.datamodel.AlignmentExportData; import jalview.datamodel.SequenceI; import jalview.gui.AlignViewport; import jalview.gui.AlignmentPanel; -import jalview.gui.AnnotationPanel; -import jalview.gui.FeatureRenderer; import jalview.gui.HTMLOptions; import jalview.math.AlignmentDimension; import jalview.util.MessageManager; @@ -25,35 +46,40 @@ public class HtmlSvgOutput AlignViewport av; FeatureRenderer fr; - AlignmentPanel ap; - AnnotationPanel annotationPanel; + AlignmentPanel ap; - public HtmlSvgOutput(AlignmentPanel ap) + public HtmlSvgOutput(File file, AlignmentPanel ap) { - - this.av = ap.av; - this.ap = ap; - this.annotationPanel = ap.getAnnotationPanel(); - generateHtmlSvgOutput(); + this.av = ap.av; + this.ap = ap; + fr = ap.cloneFeatureRenderer(); + generateHtmlSvgOutput(file); } - public void generateHtmlSvgOutput() + public void generateHtmlSvgOutput(File file) { - File file = null; try { - JalviewFileChooser chooser = getHTMLChooser(); - chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle(ap.alignFrame.getTitle()); - chooser.setToolTipText(MessageManager.getString("action.save")); - int value = chooser.showSaveDialog(ap.alignFrame); - - if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) + if (file == null) { - jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser - .getSelectedFile().getParent()); - file = chooser.getSelectedFile(); + + JalviewFileChooser chooser = getHTMLChooser(); + chooser.setFileView(new jalview.io.JalviewFileView()); + chooser.setDialogTitle(ap.alignFrame.getTitle()); + chooser.setToolTipText(MessageManager.getString("action.save")); + int value = chooser.showSaveDialog(ap.alignFrame); + + if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) + { + jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser + .getSelectedFile().getParent()); + file = chooser.getSelectedFile(); + } + else + { + return; + } } AlignmentDimension aDimension = ap.getAlignmentDimension(); @@ -89,29 +115,86 @@ public class HtmlSvgOutput } printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), 0, g1, g2); - FileOutputStream out = new FileOutputStream(file); String titleSvgData = g1.getSVGDocument(); String alignSvgData = g2.getSVGDocument(); - String htmlData = getHtml(titleSvgData, alignSvgData); + String jsonData = null; + boolean isEmbbedBioJSON = Boolean.valueOf(jalview.bin.Cache + .getDefault("EXPORT_EMBBED_BIOJSON", "true")); + if (isEmbbedBioJSON) + { + 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, av, + exportSettings); + jsonData = new FormatAdapter(ap, exportData.getSettings()) + .formatSequences(JSONFile.FILE_DESC, + exportData.getAlignment(), + exportData.getOmitHidden(), + exportData.getStartEndPostions(), + av.getColumnSelection()); + } + String htmlData = getHtml(titleSvgData, alignSvgData, jsonData); + FileOutputStream out = new FileOutputStream(file); out.write(htmlData.getBytes()); out.flush(); out.close(); - - jalview.util.BrowserLauncher.openURL("file:///" + file); + if (!(System.getProperty("java.awt.headless") != null && System + .getProperty("java.awt.headless").equals("true"))) + { + jalview.util.BrowserLauncher.openURL("file:///" + file); + } } catch (Exception e) { e.printStackTrace(); } } - + static JalviewFileChooser getHTMLChooser() { return new jalview.io.JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "html" }, new String[] - { "Hypertext Markup Language" }, "Hypertext Markup Language"); + jalview.bin.Cache.getProperty("LAST_DIRECTORY"), + new String[] { "html" }, + new String[] { "Hypertext Markup Language" }, + "Hypertext Markup Language"); } public int printUnwrapped(int pwidth, int pheight, int pi, Graphics... pg) @@ -210,9 +293,7 @@ public class HtmlSvgOutput - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix())) - 4; } - pg[0].drawString( - seq.getDisplayId(av.getShowJVSuffix()), - xPos, + pg[0].drawString(seq.getDisplayId(av.getShowJVSuffix()), xPos, (((i - startSeq) * av.getCharHeight()) + av.getCharHeight()) - (av.getCharHeight() / 5)); } @@ -246,19 +327,360 @@ public class HtmlSvgOutput return Printable.PAGE_EXISTS; } - - private String getHtml(String titleSvg, String alignmentSvg) + + private String getHtml(String titleSvg, String alignmentSvg, + String jsonData) { StringBuilder htmlSvg = new StringBuilder(); - htmlSvg.append("" - + "
" - + "
"); + htmlSvg.append("\n"); + if (jsonData != null) + { + htmlSvg.append("  "); + htmlSvg.append(""); + htmlSvg.append("
" + + jsonData + "
"); + htmlSvg.append("
 "); + } + htmlSvg.append("\n"); + htmlSvg.append("
"); + htmlSvg.append("
\n"); + htmlSvg.append("
\n"); htmlSvg.append(titleSvg); - htmlSvg.append("
").append(alignmentSvg); htmlSvg.append("
"); + htmlSvg.append("
\n\n\n\n"); + htmlSvg.append("
"); + htmlSvg.append( + "
") + .append(alignmentSvg).append("
").append("
"); + htmlSvg.append("
"); + + htmlSvg.append("\n" + + "\n" + + "\n"); + + // javascript for launching file in Jalview + + htmlSvg.append("\n"); + htmlSvg.append(""); return htmlSvg.toString(); } }