DialogTranslate.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.GitUtil.ShowOnConsole;
14
import com.jsql.util.LogLevelUtil;
15
import com.jsql.view.swing.dialog.translate.Language;
16
import com.jsql.view.swing.dialog.translate.SwingWorkerGithubLocale;
17
import com.jsql.view.swing.popupmenu.JPopupMenuText;
18
import com.jsql.view.swing.scrollpane.LightScrollPane;
19
import com.jsql.view.swing.text.JPopupTextArea;
20
import com.jsql.view.swing.text.JTextAreaPlaceholder;
21
import com.jsql.view.swing.ui.FlatButtonMouseAdapter;
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 javax.swing.plaf.basic.BasicProgressBarUI;
30
import java.awt.*;
31
import java.awt.event.*;
32
33
/**
34
 * A dialog displaying current locale translation percentage.
35
 */
36
public class DialogTranslate extends JDialog {
37
    
38
    /**
39
     * Log4j logger sent to view.
40
     */
41
    private static final Logger LOGGER = LogManager.getRootLogger();
42
43
    /**
44
     * Button receiving focus.
45
     */
46
    private final JButton buttonSend = new JButton("Send");
47
    
48
    private Language language;
49
    
50
    private final JLabel labelTranslation = new JLabel();
51
    
52
    // Contact info, use HTML text
53
    private final JTextArea textToTranslate = new JPopupTextArea(new JTextAreaPlaceholder("Text to translate")).getProxy();
54
    
55
    private final JProgressBar progressBarTranslation = new JProgressBar();
56
57
    private String textBeforeChange = StringUtils.EMPTY;
58
59
    /**
60
     * Create a dialog for general information on project jsql.
61
     */
62
    public DialogTranslate() {
63
        
64
        super(MediatorHelper.frame(), Dialog.ModalityType.MODELESS);
65
66 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogTranslate::setDefaultCloseOperation → NO_COVERAGE
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
67
68
        // Define a small and large app icon
69 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogTranslate::setIconImages → NO_COVERAGE
        this.setIconImages(UiUtil.getIcons());
70
71
        // Action for ESCAPE key
72 1 1. lambda$new$0 : removed call to com/jsql/view/swing/dialog/DialogTranslate::dispose → NO_COVERAGE
        ActionListener escapeListener = actionEvent -> DialogTranslate.this.dispose();
73
74 1 1. <init> : removed call to javax/swing/JRootPane::registerKeyboardAction → NO_COVERAGE
        this.getRootPane().registerKeyboardAction(
75
            escapeListener,
76
            KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
77
            JComponent.WHEN_IN_FOCUSED_WINDOW
78
        );
79
80
        JPanel lastLine = this.initializeLastLine();
81
82 1 1. <init> : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE
        this.labelTranslation.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
83
        var containerDialog = this.getContentPane();
84 1 1. <init> : removed call to java/awt/Container::add → NO_COVERAGE
        containerDialog.add(this.labelTranslation, BorderLayout.NORTH);
85 1 1. <init> : removed call to java/awt/Container::add → NO_COVERAGE
        containerDialog.add(lastLine, BorderLayout.SOUTH);
86
87 1 1. <init> : removed call to com/jsql/view/swing/dialog/DialogTranslate::initializeTextToTranslate → NO_COVERAGE
        this.initializeTextToTranslate();
88
89 1 1. <init> : removed call to java/awt/Container::add → NO_COVERAGE
        containerDialog.add(
90
            new LightScrollPane(1, 0, 1, 0, this.textToTranslate),
91
            BorderLayout.CENTER
92
        );
93
    }
94
95
    /**
96
     * Set back default setting for About frame.
97
     */
98
    public final void initializeDialog(final Language language) {
99
        
100 1 1. initializeDialog : removed call to javax/swing/JProgressBar::setValue → NO_COVERAGE
        this.progressBarTranslation.setValue(0);
101 1 1. initializeDialog : removed call to javax/swing/JProgressBar::setString → NO_COVERAGE
        this.progressBarTranslation.setString("Loading...");
102
        
103
        DialogTranslate.this.language = language;
104
        
105 1 1. initializeDialog : removed call to javax/swing/JLabel::setText → NO_COVERAGE
        this.labelTranslation.setText(
106
            String.join(
107
                "",
108
                "<html>",
109
                "<b>Contribute and translate parts of jSQL Injection into ",
110
                language.toString(),
111
                "</b><br>",
112
                "Help the community and translate some buttons, menus, tabs and tooltips into ",
113
                language.toString(),
114
                ", ",
115
                "then click on Send to forward your changes to the developer on GitHub.<br>",
116
                "<i>E.g. for French, change <b>CONTEXT_MENU_COPY = Copy</b> to <b>CONTEXT_MENU_COPY = Copier</b>, then click on Send. The list only displays what needs to be translated ",
117
                "and is updated as soon as the developer processes your request.</i>",
118
                "</html>"
119
            )
120
        );
121 1 1. initializeDialog : removed call to javax/swing/JLabel::setIcon → NO_COVERAGE
        this.labelTranslation.setIcon(language.getFlag());
122 1 1. initializeDialog : removed call to javax/swing/JLabel::setIconTextGap → NO_COVERAGE
        this.labelTranslation.setIconTextGap(8);
123
        
124 1 1. initializeDialog : removed call to com/jsql/view/swing/dialog/DialogTranslate::setTitle → NO_COVERAGE
        DialogTranslate.this.setTitle("Translate to "+ language);
125 1 1. initializeDialog : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
        this.textToTranslate.setText(null);
126 1 1. initializeDialog : removed call to javax/swing/JTextArea::setEditable → NO_COVERAGE
        this.textToTranslate.setEditable(false);
127 1 1. initializeDialog : removed call to javax/swing/JButton::setEnabled → NO_COVERAGE
        this.buttonSend.setEnabled(false);
128
        
129
        // Ubuntu Regular is compatible with all required languages, this includes Chinese and Arabic,
130
        // but it's not a technical Mono Font.
131
        // Only Monospaced works both for copy/paste utf8 foreign characters in JTextArea and
132
        // it's a technical Mono Font.
133 1 1. initializeDialog : removed call to javax/swing/JTextArea::setFont → NO_COVERAGE
        this.textToTranslate.setFont(new Font(
134
            UiUtil.FONT_NAME_MONOSPACED,
135
            Font.PLAIN,
136
            UIManager.getDefaults().getFont("TextField.font").getSize()
137
        ));
138
        
139
        LOGGER.log(LogLevelUtil.CONSOLE_DEFAULT, "Loading text to translate into {}...", () -> language);
140
        
141 1 1. initializeDialog : removed call to com/jsql/view/swing/dialog/translate/SwingWorkerGithubLocale::execute → NO_COVERAGE
        new SwingWorkerGithubLocale(this).execute();
142
    }
143
144
    private JPanel initializeLastLine() {
145
        
146
        var lastLine = new JPanel();
147 1 1. initializeLastLine : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE
        lastLine.setLayout(new BoxLayout(lastLine, BoxLayout.LINE_AXIS));
148 1 1. initializeLastLine : removed call to javax/swing/JPanel::setBorder → NO_COVERAGE
        lastLine.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
149
        
150 1 1. initializeLastLine : removed call to javax/swing/JButton::setContentAreaFilled → NO_COVERAGE
        this.buttonSend.setContentAreaFilled(false);
151 1 1. initializeLastLine : removed call to javax/swing/JButton::setBorder → NO_COVERAGE
        this.buttonSend.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8));
