java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/tags/SerializableTexturePaint.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/tags/SerializableTexturePaint.java Sat Feb 28 21:31:02 2009 +0100
1.3 @@ -0,0 +1,81 @@
1.4 +/* ================================================================
1.5 + * Cewolf : Chart enabling Web Objects Framework
1.6 + * ================================================================
1.7 + *
1.8 + * Project Info: http://cewolf.sourceforge.net
1.9 + * Project Lead: Guido Laures (guido@laures.de);
1.10 + *
1.11 + * (C) Copyright 2002, by Guido Laures
1.12 + *
1.13 + * This library is free software; you can redistribute it and/or modify it under the terms
1.14 + * of the GNU Lesser General Public License as published by the Free Software Foundation;
1.15 + * either version 2.1 of the License, or (at your option) any later version.
1.16 + *
1.17 + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
1.18 + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1.19 + * See the GNU Lesser General Public License for more details.
1.20 + *
1.21 + * You should have received a copy of the GNU Lesser General Public License along with this
1.22 + * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
1.23 + * Boston, MA 02111-1307, USA.
1.24 + */
1.25 +
1.26 +package de.laures.cewolf.taglib.tags;
1.27 +
1.28 +import java.awt.Paint;
1.29 +import java.awt.Rectangle;
1.30 +import java.awt.RenderingHints;
1.31 +import java.awt.TexturePaint;
1.32 +import java.awt.geom.AffineTransform;
1.33 +import java.awt.geom.Rectangle2D;
1.34 +import java.awt.image.BufferedImage;
1.35 +import java.awt.image.ColorModel;
1.36 +import java.io.Serializable;
1.37 +
1.38 +import de.laures.cewolf.util.ImageHelper;
1.39 +
1.40 +/**
1.41 + * Special texture paint which can be serialized.
1.42 + * @see TexturePaint
1.43 + * @author Guido Laures
1.44 + */
1.45 +public class SerializableTexturePaint implements Paint, Serializable {
1.46 +
1.47 + private String image;
1.48 + private int width;
1.49 + private int height;
1.50 + private transient Paint paint = null;
1.51 +
1.52 + public SerializableTexturePaint() {
1.53 + }
1.54 +
1.55 + /** Creates a new instance of SerializableGradientPaint */
1.56 + public SerializableTexturePaint(String image, int width, int height) {
1.57 + this.image = image;
1.58 + this.width = width;
1.59 + this.height = height;
1.60 + }
1.61 +
1.62 + private Paint getPaint() {
1.63 + if (paint == null) {
1.64 + createPaint();
1.65 + }
1.66 + return paint;
1.67 + }
1.68 +
1.69 + private void createPaint() {
1.70 + BufferedImage bim = ImageHelper.loadBufferedImage(image);
1.71 + Rectangle rect = new Rectangle(width, height);
1.72 + paint = new TexturePaint(bim, rect);
1.73 + }
1.74 +
1.75 + public java.awt.PaintContext createContext(ColorModel colorModel, Rectangle rectangle, Rectangle2D rectangle2D,
1.76 + AffineTransform affineTransform, RenderingHints renderingHints) {
1.77 + return getPaint().createContext(colorModel, rectangle, rectangle2D, affineTransform, renderingHints);
1.78 + }
1.79 +
1.80 + public int getTransparency() {
1.81 + return getPaint().getTransparency();
1.82 + }
1.83 +
1.84 +}