X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FImageMaker.java;h=723204285c7a729349138e93a08166d38f5062ca;hb=ed96e73a6db654d52a6a1b1d27c2ee707876a4c7;hp=1953a6033ae0a1366a6ff20587990a1ed879ade6;hpb=a3b4ec9805c4cee4c2dbe2a4c98913ee9c189c6b;p=jalview.git diff --git a/src/jalview/util/ImageMaker.java b/src/jalview/util/ImageMaker.java index 1953a60..7232042 100755 --- a/src/jalview/util/ImageMaker.java +++ b/src/jalview/util/ImageMaker.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,7 +20,10 @@ */ package jalview.util; +import jalview.bin.Jalview; import jalview.gui.EPSOptions; +import jalview.gui.IProgressIndicator; +import jalview.gui.SVGOptions; import jalview.io.JalviewFileChooser; import java.awt.Component; @@ -34,17 +37,26 @@ import java.io.FileOutputStream; import javax.imageio.ImageIO; import org.jfree.graphics2d.svg.SVGGraphics2D; +import org.jfree.graphics2d.svg.SVGHints; import org.jibble.epsgraphics.EpsGraphics2D; public class ImageMaker { - // public static final int EPS = 0; - // - // public static final int PNG = 1; - // - // public static final int SVG = 2; - // - // int type = -1; + public static final String SVG_DESCRIPTION = "Scalable Vector Graphics"; + + public static final String SVG_EXTENSION = "svg"; + + public static final String EPS_DESCRIPTION = "Encapsulated Postscript"; + + public static final String EPS_EXTENSION = "eps"; + + public static final String PNG_EXTENSION = "png"; + + public static final String PNG_DESCRIPTION = "Portable network graphics"; + + public static final String HTML_EXTENSION = "html"; + + public static final String HTML_DESCRIPTION = "Hypertext Markup Language"; EpsGraphics2D pg; @@ -58,23 +70,34 @@ public class ImageMaker TYPE type; + private IProgressIndicator pIndicator; + + private long pSessionId; + + private boolean headless; + public enum TYPE { - EPS("EPS", MessageManager.getString("label.eps_file"), getEPSChooser()), PNG( - "PNG", MessageManager.getString("label.png_image"), - getPNGChooser()), SVG("SVG", "SVG", getSVGChooser()); - - private JalviewFileChooser chooser; + EPS("EPS", MessageManager.getString("label.eps_file"), EPS_EXTENSION, + EPS_DESCRIPTION), + PNG("PNG", MessageManager.getString("label.png_image"), + PNG_EXTENSION, PNG_DESCRIPTION), + SVG("SVG", "SVG", SVG_EXTENSION, SVG_DESCRIPTION); private String name; private String label; - TYPE(String name, String label, JalviewFileChooser chooser) + private String extension; + + private String description; + + TYPE(String name, String label, String ext, String desc) { this.name = name; this.label = label; - this.chooser = chooser; + this.extension = ext; + this.description = desc; } public String getName() @@ -82,9 +105,9 @@ public class ImageMaker return name; } - public JalviewFileChooser getChooser() + public JalviewFileChooser getFileChooser() { - return chooser; + return new JalviewFileChooser(extension, description); } public String getLabel() @@ -94,31 +117,36 @@ public class ImageMaker } - public ImageMaker(Component parent, TYPE type, String title, int width, - int height, File file, String fileTitle) + int height, File file, String fileTitle, + IProgressIndicator pIndicator, long pSessionId, boolean headless) { + this.pIndicator = pIndicator; this.type = type; - + this.pSessionId = pSessionId; + this.headless = headless; if (file == null) { + setProgressMessage(MessageManager.formatMessage( + "status.waiting_for_user_to_select_output_file", type.name)); JalviewFileChooser chooser; - // chooser = type == EPS ? getEPSChooser() : getPNGChooser(); - chooser = type.getChooser(); - + chooser = type.getFileChooser(); chooser.setFileView(new jalview.io.JalviewFileView()); chooser.setDialogTitle(title); chooser.setToolTipText(MessageManager.getString("action.save")); - int value = chooser.showSaveDialog(parent); if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) { - jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser - .getSelectedFile().getParent()); - + jalview.bin.Cache.setProperty("LAST_DIRECTORY", + chooser.getSelectedFile().getParent()); file = chooser.getSelectedFile(); } + else + { + setProgressMessage(MessageManager.formatMessage( + "status.cancelled_image_export_operation", type.name)); + } } if (file != null) @@ -126,6 +154,9 @@ public class ImageMaker try { out = new FileOutputStream(file); + setProgressMessage(null); + setProgressMessage(MessageManager.formatMessage( + "status.exporting_alignment_as_x_file", type.getName())); if (type == TYPE.SVG) { setupSVG(width, height, fileTitle); @@ -138,11 +169,13 @@ public class ImageMaker { setupPNG(width, height); } - + } catch (Exception ex) { - System.out.println("Error creating " - + type.getName() + " file."); + System.out.println("Error creating " + type.getName() + " file."); + + setProgressMessage(MessageManager + .formatMessage("info.error_creating_file", type.getName())); } } } @@ -152,8 +185,6 @@ public class ImageMaker return graphics; } - - public void writeImage() { try @@ -165,12 +196,14 @@ public class ImageMaker pg.close(); break; case SVG: - String svg = ((SVGGraphics2D) getGraphics()).getSVGDocument(); - out.write(svg.getBytes()); + String svgData = ((SVGGraphics2D) getGraphics()).getSVGDocument(); + out.write(svgData.getBytes()); + out.flush(); out.close(); break; case PNG: - ImageIO.write(bi, "png", out); + ImageIO.write(bi, PNG_EXTENSION, out); + out.flush(); out.close(); break; } @@ -198,6 +231,8 @@ public class ImageMaker if (renderStyle == null || eps.cancelled) { + setProgressMessage(MessageManager.formatMessage( + "status.cancelled_image_export_operation", "EPS")); return; } } @@ -217,6 +252,8 @@ public class ImageMaker pg.setAccurateTextMode(accurateText); graphics = pg; + setProgressMessage(MessageManager + .formatMessage("status.export_complete", type.getName())); } catch (Exception ex) { } @@ -229,35 +266,80 @@ public class ImageMaker Graphics2D ig2 = (Graphics2D) graphics; ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + setProgressMessage(MessageManager + .formatMessage("status.export_complete", type.getName())); + } void setupSVG(int width, int height, String title) { + g2 = new SVGGraphics2D(width, height); + Graphics2D ig2 = g2; + + String renderStyle = jalview.bin.Cache.getDefault("SVG_RENDERING", + "Prompt each time"); + + // If we need to prompt, and if the GUI is visible then + // Prompt for EPS rendering style + if (renderStyle.equalsIgnoreCase("Prompt each time") + && !(System.getProperty("java.awt.headless") != null && System + .getProperty("java.awt.headless").equals("true"))) + { + SVGOptions svgOption = new SVGOptions(); + renderStyle = svgOption.getValue(); + + if (renderStyle == null || svgOption.cancelled) + { + setProgressMessage(MessageManager.formatMessage( + "status.cancelled_image_export_operation", "SVG")); + return; + } + } + + if (renderStyle.equalsIgnoreCase("Lineart")) + { + ig2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, + SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); + } + + setProgressMessage(MessageManager + .formatMessage("status.export_complete", type.getName())); graphics = g2; } static JalviewFileChooser getPNGChooser() { - return new jalview.io.JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "png" }, new String[] - { "Portable network graphics" }, "Portable network graphics"); + if (Jalview.isHeadlessMode()) + { + return null; + } + return new JalviewFileChooser(PNG_EXTENSION, PNG_DESCRIPTION); } static JalviewFileChooser getEPSChooser() { - return new jalview.io.JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "eps" }, new String[] - { "Encapsulated Postscript" }, "Encapsulated Postscript"); + if (Jalview.isHeadlessMode()) + { + return null; + } + return new JalviewFileChooser(EPS_EXTENSION, EPS_DESCRIPTION); + } + + private void setProgressMessage(String message) + { + if (pIndicator != null && !headless) + { + pIndicator.setProgressBar(message, pSessionId); + } } static JalviewFileChooser getSVGChooser() { - return new jalview.io.JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "svg" }, new String[] - { "Scalable Vector Graphics" }, "Scalable Vector Graphics"); + if (Jalview.isHeadlessMode()) + { + return null; + } + return new JalviewFileChooser(SVG_EXTENSION, SVG_DESCRIPTION); } }