X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FHtmlSvgOutput.java;h=68173ff6a6205c15929314a6d9d339772cb3eef9;hb=37de9310bec3501cbc6381e0c3dcb282fcaad812;hp=1eb86b7f688bc705c04d07510387e4c55a1a6c43;hpb=90f6f3090a255a7059d0d0f26ddd848253bf9df6;p=jalview.git diff --git a/src/jalview/io/HtmlSvgOutput.java b/src/jalview/io/HtmlSvgOutput.java index 1eb86b7..68173ff 100644 --- a/src/jalview/io/HtmlSvgOutput.java +++ b/src/jalview/io/HtmlSvgOutput.java @@ -1,11 +1,34 @@ +/* + * 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 . + * 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.HTMLOptions; +import jalview.gui.IProgressIndicator; +import jalview.gui.OOMWarning; import jalview.math.AlignmentDimension; import jalview.util.MessageManager; @@ -25,8 +48,14 @@ public class HtmlSvgOutput AlignViewport av; FeatureRenderer fr; + AlignmentPanel ap; + private IProgressIndicator pIndicator; + + private long pSessionId; + + private boolean headless; public HtmlSvgOutput(File file, AlignmentPanel ap) { @@ -38,102 +67,194 @@ public class HtmlSvgOutput public void generateHtmlSvgOutput(File file) { + pIndicator = ap.alignFrame; + pSessionId = System.currentTimeMillis(); try { - if (file == null /* - * && !(System.getProperty("java.awt.headless") != null - * && System - * .getProperty("java.awt.headless").equals("true")) - */) + headless = (System.getProperty("java.awt.headless") != null && System + .getProperty("java.awt.headless").equals("true")); + if (file == null) { - - 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(); - } - } - - AlignmentDimension aDimension = ap.getAlignmentDimension(); - SVGGraphics2D g1 = new SVGGraphics2D(aDimension.getWidth(), - aDimension.getHeight()); - SVGGraphics2D g2 = new SVGGraphics2D(aDimension.getWidth(), - aDimension.getHeight()); - - String renderStyle = jalview.bin.Cache.getDefault("HTML_RENDERING", - "Prompt each time"); - - // If we need to prompt, and if the GUI is visible then - // Prompt for rendering style - if (renderStyle.equalsIgnoreCase("Prompt each time") - && !(System.getProperty("java.awt.headless") != null && System - .getProperty("java.awt.headless").equals("true"))) - { - HTMLOptions svgOption = new HTMLOptions(); - renderStyle = svgOption.getValue(); - - if (renderStyle == null || svgOption.cancelled) + setProgressMessage(MessageManager.formatMessage( + "status.waiting_for_user_to_select_output_file", "HTML")); + 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(); + ap.alignFrame.repaint(); + } + else + { + setProgressMessage(MessageManager.formatMessage( + "status.cancelled_image_export_operation", "HTML")); return; } } - - if (renderStyle.equalsIgnoreCase("lineart")) + } catch (Exception e) + { + pIndicator.setProgressBar(MessageManager.formatMessage( + "info.error_creating_file", "HTML"), pSessionId); + e.printStackTrace(); + return; + } + final File fileX = file; + new Thread() + { + @Override + public void run() { - g1.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, - SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); - g2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, - SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); + try + { + setProgressMessage(null); + setProgressMessage(MessageManager.formatMessage( + "status.exporting_alignment_as_x_file", "HTML")); + AlignmentDimension aDimension = ap.getAlignmentDimension(); + SVGGraphics2D g1 = new SVGGraphics2D(aDimension.getWidth(), + aDimension.getHeight()); + SVGGraphics2D g2 = new SVGGraphics2D(aDimension.getWidth(), + aDimension.getHeight()); + + String renderStyle = jalview.bin.Cache.getDefault( + "HTML_RENDERING", "Prompt each time"); + + // If we need to prompt, and if the GUI is visible then + // Prompt for rendering style + if (renderStyle.equalsIgnoreCase("Prompt each time") + && !(System.getProperty("java.awt.headless") != null && System + .getProperty("java.awt.headless").equals("true"))) + { + HTMLOptions svgOption = new HTMLOptions(); + renderStyle = svgOption.getValue(); + + if (renderStyle == null || svgOption.cancelled) + { + setProgressMessage(MessageManager.formatMessage( + "status.cancelled_image_export_operation", "HTML")); + return; + } + } + + if (renderStyle.equalsIgnoreCase("Lineart")) + { + g1.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, + SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); + g2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, + SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); + } + printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), 0, + g1, g2); + + String titleSvgData = g1.getSVGDocument(); + String alignSvgData = g2.getSVGDocument(); + 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(fileX); + out.write(htmlData.getBytes()); + out.flush(); + out.close(); + if (!(System.getProperty("java.awt.headless") != null && System + .getProperty("java.awt.headless").equals("true"))) + { + jalview.util.BrowserLauncher.openURL("file:///" + fileX); + } + } catch (OutOfMemoryError err) + { + System.out.println("########################\n" + + "OUT OF MEMORY " + fileX + "\n" + + "########################"); + new OOMWarning("Creating Image for " + fileX, err); + } catch (Exception e) + { + e.printStackTrace(); + pIndicator.setProgressBar(MessageManager.formatMessage( + "info.error_creating_file", "HTML"), pSessionId); + } + setProgressMessage(MessageManager.formatMessage( + "status.export_complete", "HTML")); } - printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), 0, g1, - g2); + }.start(); - String titleSvgData = g1.getSVGDocument(); - String alignSvgData = g2.getSVGDocument(); + } - AlignmentExportData exportData = ap.alignFrame.getAlignmentForExport( - JSONFile.FILE_DESC, av); - if (exportData.getSettings().isCancelled()) - { - return; - } - String jsonData = new FormatAdapter(ap, exportData.getSettings()) - .formatSequences(JSONFile.FILE_DESC, exportData - .getAlignment(), exportData.getOmitHidden(), - exportData.getStartEndPostions(), ap - .getAlignViewport().getColumnSelection()); - - // String jsonData = JSONFile.getJSONData(ap); - String htmlData = getHtml(titleSvgData, alignSvgData, jsonData); - - FileOutputStream out = new FileOutputStream(file); - out.write(htmlData.getBytes()); - out.flush(); - out.close(); - if (!(System.getProperty("java.awt.headless") != null && System - .getProperty("java.awt.headless").equals("true"))) - { - jalview.util.BrowserLauncher.openURL("file:///" + file); - } - } catch (Exception e) + private void setProgressMessage(String message) + { + if (pIndicator != null && !headless) { - e.printStackTrace(); + pIndicator.setProgressBar(message, pSessionId); + } + else + { + System.out.println(message); } } - + 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) @@ -232,9 +353,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)); } @@ -268,7 +387,7 @@ public class HtmlSvgOutput return Printable.PAGE_EXISTS; } - + private String getHtml(String titleSvg, String alignmentSvg, String jsonData) { @@ -276,36 +395,56 @@ public class HtmlSvgOutput htmlSvg.append("\n"); if (jsonData != null) { - htmlSvg.append(""); - htmlSvg.append(""); + htmlSvg.append("  "); + htmlSvg.append(""); + htmlSvg.append("
" + + jsonData + "
"); + htmlSvg.append("
 "); } htmlSvg.append("\n"); - htmlSvg.append("
