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 test.check;
031:
032: import java.awt.*;
033:
034: import org.jvnet.substance.utils.SubstanceThemeUtilities;
035: import org.jvnet.substance.watermark.SubstanceWatermark;
036:
037: /**
038: * Implementation of {@link org.jvnet.substance.watermark.SubstanceWatermark},
039: * drawing vertical gradient.
040: *
041: * @author Kirill Grouchnikov
042: */
043: public class SubstanceVerticalGradientWatermark implements
044: SubstanceWatermark {
045: /*
046: * (non-Javadoc)
047: *
048: * @see org.jvnet.substance.watermark.SubstanceWatermark#drawWatermarkImage(java.awt.Graphics,
049: * int, int, int, int)
050: */
051: public void drawWatermarkImage(Graphics g, Component c, int x,
052: int y, int width, int height) {
053: if (c != null)
054: if (!c.isDisplayable() || !c.isShowing())
055: return;
056:
057: Component parent = c;
058: if (parent != null) {
059: while (parent.getParent() != null)
060: parent = parent.getParent();
061: }
062: if (!parent.isShowing())
063: return;
064:
065: int dx = (parent != null) ? c.getLocationOnScreen().x
066: - parent.getLocationOnScreen().x : 0;
067: int dy = (parent != null) ? c.getLocationOnScreen().y
068: - parent.getLocationOnScreen().y : 0;
069: // int dw = (parent != null) ? parent.getWidth() : width;
070: int dh = (parent != null) ? parent.getHeight() : height;
071:
072: Graphics2D graphics = (Graphics2D) g.create();
073: graphics.setPaint(new GradientPaint(x - dx, y - dy, Color.gray,
074: x - dx, y - dy + dh, SubstanceThemeUtilities
075: .getTheme(c).getColorScheme().getMidColor()));
076: graphics.setComposite(AlphaComposite.getInstance(
077: AlphaComposite.SRC_OVER, 0.8f));
078: graphics.fillRect(x, y, width, height);
079:
080: graphics.dispose();
081: }
082:
083: /*
084: * (non-Javadoc)
085: *
086: * @see org.jvnet.substance.watermark.SubstanceWatermark#updateWatermarkImage()
087: */
088: public boolean updateWatermarkImage() {
089: return true;
090: }
091:
092: /*
093: * (non-Javadoc)
094: *
095: * @see org.jvnet.substance.watermark.SubstanceWatermark#previewWatermark(java.awt.Graphics,
096: * int, int, int, int)
097: */
098: public void previewWatermark(Graphics g, int x, int y, int width,
099: int height) {
100: this .drawWatermarkImage(g, null, x, y, width, height);
101: }
102:
103: /*
104: * (non-Javadoc)
105: *
106: * @see org.jvnet.substance.watermark.SubstanceWatermark#getDisplayName()
107: */
108: public String getDisplayName() {
109: return "Vertical Gradient";
110: }
111:
112: /*
113: * (non-Javadoc)
114: *
115: * @see org.jvnet.substance.watermark.SubstanceWatermark#isDependingOnTheme()
116: */
117: public boolean isDependingOnTheme() {
118: return false;
119: }
120:
121: /*
122: * (non-Javadoc)
123: *
124: * @see org.jvnet.substance.watermark.SubstanceWatermark#dispose()
125: */
126: public void dispose() {
127: }
128: }
|