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