DialogAbout.java

1
/*******************************************************************************
2
 * Copyhacked (H) 2012-2025.
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 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.I18nUtil;
14
import com.jsql.util.LogLevelUtil;
15
import com.jsql.util.StringUtil;
16
import com.jsql.view.swing.popupmenu.JPopupMenuText;
17
import com.jsql.view.swing.util.I18nViewUtil;
18
import com.jsql.view.swing.util.MediatorHelper;
19
import com.jsql.view.swing.util.UiUtil;
20
import org.apache.logging.log4j.LogManager;
21
import org.apache.logging.log4j.Logger;
22
23
import javax.swing.*;
24
import javax.swing.event.HyperlinkEvent;
25
import java.awt.*;
26
import java.awt.event.*;
27
import java.io.BufferedReader;
28
import java.io.IOException;
29
import java.io.InputStream;
30
import java.io.InputStreamReader;
31
import java.net.URI;
32
import java.net.URISyntaxException;
33
import java.nio.charset.StandardCharsets;
34
import java.util.Objects;
35
36
/**
37
 * A dialog displaying information about jSQL.
38
 */
39
public class DialogAbout extends JDialog {
40
    
41
    /**
42
     * Log4j logger sent to view.
43
     */
44
    private static final Logger LOGGER = LogManager.getRootLogger();
45
46
    /**
47
     * Button receiving focus.
48
     */
49
    private JButton buttonClose = null;
50
51
    /**
52
     * Create a dialog about project general information.
53
     */
54
    public DialogAbout() {
55
        super(MediatorHelper.frame(), I18nUtil.valueByKey("ABOUT_WINDOW_TITLE") +" "+ StringUtil.APP_NAME, Dialog.ModalityType.MODELESS);
56 1 1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("ABOUT_WINDOW_TITLE", this);
57 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogAbout::setDefaultCloseOperation → NO_COVERAGE
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
58 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogAbout::setIconImages → NO_COVERAGE
        this.setIconImages(UiUtil.getIcons());  // Define a small and large app icon
59
60 1 1. lambda$new$0 : removed call to com/jsql/view/swing/dialog/DialogAbout::dispose → NO_COVERAGE
        ActionListener escapeListener = actionEvent -> this.dispose();  // Action for ESCAPE key
61 1 1. <init> : removed call to javax/swing/JRootPane::registerKeyboardAction → NO_COVERAGE
        this.getRootPane().registerKeyboardAction(
62
            escapeListener,
63
            KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
64
            JComponent.WHEN_IN_FOCUSED_WINDOW
65
        );
66
        
67 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogAbout::setLayout → NO_COVERAGE
        this.setLayout(new BorderLayout());
68
69
        Container dialogPane = this.getContentPane();
70
        JPanel lastLine = this.initLastLine(escapeListener);
71
72
        var labelIcon = new JLabel(UiUtil.APP_MIDDLE.getIcon());
73 1 1. <init> : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE
        labelIcon.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
74 1 1. <init> : removed call to java/awt/Container::add → NO_COVERAGE
        dialogPane.add(labelIcon, BorderLayout.WEST);
75 1 1. <init> : removed call to java/awt/Container::add → NO_COVERAGE
        dialogPane.add(lastLine, BorderLayout.SOUTH);
76
77
        final JEditorPane text = this.initEditorPane();  // Contact info, use HTML text
78 1 1. <init> : removed call to java/awt/Container::add → NO_COVERAGE
        dialogPane.add(new JScrollPane(text), BorderLayout.CENTER);
79
80 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogAbout::initDialog → NO_COVERAGE
        this.initDialog();
81
    }
82
83
    private JPanel initLastLine(ActionListener escapeListener) {
84
        final var buttonWebpage = new JButton(I18nUtil.valueByKey("ABOUT_WEBPAGE"));
85 1 1. initLastLine : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("ABOUT_WEBPAGE", buttonWebpage);
86 1 1. initLastLine : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE
        buttonWebpage.addActionListener(ev -> {
87
            try {
88 1 1. lambda$initLastLine$1 : removed call to java/awt/Desktop::browse → NO_COVERAGE
                Desktop.getDesktop().browse(new URI(MediatorHelper.model().getMediatorUtils().getPropertiesUtil().getProperty("github.url")));
89
            } catch (IOException | URISyntaxException | UnsupportedOperationException e) {
90
                LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Browsing to Url failed", e);
91
            }
92
        });
93
94
        this.buttonClose = new JButton(I18nUtil.valueByKey("ABOUT_CLOSE"));
95 1 1. initLastLine : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("ABOUT_CLOSE", this.buttonClose);
96 1 1. initLastLine : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE
        this.buttonClose.addActionListener(escapeListener);
97
98
        var lastLine = new JPanel();
99 1 1. initLastLine : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE
        lastLine.setLayout(new BoxLayout(lastLine, BoxLayout.LINE_AXIS));
100 1 1. initLastLine : removed call to javax/swing/JPanel::setBorder → NO_COVERAGE
        lastLine.setBorder(UiUtil.BORDER_5PX);
101
        lastLine.add(buttonWebpage);
102
        lastLine.add(Box.createGlue());
103
        lastLine.add(this.buttonClose);
104 1 1. initLastLine : replaced return value with null for com/jsql/view/swing/dialog/DialogAbout::initLastLine → NO_COVERAGE
        return lastLine;
105
    }
106
107
    private JEditorPane initEditorPane() {
108
        var editorPane = new JEditorPane();
109
        
110
        // Fix #82540: NoClassDefFoundError on setText()
111
        try (
112
            InputStream inputStream = DialogAbout.class.getClassLoader().getResourceAsStream("swing/about.htm");
113
            var inputStreamReader = new InputStreamReader(Objects.requireNonNull(inputStream), StandardCharsets.UTF_8);
114
            var reader = new BufferedReader(inputStreamReader)
115
        ) {
116 1 1. initEditorPane : removed call to javax/swing/JEditorPane::setContentType → NO_COVERAGE
            editorPane.setContentType("text/html");
117
            var result = new StringBuilder();
118
            String line;
119 1 1. initEditorPane : negated conditional → NO_COVERAGE
            while ((line = reader.readLine()) != null) {
120
                result.append(line);
121
            }
122 1 1. initEditorPane : removed call to javax/swing/JEditorPane::setText → NO_COVERAGE
            editorPane.setText(result.toString().replace(
123
                "%JSQLVERSION%",
124
                MediatorHelper.model().getPropertiesUtil().getVersionJsql()
125
            ));
126
        } catch (NoClassDefFoundError | IOException e) {
127
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
128
        }
129
130 1 1. initEditorPane : removed call to javax/swing/JEditorPane::addMouseListener → NO_COVERAGE
        editorPane.addMouseListener(new MouseAdapter() {
131
            @Override
132
            public void mousePressed(MouseEvent e) {
133 1 1. mousePressed : removed call to java/awt/event/MouseAdapter::mousePressed → NO_COVERAGE
                super.mousePressed(e);
134
                editorPane.requestFocusInWindow();
135
            }
136
        });
137 1 1. initEditorPane : removed call to javax/swing/JEditorPane::addFocusListener → NO_COVERAGE
        editorPane.addFocusListener(new FocusAdapter() {
138
            @Override
139
            public void focusGained(FocusEvent focusEvent) {
140 1 1. focusGained : removed call to javax/swing/text/Caret::setVisible → NO_COVERAGE
                editorPane.getCaret().setVisible(true);
141 1 1. focusGained : removed call to javax/swing/text/Caret::setSelectionVisible → NO_COVERAGE
                editorPane.getCaret().setSelectionVisible(true);
142
            }
143
        });
144
145 1 1. initEditorPane : removed call to javax/swing/JEditorPane::setDragEnabled → NO_COVERAGE
        editorPane.setDragEnabled(true);
146 1 1. initEditorPane : removed call to javax/swing/JEditorPane::setEditable → NO_COVERAGE
        editorPane.setEditable(false);
147 1 1. initEditorPane : removed call to javax/swing/text/Caret::setBlinkRate → NO_COVERAGE
        editorPane.getCaret().setBlinkRate(0);
148 1 1. initEditorPane : removed call to javax/swing/JEditorPane::setCaretPosition → NO_COVERAGE
        editorPane.setCaretPosition(0);
149 1 1. initEditorPane : removed call to javax/swing/JEditorPane::setComponentPopupMenu → NO_COVERAGE
        editorPane.setComponentPopupMenu(new JPopupMenuText(editorPane));
150 1 1. initEditorPane : removed call to javax/swing/JEditorPane::addHyperlinkListener → NO_COVERAGE
        editorPane.addHyperlinkListener(linkEvent -> {
151 1 1. lambda$initEditorPane$2 : negated conditional → NO_COVERAGE
            if (HyperlinkEvent.EventType.ACTIVATED.equals(linkEvent.getEventType())) {
152
                try {
153 1 1. lambda$initEditorPane$2 : removed call to java/awt/Desktop::browse → NO_COVERAGE
                    Desktop.getDesktop().browse(linkEvent.getURL().toURI());
154
                } catch (IOException | URISyntaxException | UnsupportedOperationException e) {
155
                    LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Browsing to Url failed", e);
156
                }
157
            }
158
        });
159
        
160 1 1. initEditorPane : replaced return value with null for com/jsql/view/swing/dialog/DialogAbout::initEditorPane → NO_COVERAGE
        return editorPane;
161
    }
162
163
    /**
164
     * Set back default setting for About frame.
165
     */
166
    public final void initDialog() {
167 1 1. initDialog : removed call to com/jsql/view/swing/dialog/DialogAbout::setSize → NO_COVERAGE
        this.setSize(560, 400);
168 1 1. initDialog : removed call to com/jsql/view/swing/dialog/DialogAbout::setLocationRelativeTo → NO_COVERAGE
        this.setLocationRelativeTo(MediatorHelper.frame());
169
        this.buttonClose.requestFocusInWindow();
170 1 1. initDialog : removed call to javax/swing/JRootPane::setDefaultButton → NO_COVERAGE
        this.getRootPane().setDefaultButton(this.buttonClose);
171
    }
172
173
    public void requestButtonFocus() {
174
        this.buttonClose.requestFocusInWindow();
175
    }
176
}

Mutations

56

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

57

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

58

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

60

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

61

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

67

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

73

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

74

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

75

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

78

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

80

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

85

1.1
Location : initLastLine
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

86

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

88

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

95

1.1
Location : initLastLine
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

96

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

99

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

100

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

104

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

116

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

119

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

122

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

130

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

133

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

137

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

140

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

141

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

145

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

146

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

147

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

148

1.1
Location : initEditorPane
Killed by : none
removed call to javax/swing/JEditorPane::setCaretPosition → NO_COVERAGE

149

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

150

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

151

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

153

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

160

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

167

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

168

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

170

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

Active mutators

Tests examined


Report generated by PIT 1.19.1