2
* Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of Substance Kirill Grouchnikov nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
package org.pushingpixels.substance.api.painter.border;
33
import java.awt.MultipleGradientPaint.CycleMethod;
35
import org.pushingpixels.substance.api.SubstanceColorScheme;
36
import org.pushingpixels.substance.internal.utils.*;
39
* The default border painter. This class is part of officially supported API.
41
* @author Kirill Grouchnikov
43
public class StandardBorderPainter implements SubstanceBorderPainter {
48
* org.pushingpixels.substance.api.trait.SubstanceTrait#getDisplayName()
51
public String getDisplayName() {
59
* org.pushingpixels.substance.api.painter.border.SubstanceBorderPainter
60
* #isPaintingInnerContour()
63
public boolean isPaintingInnerContour() {
68
public void paintBorder(Graphics g, Component c, int width, int height,
69
Shape contour, Shape innerContour, SubstanceColorScheme borderScheme) {
73
Graphics2D graphics = (Graphics2D) g.create();
74
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
75
RenderingHints.VALUE_ANTIALIAS_ON);
76
graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
77
RenderingHints.VALUE_STROKE_NORMALIZE);
79
Color topBorderColor = getTopBorderColor(borderScheme);
80
Color midBorderColor = getMidBorderColor(borderScheme);
81
Color bottomBorderColor = getBottomBorderColor(borderScheme);
83
if ((topBorderColor != null) && (midBorderColor != null)
84
&& (bottomBorderColor != null)) {
85
float strokeWidth = SubstanceSizeUtils
86
.getBorderStrokeWidth(SubstanceSizeUtils
87
.getComponentFontSize(c));
88
// issue 433 - the "c" can be null when painting
89
// the border of a tree icon used outside the
91
boolean isSpecialButton = c instanceof SubstanceInternalArrowButton;
92
int joinKind = isSpecialButton ? BasicStroke.JOIN_MITER
93
: BasicStroke.JOIN_ROUND;
94
int capKind = isSpecialButton ? BasicStroke.CAP_SQUARE
95
: BasicStroke.CAP_BUTT;
96
graphics.setStroke(new BasicStroke(strokeWidth, capKind, joinKind));
98
MultipleGradientPaint gradient = new LinearGradientPaint(0, 0, 0,
99
height, new float[] { 0.0f, 0.5f, 1.0f },
100
new Color[] { topBorderColor, midBorderColor,
101
bottomBorderColor }, CycleMethod.REPEAT);
102
graphics.setPaint(gradient);
103
graphics.draw(contour);
110
* Computes the color of the top portion of the border. Override to provide
113
* @param borderScheme
114
* The border color scheme.
115
* @return The color of the top portion of the border.
117
public Color getTopBorderColor(SubstanceColorScheme borderScheme) {
118
return SubstanceColorUtilities.getTopBorderColor(borderScheme);
122
* Computes the color of the middle portion of the border. Override to
123
* provide different visual.
125
* @param borderScheme
126
* The border color scheme.
127
* @return The color of the middle portion of the border.
129
public Color getMidBorderColor(SubstanceColorScheme borderScheme) {
130
return SubstanceColorUtilities.getMidBorderColor(borderScheme);
134
* Computes the color of the bottom portion of the border. Override to
135
* provide different visual.
137
* @param borderScheme
138
* The border color scheme.
139
* @return The color of the bottom portion of the border.
141
public Color getBottomBorderColor(SubstanceColorScheme borderScheme) {
142
return SubstanceColorUtilities.getBottomBorderColor(borderScheme);