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;
34
import org.pushingpixels.substance.api.ColorSchemeTransform;
35
import org.pushingpixels.substance.api.SubstanceColorScheme;
36
import org.pushingpixels.substance.internal.utils.*;
39
* Delegate border painter that allows tweaking the visual appearance of
42
* @author Kirill Grouchnikov
44
public class DelegateBorderPainter extends StandardBorderPainter {
46
* Display name of this border painter.
48
protected String displayName;
51
* The delegate border painter.
53
protected StandardBorderPainter delegate;
56
* 8-digit hexadecimal mask applied on the top color painted by
57
* {@link #delegate}. Can be used to apply custom translucency. For example,
58
* value 0x80FFFFFF will result in 50% translucency of the original top
61
protected int topMask;
64
* 8-digit hexadecimal mask applied on the middle color painted by
65
* {@link #delegate}. Can be used to apply custom translucency. For example,
66
* value 0x80FFFFFF will result in 50% translucency of the original middle
69
protected int midMask;
72
* 8-digit hexadecimal mask applied on the bottom color painted by
73
* {@link #delegate}. Can be used to apply custom translucency. For example,
74
* value 0x80FFFFFF will result in 50% translucency of the original bottom
77
protected int bottomMask;
80
* Transformation to be applied on the color schemes prior to compute the
81
* colors to be used for border painting.
83
protected ColorSchemeTransform transform;
86
* Creates a new delegate border painter
89
* Display name of this border painter.
91
* The delegate border painter.
93
* Transformation to be applied on the color schemes prior to
94
* compute the colors to be used for border painting.
96
public DelegateBorderPainter(String displayName,
97
StandardBorderPainter delegate, ColorSchemeTransform transform) {
98
this(displayName, delegate, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
103
* Creates a new delegate border painter
106
* Display name of this border painter.
108
* The delegate border painter.
110
* 8-digit hexadecimal mask applied on the top color painted by
111
* the <code>delegate</code>.
113
* 8-digit hexadecimal mask applied on the middle color painted
114
* by the <code>delegate</code>.
116
* 8-digit hexadecimal mask applied on the bottom color painted
117
* by the <code>delegate</code>.
119
* Transformation to be applied on the color schemes prior to
120
* compute the colors to be used for border painting.
122
public DelegateBorderPainter(String displayName,
123
StandardBorderPainter delegate, int topMask, int midMask,
124
int bottomMask, ColorSchemeTransform transform) {
125
this.displayName = displayName;
126
this.delegate = delegate;
127
this.topMask = topMask;
128
this.midMask = midMask;
129
this.bottomMask = bottomMask;
130
this.transform = transform;
134
* Map of transformed color schemes (to speed up the subsequent lookups).
136
protected final static LazyResettableHashMap<SubstanceColorScheme> transformMap = new LazyResettableHashMap<SubstanceColorScheme>(
137
"DelegateBorderPainter");
140
public Color getTopBorderColor(SubstanceColorScheme borderScheme) {
141
return new Color(this.topMask
142
& this.delegate.getTopBorderColor(borderScheme).getRGB(), true);
146
public Color getMidBorderColor(SubstanceColorScheme borderScheme) {
147
return new Color(this.midMask
148
& this.delegate.getMidBorderColor(borderScheme).getRGB(), true);
152
public Color getBottomBorderColor(SubstanceColorScheme borderScheme) {
153
return new Color(this.bottomMask
154
& this.delegate.getBottomBorderColor(borderScheme).getRGB(),
159
public void paintBorder(Graphics g, Component c, int width, int height,
160
Shape contour, Shape innerContour, SubstanceColorScheme borderScheme) {
161
super.paintBorder(g, c, width, height, contour, innerContour,
162
getShiftScheme(borderScheme));
166
public String getDisplayName() {
167
return this.displayName;
171
* Retrieves a transformed color scheme.
174
* Original color scheme.
175
* @return Transformed color scheme.
177
private SubstanceColorScheme getShiftScheme(SubstanceColorScheme orig) {
178
HashMapKey key = SubstanceCoreUtilities.getHashKey(orig
179
.getDisplayName(), this.getDisplayName(), this.transform);
180
SubstanceColorScheme result = transformMap.get(key);
181
if (result == null) {
182
result = this.transform.transform(orig);
183
transformMap.put(key, result);