Skip to content

Commit ab6ec0b

Browse files
committed
Code tabs automatically resize when new ones are opened. Changed some node label texts.
1 parent 5cfe0fe commit ab6ec0b

File tree

8 files changed

+56
-32
lines changed

8 files changed

+56
-32
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ private void analyseSolutions() {
121121
for (Exercise exercise : exercises) {
122122
// Finds the average solution length for this exercise
123123
exercise.findAverageSolutionSourceCodeLength();
124-
System.out.println(exercise.getName() + " - " + exercise.getAverageSolutionSourceCodeLength() + " source codes");
124+
System.out.println("\n" + exercise.getName() + " - Average length of source codes: " + exercise.getAverageSolutionSourceCodeLength() );
125125
if (preprocessSourceCode){
126126
exercise.findAverageSolutionPreprocessedCodeLength();
127-
System.out.println(exercise.getName() + " - " + exercise.getAverageSolutionPreprocessedCodeLength() + " preprocessed codes");
128-
System.out.println("Preprocessing removed on average " + Math.round(exercise.getAverageSolutionSourceCodeLength()
129-
- exercise.getAverageSolutionPreprocessedCodeLength()) + " characters per solution for exercise " + exercise.getName());
127+
System.out.println(exercise.getName() + " - Average length of preprocessed codes: " + exercise.getAverageSolutionPreprocessedCodeLength());
128+
System.out.println(exercise.getName() + " - Preprocessing removed on average " + Math.round(exercise.getAverageSolutionSourceCodeLength()
129+
- exercise.getAverageSolutionPreprocessedCodeLength()) + " characters per solution");
130130
}
131131

132132
// If user chose a custom similarity threshold then it is used, otherwise it is calculated
@@ -147,6 +147,7 @@ private void analyseSolutions() {
147147
* @param exercise the {@code Exercise} on which the comparison is performed
148148
*/
149149
private void compareSolutions(Exercise exercise) {
150+
System.out.println("\nSimilar pairs for " + exercise.getName() + ":");
150151
List<Solution> solutions = exercise.getSolutions();
151152
for (int i = 0, solutionCount = solutions.size(); i < solutionCount; i++) {
152153
Solution solution1 = solutions.get(i);
@@ -157,8 +158,8 @@ private void compareSolutions(Exercise exercise) {
157158
solution1.addSimilarSolution(solution2);
158159
solution2.addSimilarSolution(solution1);
159160
similarSolutionPairs.add(new SimilarSolutionPair(similarity, solution1, solution2));
160-
System.out.println(solution1.getExerciseName() + ": " + solution1.getAuthor() + ", " +
161-
solution2.getAuthor() + " - " + String.format("%.1f%%", similarity * 100));
161+
System.out.println("\t" + String.format("%.1f%%", similarity * 100) + "\t" +
162+
solution1.getAuthor() + ", " + solution2.getAuthor() );
162163
}
163164
analysedSolutionPairsCount++;
164165
updateAnalysingProgress();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void calculateSimilarityThreshold() {
7979
lengthMultiplier = averageSolutionLength / 100;
8080

8181
similarityThreshold = Math.pow(0.985, lengthMultiplier);
82-
System.out.println(similarityThreshold);
82+
System.out.println(name + " - Used similarity threshold: " +similarityThreshold);
8383
}
8484

8585
}

src/main/java/ee/ut/similaritydetector/ui/components/AccordionTableView.java

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

33
import javafx.beans.binding.Bindings;
4-
import javafx.scene.control.SelectionMode;
5-
import javafx.scene.control.TableColumn;
6-
import javafx.scene.control.TableView;
7-
import javafx.scene.control.TitledPane;
4+
import javafx.scene.control.*;
85
import javafx.scene.control.cell.PropertyValueFactory;
96
import javafx.scene.layout.AnchorPane;
107
import ee.ut.similaritydetector.backend.SimilarSolutionCluster;
@@ -65,10 +62,12 @@ public AccordionTableView(SimilarSolutionCluster cluster) {
6562
// To remove empty rows from the bottom of the table we have to set fixed cell size
6663
tableView.setFixedCellSize(cellSize);
6764
tableView.prefHeightProperty().bind(Bindings.size(tableView.getItems()).multiply(tableView.getFixedCellSize()).add(1));
68-
tableView.minHeight(cellSize + 2);
65+
tableView.minHeight(cellSize + 1);
6966

70-
// TitledPane header and content
67+
// TitledPane header
7168
this.setText(cluster.getName());
69+
70+
// TitledPane's content
7271
this.setContent(anchorPane);
7372

7473
// TitledPane restrictions

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

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

3+
import ee.ut.similaritydetector.backend.Analyser;
34
import javafx.application.Platform;
45
import javafx.beans.binding.Bindings;
56
import javafx.fxml.FXML;
@@ -23,6 +24,7 @@ public class CodeViewController {
2324

2425
private final List<AccordionTableView> clusterPanes;
2526
private final List<TableView<SimilarSolutionPair>> clusterTables;
27+
private Analyser analyser;
2628

2729
private static CodeViewController instance;
2830

@@ -36,8 +38,6 @@ public class CodeViewController {
3638
@FXML
3739
private MenuItem closeAllTabsMenuItem;
3840

39-
private List<SimilarSolutionCluster> clusters;
40-
4141
private final List<CodePaneController> openCodePanes;
4242

4343

@@ -52,18 +52,18 @@ public static CodeViewController getInstance() {
5252
return instance;
5353
}
5454

55-
public void setClusters(List<SimilarSolutionCluster> clusters) {
56-
this.clusters = clusters;
55+
public void setAnalyser(Analyser analyser) {
56+
this.analyser = analyser;
5757
}
5858

5959
public void addCodePane(CodePaneController codePaneController) {
60-
openCodePanes.add(codePaneController);
61-
codeSplitPane.getItems().add(codePaneController.getRoot());
60+
Platform.runLater(() -> openCodePanes.add(codePaneController));
61+
Platform.runLater(() -> codeSplitPane.getItems().add(codePaneController.getRoot()));
6262
}
6363

6464
public void removeCodePane(CodePaneController codePaneController) {
65-
openCodePanes.remove(codePaneController);
66-
codeSplitPane.getItems().remove(codePaneController.getRoot());
65+
Platform.runLater(() -> openCodePanes.remove(codePaneController));
66+
Platform.runLater(() -> codeSplitPane.getItems().remove(codePaneController.getRoot()));
6767
}
6868

6969
public List<CodePaneController> getOpenCodePanes() {
@@ -89,7 +89,7 @@ private void initialize() {
8989
* Creates the {@code AccordionTableView} elements from each {@code SimilarSolutionCluster} and adds to the view.
9090
*/
9191
public void createClusterItems() {
92-
for (SimilarSolutionCluster cluster : clusters) {
92+
for (SimilarSolutionCluster cluster : analyser.getSimilarSolutionClusters()) {
9393
AccordionTableView solutionClusterItem = new AccordionTableView(cluster);
9494
VBox.setVgrow(solutionClusterItem, Priority.NEVER);
9595
clusterPanes.add(solutionClusterItem);
@@ -136,6 +136,14 @@ private void addCustomListener(TableView<SimilarSolutionPair> tableView) {
136136
row.setOnMouseClicked(event -> {
137137
if (event.getClickCount() == 2 && !row.isEmpty()) {
138138
SimilarSolutionPair solutionPair = row.getItem();
139+
// Closes opened tabs that are from a different cluster than this solution pair
140+
SimilarSolutionCluster currentCluster = analyser.getSimilarSolutionClusters().stream().filter(cluster ->
141+
cluster.getSolutionPairs().contains(solutionPair)).findAny().get();
142+
for (CodePaneController codeTab : openCodePanes) {
143+
if (! currentCluster.containsSolution(codeTab.getSolution())) {
144+
closeCodeTab(codeTab);
145+
}
146+
}
139147
// First solution
140148
try {
141149
createNewCodePane(solutionPair.getFirstSolution());
@@ -150,6 +158,8 @@ private void addCustomListener(TableView<SimilarSolutionPair> tableView) {
150158
e.printStackTrace();
151159
showSolutionCodeReadingErrorAlert(solutionPair.getFirstSolution());
152160
}
161+
// Resize code panes equally
162+
Platform.runLater(this::resizeCodePanes);
153163
}
154164
});
155165
return row;
@@ -219,9 +229,14 @@ public void resizeClusterTableColumns() {
219229
* @param table the {@code TableView} to be resized
220230
*/
221231
private void resizeTableColumns(TableView<?> table) {
232+
table.applyCss();
233+
table.layout();
222234
double columnsWidth = table.getColumns().stream().mapToDouble(TableColumnBase::getWidth).sum();
223235
double tableWidth = table.getWidth();
224-
System.out.println(columnsWidth + " - " + tableWidth);
236+
if (tableWidth == 0) {
237+
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
238+
return;
239+
}
225240
if (tableWidth > columnsWidth) {
226241
tableWidth -= 4; // So random horizontal scroll doesn't happen
227242
TableColumn<?, ?> col1 = table.getColumns().get(0);
@@ -247,23 +262,32 @@ private void resizeTableColumns(TableView<?> table) {
247262
}
248263
}
249264

265+
private void resizeCodePanes() {
266+
int nrPanes = openCodePanes.size();
267+
double[] dividerPositions = new double[nrPanes];
268+
double dividerSize = 1.0 / nrPanes;
269+
for (int i = 0; i < nrPanes; i++) {
270+
dividerPositions[i] = dividerSize * (i + 1);
271+
}
272+
Platform.runLater(() -> codeSplitPane.setDividerPositions(dividerPositions));
273+
}
274+
250275
/**
251276
* Closes the given code tab
252277
*
253278
* @param codePaneController {@link CodePaneController}
254279
*/
255280
public void closeCodeTab(CodePaneController codePaneController) {
256281
removeCodePane(codePaneController);
257-
codeSplitPane.getItems().remove(codePaneController.getRoot());
258282
}
259283

260284
/**
261285
* Closes all code tabs that are currently open.
262286
*/
263287
@FXML
264288
private void closeAllCodeTabs() {
265-
openCodePanes.clear();
266-
codeSplitPane.getItems().clear();
289+
Platform.runLater(openCodePanes::clear);
290+
Platform.runLater(() -> codeSplitPane.getItems().clear());
267291
}
268292

269293
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private void openCodeView() throws IOException {
132132
"/ee/ut/similaritydetector/fxml/code_view.fxml"));
133133
Parent root = loader.load();
134134
CodeViewController controller = loader.getController();
135-
controller.setClusters(analyser.getSimilarSolutionClusters());
135+
controller.setAnalyser(analyser);
136136
Platform.runLater(controller::createClusterItems);
137137
double width = MainViewController.stage.getScene().getWidth() > 1200 ?
138138
MainViewController.stage.getScene().getWidth() : 1200;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
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="60.0" prefWidth="175.0" text="Choose the solutions ZIP" />
72+
<Button fx:id="fileChooseButton" alignment="CENTER" mnemonicParsing="false" onAction="#chooseFile" prefHeight="60.0" prefWidth="175.0" text="Choose solutions ZIP" />
7373
<VBox fx:id="fileArea" alignment="CENTER" prefHeight="200.0" prefWidth="100.0" StackPane.alignment="BOTTOM_CENTER" spacing="-10">
7474
<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" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<TableColumn fx:id="suspiciousSolutionsColumn" editable="false" prefWidth="100.0" sortType="DESCENDING" styleClass="number-column, column-header-alignment-center" text="Suspicious&#10;solutions" />
6262
<TableColumn fx:id="similarPairsColumn" editable="false" prefWidth="100.0" sortType="DESCENDING" styleClass="number-column" text="Similar pairs " />
6363
<TableColumn fx:id="similarClustersColumn" editable="false" prefWidth="100.0" sortType="DESCENDING" styleClass="number-column" text="Similar clusters" />
64-
<TableColumn fx:id="similarityThresholdColumn" editable="false" prefWidth="100.0" sortType="DESCENDING" styleClass="number-column, column-header-alignment-center" text="Similarity &#10;threshold&#10;" />
64+
<TableColumn fx:id="similarityThresholdColumn" editable="false" prefWidth="100.0" sortType="DESCENDING" styleClass="number-column, column-header-alignment-center" text="Used similarity &#10;threshold" />
6565
</columns>
6666
<VBox.margin>
6767
<Insets left="75.0" right="75.0" />

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
-fx-opacity: 0;
2929
}
3030

31-
.titledPane>.title {
32-
-fx-pref-height: 50; /* increase available area */
31+
.titledPane-multiline > .title {
32+
-fx-pref-height: 40; /* increase available area */
3333
-fx-alignment: top-center;
3434
-fx-padding: 4 4 4 30; /* increase left padding to align text */
3535
}
3636

37-
#titledPane>.title>.arrow-button {
37+
.titledPane-multiline > .title > .arrow-button {
3838
-fx-translate-x: -20; /* move back arrow, which is also subject to the padding */
3939
}

0 commit comments

Comments
 (0)