java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/tags/SerializableGradientPaint.java
changeset 1 639991d0808a
     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/SerializableGradientPaint.java	Sat Feb 28 21:31:02 2009 +0100
     1.3 @@ -0,0 +1,103 @@
     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.Color;
    1.29 +import java.awt.GradientPaint;
    1.30 +import java.awt.Paint;
    1.31 +import java.awt.Rectangle;
    1.32 +import java.awt.RenderingHints;
    1.33 +import java.awt.geom.AffineTransform;
    1.34 +import java.awt.geom.Rectangle2D;
    1.35 +import java.awt.image.ColorModel;
    1.36 +import java.io.Serializable;
    1.37 +
    1.38 +/** 
    1.39 + * Special gradient paint which can be serialized.
    1.40 + * @see GradientPaint
    1.41 + * @author  Guido Laures 
    1.42 + */
    1.43 +public class SerializableGradientPaint implements Paint, Serializable {
    1.44 +
    1.45 +    private int x1;
    1.46 +    private int y1;
    1.47 +    private Color c1 = Color.white;
    1.48 +    private int x2;
    1.49 +    private int y2;
    1.50 +    private Color c2 = Color.white;
    1.51 +    private boolean cyclic = false;
    1.52 +    private transient Paint paint = null;
    1.53 +
    1.54 +    public SerializableGradientPaint() {
    1.55 +    }
    1.56 +
    1.57 +    /** Creates a new instance of SerializableGradientPaint */
    1.58 +    public SerializableGradientPaint(int x1, int y1, Color c1, int x2, int y2, Color c2) {
    1.59 +        this.x1 = x1;
    1.60 +        this.y1 = y1;
    1.61 +        this.c1 = c1;
    1.62 +        this.x2 = x2;
    1.63 +        this.y2 = y2;
    1.64 +        this.c2 = c2;
    1.65 +    }
    1.66 +
    1.67 +    private Paint getPaint() {
    1.68 +        if (paint == null) {
    1.69 +            createPaint();
    1.70 +        }
    1.71 +        return paint;
    1.72 +    }
    1.73 +
    1.74 +    private void createPaint() {
    1.75 +        paint = new GradientPaint(x1, y1, c1, x2, y2, c2, cyclic);
    1.76 +    }
    1.77 +
    1.78 +    public void setPoint1(int x, int y, Color c) {
    1.79 +        this.x1 = x;
    1.80 +        this.y1 = y;
    1.81 +        this.c1 = c;
    1.82 +    }
    1.83 +
    1.84 +    public void setPoint2(int x, int y, Color c) {
    1.85 +        this.x2 = x;
    1.86 +        this.y2 = y;
    1.87 +        this.c2 = c;
    1.88 +    }
    1.89 +
    1.90 +    public java.awt.PaintContext createContext(ColorModel colorModel, Rectangle rectangle, Rectangle2D rectangle2D,
    1.91 +    AffineTransform affineTransform, RenderingHints renderingHints) {
    1.92 +        return getPaint().createContext(colorModel, rectangle, rectangle2D, affineTransform, renderingHints);
    1.93 +    }
    1.94 +
    1.95 +    public int getTransparency() {
    1.96 +        return getPaint().getTransparency();
    1.97 +    }
    1.98 +
    1.99 +    public void setCyclic(boolean b) {
   1.100 +        this.cyclic = b;
   1.101 +    }
   1.102 +
   1.103 +    public String toString() {
   1.104 +        return "" + x1 + "," + y1 + "," + c1 + "," + x2 + "," + y2 + "," + c2;
   1.105 +    }
   1.106 +}