DialogAbout.java

1
/*******************************************************************************
2
 * Copyhacked (H) 2012-2020.
3
 * This program and the accompanying materials
4
 * are made available under no term at all, use it like
5
 * you want, but share and discuss about it
6
 * every time possible with every body.
7
 * 
8
 * Contributors:
9
 *      ron190 at ymail dot com - initial implementation
10
 ******************************************************************************/
11
package com.jsql.view.swing.dialog;
12
13
import com.jsql.util.LogLevelUtil;
14
import com.jsql.view.swing.popupmenu.JPopupMenuText;
15
import com.jsql.view.swing.scrollpane.LightScrollPane;
16
import com.jsql.view.swing.ui.FlatButtonMouseAdapter;
17
import com.jsql.view.swing.util.MediatorHelper;
18
import com.jsql.view.swing.util.UiUtil;
19
import org.apache.logging.log4j.LogManager;
20
import org.apache.logging.log4j.Logger;
21
22
import javax.swing.*;
23
import javax.swing.event.HyperlinkEvent;
24
import java.awt.*;
25
import java.awt.event.*;
26
import java.io.BufferedReader;
27
import java.io.IOException;
28
import java.io.InputStream;
29
import java.io.InputStreamReader;
30
import java.net.URI;
31
import java.net.URISyntaxException;
32
import java.nio.charset.StandardCharsets;
33
import java.util.Objects;
34
35
/**
36
 * A dialog displaying information about jSQL.
37
 */
38
public class DialogAbout extends JDialog {
39
    
40
    /**
41
     * Log4j logger sent to view.
42
     */
43
    private static final Logger LOGGER = LogManager.getRootLogger();
44
45
    /**
46
     * Button receiving focus.
47
     */
48
    private JButton buttonClose = null;
49
    
50
    /**
51
     * Dialog scroller.
52
     */
53
    private final LightScrollPane scrollPane;
54
55
    /**
56
     * Create a dialog about project general information.
57
     */
58
    public DialogAbout() {
59
        
60
        super(MediatorHelper.frame(), "About jSQL Injection", Dialog.ModalityType.MODELESS);
61
62 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogAbout::setDefaultCloseOperation → NO_COVERAGE
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
63
64
        // Define a small and large app icon
65 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogAbout::setIconImages → NO_COVERAGE
        this.setIconImages(UiUtil.getIcons());
66
67
        // Action for ESCAPE key
68 1 1. lambda$new$0 : removed call to com/jsql/view/swing/dialog/DialogAbout::dispose → NO_COVERAGE
        ActionListener escapeListener = actionEvent -> DialogAbout.this.dispose();
69
70 1 1. <init> : removed call to javax/swing/JRootPane::registerKeyboardAction → NO_COVERAGE
        this.getRootPane().registerKeyboardAction(
71
            escapeListener,
72
            KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
73
            JComponent.WHEN_IN_FOCUSED_WINDOW
74
        );
75
        
76 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogAbout::setLayout → NO_COVERAGE
        this.setLayout(new BorderLayout());
77
        Container dialogPane = this.getContentPane();
78
79
        JPanel lastLine = this.initializeLastLine(escapeListener);
80
81
        var iconJsql = new JLabel(new ImageIcon(Objects.requireNonNull(UiUtil.URL_ICON_96)));
82 1 1. <init> : removed call to java/awt/Container::add → NO_COVERAGE
        dialogPane.add(iconJsql, BorderLayout.WEST);
83 1 1. <init> : removed call to java/awt/Container::add → NO_COVERAGE
        dialogPane.add(lastLine, BorderLayout.SOUTH);
84
85
        // Contact info, use HTML text
86
        final JEditorPane text = this.initializeEditorPane();
87
88
        this.scrollPane = new LightScrollPane(1, 1, 1, 0, text);
89 1 1. <init> : removed call to java/awt/Container::add → NO_COVERAGE
        dialogPane.add(this.scrollPane, BorderLayout.CENTER);
90
91 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogAbout::initializeDialog → NO_COVERAGE
        this.initializeDialog();
92
    }
93
94
    private JPanel initializeLastLine(ActionListener escapeListener) {
95
        
96
        var lastLine = new JPanel();
97 1 1. initializeLastLine : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE
        lastLine.setLayout(new BoxLayout(lastLine, BoxLayout.LINE_AXIS));
98 1 1. initializeLastLine : removed call to javax/swing/JPanel::setBorder → NO_COVERAGE
        lastLine.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
99
        
100
        final JButton buttonWebpage = this.initializeButtonWebpage();
101
        
102 1 1. initializeLastLine : removed call to com/jsql/view/swing/dialog/DialogAbout::initializeButtonClose → NO_COVERAGE
        this.initializeButtonClose(escapeListener);
103
        
104
        lastLine.add(buttonWebpage);
105
        lastLine.add(Box.createGlue());
106
        lastLine.add(this.buttonClose);
107
        
108 1 1. initializeLastLine : replaced return value with null for com/jsql/view/swing/dialog/DialogAbout::initializeLastLine → NO_COVERAGE
        return lastLine;
109
    }
110
111
    private void initializeButtonClose(ActionListener escapeListener) {
112
        
113
        this.buttonClose = new JButton("Close");
114 1 1. initializeButtonClose : removed call to javax/swing/JButton::setBorder → NO_COVERAGE
        this.buttonClose.setBorder(BorderFactory.createCompoundBorder(
115
            UiUtil.BORDER_FOCUS_GAINED,
116
            BorderFactory.createEmptyBorder(2, 20, 2, 20))
117
        );
118 1 1. initializeButtonClose : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE
        this.buttonClose.addActionListener(escapeListener);
119
        
120 1 1. initializeButtonClose : removed call to javax/swing/JButton::setContentAreaFilled → NO_COVERAGE
        this.buttonClose.setContentAreaFilled(false);
121 1 1. initializeButtonClose : removed call to javax/swing/JButton::setBorder → NO_COVERAGE
        this.buttonClose.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8));
