ShadowPopupBorder.java

1
package com.jsql.view.swing.shadow;
2
3
/*
4
 * Copyright (c) 2001-2013 JGoodies Software GmbH. All Rights Reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 *  o Redistributions of source code must retain the above copyright notice,
10
 *    this list of conditions and the following disclaimer.
11
 *
12
 *  o Redistributions in binary form must reproduce the above copyright notice,
13
 *    this list of conditions and the following disclaimer in the documentation
14
 *    and/or other materials provided with the distribution.
15
 *
16
 *  o Neither the name of JGoodies Software GmbH nor the names of
17
 *    its contributors may be used to endorse or promote products derived
18
 *    from this software without specific prior written permission.
19
 *
20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
 */
32
33
import com.jsql.util.LogLevelUtil;
34
import com.jsql.view.swing.util.UiUtil;
35
import org.apache.logging.log4j.LogManager;
36
import org.apache.logging.log4j.Logger;
37
38
import javax.swing.*;
39
import javax.swing.border.AbstractBorder;
40
import java.awt.*;
41
42
/**
43
 * A border with a drop shadow intended to be used as the outer border
44
 * of popups. Can paint the screen background if used with heavy-weight
45
 * popup windows.
46
 *
47
 * @author Karsten Lentzsch
48
 * @version $Revision: 1.9 $
49
 *
50
 * @see ShadowPopup
51
 * @see ShadowPopupFactory
52
 */
53
public final class ShadowPopupBorder extends AbstractBorder {
54
    
55
    /**
56
     * Log4j logger sent to view.
57
     */
58
    private static final Logger LOGGER = LogManager.getRootLogger();
59
60
    /**
61
     * The drop shadow needs 5 pixels at the bottom and the right hand side.
62
     */
63
    private static final int SHADOW_SIZE = 5;
64
65
    /**
66
     * The singleton instance used to draw all borders.
67
     */
68
    private static final ShadowPopupBorder instance = new ShadowPopupBorder();
69
70
    /**
71
     * The drop shadow is created from a PNG image with 8 bit alpha channel.
72
     */
73
    private static final Image shadow = UiUtil.IMG_SHADOW;
74
75
76
    // Instance Creation *****************************************************
77
78
    /**
79
     * Returns the singleton instance used to draw all borders.
80
     */
81
    public static ShadowPopupBorder getInstance() {
82 1 1. getInstance : replaced return value with null for com/jsql/view/swing/shadow/ShadowPopupBorder::getInstance → NO_COVERAGE
        return instance;
83
    }
84
85
    /**
86
     * Paints the border for the specified component with the specified
87
     * position and size.
88
     */
89
    @Override
90
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
91
        
92
        // Fix #7497, Fix #8247, Fix #8332: BufImgSurfaceData cannot be cast to XRSurfaceData on drawImage()
93
        try {
94
            // fake drop shadow effect in case of heavy weight popups
95
            JComponent popup = (JComponent) c;
96
            
97
            Image hShadowBg = (Image) popup.getClientProperty(ShadowPopupFactory.PROP_HORIZONTAL_BACKGROUND);
98
            
99 1 1. paintBorder : negated conditional → NO_COVERAGE
            if (hShadowBg != null) {
100 2 1. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
2. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE
                g.drawImage(hShadowBg, x, y + height - 5, c);
101
            }
102
            
103
            Image vShadowBg = (Image) popup.getClientProperty(ShadowPopupFactory.PROP_VERTICAL_BACKGROUND);
104
            
105 1 1. paintBorder : negated conditional → NO_COVERAGE
            if (vShadowBg != null) {
106 2 1. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
2. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE
                g.drawImage(vShadowBg, x + width - 5, y, c);
107
            }
108
    
109
            // draw drop shadow
110 5 1. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
2. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
3. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
4. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
5. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE
            g.drawImage(shadow, x +  5, y + height - 5, x + 10, y + height, 0, 6, 5, 11, null, c);
111 6 1. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
2. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE
3. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
4. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
5. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
6. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE
            g.drawImage(shadow, x + 10, y + height - 5, x + width - 5, y + height, 5, 6, 6, 11, null, c);
112 5 1. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
2. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE
3. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
4. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
5. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
            g.drawImage(shadow, x + width - 5, y + 5, x + width, y + 10, 6, 0, 11, 5, null, c);
113 6 1. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
2. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE
3. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
4. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
5. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE
6. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
            g.drawImage(shadow, x + width - 5, y + 10, x + width, y + height - 5, 6, 5, 11, 6, null, c);
114 6 1. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
2. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
3. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE
4. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
5. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE
6. paintBorder : Replaced integer addition with subtraction → NO_COVERAGE
            g.drawImage(shadow, x + width - 5, y + height - 5, x + width, y + height, 6, 6, 11, 11, null, c);
115
            
116
        } catch (ClassCastException e) {
117
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
118
        }
119
    }
120
121
122
    /**
123
     * Returns the insets of the border.
124
     */
125
    @Override
126
    public Insets getBorderInsets(Component c) {
127 1 1. getBorderInsets : replaced return value with null for com/jsql/view/swing/shadow/ShadowPopupBorder::getBorderInsets → NO_COVERAGE
        return new Insets(0, 0, SHADOW_SIZE, SHADOW_SIZE);
128
    }
129
130
131
    /**
132
     * Reinitializes the insets parameter with this Border's current Insets.
133
     * @param c the component for which this border insets value applies
134
     * @param insets the object to be reinitialized
135
     * @return the {@code insets} object
136
     */
137
    @Override
138
    public Insets getBorderInsets(Component c, Insets insets) {
139
        
140
        insets.left = insets.top = 0;
141
        insets.right = insets.bottom = SHADOW_SIZE;
142 1 1. getBorderInsets : replaced return value with null for com/jsql/view/swing/shadow/ShadowPopupBorder::getBorderInsets → NO_COVERAGE
        return insets;
143
    }
144
}

Mutations

82

1.1
Location : getInstance
Killed by : none
replaced return value with null for com/jsql/view/swing/shadow/ShadowPopupBorder::getInstance → NO_COVERAGE

99

1.1
Location : paintBorder
Killed by : none
negated conditional → NO_COVERAGE

100

1.1
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : paintBorder
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

105

1.1
Location : paintBorder
Killed by : none
negated conditional → NO_COVERAGE

106

1.1
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : paintBorder
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

110

1.1
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

5.5
Location : paintBorder
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

111

1.1
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : paintBorder
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

3.3
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

5.5
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

6.6
Location : paintBorder
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

112

1.1
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : paintBorder
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

3.3
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

5.5
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

113

1.1
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : paintBorder
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

3.3
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

5.5
Location : paintBorder
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

6.6
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

114

1.1
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location : paintBorder
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

4.4
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

5.5
Location : paintBorder
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

6.6
Location : paintBorder
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

127

1.1
Location : getBorderInsets
Killed by : none
replaced return value with null for com/jsql/view/swing/shadow/ShadowPopupBorder::getBorderInsets → NO_COVERAGE

142

1.1
Location : getBorderInsets
Killed by : none
replaced return value with null for com/jsql/view/swing/shadow/ShadowPopupBorder::getBorderInsets → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1