Skip to content

Commit 5cfe0fe

Browse files
committed
Possibility to start a new analysis from results view.
Zip image hover color and default color change. Analysis time is measured.
1 parent 9fe2926 commit 5cfe0fe

File tree

6 files changed

+81
-19
lines changed

6 files changed

+81
-19
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class Analyser extends Task<Void> {
2222

2323
private int totalSolutionPairsCount;
2424
private int analysedSolutionPairsCount;
25+
private double analysisDuration;
2526

2627
private final MainViewController mainViewController;
2728

@@ -66,6 +67,14 @@ public int getAnalysedSolutionPairsCount() {
6667
return analysedSolutionPairsCount;
6768
}
6869

70+
public double getAnalysisDuration() {
71+
return analysisDuration;
72+
}
73+
74+
public void setAnalysisDuration(double analysisDuration) {
75+
this.analysisDuration = analysisDuration;
76+
}
77+
6978
@Override
7079
protected Void call() {
7180
updateProgress(0,100);

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import javax.swing.*;
2020
import java.io.File;
2121
import java.io.IOException;
22+
import java.math.BigDecimal;
23+
import java.math.RoundingMode;
2224

2325
import static ee.ut.similaritydetector.ui.utils.AlertUtils.showAlert;
2426
import static ee.ut.similaritydetector.ui.utils.AlertUtils.showAndWaitAlert;
@@ -135,9 +137,14 @@ private void startAnalysis() {
135137
//Starts the backend similarity analysis on a new thread
136138
Thread analyserThread = new Thread(analyser, "analyser_thread");
137139
analyserThread.setDaemon(true);
140+
long startTime = System.nanoTime();
138141
analyserThread.start();
139142

140143
analyser.setOnSucceeded(workerStateEvent -> {
144+
long endTime = System.nanoTime();
145+
BigDecimal duration = new BigDecimal(Double.toString(((double) endTime - startTime) / 1000000000));
146+
duration = duration.setScale(1, RoundingMode.HALF_UP);
147+
analyser.setAnalysisDuration(duration.doubleValue());
141148
if (analyser.getSimilarSolutionPairs().size() == 0) {
142149
showAlert("No similar solutions were detected",
143150
"Try lowering the similarity threshold or check if the ZIP structure is correct",
@@ -181,7 +188,7 @@ private void hideOptions(){
181188
/**
182189
* Animates the opening of options pane.
183190
*/
184-
private void openOptions(){
191+
public void openOptions(){
185192
Duration duration = Duration.millis(300);
186193
Timeline timeline = new Timeline(
187194
new KeyFrame(duration,
@@ -224,9 +231,10 @@ private void openResultsView(Analyser analyser) throws IOException {
224231
Parent root = loader.load();
225232
ResultsViewController controller = loader.getController();
226233
controller.setAnalyser(analyser);
234+
controller.setMainViewController(this);
227235
Platform.runLater(controller::readStatistics);
228236

229-
Scene resultsViewScene = new Scene(root, 800, 600);
237+
Scene resultsViewScene = new Scene(root, MainViewController.stage.getScene().getWidth(), MainViewController.stage.getScene().getHeight());
230238
stage.setScene(resultsViewScene);
231239
stage.setTitle("Source code similarity detector - Results - " + analyser.getZipDirectory().getName());
232240

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
public class ResultsViewController {
2222

2323
private Analyser analyser;
24+
private MainViewController mainViewController;
2425

2526
@FXML
2627
private MenuBarController menuBarController;
@@ -32,6 +33,8 @@ public class ResultsViewController {
3233
private Label totalSolutionsLabel;
3334
@FXML
3435
private Label solutionPairsLabel;
36+
@FXML
37+
private Label analysisDurationLabel;
3538

3639
@FXML
3740
private TableView<ExerciseStatistics> exerciseStatisticsTable;
@@ -50,6 +53,8 @@ public class ResultsViewController {
5053

5154
@FXML
5255
private Button viewClustersButton;
56+
@FXML
57+
private Button runNewAnalysisButton;
5358

5459

5560
public ResultsViewController() {
@@ -59,6 +64,10 @@ public void setAnalyser(Analyser analyser) {
5964
this.analyser = analyser;
6065
}
6166

67+
public void setMainViewController(MainViewController mainViewController) {
68+
this.mainViewController = mainViewController;
69+
}
70+
6271
@FXML
6372
private void initialize() {
6473
}
@@ -70,6 +79,7 @@ public void readStatistics() {
7079
title.setText("Results - " + analyser.getZipDirectory().getName());
7180
totalSolutionsLabel.setText(String.valueOf(analyser.getExercises().stream().mapToInt(Exercise::getSolutionCount).sum()));
7281
solutionPairsLabel.setText(String.valueOf(analyser.getAnalysedSolutionPairsCount()));
82+
analysisDurationLabel.setText(analyser.getAnalysisDuration() + " s");
7383
fillExerciseStatisticsTable();
7484
// To remove empty rows from the bottom of the table we have to set fixed cell
7585
int cellSize = 30;
@@ -92,7 +102,7 @@ private void fillExerciseStatisticsTable() {
92102
/**
93103
* If no similar solutions were found then the cluster viewing button is not interactable.
94104
*/
95-
public void toggleClusterButtonUsability() {
105+
protected void toggleClusterButtonUsability() {
96106
if (analyser.getSimilarSolutionClusters() != null && analyser.getSimilarSolutionClusters().size() != 0) {
97107
viewClustersButton.setDisable(false);
98108
}
@@ -117,15 +127,18 @@ private void viewClusters() {
117127
*
118128
* @throws IOException if the code view could not be opened
119129
*/
120-
public void openCodeView() throws IOException {
130+
private void openCodeView() throws IOException {
121131
FXMLLoader loader = new FXMLLoader(getClass().getResource(
122132
"/ee/ut/similaritydetector/fxml/code_view.fxml"));
123133
Parent root = loader.load();
124134
CodeViewController controller = loader.getController();
125135
controller.setClusters(analyser.getSimilarSolutionClusters());
126136
Platform.runLater(controller::createClusterItems);
127-
128-
Scene codeViewScene = new Scene(root, 1200, 700);
137+
double width = MainViewController.stage.getScene().getWidth() > 1200 ?
138+
MainViewController.stage.getScene().getWidth() : 1200;
139+
double height = MainViewController.stage.getScene().getHeight() > 700 ?
140+
MainViewController.stage.getScene().getHeight() : 700;
141+
Scene codeViewScene = new Scene(root, width, height);
129142
Stage newWindow = new Stage();
130143
newWindow.setMinWidth(800);
131144
newWindow.setMinHeight(600);
@@ -144,4 +157,31 @@ public void openCodeView() throws IOException {
144157
Platform.runLater(controller::resizeClusterTableColumns);
145158
}
146159

160+
@FXML
161+
private void runNewAnalysis() {
162+
try {
163+
openMainView();
164+
} catch (IOException e) {
165+
e.printStackTrace();
166+
showAndWaitAlert("Could not navigate back to main view", "Try restarting the application", Alert.AlertType.ERROR);
167+
}
168+
}
169+
170+
private void openMainView() throws IOException {
171+
FXMLLoader loader = new FXMLLoader(getClass().getResource("/ee/ut/similaritydetector/fxml/main_view.fxml"));
172+
Parent root = loader.load();
173+
loader.setController(mainViewController);
174+
MainViewController.stage.setTitle("Source code similarity detector");
175+
Scene scene = new Scene(root, MainViewController.stage.getScene().getWidth(), MainViewController.stage.getScene().getHeight());
176+
MainViewController.stage.setScene(scene);
177+
// Icon from: https://icons-for-free.com/spy-131964785010048699/ [25.03.2021]
178+
MainViewController.stage.getIcons().add(new Image(getClass().getResourceAsStream("/ee/ut/similaritydetector/img/app_icon.png")));
179+
180+
// Persists dark theme if it was activated before
181+
Platform.runLater(menuBarController::persistCurrentTheme);
182+
183+
mainViewController.openOptions();
184+
MainViewController.stage.show();
185+
}
186+
147187
}

src/main/resources/ee/ut/similaritydetector/fxml/main_view.fxml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
<AnchorPane VBox.vgrow="ALWAYS">
7070
<children>
7171
<StackPane prefHeight="150.0" prefWidth="200.0" AnchorPane.bottomAnchor="-125.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
72-
<Button fx:id="fileChooseButton" alignment="CENTER" mnemonicParsing="false" onAction="#chooseFile" prefHeight="50.0" prefWidth="120.0" text="Choose a ZIP file" />
73-
<VBox fx:id="fileArea" alignment="CENTER" prefHeight="200.0" prefWidth="100.0" StackPane.alignment="BOTTOM_CENTER">
74-
<ImageView id="zipImg" fx:id="zipImg" fitHeight="100.0" fitWidth="60.0" onMouseClicked="#chooseFile" pickOnBounds="true" preserveRatio="true">
72+
<Button fx:id="fileChooseButton" alignment="CENTER" mnemonicParsing="false" onAction="#chooseFile" prefHeight="60.0" prefWidth="175.0" text="Choose the solutions ZIP" />
73+
<VBox fx:id="fileArea" alignment="CENTER" prefHeight="200.0" prefWidth="100.0" StackPane.alignment="BOTTOM_CENTER" spacing="-10">
74+
<ImageView id="zipImg" fx:id="zipImg" fitHeight="125.0" fitWidth="80.0" onMouseClicked="#chooseFile" pickOnBounds="true" preserveRatio="true">
7575
<Image url="/ee/ut/similaritydetector/img/zip_icon.png" />
7676
</ImageView>
7777
<Label fx:id="fileNameLabel" alignment="CENTER" contentDisplay="CENTER" onMouseClicked="#chooseFile" prefHeight="50.0" prefWidth="100.0" textAlignment="CENTER" wrapText="true" />

src/main/resources/ee/ut/similaritydetector/fxml/results_view.fxml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<children>
3232
<Label text="Total solutions:" />
3333
<Label text="Solution pairs analysed:" />
34+
<Label layoutX="310.0" layoutY="37.0" text="Analysis duration:" />
3435
</children>
3536
</VBox>
3637
</children>
@@ -41,6 +42,7 @@
4142
<children>
4243
<Label fx:id="totalSolutionsLabel" />
4344
<Label fx:id="solutionPairsLabel" />
45+
<Label fx:id="analysisDurationLabel" layoutX="10.0" layoutY="51.0" />
4446
</children>
4547
<padding>
4648
<Insets right="50.0" />
@@ -73,11 +75,15 @@
7375
<Insets />
7476
</VBox.margin>
7577
</VBox>
76-
<Button fx:id="viewClustersButton" alignment="CENTER" contentDisplay="CENTER" disable="true" maxHeight="50.0" minHeight="50.0" mnemonicParsing="false" onAction="#viewClusters" prefHeight="50.0" prefWidth="175.0" text="View similar pairs &amp; clusters" textAlignment="CENTER" VBox.vgrow="ALWAYS">
78+
<HBox alignment="TOP_CENTER" spacing="50.0" VBox.vgrow="ALWAYS">
79+
<children>
80+
<Button fx:id="viewClustersButton" alignment="CENTER" contentDisplay="CENTER" disable="true" maxHeight="65.0" minHeight="55.0" mnemonicParsing="false" onAction="#viewClusters" prefHeight="60.0" prefWidth="175.0" text="View similar pairs &amp; clusters" textAlignment="CENTER" />
81+
<Button fx:id="runNewAnalysisButton" alignment="CENTER" contentDisplay="CENTER" maxHeight="65.0" minHeight="55.0" mnemonicParsing="false" onAction="#runNewAnalysis" prefHeight="60.0" prefWidth="175.0" text="Run new analysis" textAlignment="CENTER" />
82+
</children>
7783
<VBox.margin>
78-
<Insets bottom="50.0" />
84+
<Insets bottom="0.0" />
7985
</VBox.margin>
80-
</Button>
86+
</HBox>
8187
</children>
8288
</VBox>
8389
</children>

src/main/resources/ee/ut/similaritydetector/style/main_view_style.scss

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44

55
#fileNameLabel:hover {
66
-fx-cursor: hand;
7-
-fx-text-fill: #0388fc;
7+
-fx-text-fill: #1eaefc;
88
}
99

10-
#zipImg:hover {
11-
-fx-cursor: hand;
10+
#zipImg {
11+
-fx-image: url(/ee/ut/similaritydetector/img/zip_icon_light.png);
1212
}
1313

14-
#fileArea {
15-
14+
#zipImg:hover {
15+
-fx-cursor: hand;
16+
-fx-image: url(/ee/ut/similaritydetector/img/zip_icon_hover.png);
1617
}
17-
18-

0 commit comments

Comments
 (0)