152 1 1. initializeLastLine : removed call to javax/swing/JButton::setBackground → NO_COVERAGE
        this.buttonSend.setBackground(UiUtil.COLOR_FOCUS_GAINED);
153 1 1. initializeLastLine : removed call to javax/swing/JButton::setToolTipText → NO_COVERAGE
        this.buttonSend.setToolTipText(
154
            String.join(
155
                "",
156
                "<html>",
157
                "<b>Send your translation to the developer</b><br>",
158
                "Your translation will be integrated in the next version of jSQL",
159
                "</html>"
160
            )
161
        );
162
        
163 1 1. initializeLastLine : removed call to javax/swing/JButton::addMouseListener → NO_COVERAGE
        this.buttonSend.addMouseListener(new FlatButtonMouseAdapter(this.buttonSend));
164
        
165 1 1. initializeLastLine : removed call to javax/swing/JButton::addActionListener → NO_COVERAGE
        this.buttonSend.addActionListener(actionEvent -> {
166
            
167 1 1. lambda$initializeLastLine$2 : negated conditional → NO_COVERAGE
            if (this.textToTranslate.getText().equals(this.textBeforeChange)) {
168
                
169
                LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Nothing changed, translate a piece of text then click on Send");
170
                return;
171
            }
172
            
173
            // Escape Markdown character # for h1 in .properties
174
            String clientDescription = this.textToTranslate
175
                .getText()
176
                .replace("\\\\", "\\\\\\\\")
177
                .replaceAll("(?m)^#","\\\\#")
178
                .replace("<", "\\<");
179
              
180 1 1. lambda$initializeLastLine$2 : removed call to com/jsql/util/GitUtil::sendReport → NO_COVERAGE
            MediatorHelper.model().getMediatorUtils().getGitUtil().sendReport(
181
                clientDescription,
182
                ShowOnConsole.YES,
183
                DialogTranslate.this.language +" translation"
184
            );
185 1 1. lambda$initializeLastLine$2 : removed call to com/jsql/view/swing/dialog/DialogTranslate::setVisible → NO_COVERAGE
            DialogTranslate.this.setVisible(false);
186
        });
