Skip to content

Commit ffa9f43

Browse files
committed
Added Estonian as default application language.
Added possibility to change the application language.
1 parent ae21cf0 commit ffa9f43

24 files changed

+399
-111
lines changed

src/main/java/ee/ut/similaritydetector/backend/Analyser.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package ee.ut.similaritydetector.backend;
22

3+
import ee.ut.similaritydetector.ui.utils.UserPreferences;
34
import javafx.concurrent.Task;
45
import ee.ut.similaritydetector.ui.controllers.MainViewController;
56

67
import java.io.File;
78
import java.util.ArrayList;
89
import java.util.List;
10+
import java.util.ResourceBundle;
911
import java.util.concurrent.atomic.AtomicInteger;
1012

1113
import static ee.ut.similaritydetector.backend.LevenshteinDistance.normalisedLevenshteinSimilarity;
@@ -99,11 +101,12 @@ private void updateGeneratingProgress(int done, int total) {
99101
}
100102

101103
public void startAnalysis() {
102-
mainViewController.setProgressText("Processing solutions...");
104+
ResourceBundle langBundle = ResourceBundle.getBundle(MainViewController.resourceBundlePath, UserPreferences.getInstance().getLocale());
105+
mainViewController.setProgressText(langBundle.getString("processing_solutions"));
103106
SolutionParser solutionParser = new SolutionParser(zipDirectory, preprocessSourceCode, anonymousResults, this);
104107
exercises = solutionParser.parseSolutions();
105108

106-
mainViewController.setProgressText("Analysing solutions...");
109+
mainViewController.setProgressText(langBundle.getString("analysing_solutions"));
107110
analyseSolutions();
108111

109112
// Performing the pairwise comparison of solutions for each exercise
@@ -262,7 +265,8 @@ else if (similarSolutionClusters.stream().anyMatch(c -> c.containsSolution(sol1)
262265
* Generates syntax highlighting HTML for each suspicious solution.
263266
*/
264267
private void generateSyntaxHighlightingHTML() {
265-
mainViewController.setProgressText("Preparing results...");
268+
ResourceBundle langBundle = ResourceBundle.getBundle(MainViewController.resourceBundlePath, UserPreferences.getInstance().getLocale());
269+
mainViewController.setProgressText(langBundle.getString("preparing_results"));
266270
int total = similarSolutionClusters.stream().mapToInt(cluster -> cluster.getSolutions().size()).sum();
267271
AtomicInteger done = new AtomicInteger();
268272
similarSolutionClusters.forEach(cluster -> cluster.getSolutions().forEach(solution -> {

src/main/java/ee/ut/similaritydetector/ui/SimilarityDetectorLauncher.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import javafx.stage.Stage;
1313
import javafx.stage.WindowEvent;
1414
import ee.ut.similaritydetector.ui.controllers.MainViewController;
15-
import ee.ut.similaritydetector.ui.utils.UserData;
15+
import ee.ut.similaritydetector.ui.utils.UserPreferences;
1616
import java.io.File;
1717
import java.io.IOException;
18-
import java.net.URL;
1918
import java.util.Optional;
19+
import java.util.ResourceBundle;
2020

2121
import static ee.ut.similaritydetector.backend.SolutionParser.outputDirectoryPath;
2222

@@ -38,17 +38,18 @@ public void start(Stage stage) throws Exception {
3838
* @throws IOException if fails to load main_view.fxml
3939
*/
4040
public void loadMainView(Stage stage) throws IOException {
41-
URL fxmlLocation = this.getClass().getResource("/ee/ut/similaritydetector/fxml/main_view.fxml");
42-
Parent root = FXMLLoader.load(fxmlLocation);
41+
ResourceBundle langBundle = ResourceBundle.getBundle(MainViewController.resourceBundlePath, UserPreferences.getInstance().getLocale());
42+
FXMLLoader loader = new FXMLLoader(getClass().getResource("/ee/ut/similaritydetector/fxml/main_view.fxml"));
43+
loader.setResources(langBundle);
44+
Parent root = loader.load();
4345
stage.setMinWidth(800);
4446
stage.setMinHeight(600);
45-
stage.setTitle("Source code similarity detector");
47+
stage.setTitle(langBundle.getString("app_name"));
4648
Scene scene = new Scene(root, 800, 600);
4749
stage.setScene(scene);
4850
// Icon from: https://icons-for-free.com/spy-131964785010048699/ [25.03.2021]
4951
stage.getIcons().add(new Image(getClass().getResourceAsStream("/ee/ut/similaritydetector/img/app_icon.png")));
5052
stage.show();
51-
UserData.getInstance().setDarkMode(false);
5253
stage.setOnCloseRequest(this::showExitConfirmationAlert);
5354
MainViewController.stage = stage;
5455
}
@@ -61,16 +62,19 @@ public void loadMainView(Stage stage) throws IOException {
6162
private void showExitConfirmationAlert(WindowEvent windowEvent) {
6263
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
6364
alert.setTitle("");
64-
alert.setHeaderText("Are you sure you want to exit?");
65+
ResourceBundle langBundle = ResourceBundle.getBundle(MainViewController.resourceBundlePath, UserPreferences.getInstance().getLocale());
66+
alert.setHeaderText(langBundle.getString("exit_msg"));
6567
//alert.setContentText("Results might not have been saved.");
6668
ButtonType exitButtonType = ButtonType.OK;
67-
Button exitButton = (Button) alert.getDialogPane().lookupButton(ButtonType.OK);
68-
exitButton.setText("Exit");
69+
Button exitButton = (Button) alert.getDialogPane().lookupButton(exitButtonType);
70+
exitButton.setText(langBundle.getString("exit"));
71+
Button cancelButton = (Button) alert.getDialogPane().lookupButton(ButtonType.CANCEL);
72+
cancelButton.setText(langBundle.getString("cancel"));
6973

7074
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
7175
stage.getIcons().add(new Image(getClass().getResourceAsStream("/ee/ut/similaritydetector/img/app_icon.png")));
7276
// Dark mode
73-
if (UserData.getInstance().isDarkMode()) {
77+
if (UserPreferences.getInstance().isDarkMode()) {
7478
alert.getDialogPane().getStylesheets().add(String.valueOf(this.getClass().getResource(
7579
"/ee/ut/similaritydetector/style/dark_mode.scss")));
7680
}
@@ -119,9 +123,6 @@ private static boolean deleteDirectory(File directory) {
119123
*/
120124
@Override
121125
public void stop() throws Exception {
122-
/* TODO: siin teha asjad, mida sulgemisel vaja oleks:
123-
resources kausta kustutamine?,
124-
salvestada äkki ümber sarnased tööd kuhugi? */
125126
deleteOutputFiles();
126127
super.stop();
127128
}

src/main/java/ee/ut/similaritydetector/ui/controllers/CodePaneController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ee.ut.similaritydetector.ui.controllers;
22

33
import ee.ut.similaritydetector.backend.Solution;
4-
import ee.ut.similaritydetector.ui.utils.UserData;
4+
import ee.ut.similaritydetector.ui.utils.UserPreferences;
55
import javafx.fxml.FXML;
66
import javafx.scene.control.*;
77
import javafx.scene.layout.AnchorPane;
@@ -55,7 +55,7 @@ private void onTabClosed() {
5555
*/
5656
public void loadSolutionSourceCode() throws Exception {
5757
codeTab.setText(solution.getAuthor() + " - " + solution.getExerciseName());
58-
if (UserData.getInstance().isDarkMode()) {
58+
if (UserPreferences.getInstance().isDarkMode()) {
5959
loadDarkThemeHTML();
6060
} else {
6161
loadLightThemeHTML();

src/main/java/ee/ut/similaritydetector/ui/controllers/CodeViewController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ee.ut.similaritydetector.ui.controllers;
22

33
import ee.ut.similaritydetector.backend.Analyser;
4+
import ee.ut.similaritydetector.ui.utils.UserPreferences;
45
import javafx.animation.Interpolator;
56
import javafx.animation.KeyFrame;
67
import javafx.animation.KeyValue;
@@ -24,11 +25,14 @@
2425
import java.io.IOException;
2526
import java.util.ArrayList;
2627
import java.util.List;
28+
import java.util.ResourceBundle;
2729

2830
import static ee.ut.similaritydetector.ui.utils.AlertUtils.showAndWaitAlert;
2931

3032
public class CodeViewController {
3133

34+
public static final String resourceBundlePath = "ee.ut.similaritydetector.language.code_view";
35+
3236
private final List<AccordionTableView> clusterPanes;
3337
private final List<TableView<SimilarSolutionPair>> clusterTables;
3438
private Analyser analyser;
@@ -267,7 +271,8 @@ private void createNewCodePane(Solution solution) throws IOException {
267271
* @param solution {@link Solution}
268272
*/
269273
private void showSolutionCodeReadingErrorAlert(Solution solution) {
270-
showAndWaitAlert("Could not load solution code",
274+
ResourceBundle langBundle = ResourceBundle.getBundle(resourceBundlePath, UserPreferences.getInstance().getLocale());
275+
showAndWaitAlert(langBundle.getString("error_msg1"),
271276
solution.getExerciseName() + " - " + solution.getAuthor(),
272277
Alert.AlertType.ERROR);
273278
}

src/main/java/ee/ut/similaritydetector/ui/controllers/MainViewController.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ee.ut.similaritydetector.ui.controllers;
22

33
import ee.ut.similaritydetector.ui.SimilarityDetectorLauncher;
4+
import ee.ut.similaritydetector.ui.utils.UserPreferences;
45
import javafx.animation.*;
56
import javafx.application.Platform;
67
import javafx.fxml.FXML;
@@ -21,12 +22,15 @@
2122
import java.io.IOException;
2223
import java.math.BigDecimal;
2324
import java.math.RoundingMode;
25+
import java.util.ResourceBundle;
2426

2527
import static ee.ut.similaritydetector.ui.utils.AlertUtils.showAlert;
2628
import static ee.ut.similaritydetector.ui.utils.AlertUtils.showAndWaitAlert;
2729

2830
public class MainViewController {
2931

32+
public static final String resourceBundlePath = "ee.ut.similaritydetector.language.main_view";
33+
3034
public static Stage stage;
3135
public static File zipDirectory;
3236

@@ -82,9 +86,9 @@ private void initialize() {
8286

8387
// Tooltip rules
8488
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
85-
toolTipManager.setDismissDelay(10000);
86-
toolTipManager.setInitialDelay(600);
87-
toolTipManager.setReshowDelay(300);
89+
toolTipManager.setDismissDelay(20000);
90+
toolTipManager.setInitialDelay(500);
91+
toolTipManager.setReshowDelay(100);
8892

8993
// Persists dark theme if it was activated before
9094
Platform.runLater(menuBarController::persistCurrentTheme);
@@ -96,7 +100,8 @@ private void initialize() {
96100
@FXML
97101
private void chooseFile() {
98102
FileChooser fileChooser = new FileChooser();
99-
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("ZIP files (*.zip)", "*.zip");
103+
ResourceBundle langBundle = ResourceBundle.getBundle(resourceBundlePath, UserPreferences.getInstance().getLocale());
104+
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(langBundle.getString("zip_descriptor"), "*.zip");
100105
fileChooser.getExtensionFilters().add(extFilter);
101106
if (zipDirectory != null) {
102107
fileChooser.setInitialDirectory(zipDirectory.getParentFile());
@@ -135,7 +140,8 @@ private void startAnalysis() {
135140
}
136141
progressBar.progressProperty().bind(analyser.progressProperty());
137142
progressPercentageLabel.textProperty().bind(analyser.progressProperty().multiply(100).asString("%.0f%%"));
138-
setProgressText("Starting analysis...");
143+
ResourceBundle langBundle = ResourceBundle.getBundle(resourceBundlePath, UserPreferences.getInstance().getLocale());
144+
setProgressText(langBundle.getString("starting_analysis"));
139145

140146
//Starts the backend similarity analysis on a new thread
141147
Thread analyserThread = new Thread(analyser, "analyser_thread");
@@ -149,8 +155,8 @@ private void startAnalysis() {
149155
duration = duration.setScale(1, RoundingMode.HALF_UP);
150156
analyser.setAnalysisDuration(duration.doubleValue());
151157
if (analyser.getSimilarSolutionPairs().size() == 0) {
152-
showAlert("No similar solutions were detected",
153-
"Try lowering the similarity threshold or check if the ZIP structure is correct",
158+
showAlert(langBundle.getString("error_msg1"),
159+
langBundle.getString("context_msg1"),
154160
Alert.AlertType.INFORMATION);
155161
resetMainView();
156162
SimilarityDetectorLauncher.deleteOutputFiles();
@@ -160,16 +166,18 @@ private void startAnalysis() {
160166
openResultsView(analyser);
161167
} catch (IOException e) {
162168
e.printStackTrace();
163-
showAlert("Failed to load results",
164-
"Check your solutions ZIP structure and try again",
169+
showAlert(langBundle.getString("error_msg2"),
170+
langBundle.getString("context_msg2"),
165171
Alert.AlertType.ERROR);
166172
resetMainView();
167173
}
168174
});
169175

170176
analyser.setOnFailed(event -> {
171177
analyser.getException().printStackTrace();
172-
showAndWaitAlert("Analysis failed", analyser.getException().getMessage(), Alert.AlertType.ERROR);
178+
showAndWaitAlert(langBundle.getString("error_msg3"),
179+
langBundle.getString("context_msg2"),
180+
Alert.AlertType.ERROR);
173181
resetMainView();
174182
SimilarityDetectorLauncher.deleteOutputFiles();
175183
});
@@ -229,8 +237,9 @@ private void resetMainView() {
229237
*/
230238
@FXML
231239
private void openResultsView(Analyser analyser) throws IOException {
232-
FXMLLoader loader = new FXMLLoader(getClass().getResource(
233-
"/ee/ut/similaritydetector/fxml/results_view.fxml"));
240+
ResourceBundle langBundle = ResourceBundle.getBundle(ResultsViewController.resourceBundlePath, UserPreferences.getInstance().getLocale());
241+
FXMLLoader loader = new FXMLLoader(getClass().getResource("/ee/ut/similaritydetector/fxml/results_view.fxml"));
242+
loader.setResources(langBundle);
234243
Parent root = loader.load();
235244
ResultsViewController controller = loader.getController();
236245
controller.setAnalyser(analyser);
@@ -239,7 +248,7 @@ private void openResultsView(Analyser analyser) throws IOException {
239248

240249
Scene resultsViewScene = new Scene(root, MainViewController.stage.getScene().getWidth(), MainViewController.stage.getScene().getHeight());
241250
stage.setScene(resultsViewScene);
242-
stage.setTitle("Source code similarity detector - Results - " + analyser.getZipDirectory().getName());
251+
stage.setTitle(langBundle.getString("app_name") + " - " + langBundle.getString("results") + " - " + analyser.getZipDirectory().getName());
243252

244253
// Makes the "View clusters" button clickable if analysis found any clusters
245254
controller.toggleClusterButtonUsability();

0 commit comments

Comments
 (0)