122 1 1. initializeButtonClose : removed call to javax/swing/JButton::setBackground → NO_COVERAGE
        this.buttonClose.setBackground(UiUtil.COLOR_FOCUS_GAINED);
123
        
124 1 1. initializeButtonClose : removed call to javax/swing/JButton::addMouseListener → NO_COVERAGE
        this.buttonClose.addMouseListener(new FlatButtonMouseAdapter(this.buttonClose));
125
    }
126
127
    private JButton initializeButtonWebpage() {
128
        
129
        final var buttonWebpage = new JButton("Webpage");
130
        
131 1 1. initializeButtonWebpage : removed call to javax/swing/JButton::setBorder → NO_COVERAGE
        buttonWebpage.setBorder(BorderFactory.createCompoundBorder(
132
            UiUtil.BORDER_FOCUS_GAINED,
133
            BorderFactory.createEmptyBorder(2, 20, 2, 20))
134
        );
135
        
136 1 1. initializeButtonWebpage : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE
        buttonWebpage.addActionListener(ev -> {
137
            try {
138 1 1. lambda$initializeButtonWebpage$1 : removed call to java/awt/Desktop::browse → NO_COVERAGE
                Desktop.getDesktop().browse(new URI((String) MediatorHelper.model().getMediatorUtils().getPropertiesUtil().getProperties().get("github.url")));
139
            } catch (IOException | URISyntaxException | UnsupportedOperationException e) {
140
                LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Browsing to Url failed", e);
141
            }
142
        });
143
        
144 1 1. initializeButtonWebpage : removed call to javax/swing/JButton::setContentAreaFilled → NO_COVERAGE
        buttonWebpage.setContentAreaFilled(false);
145 1 1. initializeButtonWebpage : removed call to javax/swing/JButton::setBorder → NO_COVERAGE
        buttonWebpage.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8));