187
188 1 1. initializeLastLine : removed call to com/jsql/view/swing/dialog/DialogTranslate::setLayout → NO_COVERAGE
        this.setLayout(new BorderLayout());
189
        
190 1 1. initializeLastLine : removed call to javax/swing/JProgressBar::setUI → NO_COVERAGE
        this.progressBarTranslation.setUI(new BasicProgressBarUI());
191 1 1. initializeLastLine : removed call to javax/swing/JProgressBar::setOpaque → NO_COVERAGE
        this.progressBarTranslation.setOpaque(false);
192 1 1. initializeLastLine : removed call to javax/swing/JProgressBar::setStringPainted → NO_COVERAGE
        this.progressBarTranslation.setStringPainted(true);
193 1 1. initializeLastLine : removed call to javax/swing/JProgressBar::setValue → NO_COVERAGE
        this.progressBarTranslation.setValue(0);
194
        
195
        lastLine.add(this.progressBarTranslation);
196
        lastLine.add(Box.createGlue());
197
        lastLine.add(this.buttonSend);
198
        
199 1 1. initializeLastLine : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::initializeLastLine → NO_COVERAGE
        return lastLine;
200
    }
201
202
    private void initializeTextToTranslate() {
203
        
204 1 1. initializeTextToTranslate : removed call to javax/swing/JTextArea::addMouseListener → NO_COVERAGE
        this.textToTranslate.addMouseListener(new MouseAdapter() {
205
            
206
            @Override
207
            public void mousePressed(MouseEvent e) {
208
                
209 1 1. mousePressed : removed call to java/awt/event/MouseAdapter::mousePressed → NO_COVERAGE
                super.mousePressed(e);
210
                DialogTranslate.this.textToTranslate.requestFocusInWindow();
211
            }
212
        });
213
214 1 1. initializeTextToTranslate : removed call to javax/swing/JTextArea::addFocusListener → NO_COVERAGE
        this.textToTranslate.addFocusListener(new FocusAdapter() {
215
            
216
            @Override
217
            public void focusGained(FocusEvent arg0) {
218
                
219 1 1. focusGained : removed call to javax/swing/text/Caret::setVisible → NO_COVERAGE
                DialogTranslate.this.textToTranslate.getCaret().setVisible(true);
220 1 1. focusGained : removed call to javax/swing/text/Caret::setSelectionVisible → NO_COVERAGE
                DialogTranslate.this.textToTranslate.getCaret().setSelectionVisible(true);
221
            }
222
        });
223
224 1 1. initializeTextToTranslate : removed call to javax/swing/JTextArea::setBorder → NO_COVERAGE
        this.textToTranslate.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
225 1 1. initializeTextToTranslate : removed call to javax/swing/JTextArea::setDragEnabled → NO_COVERAGE
        this.textToTranslate.setDragEnabled(true);
226 1 1. initializeTextToTranslate : removed call to javax/swing/text/Caret::setBlinkRate → NO_COVERAGE
        this.textToTranslate.getCaret().setBlinkRate(500);
227
228 1 1. initializeTextToTranslate : removed call to javax/swing/JTextArea::setComponentPopupMenu → NO_COVERAGE
        this.textToTranslate.setComponentPopupMenu(new JPopupMenuText(this.textToTranslate));
229
    }
