JTextPanePlaceholder.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.commons.lang3.StringUtils;
6
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
8
import org.jsoup.Jsoup;
9
10
import javax.swing.*;
11
import java.awt.*;
12
import java.util.ConcurrentModificationException;
13
14
/**
15
 * Textfield with information text displayed when empty.
16
 */
17
public class JTextPanePlaceholder extends JTextPane {
18
    
19
    /**
20
     * Log4j logger sent to view.
21
     */
22
    private static final Logger LOGGER = LogManager.getRootLogger();
23
    
24
    /**
25
     * Text to display when empty.
26
     */
27
    private final String placeholderText;
28
29
    /**
30
     * Create a textfield with hint.
31
     * @param placeholder Text displayed when empty
32
     */
33
    public JTextPanePlaceholder(String placeholder) {
34
        
35
        this.placeholderText = placeholder;
36 1 1. <init> : removed call to com/jsql/view/swing/util/UiUtil::initialize → NO_COVERAGE
        UiUtil.initialize(this);
37
    }
38
39
    @Override
40
    public void paint(Graphics g) {
41
        // Fix #4012: ArrayIndexOutOfBoundsException on paint()
42
        // Fix #38546: ConcurrentModificationException on getText()
43
        // Fix #37872: IndexOutOfBoundsException on getText()
44
        // Fix #48915: ClassCastException on paint()
45
        // Unhandled IllegalArgumentException #91471 on paint()
46
        try {
47 1 1. paint : removed call to javax/swing/JTextPane::paint → NO_COVERAGE
            super.paint(g);
48
            
49 1 1. paint : negated conditional → NO_COVERAGE
            if (StringUtils.isEmpty(Jsoup.parse(this.getText()).text().trim())) {
50 1 1. paint : removed call to com/jsql/view/swing/util/UiUtil::drawPlaceholder → NO_COVERAGE
                UiUtil.drawPlaceholder(this, g, this.placeholderText);
51
            }
52
        } catch (IllegalArgumentException | ConcurrentModificationException | IndexOutOfBoundsException | ClassCastException e) {
53
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
54
        }
55
    }
56
}

Mutations

36

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/util/UiUtil::initialize → NO_COVERAGE

47

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

49

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

50

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

Active mutators

Tests examined


Report generated by PIT 1.16.1