JTextFieldPlaceholder.java

1
package com.jsql.view.swing.text;
2
3
import com.jsql.util.LogLevelUtil;
4
import com.jsql.view.swing.util.UiUtil;
5
import org.apache.logging.log4j.LogManager;
6
import org.apache.logging.log4j.Logger;
7
8
import javax.swing.*;
9
import java.awt.*;
10
11
/**
12
 * Textfield with information text displayed when empty.
13
 */
14
public class JTextFieldPlaceholder extends JTextField {
15
    
16
    /**
17
     * Log4j logger sent to view.
18
     */
19
    private static final Logger LOGGER = LogManager.getRootLogger();
20
    
21
    /**
22
     * Text to display when empty.
23
     */
24
    private String placeholderText;
25
    private int xOffset;
26
27
    /**
28
     * Create a textfield with hint and default value.
29
     * @param placeholder Text displayed when empty
30
     * @param value Default value
31
     */
32
    public JTextFieldPlaceholder(String placeholder, String value) {
33
        this(placeholder);
34 1 1. <init> : removed call to com/jsql/view/swing/text/JTextFieldPlaceholder::setText → NO_COVERAGE
        this.setText(value);
35
    }
36
    
37
    /**
38
     * Create a textfield with hint.
39
     * @param placeholder Text displayed when empty
40
     */
41
    public JTextFieldPlaceholder(String placeholder) {
42
        this.placeholderText = placeholder;
43
    }
44
45
    public JTextFieldPlaceholder(String placeholder, int xOffset) {
46
        this(placeholder);
47
        this.xOffset = xOffset;
48
    }
49
50
    @Override
51
    public void paint(Graphics g) {
52
        try {
53 1 1. paint : removed call to javax/swing/JTextField::paint → NO_COVERAGE
            super.paint(g);
54
        } catch (ClassCastException e) {  // Fix #4301, ClassCastException: sun.awt.image.BufImgSurfaceData cannot be cast to sun.java2d.xr.XRSurfaceData
55
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
56
        }
57 1 1. paint : negated conditional → NO_COVERAGE
        if (this.getText().isEmpty()) {
58
            int h = this.getHeight();
59
            var fm = g.getFontMetrics();
60 5 1. paint : Replaced integer division with multiplication → NO_COVERAGE
2. paint : removed call to com/jsql/view/swing/util/UiUtil::drawPlaceholder → NO_COVERAGE
3. paint : Replaced integer subtraction with addition → NO_COVERAGE
4. paint : Replaced integer division with multiplication → NO_COVERAGE
5. paint : Replaced integer addition with subtraction → NO_COVERAGE
            UiUtil.drawPlaceholder(this, g, this.placeholderText, this.xOffset, h / 2 + fm.getAscent() / 2 - 1);
61
        }
62
    }
63
64
    public void setPlaceholderText(String placeholderText) {
65
        this.placeholderText = placeholderText;
66
    }
67
}

Mutations

34

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/text/JTextFieldPlaceholder::setText → NO_COVERAGE

53

1.1
Location : paint
Killed by : none
removed call to javax/swing/JTextField::paint → NO_COVERAGE

57

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

60

1.1
Location : paint
Killed by : none
Replaced integer division with multiplication → NO_COVERAGE

2.2
Location : paint
Killed by : none
removed call to com/jsql/view/swing/util/UiUtil::drawPlaceholder → NO_COVERAGE

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

4.4
Location : paint
Killed by : none
Replaced integer division with multiplication → NO_COVERAGE

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

Active mutators

Tests examined


Report generated by PIT 1.18.2