GUI.java

1
/**
2
 * SpamSchutz - simple way to protect your mail addresses from naïve spammers
3
 * Copyright (C) 2011, Aiki IT
4
 * <p/>
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 * <p/>
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 * <p/>
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
package de.aikiit.spamprotector;
19
20
import com.google.common.annotations.VisibleForTesting;
21
import de.aikiit.spamprotector.converter.SpamProtector;
22
23
import javax.swing.JButton;
24
import javax.swing.JLabel;
25
import javax.swing.JOptionPane;
26
import javax.swing.JPanel;
27
import javax.swing.JTextField;
28
import javax.swing.SwingUtilities;
29
import java.awt.BorderLayout;
30
import java.awt.Dimension;
31
import java.awt.FlowLayout;
32
import java.time.LocalDate;
33
34
import static de.aikiit.spamprotector.util.LocalizationHelper.getBundleString;
35
import static de.aikiit.spamprotector.util.LocalizationHelper.getParameterizedBundleString;
36
37
/**
38
 * This class contains the main UI of this application (both input windows
39
 * and all command buttons).
40
 */
41
class GUI extends JPanel {
42
43
    /**
44
     * Constant to define the dimension of a text box.
45
     */
46
    private static final Dimension BOX_DIMENSION = new Dimension(300, 200);
47
48
    @VisibleForTesting
49
    static final LocalDate now = LocalDate.now();
50
51
    /**
52
     * Launches and configures the main UI component.
53
     */
54
    GUI() {
55 1 1. <init> : removed call to javax/swing/SwingUtilities::invokeLater → NO_COVERAGE
        SwingUtilities.invokeLater(this::init);
56
    }
57
58
    /**
59
     * Internal helper to initialize the UI depending on the surrounding this
60
     * application is started.
61
     */
62
    private void init() {
63
        // command help
64
        final JPanel buttonArea = new JPanel();
65
        JButton help = new JButton(getBundleString("spamschutz.ui.help"));
66 1 1. init : removed call to javax/swing/JButton::setMnemonic → NO_COVERAGE
        help.setMnemonic(getBundleString("spamschutz.ui.help.mnemonic").charAt(0));
67 2 1. lambda$init$0 : removed call to javax/swing/JOptionPane::showMessageDialog → NO_COVERAGE
2. init : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE
        help.addActionListener(e -> JOptionPane.showMessageDialog(null, getParameterizedBundleString("spamschutz.ui.help.text",
68
                        String.valueOf(now.getYear()),
69
                        de.aikiit.spamprotector.util.Version.VERSION),
70
                getBundleString("spamschutz.ui.help.title"),
71
                JOptionPane.INFORMATION_MESSAGE));
72
73
        final JTextField input = new JTextField();
74 1 1. init : removed call to javax/swing/JTextField::setSize → NO_COVERAGE
        input.setSize(BOX_DIMENSION);
75 1 1. init : removed call to javax/swing/JTextField::setPreferredSize → NO_COVERAGE
        input.setPreferredSize(BOX_DIMENSION);
76
        final JTextField output = new JTextField(getBundleString("spamschutz.ui.default.output"));
77 1 1. init : removed call to javax/swing/JTextField::setSize → NO_COVERAGE
        output.setSize(BOX_DIMENSION);
78 1 1. init : removed call to javax/swing/JTextField::setPreferredSize → NO_COVERAGE
        output.setPreferredSize(BOX_DIMENSION);
79
80
        // read input field
81
        final JButton start = new JButton(getBundleString("spamschutz.ui.button.rtl"));
82 1 1. init : removed call to javax/swing/JButton::setMnemonic → NO_COVERAGE
        start.setMnemonic(getBundleString("spamschutz.ui.button.rtl.mnemonic").charAt(0));
83 2 1. init : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE
2. lambda$init$1 : removed call to javax/swing/JTextField::setText → NO_COVERAGE
        start.addActionListener(e -> output.setText(SpamProtector.toEncoded(input.getText())));
84
85
        // read output field
86
        final JButton revert = new JButton(getBundleString("spamschutz.ui.button.ltr"));
87 1 1. init : removed call to javax/swing/JButton::setMnemonic → NO_COVERAGE
        revert.setMnemonic(getBundleString("spamschutz.ui.button.ltr.mnemonic").charAt(0));
88 2 1. init : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE
2. lambda$init$2 : removed call to javax/swing/JTextField::setText → NO_COVERAGE
        revert.addActionListener(e -> input.setText(SpamProtector.toPlain(output.getText())));
89
90
        final JButton reset = new JButton(getBundleString("spamschutz.ui.reset"));
91 1 1. init : removed call to javax/swing/JButton::setMnemonic → NO_COVERAGE
        reset.setMnemonic(getBundleString("spamschutz.ui.reset.mnemonic").charAt(0));
92 1 1. init : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE
        reset.addActionListener(e -> {
93 1 1. lambda$init$3 : removed call to javax/swing/JTextField::setText → NO_COVERAGE
            input.setText("");
94 1 1. lambda$init$3 : removed call to javax/swing/JTextField::setText → NO_COVERAGE
            output.setText("");
95
        });
96
97
        buttonArea.add(revert);
98
        buttonArea.add(start);
99
        buttonArea.add(reset);
100
101
        // fields
102
        final JPanel ioArea = new JPanel(new FlowLayout());
103
104
        final JLabel inputLabel = new JLabel(getBundleString("spamschutz.ui.input"));
105 1 1. init : removed call to javax/swing/JLabel::setDisplayedMnemonic → NO_COVERAGE
        inputLabel.setDisplayedMnemonic(getBundleString("spamschutz.ui.input.mnemonic").charAt(0));
106 1 1. init : removed call to javax/swing/JLabel::setLabelFor → NO_COVERAGE
        inputLabel.setLabelFor(input);
107
        ioArea.add(inputLabel);
108
        ioArea.add(input);
109
110
        final JLabel outputLabel = new JLabel(getBundleString("spamschutz.ui.output"));
111 1 1. init : removed call to javax/swing/JLabel::setDisplayedMnemonic → NO_COVERAGE
        outputLabel.setDisplayedMnemonic(getBundleString("spamschutz.ui.output.mnemonic").charAt(0));
112 1 1. init : removed call to javax/swing/JLabel::setLabelFor → NO_COVERAGE
        outputLabel.setLabelFor(output);
113
        ioArea.add(outputLabel);
114
        ioArea.add(output);
115
116
        // window layout
117 1 1. init : removed call to de/aikiit/spamprotector/GUI::setLayout → NO_COVERAGE
        this.setLayout(new BorderLayout());
118 1 1. init : removed call to de/aikiit/spamprotector/GUI::add → NO_COVERAGE
        this.add(buttonArea, BorderLayout.NORTH);
119 1 1. init : removed call to de/aikiit/spamprotector/GUI::add → NO_COVERAGE
        this.add(ioArea, BorderLayout.CENTER);
120
121
        final JButton end = new JButton(getBundleString("spamschutz.ui.end"));
122 1 1. init : removed call to javax/swing/JButton::setMnemonic → NO_COVERAGE
        end.setMnemonic(getBundleString("spamschutz.ui.end.mnemonic").charAt(0));
123 2 1. lambda$init$4 : removed call to java/lang/System::exit → NO_COVERAGE
2. init : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE
        end.addActionListener(e -> System.exit(0));
124
        buttonArea.add(end);
125
        buttonArea.add(help);
126 1 1. init : removed call to de/aikiit/spamprotector/GUI::setVisible → NO_COVERAGE
        this.setVisible(true);
127
    }
128
}

