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

Mutations

60

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

61

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

63

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

64

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

72

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

77

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

79

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

86

1.1
Location : initDialog
Killed by : none
removed call to javax/swing/JProgressBar::setValue → NO_COVERAGE

87

1.1
Location : initDialog
Killed by : none
removed call to javax/swing/JProgressBar::setString → NO_COVERAGE

92

1.1
Location : initDialog
Killed by : none
removed call to javax/swing/JLabel::setText → NO_COVERAGE

100

1.1
Location : initDialog
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

101

1.1
Location : initDialog
Killed by : none
removed call to javax/swing/JTextArea::setEditable → NO_COVERAGE

102

1.1
Location : initDialog
Killed by : none
removed call to javax/swing/JButton::setEnabled → NO_COVERAGE

108

1.1
Location : initDialog
Killed by : none
removed call to javax/swing/JTextArea::setFont → NO_COVERAGE

114

1.1
Location : initDialog
Killed by : none
removed call to com/jsql/view/swing/dialog/translate/WorkerTranslateInto::execute → NO_COVERAGE

116

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

117

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

118

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

119

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

120

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

121

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

123

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

128

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

129

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

131

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

141

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

142

1.1
Location : lambda$initLastLine$1
Killed by : none
negated conditional → NO_COVERAGE

153

1.1
Location : lambda$initLastLine$1
Killed by : none
removed call to com/jsql/util/GitUtil::sendReport → NO_COVERAGE

158

1.1
Location : lambda$initLastLine$1
Killed by : none
removed call to com/jsql/view/swing/dialog/DialogTranslate::setVisible → NO_COVERAGE

161

1.1
Location : initLastLine
Killed by : none
removed call to com/jsql/view/swing/dialog/DialogTranslate::setLayout → NO_COVERAGE

163

1.1
Location : initLastLine
Killed by : none
removed call to javax/swing/JProgressBar::setStringPainted → NO_COVERAGE

164

1.1
Location : initLastLine
Killed by : none
removed call to javax/swing/JProgressBar::setValue → NO_COVERAGE

169

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

173

1.1
Location : initTextToTranslate
Killed by : none
removed call to javax/swing/JTextArea::addMouseListener → NO_COVERAGE

176

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

180

1.1
Location : initTextToTranslate
Killed by : none
removed call to javax/swing/JTextArea::addFocusListener → NO_COVERAGE

183

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

184

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

187

1.1
Location : initTextToTranslate
Killed by : none
removed call to javax/swing/JTextArea::setBorder → NO_COVERAGE

188

1.1
Location : initTextToTranslate
Killed by : none
removed call to javax/swing/JTextArea::setDragEnabled → NO_COVERAGE

189

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

190

1.1
Location : initTextToTranslate
Killed by : none
removed call to javax/swing/JTextArea::setComponentPopupMenu → NO_COVERAGE

197

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

201

1.1
Location : getTextBeforeChange
Killed by : none
replaced return value with "" for com/jsql/view/swing/dialog/DialogTranslate::getTextBeforeChange → NO_COVERAGE

209

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

213

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

217

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

Active mutators

Tests examined


Report generated by PIT 1.19.1