230
    
231
    
232
    // Getter / Setter
233
234
    public Language getLanguage() {
235 1 1. getLanguage : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::getLanguage → NO_COVERAGE
        return this.language;
236
    }
237
238
    public void setLanguage(Language language) {
239
        this.language = language;
240
    }
241
242
    public String getTextBeforeChange() {
243 1 1. getTextBeforeChange : replaced return value with "" for com/jsql/view/swing/dialog/DialogTranslate::getTextBeforeChange → NO_COVERAGE
        return this.textBeforeChange;
244
    }
245
246
    public void setTextBeforeChange(String textBeforeChange) {
247
        this.textBeforeChange = textBeforeChange;
248
    }
249
250
    public JButton getButtonSend() {
251 1 1. getButtonSend : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::getButtonSend → NO_COVERAGE
        return this.buttonSend;
252
    }
253
254
    public JLabel getLabelTranslation() {
255 1 1. getLabelTranslation : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::getLabelTranslation → NO_COVERAGE
        return this.labelTranslation;
256
    }
257
258
    public JTextArea getTextToTranslate() {
259 1 1. getTextToTranslate : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::getTextToTranslate → NO_COVERAGE
        return this.textToTranslate;
260
    }
261
262
    public JProgressBar getProgressBarTranslation() {
263 1 1. getProgressBarTranslation : replaced return value with null for com/jsql/view/swing/dialog/DialogTranslate::getProgressBarTranslation → NO_COVERAGE
        return this.progressBarTranslation;
264
    }
265
}

Mutations

66

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

69

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

72

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

74

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

82

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

84

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

85

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

87

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

89

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

100

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

101

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

105

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

121

1.1
Location : initializeDialog
Killed by : none
removed call to javax/swing/JLabel::setIcon → NO_COVERAGE

122

1.1
Location : initializeDialog
Killed by : none
removed call to javax/swing/JLabel::setIconTextGap → NO_COVERAGE

124

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

125

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

126

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

127

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

133

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

141

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

147

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

148

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

150

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

151

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

152

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

153

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

163

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

165

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

167

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

180

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

185

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

188

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

190

1.1
Location : initializeLastLine
Killed by : none
removed call to javax/swing/JProgressBar::setUI → NO_COVERAGE

191

1.1
Location : initializeLastLine
Killed by : none
removed call to javax/swing/JProgressBar::setOpaque → NO_COVERAGE

192

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

193

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

199

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

204

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

209

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

214

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

219

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

220

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

224

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

225

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

226

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

228

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

235

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

243

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

251

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

255

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

259

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

263

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.16.1