~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/StandardBorderPainter.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
import java.awt.MultipleGradientPaint.CycleMethod;
 
34
 
 
35
import org.pushingpixels.substance.api.SubstanceColorScheme;
 
36
import org.pushingpixels.substance.internal.utils.*;
 
37
 
 
38
/**
 
39
 * The default border painter. This class is part of officially supported API.
 
40
 * 
 
41
 * @author Kirill Grouchnikov
 
42
 */
 
43
public class StandardBorderPainter implements SubstanceBorderPainter {
 
44
        /*
 
45
         * (non-Javadoc)
 
46
         * 
 
47
         * @see
 
48
         * org.pushingpixels.substance.api.trait.SubstanceTrait#getDisplayName()
 
49
         */
 
50
        @Override
 
51
    public String getDisplayName() {
 
52
                return "Standard";
 
53
        }
 
54
 
 
55
        /*
 
56
         * (non-Javadoc)
 
57
         * 
 
58
         * @see
 
59
         * org.pushingpixels.substance.api.painter.border.SubstanceBorderPainter
 
60
         * #isPaintingInnerContour()
 
61
         */
 
62
        @Override
 
63
        public boolean isPaintingInnerContour() {
 
64
                return false;
 
65
        }
 
66
 
 
67
        @Override
 
68
        public void paintBorder(Graphics g, Component c, int width, int height,
 
69
                        Shape contour, Shape innerContour, SubstanceColorScheme borderScheme) {
 
70
                if (contour == null)
 
71
                        return;
 
72
 
 
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);
 
78
 
 
79
                Color topBorderColor = getTopBorderColor(borderScheme);
 
80
                Color midBorderColor = getMidBorderColor(borderScheme);
 
81
                Color bottomBorderColor = getBottomBorderColor(borderScheme);
 
82
 
 
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
 
90
                        // JTree context.
 
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));
 
97
 
 
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);
 
104
                }
 
105
 
 
106
                graphics.dispose();
 
107
        }
 
108
 
 
109
        /**
 
110
         * Computes the color of the top portion of the border. Override to provide
 
111
         * different visual.
 
112
         * 
 
113
         * @param borderScheme
 
114
         *            The border color scheme.
 
115
         * @return The color of the top portion of the border.
 
116
         */
 
117
        public Color getTopBorderColor(SubstanceColorScheme borderScheme) {
 
118
                return SubstanceColorUtilities.getTopBorderColor(borderScheme);
 
119
        }
 
120
 
 
121
        /**
 
122
         * Computes the color of the middle portion of the border. Override to
 
123
         * provide different visual.
 
124
         * 
 
125
         * @param borderScheme
 
126
         *            The border color scheme.
 
127
         * @return The color of the middle portion of the border.
 
128
         */
 
129
        public Color getMidBorderColor(SubstanceColorScheme borderScheme) {
 
130
                return SubstanceColorUtilities.getMidBorderColor(borderScheme);
 
131
        }
 
132
 
 
133
        /**
 
134
         * Computes the color of the bottom portion of the border. Override to
 
135
         * provide different visual.
 
136
         * 
 
137
         * @param borderScheme
 
138
         *            The border color scheme.
 
139
         * @return The color of the bottom portion of the border.
 
140
         */
 
141
        public Color getBottomBorderColor(SubstanceColorScheme borderScheme) {
 
142
                return SubstanceColorUtilities.getBottomBorderColor(borderScheme);
 
143
        }
 
144
 
 
145
}