X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FImageMaker.java;h=3c6b05fc4d9e9e41393a391e9f0a5770c384b8c4;hb=797df64fa2a0a30773d0f48f5494d4155e5a8be3;hp=9323d0dbc266bd73a5a1725c18ca1f950a89ae9f;hpb=9dcd8056f4a166c13b75a19e6fd1bea9badec5ca;p=jalview.git diff --git a/src/jalview/util/ImageMaker.java b/src/jalview/util/ImageMaker.java index 9323d0d..3c6b05f 100755 --- a/src/jalview/util/ImageMaker.java +++ b/src/jalview/util/ImageMaker.java @@ -1,185 +1,185 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * - * This program 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 2 - * of the License, or (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ -package jalview.util; - -import java.awt.RenderingHints; -import javax.imageio.ImageIO; -import org.jibble.epsgraphics.EpsGraphics2D; -import jalview.gui.EPSOptions; -import java.awt.Graphics2D; -import java.io.*; -import java.awt.image.BufferedImage; -import java.awt.Graphics; -import jalview.io.*; -import java.awt.*; - - -public class ImageMaker -{ - public static final int EPS = 0; - public static final int PNG = 1; - int type = -1; - - EpsGraphics2D pg; - Graphics graphics; - FileOutputStream out; - BufferedImage bi; - - public ImageMaker(Component parent, int type, String title, - int width, int height, File file, String EPStitle) - { - this.type = type; - - if (file == null) - { - JalviewFileChooser chooser; - chooser = type == EPS ? getEPSChooser() : getPNGChooser(); - - chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle(title); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(parent); - - if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); - - file = chooser.getSelectedFile(); - } - } - - if(file!=null) - { - try - { - out = new FileOutputStream(file); - - if (type == EPS) - setupEPS(width, height, EPStitle); - else - setupPNG(width, height); - } - catch (Exception ex) - { - System.out.println("Error creating " + (type == EPS ? "EPS" : "PNG") + - " file."); - } - } - } - - public Graphics getGraphics() - { - return graphics; - } - - - void setupPNG(int width, int height) - { - bi = new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - graphics = bi.getGraphics(); - Graphics2D ig2 = (Graphics2D) graphics; - ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - } - - public void writeImage() - { - try{ - switch(type) - { - case EPS: - pg.flush(); - pg.close(); - break; - case PNG: - ImageIO.write(bi, "png", out); - out.close(); - break; - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - - void setupEPS(int width, int height, String title) - { - boolean accurateText = true; - - String renderStyle = jalview.bin.Cache.getDefault("EPS_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"))) - { - EPSOptions eps = new EPSOptions(); - renderStyle = eps.getValue(); - - if (renderStyle == null || eps.cancelled) - return; - } - - if (renderStyle.equalsIgnoreCase("text")) - { - accurateText = false; - } - - try { - pg = new EpsGraphics2D(title, out, 0, 0, width, - height); - Graphics2D ig2 = (Graphics2D) pg; - ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - pg.setAccurateTextMode(accurateText); - - graphics = pg; - } - catch (Exception ex) { } - } - - - JalviewFileChooser getPNGChooser() - { - return new jalview.io.JalviewFileChooser(jalview.bin.Cache.getProperty( - "LAST_DIRECTORY"), new String[] - {"png"}, - new String[] - {"Portable network graphics"}, - "Portable network graphics"); - } - - JalviewFileChooser getEPSChooser() - { - return new jalview.io.JalviewFileChooser(jalview.bin.Cache.getProperty( - "LAST_DIRECTORY"), new String[] - {"eps"}, - new String[] - {"Encapsulated Postscript"}, - "Encapsulated Postscript"); - } -} +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle + * + * 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 . + */ +package jalview.util; + +import java.io.*; +import javax.imageio.*; + +import java.awt.*; +import java.awt.image.*; + +import org.jibble.epsgraphics.*; +import jalview.gui.*; +import jalview.io.*; + +public class ImageMaker +{ + public static final int EPS = 0; + + public static final int PNG = 1; + + int type = -1; + + EpsGraphics2D pg; + + Graphics graphics; + + FileOutputStream out; + + BufferedImage bi; + + public ImageMaker(Component parent, int type, String title, int width, + int height, File file, String EPStitle) + { + this.type = type; + + if (file == null) + { + JalviewFileChooser chooser; + chooser = type == EPS ? getEPSChooser() : getPNGChooser(); + + chooser.setFileView(new jalview.io.JalviewFileView()); + chooser.setDialogTitle(title); + chooser.setToolTipText("Save"); + + int value = chooser.showSaveDialog(parent); + + if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) + { + jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser + .getSelectedFile().getParent()); + + file = chooser.getSelectedFile(); + } + } + + if (file != null) + { + try + { + out = new FileOutputStream(file); + + if (type == EPS) + { + setupEPS(width, height, EPStitle); + } + else + { + setupPNG(width, height); + } + } catch (Exception ex) + { + System.out.println("Error creating " + + (type == EPS ? "EPS" : "PNG") + " file."); + } + } + } + + public Graphics getGraphics() + { + return graphics; + } + + void setupPNG(int width, int height) + { + bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + graphics = bi.getGraphics(); + Graphics2D ig2 = (Graphics2D) graphics; + ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + } + + public void writeImage() + { + try + { + switch (type) + { + case EPS: + pg.flush(); + pg.close(); + break; + case PNG: + ImageIO.write(bi, "png", out); + out.close(); + break; + } + } catch (Exception ex) + { + ex.printStackTrace(); + } + } + + void setupEPS(int width, int height, String title) + { + boolean accurateText = true; + + String renderStyle = jalview.bin.Cache.getDefault("EPS_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"))) + { + EPSOptions eps = new EPSOptions(); + renderStyle = eps.getValue(); + + if (renderStyle == null || eps.cancelled) + { + return; + } + } + + if (renderStyle.equalsIgnoreCase("text")) + { + accurateText = false; + } + + try + { + pg = new EpsGraphics2D(title, out, 0, 0, width, height); + Graphics2D ig2 = (Graphics2D) pg; + ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + pg.setAccurateTextMode(accurateText); + + graphics = pg; + } catch (Exception ex) + { + } + } + + JalviewFileChooser getPNGChooser() + { + return new jalview.io.JalviewFileChooser( + jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] + { "png" }, new String[] + { "Portable network graphics" }, "Portable network graphics"); + } + + JalviewFileChooser getEPSChooser() + { + return new jalview.io.JalviewFileChooser( + jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] + { "eps" }, new String[] + { "Encapsulated Postscript" }, "Encapsulated Postscript"); + } +}