JTextFieldWithIcon.java

1
/*******************************************************************************
2
 * Copyhacked (H) 2012-2020.
3
 * This program and the accompanying materials
4
 * are made available under no term at all, use it like
5
 * you want, but share and discuss about it
6
 * every time possible with every body.
7
 *
8
 * Contributors:
9
 *      ron190 at ymail dot com - initial implementation
10
 *******************************************************************************/
11
package com.jsql.view.swing.text;
12
13
import com.jsql.util.I18nUtil;
14
import com.jsql.util.LogLevelUtil;
15
import com.jsql.view.swing.util.UiUtil;
16
import org.apache.logging.log4j.LogManager;
17
import org.apache.logging.log4j.Logger;
18
19
import javax.swing.*;
20
import java.awt.*;
21
22
/**
23
 * A JTextField with globe icon displayed on the left.
24
 */
25
public class JTextFieldWithIcon extends JTextFieldPlaceholder {
26
    
27
    /**
28
     * Log4j logger sent to view.
29
     */
30
    private static final Logger LOGGER = LogManager.getRootLogger();
31
32
    public JTextFieldWithIcon(String placeholder) {
33
        super(placeholder);
34
    }
35
36
    @Override
37
    protected void paintComponent(Graphics g) {
38
        
39
        // Unhandled InternalError #92917: Unable to Stroke shape (no dcpr in java.library.path)
40 1 1. paintComponent : removed call to com/jsql/view/swing/text/JTextFieldPlaceholder::paintComponent → NO_COVERAGE
        super.paintComponent(g);
41
        var url = UiUtil.URL_GLOBE;
42
        
43 1 1. paintComponent : negated conditional → NO_COVERAGE
        if (url == null) {
44
            return;  // Fix NullPointerException in constructor ImageIcon()
45
        }
46
        
47
        Image image = null;
48
        
49
        try {
50
            image = new ImageIcon(url).getImage();
51
        } catch (IllegalArgumentException e) {
52
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);  // Exception if globe.png is unavailable
53
        }
54
55
        var border = UIManager.getBorder("TextField.border");
56
        int x = border.getBorderInsets(this).left;
57 2 1. paintComponent : Replaced integer subtraction with addition → NO_COVERAGE
2. paintComponent : Replaced integer division with multiplication → NO_COVERAGE
        int y = (this.getHeight() - 16) / 2;
58
59
        // Fix #1654 (Linux only) : ClassCastException: sun.awt.image.BufImgSurfaceData cannot be cast to sun.java2d.xr.XRSurfaceData
60
        try {
61
            g.drawImage(
62
                image,
63 1 1. paintComponent : negated conditional → NO_COVERAGE
                ComponentOrientation.RIGHT_TO_LEFT.equals(ComponentOrientation.getOrientation(I18nUtil.getLocaleDefault()))
64 3 1. paintComponent : Replaced integer addition with subtraction → NO_COVERAGE
2. paintComponent : Replaced integer addition with subtraction → NO_COVERAGE
3. paintComponent : Replaced integer subtraction with addition → NO_COVERAGE
                ? JTextFieldWithIcon.this.getWidth() - (16 + x + 4)
65 2 1. paintComponent : Replaced integer addition with subtraction → NO_COVERAGE
2. paintComponent : Replaced integer addition with subtraction → NO_COVERAGE
                : x + 4,
66
                y + 1,
67
                this
68
            );
69
        } catch (ClassCastException e) {
70
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
71
        }
72
    }
73
}

Mutations

40

1.1
Location : paintComponent
Killed by : none
removed call to com/jsql/view/swing/text/JTextFieldPlaceholder::paintComponent → NO_COVERAGE

43

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

57

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

2.2
Location : paintComponent
Killed by : none
Replaced integer division with multiplication → NO_COVERAGE

63

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

64

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

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

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

65

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

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

Active mutators

Tests examined


Report generated by PIT 1.16.1