X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FImageMaker.java;h=632c2ad293ac9ad49adb85dc55955050e7c75ee2;hb=d4b1e4d0c74b1c6d0f3c3556b10be91a6aaea475;hp=02427f2cb4a08f783d54b4e18ef6cb9e97784a74;hpb=55e2e9b22b133db8b9ff0979b0338a33081fc8fd;p=jalview.git diff --git a/src/jalview/util/ImageMaker.java b/src/jalview/util/ImageMaker.java index 02427f2..632c2ad 100755 --- a/src/jalview/util/ImageMaker.java +++ b/src/jalview/util/ImageMaker.java @@ -1,17 +1,32 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 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.event.ActionEvent; -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 javax.imageio.*; + import java.awt.*; +import java.awt.image.*; +import org.jibble.epsgraphics.*; +import jalview.gui.*; +import jalview.io.*; public class ImageMaker { @@ -25,7 +40,7 @@ public class ImageMaker BufferedImage bi; public ImageMaker(Component parent, int type, String title, - int width, int height, File file, String EPStitle) + int width, int height, File file, String EPStitle) { this.type = type; @@ -49,19 +64,26 @@ public class ImageMaker } } - try + if (file != null) { - 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."); + 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."); + } } } @@ -70,21 +92,21 @@ public class ImageMaker 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); + 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) + try + { + switch (type) { case EPS: pg.flush(); @@ -98,7 +120,7 @@ public class ImageMaker } catch (Exception ex) { - ex.printStackTrace(); + ex.printStackTrace(); } } @@ -120,7 +142,9 @@ public class ImageMaker renderStyle = eps.getValue(); if (renderStyle == null || eps.cancelled) + { return; + } } if (renderStyle.equalsIgnoreCase("text")) @@ -128,9 +152,10 @@ public class ImageMaker accurateText = false; } - try { + try + { pg = new EpsGraphics2D(title, out, 0, 0, width, - height); + height); Graphics2D ig2 = (Graphics2D) pg; ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -139,10 +164,10 @@ public class ImageMaker graphics = pg; } - catch (Exception ex) { } + catch (Exception ex) + {} } - JalviewFileChooser getPNGChooser() { return new jalview.io.JalviewFileChooser(jalview.bin.Cache.getProperty(