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.decoration;
031:
032: import java.awt.*;
033: import java.awt.geom.GeneralPath;
034: import java.awt.image.BufferedImage;
035:
036: import javax.swing.*;
037:
038: import org.jvnet.substance.color.ColorScheme;
039: import org.jvnet.substance.theme.SubstanceTheme;
040: import org.jvnet.substance.utils.SubstanceCoreUtilities;
041:
042: /**
043: * Implementation of {@link SubstanceDecorationPainter} that uses "arc" painting
044: * on title panes and lighter gradient near the center of the application frame.
045: *
046: * @author Kirill Grouchnikov
047: */
048: public class ArcDecorationPainter implements SubstanceDecorationPainter {
049: /**
050: * The display name for the decoration painters of this class.
051: */
052: public static final String DISPLAY_NAME = "Arc";
053:
054: /*
055: * (non-Javadoc)
056: *
057: * @see org.jvnet.substance.utils.SubstanceTrait#getDisplayName()
058: */
059: public String getDisplayName() {
060: return DISPLAY_NAME;
061: }
062:
063: /*
064: * (non-Javadoc)
065: *
066: * @see org.jvnet.substance.painter.decoration.SubstanceDecorationPainter#paintDecorationArea(java.awt.Graphics2D,
067: * java.awt.Component,
068: * org.jvnet.substance.painter.decoration.DecorationAreaType, int, int,
069: * org.jvnet.substance.theme.SubstanceTheme)
070: */
071: public void paintDecorationArea(Graphics2D graphics,
072: Component comp, DecorationAreaType decorationAreaType,
073: int width, int height, SubstanceTheme theme) {
074: switch (decorationAreaType) {
075: case PRIMARY_TITLE_PANE:
076: case SECONDARY_TITLE_PANE:
077: this .paintTitleBackground(graphics, comp, width, height,
078: theme);
079: break;
080: default:
081: this .paintExtraBackground(graphics, SubstanceCoreUtilities
082: .getHeaderParent(comp), comp, width, height, theme);
083: }
084: }
085:
086: private void paintTitleBackground(Graphics2D graphics,
087: Component comp, int width, int height, SubstanceTheme theme) {
088: // create rectangular background and later draw it on
089: // result image with contour clip.
090: BufferedImage rectangular = SubstanceCoreUtilities
091: .getBlankImage(width, height);
092: Graphics2D rgraphics = (Graphics2D) rectangular.getGraphics();
093: rgraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
094: RenderingHints.VALUE_ANTIALIAS_ON);
095:
096: ColorScheme scheme = theme.getColorScheme();
097:
098: // Fill background
099: GeneralPath clipTop = new GeneralPath();
100: clipTop.moveTo(0, 0);
101: clipTop.lineTo(width, 0);
102: clipTop.lineTo(width, height / 2);
103: clipTop.quadTo(width / 2, height / 4, 0, height / 2);
104: clipTop.lineTo(0, 0);
105:
106: rgraphics.setClip(clipTop);
107: GradientPaint gradientTopLeft = new GradientPaint(0, 0, scheme
108: .getLightColor(), width / 2, 0, scheme
109: .getUltraLightColor());
110: rgraphics.setPaint(gradientTopLeft);
111: rgraphics.fillRect(0, 0, width / 2, height);
112: GradientPaint gradientTopRight = new GradientPaint(width / 2,
113: 0, scheme.getUltraLightColor(), width, 0, scheme
114: .getLightColor());
115: rgraphics.setPaint(gradientTopRight);
116: rgraphics.fillRect(width / 2, 0, width - width / 2, height);
117:
118: // Color darker = SubstanceColorUtilities.getInterpolatedColor(scheme
119: // .getMidColor(), scheme.getDarkColor(), 0.8);
120: GradientPaint gradientBottomLeft = new GradientPaint(0,
121: height / 2, scheme.getMidColor(), width / 2,
122: height / 2, scheme.getLightColor());
123: GradientPaint gradientBottomRight = new GradientPaint(
124: width / 2, height / 2, scheme.getLightColor(), width,
125: height / 2, scheme.getMidColor());
126:
127: GeneralPath clipBottom = new GeneralPath();
128: clipBottom.moveTo(0, height);
129: clipBottom.lineTo(width, height);
130: clipBottom.lineTo(width, height / 2);
131: clipBottom.quadTo(width / 2, height / 4, 0, height / 2);
132: clipBottom.lineTo(0, height);
133:
134: rgraphics.setClip(clipBottom);
135: rgraphics.setPaint(gradientBottomLeft);
136: rgraphics.fillRect(0, 0, width / 2, height);
137: rgraphics.setPaint(gradientBottomRight);
138: rgraphics.fillRect(width / 2, 0, width - width / 2, height);
139:
140: GeneralPath mid = new GeneralPath();
141: mid.moveTo(width, height / 2);
142: mid.quadTo(width / 2, height / 4, 0, height / 2);
143: rgraphics.setPaint(gradientBottomLeft);
144: rgraphics.setClip(new Rectangle(0, 0, width / 2, height));
145: rgraphics.draw(mid);
146: rgraphics.setPaint(gradientBottomRight);
147: rgraphics.setClip(new Rectangle(width / 2, 0,
148: width - width / 2, height));
149: rgraphics.draw(mid);
150:
151: graphics.drawImage(rectangular, 0, 0, null);
152: }
153:
154: private void paintExtraBackground(Graphics2D graphics,
155: Container parent, Component comp, int width, int height,
156: SubstanceTheme theme) {
157:
158: // System.out.println(comp.getClass().getSimpleName() + " -- W: " +
159: // width
160: // + ", H: " + height);
161: // System.out.println(graphics.getTransform());
162: // System.out.println(graphics.getClip());
163:
164: JRootPane rootPane = SwingUtilities.getRootPane(parent);
165: // fix for bug 234 - Window doesn't have a root pane.
166: int dx = 0;
167: JComponent titlePane = null;
168: if (rootPane != null) {
169: titlePane = SubstanceCoreUtilities.getTitlePane(rootPane);
170: if (titlePane != null) {
171: if (comp.isShowing() && titlePane.isShowing()) {
172: dx += (comp.getLocationOnScreen().x - titlePane
173: .getLocationOnScreen().x);
174: } else {
175: // have to traverse the hierarchy
176: Component c = comp;
177: dx = 0;
178: while (c != rootPane) {
179: dx += c.getX();
180: c = c.getParent();
181: }
182: c = titlePane;
183: while (c != rootPane) {
184: dx -= c.getX();
185: c = c.getParent();
186: }
187: }
188: }
189: }
190: // int dy = comp.getY();
191:
192: int pWidth = (titlePane == null) ? parent.getWidth()
193: : titlePane.getWidth();
194: // int pHeight = parent.getHeight();
195: // System.out.println("DX: " + dx + ", pW: " + pWidth);// + ", pH: " +
196: // pHeight);
197:
198: ColorScheme scheme = theme.getColorScheme();
199: // System.out.println("Using " + scheme.)
200: GradientPaint gradientBottomLeft = new GradientPaint(-dx, 0,
201: scheme.getMidColor(), -dx + pWidth / 2, 0, scheme
202: .getLightColor());
203: GradientPaint gradientBottomRight = new GradientPaint(-dx
204: + pWidth / 2, 0, scheme.getLightColor(), -dx + pWidth,
205: 0, scheme.getMidColor());
206:
207: graphics.setPaint(gradientBottomLeft);
208: graphics.fillRect(-dx, 0, pWidth / 2, height);
209: graphics.setPaint(gradientBottomRight);
210: // fix for defect 195 - fill the remaining width (don't use
211: // pWidth / 2 since this will leave the last pixel on odd widths).
212: graphics.fillRect(-dx + pWidth / 2, 0, pWidth - pWidth / 2,
213: height);
214:
215: // System.out.println("left " + (-dx) + ":" + 0 + ":" + pWidth / 2 + ":"
216: // + height);
217: // System.out.println("right " + (-dx + pWidth / 2) + ":" + 0 + ":"
218: // + (pWidth - pWidth / 2) + ":" + height);
219:
220: // graphics.translate(dx, 0);
221: }
222: }
|