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 JPasswordFieldPlaceholder extends JPasswordField { | |
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 | ||
26 | /** | |
27 | * Create a textfield with hint. | |
28 | * @param placeholder Text displayed when empty | |
29 | */ | |
30 | public JPasswordFieldPlaceholder(String placeholder) { | |
31 | this.placeholderText = placeholder; | |
32 | } | |
33 | ||
34 | @Override | |
35 | public void paint(Graphics g) { | |
36 | try { | |
37 |
1
1. paint : removed call to javax/swing/JPasswordField::paint → NO_COVERAGE |
super.paint(g); |
38 | } catch (ClassCastException e) { // Fix #4301, ClassCastException: sun.awt.image.BufImgSurfaceData cannot be cast to sun.java2d.xr.XRSurfaceData | |
39 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
40 | } | |
41 |
1
1. paint : negated conditional → NO_COVERAGE |
if (new String(this.getPassword()).isEmpty()) { |
42 | int h = this.getHeight(); | |
43 | var fm = g.getFontMetrics(); | |
44 |
5
1. paint : Replaced integer subtraction with addition → NO_COVERAGE 2. paint : Replaced integer division with multiplication → NO_COVERAGE 3. paint : removed call to com/jsql/view/swing/util/UiUtil::drawPlaceholder → 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, 0, h / 2 + fm.getAscent() / 2 - 1); |
45 | } | |
46 | } | |
47 | ||
48 | public void setPlaceholderText(String placeholderText) { | |
49 | this.placeholderText = placeholderText; | |
50 | } | |
51 | } | |
Mutations | ||
37 |
1.1 |
|
41 |
1.1 |
|
44 |
1.1 2.2 3.3 4.4 5.5 |