1 |
03a2d08f
|
Michal Horký
|
import java.io.File;
|
2 |
|
|
|
3 |
|
|
import javafx.application.Application;
|
4 |
|
|
import javafx.geometry.Insets;
|
5 |
|
|
import javafx.geometry.Pos;
|
6 |
|
|
import javafx.scene.Parent;
|
7 |
|
|
import javafx.scene.Scene;
|
8 |
|
|
import javafx.scene.control.Button;
|
9 |
|
|
import javafx.scene.control.Label;
|
10 |
|
|
import javafx.scene.layout.HBox;
|
11 |
|
|
import javafx.scene.layout.VBox;
|
12 |
|
|
import javafx.stage.FileChooser;
|
13 |
|
|
import javafx.stage.Stage;
|
14 |
|
|
|
15 |
|
|
public class Deserializer extends Application {
|
16 |
|
|
|
17 |
|
|
private Stage stage;
|
18 |
|
|
private File inputFile;
|
19 |
|
|
private File outputFile;
|
20 |
|
|
|
21 |
|
|
Button convert;
|
22 |
|
|
|
23 |
|
|
// TODO delete after deserializer debugging is complete...
|
24 |
|
|
private boolean testing;
|
25 |
|
|
|
26 |
|
|
public static void main(String[] args) {
|
27 |
|
|
launch(args);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
@Override
|
31 |
|
|
public void init() throws Exception {
|
32 |
|
|
super.init();
|
33 |
e3d5fc53
|
@havlijan17
|
testing = false;
|
34 |
03a2d08f
|
Michal Horký
|
}
|
35 |
|
|
|
36 |
|
|
@Override
|
37 |
|
|
public void start(Stage stage) throws Exception {
|
38 |
|
|
this.stage = stage;
|
39 |
|
|
stage.setTitle("Java object universal deserializer");
|
40 |
|
|
stage.setScene(createScene());
|
41 |
|
|
stage.setMinWidth(400);
|
42 |
|
|
stage.show();
|
43 |
4bbee803
|
@havlijan17
|
|
44 |
|
|
//tests
|
45 |
f783f25c
|
@havlijan17
|
Converter thread = new Converter(this, new File("Deserializer/simple.out"), new File("Deserializer/bcha.json"));
|
46 |
13814aae
|
@havlijan17
|
thread.start();
|
47 |
03a2d08f
|
Michal Horký
|
}
|
48 |
|
|
|
49 |
|
|
private Scene createScene() {
|
50 |
|
|
return new Scene(createLayout());
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
private Parent createLayout() {
|
54 |
|
|
VBox layout = new VBox();
|
55 |
|
|
layout.setPadding(new Insets(10.0));
|
56 |
|
|
layout.setSpacing(10.0);
|
57 |
|
|
|
58 |
|
|
Label forInputFile = new Label("Soubor k deserializaci:");
|
59 |
b639237c
|
Michal Horký
|
Label inputFile = new Label(" Ještě nebyl vybrán žádný soubor...");
|
60 |
03a2d08f
|
Michal Horký
|
inputFile.setStyle("-fx-font-style: italic;");
|
61 |
|
|
VBox forInput = new VBox();
|
62 |
|
|
forInput.getChildren().add(forInputFile);
|
63 |
|
|
forInput.getChildren().add(inputFile);
|
64 |
|
|
|
65 |
b639237c
|
Michal Horký
|
Label forOutputFile = new Label("Výstupní soubor:");
|
66 |
|
|
Label outputFile = new Label(" Ještě nebyl vybrán žádný soubor...");
|
67 |
03a2d08f
|
Michal Horký
|
outputFile.setStyle("-fx-font-style: italic;");
|
68 |
|
|
VBox forOutput = new VBox();
|
69 |
|
|
forOutput.getChildren().add(forOutputFile);
|
70 |
|
|
forOutput.getChildren().add(outputFile);
|
71 |
|
|
|
72 |
b639237c
|
Michal Horký
|
convert = new Button("Převést");
|
73 |
03a2d08f
|
Michal Horký
|
convert.setOnAction(event -> {
|
74 |
|
|
// a.data a b.data are customers test files (binary files).
|
75 |
|
|
convert.setDisable(true);
|
76 |
|
|
Converter thread = new Converter(this, testing ? new File("a.data") : this.inputFile, testing ? new File("results.json") : this.outputFile);
|
77 |
|
|
thread.start();
|
78 |
|
|
});
|
79 |
|
|
convert.setDisable(!testing);
|
80 |
b639237c
|
Michal Horký
|
Button setInputFile = new Button("Vstupní soubor");
|
81 |
03a2d08f
|
Michal Horký
|
setInputFile.setOnAction(event -> {
|
82 |
|
|
FileChooser fCh = new FileChooser();
|
83 |
|
|
fCh.setInitialDirectory(new File("."));
|
84 |
|
|
// The input can be a zip file or file without a specific extension -> file chooser without extension filters...
|
85 |
|
|
// fCh.getExtensionFilters().add(new FileChooser.ExtensionFilter("Binary Files", "*.out"));
|
86 |
|
|
File file = fCh.showOpenDialog(stage);
|
87 |
|
|
if (file != null) {
|
88 |
|
|
this.inputFile = file;
|
89 |
|
|
inputFile.setText(this.inputFile == null ? "" : this.inputFile.getAbsolutePath());
|
90 |
|
|
inputFile.setStyle("-fx-font-weight: bold;");
|
91 |
|
|
convert.setDisable(this.inputFile == null || this.outputFile == null);
|
92 |
|
|
}
|
93 |
|
|
});
|
94 |
b639237c
|
Michal Horký
|
Button setOutputFile = new Button("Výstupní soubor");
|
95 |
03a2d08f
|
Michal Horký
|
setOutputFile.setOnAction(event -> {
|
96 |
|
|
FileChooser fCh = new FileChooser();
|
97 |
|
|
fCh.setInitialDirectory(new File("."));
|
98 |
|
|
fCh.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON Files", "*.json"));
|
99 |
|
|
File file = fCh.showSaveDialog(stage);
|
100 |
|
|
if (file != null) {
|
101 |
|
|
this.outputFile = file;
|
102 |
|
|
outputFile.setText(this.outputFile == null ? "" : this.outputFile.getAbsolutePath());
|
103 |
|
|
outputFile.setStyle("-fx-font-weight: bold;");
|
104 |
|
|
convert.setDisable(this.inputFile == null || this.outputFile == null);
|
105 |
|
|
}
|
106 |
|
|
});
|
107 |
|
|
HBox footer = new HBox();
|
108 |
|
|
footer.setSpacing(10.0);
|
109 |
|
|
footer.setAlignment(Pos.CENTER_RIGHT);
|
110 |
|
|
footer.getChildren().add(setInputFile);
|
111 |
|
|
footer.getChildren().add(setOutputFile);
|
112 |
|
|
footer.getChildren().add(convert);
|
113 |
|
|
|
114 |
|
|
layout.getChildren().add(forInput);
|
115 |
|
|
layout.getChildren().add(forOutput);
|
116 |
|
|
layout.getChildren().add(footer);
|
117 |
|
|
|
118 |
|
|
return layout;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
public void convertIsComplete() {
|
122 |
|
|
convert.setDisable(false);
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
}
|