AbstractRadioLink.java

1
package com.jsql.view.swing.radio;
2
3
import com.jsql.view.swing.util.UiUtil;
4
5
import javax.swing.*;
6
import java.awt.*;
7
import java.awt.font.TextAttribute;
8
import java.util.HashMap;
9
import java.util.List;
10
import java.util.Map;
11
12
/**
13
 * A label to mimic a radio button contained in a group.
14
 * Display as underlined if label is selected.
15
 */
16
public abstract class AbstractRadioLink extends JLabel {
17
    
18
    /**
19
     * Build a radio label.
20
     * @param string Text for label
21
     * @param isSelected Is the radio selected by default?
22
     */
23
    protected AbstractRadioLink(String string, boolean isSelected) {
24
        
25
        this(string);
26
        
27 1 1. <init> : negated conditional → NO_COVERAGE
        if (isSelected) {
28 1 1. <init> : removed call to com/jsql/view/swing/radio/AbstractRadioLink::setUnderlined → NO_COVERAGE
            this.setUnderlined();
29
        }
30
    }
31
32
    /**
33
     * Build a radio label.
34
     * @param string Text for label
35
     */
36
    protected AbstractRadioLink(String string) {
37
        super(string);
38
    }
39
40
    /**
41
     * An action run when radio is checked by user.
42
     */
43
    public abstract void action();
44
    
45
    /**
46
     * Group of radio components, either the radio for HTTP method or the one for injection strategy.
47
     * @return
48
     */
49
    public abstract List<JLabel> getGroup();
50
51
    /**
52
     * Radio is selectable/hoverable if it is not already selected (bold).
53
     * @return True if radio is not already selected
54
     */
55
    protected boolean isActivable() {
56
        
57 2 1. isActivable : replaced boolean return with true for com/jsql/view/swing/radio/AbstractRadioLink::isActivable → NO_COVERAGE
2. isActivable : negated conditional → NO_COVERAGE
        return !AbstractRadioLink.this.getFont().getAttributes().containsValue(TextAttribute.WEIGHT_BOLD);
58
    }
59
60
    /**
61
     * Change font of radio label to underline.
62
     */
63
    public final void setUnderlined() {
64
        
65
        var font = this.getFont();
66
        
67
        Map<TextAttribute, Object> attributes = new HashMap<>(font.getAttributes());
68
        attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED);
69
        attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
70
        
71 1 1. setUnderlined : removed call to com/jsql/view/swing/radio/AbstractRadioLink::setFont → NO_COVERAGE
        this.setFont(font.deriveFont(attributes));
72
    }
73
    
74
    public void setSelected() {
75
        
76
        for (JLabel label: this.getGroup()) {
77 1 1. setSelected : negated conditional → NO_COVERAGE
            if (this != label) {
78 1 1. setSelected : removed call to javax/swing/JLabel::setFont → NO_COVERAGE
                label.setFont(UiUtil.FONT_NON_MONO);
79
            } else {
80 1 1. setSelected : removed call to com/jsql/view/swing/radio/AbstractRadioLink::action → NO_COVERAGE
                this.action();
81
            }
82
        }
83
84 1 1. setSelected : removed call to com/jsql/view/swing/radio/AbstractRadioLink::setUnderlined → NO_COVERAGE
        this.setUnderlined();
85
86 1 1. setSelected : removed call to com/jsql/view/swing/radio/AbstractRadioLink::setCursor → NO_COVERAGE
        this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
87
    }
88
}

Mutations

27

1.1
Location : <init>
Killed by : none
negated conditional → NO_COVERAGE

28

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/radio/AbstractRadioLink::setUnderlined → NO_COVERAGE

57

1.1
Location : isActivable
Killed by : none
replaced boolean return with true for com/jsql/view/swing/radio/AbstractRadioLink::isActivable → NO_COVERAGE

2.2
Location : isActivable
Killed by : none
negated conditional → NO_COVERAGE

71

1.1
Location : setUnderlined
Killed by : none
removed call to com/jsql/view/swing/radio/AbstractRadioLink::setFont → NO_COVERAGE

77

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

78

1.1
Location : setSelected
Killed by : none
removed call to javax/swing/JLabel::setFont → NO_COVERAGE

80

1.1
Location : setSelected
Killed by : none
removed call to com/jsql/view/swing/radio/AbstractRadioLink::action → NO_COVERAGE

84

1.1
Location : setSelected
Killed by : none
removed call to com/jsql/view/swing/radio/AbstractRadioLink::setUnderlined → NO_COVERAGE

86

1.1
Location : setSelected
Killed by : none
removed call to com/jsql/view/swing/radio/AbstractRadioLink::setCursor → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1