001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance.painter;
031:
032: import java.awt.*;
033: import java.awt.geom.GeneralPath;
034: import java.awt.image.BufferedImage;
035:
036: import org.jvnet.substance.color.ColorScheme;
037: import org.jvnet.substance.utils.SubstanceColorUtilities;
038: import org.jvnet.substance.utils.SubstanceCoreUtilities;
039:
040: /**
041: * Gradient painter that returns images with flat appearance and wavy color
042: * areas. This class is part of officially supported API.
043: *
044: * @author Kirill Grouchnikov
045: */
046: public class WaveGradientPainter extends BaseGradientPainter {
047: /*
048: * (non-Javadoc)
049: *
050: * @see org.jvnet.substance.painter.SubstanceGradientPainter#getDisplayName()
051: */
052: public String getDisplayName() {
053: return "Wave";
054: }
055:
056: /*
057: * (non-Javadoc)
058: *
059: * @see org.jvnet.substance.painter.SubstanceGradientPainter#getContourBackground(int,
060: * int, java.awt.Shape, boolean, org.jvnet.substance.color.ColorScheme,
061: * org.jvnet.substance.color.ColorScheme, float, boolean, boolean)
062: */
063: public BufferedImage getContourBackground(int width, int height,
064: Shape contour, boolean isFocused, ColorScheme colorScheme1,
065: ColorScheme colorScheme2, float cyclePos, boolean hasShine,
066: boolean useCyclePosAsInterpolation) {
067:
068: BufferedImage mixResult = this .getMixContourBackground(width,
069: height, contour, isFocused, colorScheme1, colorScheme2,
070: cyclePos, hasShine, useCyclePosAsInterpolation);
071: if (mixResult != null)
072: return mixResult;
073:
074: // create rectangular background and later draw it on
075: // result image with contour clip.
076: BufferedImage rectangular = SubstanceCoreUtilities
077: .getBlankImage(width, height);
078: Graphics2D rgraphics = (Graphics2D) rectangular.getGraphics();
079: rgraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
080: RenderingHints.VALUE_ANTIALIAS_ON);
081:
082: ColorScheme interpolationScheme1 = colorScheme1;
083: ColorScheme interpolationScheme2 = useCyclePosAsInterpolation ? colorScheme2
084: : colorScheme1;
085:
086: double cycleCoef = 1.0 - cyclePos / 10.0;
087:
088: // Color topBorderColor = SubstanceColorUtilities.getTopBorderColor(
089: // interpolationScheme1, interpolationScheme2, cycleCoef);
090: // Color midBorderColor = SubstanceColorUtilities.getMidBorderColor(
091: // interpolationScheme1, interpolationScheme2, cycleCoef);
092: // Color bottomBorderColor = SubstanceColorUtilities.getBottomBorderColor(
093: // interpolationScheme1, interpolationScheme2, cycleCoef);
094:
095: Color darkFillColor = SubstanceColorUtilities.getTopFillColor(
096: interpolationScheme1, interpolationScheme2, cycleCoef,
097: useCyclePosAsInterpolation);
098: Color midFillColor = SubstanceColorUtilities.getMidFillColor(
099: interpolationScheme1, interpolationScheme2, cycleCoef,
100: useCyclePosAsInterpolation);
101: Color lightFillColor = SubstanceColorUtilities
102: .getBottomFillColor(interpolationScheme1,
103: interpolationScheme2, cycleCoef,
104: useCyclePosAsInterpolation);
105:
106: if (!useCyclePosAsInterpolation) {
107: lightFillColor = SubstanceColorUtilities
108: .getInterpolatedColor(interpolationScheme1
109: .getUltraLightColor(), interpolationScheme1
110: .getExtraLightColor(), cycleCoef);
111: midFillColor = SubstanceColorUtilities
112: .getInterpolatedColor(interpolationScheme1
113: .getLightColor(), interpolationScheme1
114: .getMidColor(), cycleCoef);
115: darkFillColor = SubstanceColorUtilities
116: .getInterpolatedColor(interpolationScheme1
117: .getMidColor(), interpolationScheme1
118: .getMidColor(), cycleCoef);
119: } else {
120: lightFillColor = SubstanceColorUtilities
121: .getInterpolatedColor(interpolationScheme1
122: .getUltraLightColor(), interpolationScheme2
123: .getUltraLightColor(), cycleCoef);
124: midFillColor = SubstanceColorUtilities
125: .getInterpolatedColor(interpolationScheme1
126: .getLightColor(), interpolationScheme2
127: .getLightColor(), cycleCoef);
128: darkFillColor = SubstanceColorUtilities
129: .getInterpolatedColor(interpolationScheme1
130: .getMidColor(), interpolationScheme2
131: .getMidColor(), cycleCoef);
132: }
133:
134: // Fill background
135: GradientPaint gradientTop = new GradientPaint(0, 0,
136: lightFillColor, width / 4, height / 2, midFillColor);
137: GeneralPath clipTop = new GeneralPath();
138: clipTop.moveTo(0, 0);
139: clipTop.lineTo(width, 0);
140: clipTop.curveTo(5 * width / 6, height / 3, 3 * width / 4,
141: height / 2, width / 2, height / 2);
142: clipTop.curveTo(width / 3, height / 2, width / 4, height, 0,
143: 7 * height / 8);
144: clipTop.lineTo(0, 0);
145:
146: rgraphics.setClip(clipTop);
147: rgraphics.setPaint(gradientTop);
148: rgraphics.fillRect(0, 0, width, height);
149:
150: GradientPaint gradientBottom = new GradientPaint(2 * width / 3,
151: 2 * height / 3, darkFillColor, width, height,
152: midFillColor);
153:
154: GeneralPath clipBottom = new GeneralPath();
155: clipBottom.moveTo(0, height);
156: clipBottom.lineTo(width, height);
157: clipBottom.lineTo(width, 0);
158: clipBottom.curveTo(5 * width / 6, height / 3, 3 * width / 4,
159: height / 2, width / 2, height / 2);
160: clipBottom.curveTo(width / 3, height / 2, width / 4, height, 0,
161: 7 * height / 8);
162: clipBottom.lineTo(0, height);
163:
164: rgraphics.setClip(clipBottom);
165: rgraphics.setPaint(gradientBottom);
166: rgraphics.fillRect(0, 0, width, height);
167:
168: rgraphics.setClip(null);
169: GeneralPath mid = new GeneralPath();
170: mid.moveTo(width, 0);
171: mid.curveTo(5 * width / 6, height / 3, 3 * width / 4,
172: height / 2, width / 2, height / 2);
173: mid.curveTo(width / 3, height / 2, width / 4, height, 0,
174: 7 * height / 8);
175: rgraphics.draw(mid);
176:
177: BufferedImage image = SubstanceCoreUtilities.getBlankImage(
178: width, height);
179: Graphics2D graphics = (Graphics2D) image.getGraphics();
180: graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
181: RenderingHints.VALUE_ANTIALIAS_ON);
182:
183: graphics.setClip(contour);
184: graphics.drawImage(rectangular, 0, 0, null);
185:
186: graphics.setClip(null);
187:
188: // // Draw border
189: // GradientPaint gradientBorderTop = new GradientPaint(0, 0,
190: // topBorderColor, 0, height / 2, midBorderColor);
191: // graphics.setPaint(gradientBorderTop);
192: // graphics.setClip(0, 0, width, height / 2);
193: // graphics.draw(contour);
194: //
195: // GradientPaint gradientBorderBottom = new GradientPaint(0, height / 2,
196: // midBorderColor, 0, height - 2, bottomBorderColor);
197: // graphics.setPaint(gradientBorderBottom);
198: // graphics.setClip(0, height / 2, width, 1 + height / 2);
199: // graphics.draw(contour);
200:
201: return image;
202: }
203: }
|