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