11package ee .ut .similaritydetector .ui .controllers ;
22
33import ee .ut .similaritydetector .ui .SimilarityDetectorLauncher ;
4+ import ee .ut .similaritydetector .ui .utils .UserPreferences ;
45import javafx .animation .*;
56import javafx .application .Platform ;
67import javafx .fxml .FXML ;
2122import java .io .IOException ;
2223import java .math .BigDecimal ;
2324import java .math .RoundingMode ;
25+ import java .util .ResourceBundle ;
2426
2527import static ee .ut .similaritydetector .ui .utils .AlertUtils .showAlert ;
2628import static ee .ut .similaritydetector .ui .utils .AlertUtils .showAndWaitAlert ;
2729
2830public 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