~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to substance/src/main/java/org/pushingpixels/substance/api/painter/border/DelegateBorderPainter.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without 
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 * 
 
7
 *  o Redistributions of source code must retain the above copyright notice, 
 
8
 *    this list of conditions and the following disclaimer. 
 
9
 *     
 
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. 
 
13
 *     
 
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. 
 
17
 *     
 
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. 
 
29
 */
 
30
package org.pushingpixels.substance.api.painter.border;
 
31
 
 
32
import java.awt.*;
 
33
 
 
34
import org.pushingpixels.substance.api.ColorSchemeTransform;
 
35
import org.pushingpixels.substance.api.SubstanceColorScheme;
 
36
import org.pushingpixels.substance.internal.utils.*;
 
37
 
 
38
/**
 
39
 * Delegate border painter that allows tweaking the visual appearance of
 
40
 * borders.
 
41
 * 
 
42
 * @author Kirill Grouchnikov
 
43
 */
 
44
public class DelegateBorderPainter extends StandardBorderPainter {
 
45
        /**
 
46
         * Display name of this border painter.
 
47
         */
 
48
        protected String displayName;
 
49
 
 
50
        /**
 
51
         * The delegate border painter.
 
52
         */
 
53
        protected StandardBorderPainter delegate;
 
54
 
 
55
        /**
 
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
 
59
         * border color.
 
60
         */
 
61
        protected int topMask;
 
62
 
 
63
        /**
 
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
 
67
         * border color.
 
68
         */
 
69
        protected int midMask;
 
70
 
 
71
        /**
 
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
 
75
         * border color.
 
76
         */
 
77
        protected int bottomMask;
 
78
 
 
79
        /**
 
80
         * Transformation to be applied on the color schemes prior to compute the
 
81
         * colors to be used for border painting.
 
82
         */
 
83
        protected ColorSchemeTransform transform;
 
84
 
 
85
        /**
 
86
         * Creates a new delegate border painter
 
87
         * 
 
88
         * @param displayName
 
89
         *            Display name of this border painter.
 
90
         * @param delegate
 
91
         *            The delegate border painter.
 
92
         * @param transform
 
93
         *            Transformation to be applied on the color schemes prior to
 
94
         *            compute the colors to be used for border painting.
 
95
         */
 
96
        public DelegateBorderPainter(String displayName,
 
97
                        StandardBorderPainter delegate, ColorSchemeTransform transform) {
 
98
                this(displayName, delegate, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
 
99
                                transform);
 
100
        }
 
101
 
 
102
        /**
 
103
         * Creates a new delegate border painter
 
104
         * 
 
105
         * @param displayName
 
106
         *            Display name of this border painter.
 
107
         * @param delegate
 
108
         *            The delegate border painter.
 
109
         * @param topMask
 
110
         *            8-digit hexadecimal mask applied on the top color painted by
 
111
         *            the <code>delegate</code>.
 
112
         * @param midMask
 
113
         *            8-digit hexadecimal mask applied on the middle color painted
 
114
         *            by the <code>delegate</code>.
 
115
         * @param bottomMask
 
116
         *            8-digit hexadecimal mask applied on the bottom color painted
 
117
         *            by the <code>delegate</code>.
 
118
         * @param transform
 
119
         *            Transformation to be applied on the color schemes prior to
 
120
         *            compute the colors to be used for border painting.
 
121
         */
 
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;
 
131
        }
 
132
 
 
133
        /**
 
134
         * Map of transformed color schemes (to speed up the subsequent lookups).
 
135
         */
 
136
        protected final static LazyResettableHashMap<SubstanceColorScheme> transformMap = new LazyResettableHashMap<SubstanceColorScheme>(
 
137
                        "DelegateBorderPainter");
 
138
 
 
139
        @Override
 
140
        public Color getTopBorderColor(SubstanceColorScheme borderScheme) {
 
141
                return new Color(this.topMask
 
142
                                & this.delegate.getTopBorderColor(borderScheme).getRGB(), true);
 
143
        }
 
144
 
 
145
        @Override
 
146
        public Color getMidBorderColor(SubstanceColorScheme borderScheme) {
 
147
                return new Color(this.midMask
 
148
                                & this.delegate.getMidBorderColor(borderScheme).getRGB(), true);
 
149
        }
 
150
 
 
151
        @Override
 
152
        public Color getBottomBorderColor(SubstanceColorScheme borderScheme) {
 
153
                return new Color(this.bottomMask
 
154
                                & this.delegate.getBottomBorderColor(borderScheme).getRGB(),
 
155
                                true);
 
156
        }
 
157
 
 
158
        @Override
 
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));
 
163
        }
 
164
 
 
165
        @Override
 
166
        public String getDisplayName() {
 
167
                return this.displayName;
 
168
        }
 
169
 
 
170
        /**
 
171
         * Retrieves a transformed color scheme.
 
172
         * 
 
173
         * @param orig
 
174
         *            Original color scheme.
 
175
         * @return Transformed color scheme.
 
176
         */
 
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);
 
184
                }
 
185
                return result;
 
186
        }
 
187
 
 
188
}