Mutations

55

1.1
Location : <init>
Killed by : none
removed call to javax/swing/SwingUtilities::invokeLater → NO_COVERAGE

66

1.1
Location : init
Killed by : none
removed call to javax/swing/JButton::setMnemonic → NO_COVERAGE

67

1.1
Location : lambda$init$0
Killed by : none
removed call to javax/swing/JOptionPane::showMessageDialog → NO_COVERAGE

2.2
Location : init
Killed by : none
removed call to javax/swing/JButton::addActionListener → NO_COVERAGE

74

1.1
Location : init
Killed by : none
removed call to javax/swing/JTextField::setSize → NO_COVERAGE

75

1.1
Location : init
Killed by : none
removed call to javax/swing/JTextField::setPreferredSize → NO_COVERAGE

77

1.1
Location : init
Killed by : none
removed call to javax/swing/JTextField::setSize → NO_COVERAGE

78

1.1
Location : init
Killed by : none
removed call to javax/swing/JTextField::setPreferredSize → NO_COVERAGE

82

1.1
Location : init
Killed by : none
removed call to javax/swing/JButton::setMnemonic → NO_COVERAGE

83

1.1
Location : init
Killed by : none
removed call to javax/swing/JButton::addActionListener → NO_COVERAGE

2.2
Location : lambda$init$1
Killed by : none
removed call to javax/swing/JTextField::setText → NO_COVERAGE

87

1.1
Location : init
Killed by : none
removed call to javax/swing/JButton::setMnemonic → NO_COVERAGE

88

1.1
Location : init
Killed by : none
removed call to javax/swing/JButton::addActionListener → NO_COVERAGE

2.2
Location : lambda$init$2
Killed by : none
removed call to javax/swing/JTextField::setText → NO_COVERAGE

91

1.1
Location : init
Killed by : none
removed call to javax/swing/JButton::setMnemonic → NO_COVERAGE

92

1.1
Location : init
Killed by : none
removed call to javax/swing/JButton::addActionListener → NO_COVERAGE

93

1.1
Location : lambda$init$3
Killed by : none
removed call to javax/swing/JTextField::setText → NO_COVERAGE

94

1.1
Location : lambda$init$3
Killed by : none
removed call to javax/swing/JTextField::setText → NO_COVERAGE

105

1.1
Location : init
Killed by : none
removed call to javax/swing/JLabel::setDisplayedMnemonic → NO_COVERAGE

106

1.1
Location : init
Killed by : none
removed call to javax/swing/JLabel::setLabelFor → NO_COVERAGE

111

1.1
Location : init
Killed by : none
removed call to javax/swing/JLabel::setDisplayedMnemonic → NO_COVERAGE

112

1.1
Location : init
Killed by : none
removed call to javax/swing/JLabel::setLabelFor → NO_COVERAGE

117

1.1
Location : init
Killed by : none
removed call to de/aikiit/spamprotector/GUI::setLayout → NO_COVERAGE

118

1.1
Location : init
Killed by : none
removed call to de/aikiit/spamprotector/GUI::add → NO_COVERAGE

119

1.1
Location : init
Killed by : none
removed call to de/aikiit/spamprotector/GUI::add → NO_COVERAGE

122

1.1
Location : init
Killed by : none
removed call to javax/swing/JButton::setMnemonic → NO_COVERAGE

123

1.1
Location : lambda$init$4
Killed by : none
removed call to java/lang/System::exit → NO_COVERAGE

2.2
Location : init
Killed by : none
removed call to javax/swing/JButton::addActionListener → NO_COVERAGE

126

1.1
Location : init
Killed by : none
removed call to de/aikiit/spamprotector/GUI::setVisible → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.30.1 support