146 1 1. initializeButtonWebpage : removed call to javax/swing/JButton::setBackground → NO_COVERAGE
        buttonWebpage.setBackground(UiUtil.COLOR_FOCUS_GAINED);
147
        
148 1 1. initializeButtonWebpage : removed call to javax/swing/JButton::addMouseListener → NO_COVERAGE
        buttonWebpage.addMouseListener(new FlatButtonMouseAdapter(buttonWebpage));
149
        
150 1 1. initializeButtonWebpage : replaced return value with null for com/jsql/view/swing/dialog/DialogAbout::initializeButtonWebpage → NO_COVERAGE
        return buttonWebpage;
151
    }
152
153
    private JEditorPane initializeEditorPane() {
154
        
155
        var editorPane = new JEditorPane();
156
        
157
        // Fix #82540: NoClassDefFoundError on setText()
158
        try {
159 1 1. initializeEditorPane : removed call to javax/swing/JEditorPane::setContentType → NO_COVERAGE
            editorPane.setContentType("text/html");
160
161
            var result = new StringBuilder();
162
            
163
            try (
164
                InputStream inputStream = DialogAbout.class.getClassLoader().getResourceAsStream("swing/about.htm");
165
                var inputStreamReader = new InputStreamReader(Objects.requireNonNull(inputStream), StandardCharsets.UTF_8);
166
                var reader = new BufferedReader(inputStreamReader)
167
            ) {
168
                String line;
169 1 1. initializeEditorPane : negated conditional → NO_COVERAGE
                while ((line = reader.readLine()) != null) {
170
                    result.append(line);
171
                }
172
            }
173
174 1 1. initializeEditorPane : removed call to javax/swing/JEditorPane::setText → NO_COVERAGE
            editorPane.setText(result.toString().replace("%JSQLVERSION%", MediatorHelper.model().getVersionJsql()));
175
            
176
        } catch (NoClassDefFoundError | IOException e) {
177
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
178
        }
179
180 1 1. initializeEditorPane : removed call to javax/swing/JEditorPane::addMouseListener → NO_COVERAGE
        editorPane.addMouseListener(new MouseAdapter() {
181
            
182
            @Override
183
            public void mousePressed(MouseEvent e) {
184
                
185 1 1. mousePressed : removed call to java/awt/event/MouseAdapter::mousePressed → NO_COVERAGE
                super.mousePressed(e);
186
                editorPane.requestFocusInWindow();
187
            }
188
        });
189
190 1 1. initializeEditorPane : removed call to javax/swing/JEditorPane::addFocusListener → NO_COVERAGE
        editorPane.addFocusListener(new FocusAdapter() {
191
            
192
            @Override
193
            public void focusGained(FocusEvent arg0) {
194
                
195 1 1. focusGained : removed call to javax/swing/text/Caret::setVisible → NO_COVERAGE
                editorPane.getCaret().setVisible(true);
196 1 1. focusGained : removed call to javax/swing/text/Caret::setSelectionVisible → NO_COVERAGE
                editorPane.getCaret().setSelectionVisible(true);
197
            }
198
        });
199
200 1 1. initializeEditorPane : removed call to javax/swing/JEditorPane::setBorder → NO_COVERAGE
        editorPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
201 1 1. initializeEditorPane : removed call to javax/swing/JEditorPane::setDragEnabled → NO_COVERAGE
        editorPane.setDragEnabled(true);
202 1 1. initializeEditorPane : removed call to javax/swing/JEditorPane::setEditable → NO_COVERAGE
        editorPane.setEditable(false);
203
204 1 1. initializeEditorPane : removed call to javax/swing/JEditorPane::setComponentPopupMenu → NO_COVERAGE
        editorPane.setComponentPopupMenu(new JPopupMenuText(editorPane));
205
206 1 1. initializeEditorPane : removed call to javax/swing/JEditorPane::addHyperlinkListener → NO_COVERAGE
        editorPane.addHyperlinkListener(linkEvent -> {
207 1 1. lambda$initializeEditorPane$2 : negated conditional → NO_COVERAGE
            if (HyperlinkEvent.EventType.ACTIVATED.equals(linkEvent.getEventType())) {
208
                try {
209 1 1. lambda$initializeEditorPane$2 : removed call to java/awt/Desktop::browse → NO_COVERAGE
                    Desktop.getDesktop().browse(linkEvent.getURL().toURI());
210
                } catch (IOException | URISyntaxException | UnsupportedOperationException e) {
211
                    LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Browsing to Url failed", e);
212
                }
213
            }
214
        });
215
        
216 1 1. initializeEditorPane : replaced return value with null for com/jsql/view/swing/dialog/DialogAbout::initializeEditorPane → NO_COVERAGE
        return editorPane;
217
    }
