| 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.GitUtil.ShowOnConsole; | |
| 14 | import com.jsql.util.I18nUtil; | |
| 15 | import com.jsql.util.LogLevelUtil; | |
| 16 | import com.jsql.view.swing.dialog.translate.Language; | |
| 17 | import com.jsql.view.swing.dialog.translate.WorkerTranslateInto; | |
| 18 | import com.jsql.view.swing.popupmenu.JPopupMenuText; | |
| 19 | import com.jsql.view.swing.text.JPopupTextArea; | |
| 20 | import com.jsql.view.swing.text.JTextAreaPlaceholder; | |
| 21 | import com.jsql.view.swing.util.I18nViewUtil; | |
| 22 | import com.jsql.view.swing.util.MediatorHelper; | |
| 23 | import com.jsql.view.swing.util.UiUtil; | |
| 24 | import org.apache.commons.lang3.StringUtils; | |
| 25 | import org.apache.logging.log4j.LogManager; | |
| 26 | import org.apache.logging.log4j.Logger; | |
| 27 | ||
| 28 | import javax.swing.*; | |
| 29 | import java.awt.*; | |
| 30 | import java.awt.event.*; | |
| 31 | import java.util.Locale; | |
| 32 | import java.util.ResourceBundle; | |
| 33 | ||
| 34 | /** | |
| 35 | * A dialog displaying current locale translation percentage. | |
| 36 | */ | |
| 37 | public class DialogTranslate extends JDialog { | |
| 38 | | |
| 39 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
| 40 | ||
| 41 | /** | |
| 42 | * Button receiving focus. | |
| 43 | */ | |
| 44 | private final JButton buttonSend = new JButton(I18nViewUtil.valueByKey("TRANSLATION_SEND")); | |
| 45 | ||
| 46 | private Language languageInto; | |
| 47 | private final JLabel labelTranslation = new JLabel(); | |
| 48 | private final JTextArea textToTranslate = new JPopupTextArea(new JTextAreaPlaceholder(I18nViewUtil.valueByKey("TRANSLATION_PLACEHOLDER"))).getProxy(); | |
| 49 | private final JProgressBar progressBarTranslation = new JProgressBar(); | |
| 50 | private String textBeforeChange = StringUtils.EMPTY; | |
| 51 | ||
| 52 | /** | |
| 53 | * Create a dialog for general information on project jsql. | |
| 54 | */ | |
| 55 | public DialogTranslate() { | |
| 56 | super(MediatorHelper.frame(), Dialog.ModalityType.MODELESS); | |
| 57 |
1
1. <init> : removed call to com/jsql/view/swing/dialog/DialogTranslate::setDefaultCloseOperation → NO_COVERAGE |
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
| 58 |
1
1. <init> : removed call to com/jsql/view/swing/dialog/DialogTranslate::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/DialogTranslate::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 | JPanel lastLine = this.initLastLine(); | |
| 68 | ||
| 69 |
1
1. <init> : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
this.labelTranslation.setBorder(UiUtil.BORDER_5PX); |
| 70 | var contentPane = this.getContentPane(); | |
| 71 |
1
1. <init> : removed call to java/awt/Container::add → NO_COVERAGE |
contentPane.add(this.labelTranslation, BorderLayout.NORTH); |
| 72 |
1
1. <init> : removed call to java/awt/Container::add → NO_COVERAGE |
contentPane.add(lastLine, BorderLayout.SOUTH); |
| 73 | ||
| 74 |
1
1. <init> : removed call to com/jsql/view/swing/dialog/DialogTranslate::initTextToTranslate → NO_COVERAGE |
this.initTextToTranslate(); |
| 75 | ||
| 76 |
1
1. <init> : removed call to java/awt/Container::add → NO_COVERAGE |
contentPane.add(new JScrollPane(this.textToTranslate), BorderLayout.CENTER); |
| 77 | } | |
| 78 | ||
| 79 | /** | |
| 80 | * Set back default setting for About frame. | |
| 81 | */ | |
| 82 | public final void initDialog(final Language language) { | |
| 83 |
1
1. initDialog : removed call to javax/swing/JProgressBar::setValue → NO_COVERAGE |
this.progressBarTranslation.setValue(0); |
| 84 |
1
1. initDialog : removed call to javax/swing/JProgressBar::setString → NO_COVERAGE |
this.progressBarTranslation.setString("Loading..."); |
| 85 | this.languageInto = language; | |
| 86 | ||
| 87 | var bundleInto = ResourceBundle.getBundle(I18nUtil.BASE_NAME, Locale.forLanguageTag(language.getLanguageTag())); | |
| 88 | var localeInto = Locale.forLanguageTag(language.getLanguageTag()); | |
| 89 |
1
1. initDialog : removed call to javax/swing/JLabel::setText → NO_COVERAGE |
this.labelTranslation.setText( // set language into |
| 90 | String.format( | |
| 91 | bundleInto.getString("TRANSLATION_TEXT"), | |
| 92 | localeInto.getDisplayLanguage(localeInto), | |
| 93 | localeInto.getDisplayLanguage(localeInto) | |
| 94 | ) | |
| 95 | ); | |
| 96 | ||
| 97 |
1
1. initDialog : removed call to javax/swing/JTextArea::setText → NO_COVERAGE |
this.textToTranslate.setText(null); |
| 98 |
1
1. initDialog : removed call to javax/swing/JTextArea::setEditable → NO_COVERAGE |
this.textToTranslate.setEditable(false); |
| 99 |
1
1. initDialog : removed call to javax/swing/JButton::setEnabled → NO_COVERAGE |
this.buttonSend.setEnabled(false); // will be enabled when done with GitHub |
| 100 | | |
| 101 | // Ubuntu Regular is compatible with all required languages, this includes Chinese and Arabic, | |
| 102 | // but it's not a technical Mono Font. | |
| 103 | // Only Monospaced works both for copy/paste utf8 foreign characters in JTextArea, and | |
| 104 | // it's a technical Mono Font. | |
| 105 |
1
1. initDialog : removed call to javax/swing/JTextArea::setFont → NO_COVERAGE |
this.textToTranslate.setFont(new Font( |
| 106 | UiUtil.FONT_NAME_MONOSPACED, | |
| 107 | Font.PLAIN, | |
| 108 | UIManager.getDefaults().getFont("TextField.font").getSize() | |
| 109 | )); | |
| 110 | | |
| 111 |
1
1. initDialog : removed call to com/jsql/view/swing/dialog/translate/WorkerTranslateInto::execute → NO_COVERAGE |
new WorkerTranslateInto(this).execute(); |
| 112 | ||
| 113 |
1
1. initDialog : removed call to com/jsql/view/swing/dialog/DialogTranslate::setIconImage → NO_COVERAGE |
this.setIconImage(language.getFlag().getImage()); |
| 114 |
1
1. initDialog : removed call to com/jsql/view/swing/dialog/DialogTranslate::setTitle → NO_COVERAGE |
this.setTitle(bundleInto.getString("TRANSLATION_TITLE") +" "+ localeInto.getDisplayLanguage(localeInto)); |
| 115 |
1
1. initDialog : negated conditional → NO_COVERAGE |
if (!this.isVisible()) { // Center the dialog |
| 116 |
1
1. initDialog : removed call to com/jsql/view/swing/dialog/DialogTranslate::setSize → NO_COVERAGE |
this.setSize(640, 460); |
| 117 |
1
1. initDialog : removed call to com/jsql/view/swing/dialog/DialogTranslate::setLocationRelativeTo → NO_COVERAGE |
this.setLocationRelativeTo(MediatorHelper.frame()); |
| 118 |
1
1. initDialog : removed call to javax/swing/JRootPane::setDefaultButton → NO_COVERAGE |
this.getRootPane().setDefaultButton(this.getButtonSend()); |
| 119 | } | |
| 120 |
1
1. initDialog : removed call to com/jsql/view/swing/dialog/DialogTranslate::setVisible → NO_COVERAGE |
this.setVisible(true); |
| 121 | } | |
| 122 | ||
| 123 | private JPanel initLastLine() { | |
| 124 | var lastLine = new JPanel(); | |
| 125 |
1
1. initLastLine : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE |
lastLine.setLayout(new BoxLayout(lastLine, BoxLayout.LINE_AXIS)); |
| 126 |
1
1. initLastLine : removed call to javax/swing/JPanel::setBorder → NO_COVERAGE |
lastLine.setBorder(UiUtil.BORDER_5PX); |
| 127 | | |
| 128 |
1
1. initLastLine : removed call to javax/swing/JButton::setToolTipText → NO_COVERAGE |
this.buttonSend.setToolTipText( |
| 129 | String.join( | |
| 130 | StringUtils.EMPTY, | |
| 131 | "<html>", | |
| 132 | "<b>Send your translation to the developer</b><br>", | |
| 133 | "Your translation will be integrated in the next version of jSQL", | |
| 134 | "</html>" | |
| 135 | ) | |
| 136 | ); | |
| 137 | | |
| 138 |
1
1. initLastLine : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE |
this.buttonSend.addActionListener(actionEvent -> { |
| 139 |
1
1. lambda$initLastLine$1 : negated conditional → NO_COVERAGE |
if (this.textToTranslate.getText().equals(this.textBeforeChange)) { |
| 140 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Nothing changed, translate a piece of text then click on Send"); | |
| 141 | return; | |
| 142 | } | |
| 143 | | |
| 144 | // Escape Markdown character # for h1 in .properties | |
| 145 | String clientDescription = this.textToTranslate.getText() | |
| 146 | .replace("\\\\", "\\\\\\\\") | |
| 147 | .replaceAll("(?m)^#","\\\\#") | |
| 148 | .replace("<", "\\<"); | |
| 149 | | |
| 150 |
1
1. lambda$initLastLine$1 : removed call to com/jsql/util/GitUtil::sendReport → NO_COVERAGE |
MediatorHelper.model().getMediatorUtils().getGitUtil().sendReport( |
| 151 | clientDescription, | |
| 152 | ShowOnConsole.YES, | |
| 153 | this.languageInto +" translation" | |
| 154 | ); | |
| 155 |
1
1. lambda$initLastLine$1 : removed call to com/jsql/view/swing/dialog/DialogTranslate::setVisible → NO_COVERAGE |
this.setVisible(false); |
| 156 | }); | |
| 157 | ||
| 158 |
1
1. initLastLine : removed call to com/jsql/view/swing/dialog/DialogTranslate::setLayout → NO_COVERAGE |
this.setLayout(new BorderLayout()); |
| 159 | | |
| 160 |
1
1. initLastLine : removed call to javax/swing/JProgressBar::setStringPainted → NO_COVERAGE |
this.progressBarTranslation.setStringPainted(true); |
| 161 |
1
1. initLastLine : removed call to javax/swing/JProgressBar::setValue → NO_COVERAGE |
this.progressBarTranslation.setValue(0); |
| 162 | | |
| 163 | lastLine.add(this.progressBarTranslation); | |
| 164 | lastLine.add(Box.createGlue()); | |
| 165 | lastLine.add(this.buttonSend); | |
| 166 |
1
1. initLastLine : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::initLastLine → NO_COVERAGE |
return lastLine; |
| 167 | } | |
| 168 | ||
| 169 | private void initTextToTranslate() { | |
| 170 |
1
1. initTextToTranslate : removed call to javax/swing/JTextArea::addMouseListener → NO_COVERAGE |
this.textToTranslate.addMouseListener(new MouseAdapter() { |
| 171 | @Override | |
| 172 | public void mousePressed(MouseEvent e) { | |
| 173 |
1
1. mousePressed : removed call to java/awt/event/MouseAdapter::mousePressed → NO_COVERAGE |
super.mousePressed(e); |
| 174 | DialogTranslate.this.textToTranslate.requestFocusInWindow(); | |
| 175 | } | |
| 176 | }); | |
| 177 |
1
1. initTextToTranslate : removed call to javax/swing/JTextArea::addFocusListener → NO_COVERAGE |
this.textToTranslate.addFocusListener(new FocusAdapter() { |
| 178 | @Override | |
| 179 | public void focusGained(FocusEvent focusEvent) { | |
| 180 |
1
1. focusGained : removed call to javax/swing/text/Caret::setVisible → NO_COVERAGE |
DialogTranslate.this.textToTranslate.getCaret().setVisible(true); |
| 181 |
1
1. focusGained : removed call to javax/swing/text/Caret::setSelectionVisible → NO_COVERAGE |
DialogTranslate.this.textToTranslate.getCaret().setSelectionVisible(true); |
| 182 | } | |
| 183 | }); | |
| 184 |
1
1. initTextToTranslate : removed call to javax/swing/JTextArea::setBorder → NO_COVERAGE |
this.textToTranslate.setBorder(UiUtil.BORDER_5PX); |
| 185 |
1
1. initTextToTranslate : removed call to javax/swing/JTextArea::setDragEnabled → NO_COVERAGE |
this.textToTranslate.setDragEnabled(true); |
| 186 |
1
1. initTextToTranslate : removed call to javax/swing/text/Caret::setBlinkRate → NO_COVERAGE |
this.textToTranslate.getCaret().setBlinkRate(500); |
| 187 |
1
1. initTextToTranslate : removed call to javax/swing/JTextArea::setComponentPopupMenu → NO_COVERAGE |
this.textToTranslate.setComponentPopupMenu(new JPopupMenuText(this.textToTranslate)); |
| 188 | } | |
| 189 | | |
| 190 | | |
| 191 | // Getter / Setter | |
| 192 | ||
| 193 | public Language getLanguageInto() { | |
| 194 |
1
1. getLanguageInto : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::getLanguageInto → NO_COVERAGE |
return this.languageInto; |
| 195 | } | |
| 196 | ||
| 197 | public String getTextBeforeChange() { | |
| 198 |
1
1. getTextBeforeChange : replaced return value with "" for com/jsql/view/swing/dialog/DialogTranslate::getTextBeforeChange → NO_COVERAGE |
return this.textBeforeChange; |
| 199 | } | |
| 200 | ||
| 201 | public void setTextBeforeChange(String textBeforeChange) { | |
| 202 | this.textBeforeChange = textBeforeChange; | |
| 203 | } | |
| 204 | ||
| 205 | public JButton getButtonSend() { | |
| 206 |
1
1. getButtonSend : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::getButtonSend → NO_COVERAGE |
return this.buttonSend; |
| 207 | } | |
| 208 | ||
| 209 | public JTextArea getTextToTranslate() { | |
| 210 |
1
1. getTextToTranslate : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::getTextToTranslate → NO_COVERAGE |
return this.textToTranslate; |
| 211 | } | |
| 212 | ||
| 213 | public JProgressBar getProgressBarTranslation() { | |
| 214 |
1
1. getProgressBarTranslation : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::getProgressBarTranslation → NO_COVERAGE |
return this.progressBarTranslation; |
| 215 | } | |
| 216 | } | |
Mutations | ||
| 57 |
1.1 |
|
| 58 |
1.1 |
|
| 60 |
1.1 |
|
| 61 |
1.1 |
|
| 69 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 74 |
1.1 |
|
| 76 |
1.1 |
|
| 83 |
1.1 |
|
| 84 |
1.1 |
|
| 89 |
1.1 |
|
| 97 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 105 |
1.1 |
|
| 111 |
1.1 |
|
| 113 |
1.1 |
|
| 114 |
1.1 |
|
| 115 |
1.1 |
|
| 116 |
1.1 |
|
| 117 |
1.1 |
|
| 118 |
1.1 |
|
| 120 |
1.1 |
|
| 125 |
1.1 |
|
| 126 |
1.1 |
|
| 128 |
1.1 |
|
| 138 |
1.1 |
|
| 139 |
1.1 |
|
| 150 |
1.1 |
|
| 155 |
1.1 |
|
| 158 |
1.1 |
|
| 160 |
1.1 |
|
| 161 |
1.1 |
|
| 166 |
1.1 |
|
| 170 |
1.1 |
|
| 173 |
1.1 |
|
| 177 |
1.1 |
|
| 180 |
1.1 |
|
| 181 |
1.1 |
|
| 184 |
1.1 |
|
| 185 |
1.1 |
|
| 186 |
1.1 |
|
| 187 |
1.1 |
|
| 194 |
1.1 |
|
| 198 |
1.1 |
|
| 206 |
1.1 |
|
| 210 |
1.1 |
|
| 214 |
1.1 |