"); - htmlSvg.append( -"
"); - htmlSvg.append( -"
") - .append(titleSvg) - .append("
") - .append("
\n\n\n\n"); - htmlSvg.append( -"
"); + + "object {pointer-events: none;}"); + if (jsonData != null) + { + // facebox style sheet for displaying raw BioJSON data + htmlSvg.append("#facebox { position: absolute; top: 0; left: 0; z-index: 100; text-align: left; }\n" + + "#facebox .popup{ position:relative; border:3px solid rgba(0,0,0,0); -webkit-border-radius:5px;" + + "-moz-border-radius:5px; border-radius:5px; -webkit-box-shadow:0 0 18px rgba(0,0,0,0.4); -moz-box-shadow:0 0 18px rgba(0,0,0,0.4);" + + "box-shadow:0 0 18px rgba(0,0,0,0.4); }\n" + + "#facebox .content { display:table; width: 98%; padding: 10px; background: #fff; -webkit-border-radius:4px; -moz-border-radius:4px;" + + " border-radius:4px; }\n" + + "#facebox .content > p:first-child{ margin-top:0; }\n" + + "#facebox .content > p:last-child{ margin-bottom:0; }\n" + + "#facebox .close{ position:absolute; top:5px; right:5px; padding:2px; background:#fff; }\n" + + "#facebox .close img{ opacity:0.3; }\n" + + "#facebox .close:hover img{ opacity:1.0; }\n" + + "#facebox .loading { text-align: center; }\n" + + "#facebox .image { text-align: center;}\n" + + "#facebox img { border: 0; margin: 0; }\n" + + "#facebox_overlay { position: fixed; top: 0px; left: 0px; height:100%; width:100%; }\n" + + ".facebox_hide { z-index:-100; }\n" + + ".facebox_overlayBG { background-color: #000; z-index: 99; }"); + } + + htmlSvg.append(""); + htmlSvg.append("
"); + htmlSvg.append("
\n"); + htmlSvg.append("
\n"); + htmlSvg.append(titleSvg); + htmlSvg.append("
"); + htmlSvg.append("
\n\n\n\n"); + htmlSvg.append("
"); htmlSvg.append( "
") - .append(alignmentSvg) -.append("
") - .append("
"); + .append(alignmentSvg).append("
").append("
"); htmlSvg.append(""); htmlSvg.append("\n" - + "\n" + + "\n" + "\n"); - htmlSvg.append(""); + htmlSvg.append(""); return htmlSvg.toString(); } }