218
219
    /**
220
     * Set back default setting for About frame.
221
     */
222
    public final void initializeDialog() {
223
        
224 1 1. initializeDialog : removed call to javax/swing/JViewport::setViewPosition → NO_COVERAGE
        this.scrollPane.scrollPane.getViewport().setViewPosition(new Point(0, 0));
225 1 1. initializeDialog : removed call to com/jsql/view/swing/dialog/DialogAbout::setSize → NO_COVERAGE
        this.setSize(533, 400);
226 1 1. initializeDialog : removed call to com/jsql/view/swing/dialog/DialogAbout::setLocationRelativeTo → NO_COVERAGE
        this.setLocationRelativeTo(MediatorHelper.frame());
227
        this.buttonClose.requestFocusInWindow();
228 1 1. initializeDialog : removed call to javax/swing/JRootPane::setDefaultButton → NO_COVERAGE
        this.getRootPane().setDefaultButton(this.buttonClose);
229
    }
230
231
    public void requestButtonFocus() {
232
        this.buttonClose.requestFocusInWindow();
233
    }
234
}

Mutations

62

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/dialog/DialogAbout::setDefaultCloseOperation → NO_COVERAGE

65

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/dialog/DialogAbout::setIconImages → NO_COVERAGE

68

1.1
Location : lambda$new$0
Killed by : none
removed call to com/jsql/view/swing/dialog/DialogAbout::dispose → NO_COVERAGE

70

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

76

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/dialog/DialogAbout::setLayout → NO_COVERAGE

82

1.1
Location : <init>
Killed by : none
removed call to java/awt/Container::add → NO_COVERAGE

83

1.1
Location : <init>
Killed by : none
removed call to java/awt/Container::add → NO_COVERAGE

89

1.1
Location : <init>
Killed by : none
removed call to java/awt/Container::add → NO_COVERAGE

91

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/dialog/DialogAbout::initializeDialog → NO_COVERAGE

97

1.1
Location : initializeLastLine
Killed by : none
removed call to javax/swing/JPanel::setLayout → NO_COVERAGE

98

1.1
Location : initializeLastLine
Killed by : none
removed call to javax/swing/JPanel::setBorder → NO_COVERAGE

102

1.1
Location : initializeLastLine
Killed by : none
removed call to com/jsql/view/swing/dialog/DialogAbout::initializeButtonClose → NO_COVERAGE

108

1.1
Location : initializeLastLine
Killed by : none
replaced return value with null for com/jsql/view/swing/dialog/DialogAbout::initializeLastLine → NO_COVERAGE

114

1.1
Location : initializeButtonClose
Killed by : none
removed call to javax/swing/JButton::setBorder → NO_COVERAGE

118

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

120

1.1
Location : initializeButtonClose
Killed by : none
removed call to javax/swing/JButton::setContentAreaFilled → NO_COVERAGE

121

1.1
Location : initializeButtonClose
Killed by : none
removed call to javax/swing/JButton::setBorder → NO_COVERAGE

122

1.1
Location : initializeButtonClose
Killed by : none
removed call to javax/swing/JButton::setBackground → NO_COVERAGE

124

