JTextAreaPlaceholder.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
9
import javax.swing.*;
10
import java.awt.*;
11
12
/**
13
 * Textfield with information text displayed when empty.
14
 */
15
public class JTextAreaPlaceholder extends JTextArea {
16
    
17
    /**
18
     * Log4j logger sent to view.
19
     */
20
    private static final Logger LOGGER = LogManager.getRootLogger();
21
    
22
    /**
23
     * Text to display when empty.
24
     */
25
    private String placeholderText;
26
    
27
    /**
28
     * Create a textfield with hint.
29
     * @param placeholder Text displayed when empty
30
     */
31
    public JTextAreaPlaceholder(String placeholder) {
32
        this.placeholderText = placeholder;
33 1 1. <init> : removed call to com/jsql/view/swing/util/UiUtil::init → NO_COVERAGE
        UiUtil.init(this);
34
    }
35
36
    @Override
37
    public void paint(Graphics g) {
38
        // Fix #6350: ArrayIndexOutOfBoundsException on paint()
39
        // Fix #90822: IllegalArgumentException on paint()
40
        // Fix #90761: StateInvariantError on paint()
41
        // StateInvariantError possible on jdk 8 when WrappedPlainView.drawLine in paint()
42
        try {
43 1 1. paint : removed call to javax/swing/JTextArea::paint → NO_COVERAGE
            super.paint(g);
44 1 1. paint : negated conditional → NO_COVERAGE
            if (StringUtils.isEmpty(this.getText())) {
45 1 1. paint : removed call to com/jsql/view/swing/util/UiUtil::drawPlaceholder → NO_COVERAGE
                UiUtil.drawPlaceholder(this, g, this.placeholderText);
46
            }
47
        } catch (IllegalArgumentException | NullPointerException | ArrayIndexOutOfBoundsException e) {
48
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
49
        }
50
    }
51
52
    public void setPlaceholderText(String placeholderText) {
53
        this.placeholderText = placeholderText;
54
    }
55
}

Mutations

33

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

43

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

44

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

45

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.18.2