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 javax.swing.JComponent;
08: import net.xoetrope.swing.painter.XGradientBackground;
09:
10: /**
11: * Paints a background with a radial gradient
12: * <p>Copyright (c) Xoetrope Ltd., 2002-2006</p>
13: * <p>License: see license.txt</p>
14: * $Revision: 1.1 $
15: */
16: public class XFlarePainter extends XGradientBackground {
17: protected float offsetX = 0.333F;
18: protected float offsetY = 0.333F;
19:
20: /**
21: * Get the paint operation for the background
22: * @param x starting x position
23: * @param y starting y position
24: * @param start the starting color
25: * @param wScreen the width
26: * @param hScreen the height
27: * @param end the ending color
28: * @return the paint operation
29: */
30: protected Paint getBackgroundPaint(float x, float y, Color start,
31: float wScreen, float hScreen, Color end) {
32: Color[] colors = new Color[2];
33: float fractions[] = { 0.0F, 1.0F };
34: colors[0] = start;
35: colors[1] = end;
36: float wr = (1.0F - offsetX) * wScreen;
37: float hr = (1.0F - offsetY) * wScreen;
38: float radius = (float) Math.sqrt(wr * wr + hr * hr);
39: return new RadialGradientPaint(x + offsetX * wScreen, y
40: + offsetY * hScreen, radius, fractions, colors);
41: }
42: }
|