1.1
Location : initializeButtonClose
Killed by : none
removed call to javax/swing/JButton::addMouseListener → NO_COVERAGE

131

1.1
Location : initializeButtonWebpage
Killed by : none
removed call to javax/swing/JButton::setBorder → NO_COVERAGE

136

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

138

1.1
Location : lambda$initializeButtonWebpage$1
Killed by : none
removed call to java/awt/Desktop::browse → NO_COVERAGE

144

1.1
Location : initializeButtonWebpage
Killed by : none
removed call to javax/swing/JButton::setContentAreaFilled → NO_COVERAGE

145

1.1
Location : initializeButtonWebpage
Killed by : none
removed call to javax/swing/JButton::setBorder → NO_COVERAGE

146

1.1
Location : initializeButtonWebpage
Killed by : none
removed call to javax/swing/JButton::setBackground → NO_COVERAGE

148

1.1
Location : initializeButtonWebpage
Killed by : none
removed call to javax/swing/JButton::addMouseListener → NO_COVERAGE

150

1.1
Location : initializeButtonWebpage
Killed by : none
replaced return value with null for com/jsql/view/swing/dialog/DialogAbout::initializeButtonWebpage → NO_COVERAGE

159

1.1
Location : initializeEditorPane
Killed by : none
removed call to javax/swing/JEditorPane::setContentType → NO_COVERAGE

169

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

174

1.1
Location : initializeEditorPane
Killed by : none
removed call to javax/swing/JEditorPane::setText → NO_COVERAGE

180

1.1
Location : initializeEditorPane
Killed by : none
removed call to javax/swing/JEditorPane::addMouseListener → NO_COVERAGE

185

1.1
Location : mousePressed
Killed by : none
removed call to java/awt/event/MouseAdapter::mousePressed → NO_COVERAGE

190

1.1
Location : initializeEditorPane
Killed by : none
removed call to javax/swing/JEditorPane::addFocusListener → NO_COVERAGE

195

1.1
Location : focusGained
Killed by : none
removed call to javax/swing/text/Caret::setVisible → NO_COVERAGE

196

1.1
Location : focusGained
Killed by : none
removed call to javax/swing/text/Caret::setSelectionVisible → NO_COVERAGE

200

1.1
Location : initializeEditorPane
Killed by : none
removed call to javax/swing/JEditorPane::setBorder → NO_COVERAGE

201

1.1
Location : initializeEditorPane
Killed by : none
removed call to javax/swing/JEditorPane::setDragEnabled → NO_COVERAGE

202

1.1
Location : initializeEditorPane
Killed by : none
removed call to javax/swing/JEditorPane::setEditable → NO_COVERAGE

204

1.1
Location : initializeEditorPane
Killed by : none
removed call to javax/swing/JEditorPane::setComponentPopupMenu → NO_COVERAGE

206

1.1
Location : initializeEditorPane
Killed by : none
removed call to javax/swing/JEditorPane::addHyperlinkListener → NO_COVERAGE

207

1.1
Location : lambda$initializeEditorPane$2
Killed by : none
negated conditional → NO_COVERAGE

209

1.1
Location : lambda$initializeEditorPane$2
Killed by : none
removed call to java/awt/Desktop::browse → NO_COVERAGE

216

1.1
Location : initializeEditorPane
Killed by : none
replaced return value with null for com/jsql/view/swing/dialog/DialogAbout::initializeEditorPane → NO_COVERAGE

224

1.1
Location : initializeDialog
Killed by : none
removed call to javax/swing/JViewport::setViewPosition → NO_COVERAGE

225

1.1
Location : initializeDialog
Killed by : none
removed call to com/jsql/view/swing/dialog/DialogAbout::setSize → NO_COVERAGE

226

1.1
Location : initializeDialog
Killed by : none
removed call to com/jsql/view/swing/dialog/DialogAbout::setLocationRelativeTo → NO_COVERAGE

228

1.1
Location : initializeDialog
Killed by : none
removed call to javax/swing/JRootPane::setDefaultButton → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1