01: package com.xoetrope.swing.painter;
02:
03: import com.xoetrope.batik.ext.awt.RadialGradientPaint;
04: import java.awt.Color;
05: import java.awt.Graphics2D;
06: import java.awt.Paint;
07: import java.awt.geom.Rectangle2D;
08: import net.xoetrope.swing.painter.XGradientBackground;
09:
10: /**
11: * Paints a set of coloured gradients in horizontal bands
12: *
13: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
14: * the GNU Public License (GPL), please see license.txt for more details. If
15: * you make commercial use of this software you must purchase a commercial
16: * license from Xoetrope.</p>
17: * <p> $Revision: 1.3 $</p>
18: */
19: public class XBandPainter extends XGradientBackground {
20: protected int numBands = 3;
21:
22: /**
23: * Paint an area of the background
24: * @param g2 the graphics context
25: * @param w the width coordinate
26: * @param h the height coordinate
27: * @param wScreen the width of the gradient
28: * @param h the height of the gradient
29: * @param start the start color
30: * @param end the end color
31: */
32: protected void paintBackground(Graphics2D g2, float w, float h,
33: float wScreen, float hScreen, Color start, Color end) {
34: float[] hsb1 = new float[3];
35: float[] hsb2 = new float[3];
36: start.RGBtoHSB(start.getRed(), start.getGreen(), start
37: .getBlue(), hsb1);
38: end.RGBtoHSB(end.getRed(), end.getGreen(), end.getBlue(), hsb2);
39:
40: float dy = h / numBands;
41: float dh = (hsb2[0] - hsb1[0]) / numBands;
42: float ds = (hsb2[1] - hsb1[1]) / numBands;
43: float db = (hsb2[2] - hsb1[2]) / numBands;
44: for (float ii = 0.0F; ii < numBands; ii += 1.0F) {
45: float jj = ii + 1.0F;
46: Color color1 = Color.getHSBColor(hsb1[0] + ii * dh, hsb1[1]
47: + ii * ds, hsb1[2] + ii * db);
48: Color color2 = Color.getHSBColor(hsb1[0] + jj * dh, hsb1[1]
49: + jj * ds, hsb1[2] + jj * db);
50:
51: g2.setPaint(getBackgroundPaint(color1, wScreen, hScreen,
52: color2));
53:
54: Rectangle2D rect = new Rectangle2D.Float(0.0F, ii * dy, w,
55: dy);
56: g2.fill(rect);
57: }
58: }
59: }
|