1
|
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
|
testing = true;
|
34
|
}
|
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
|
}
|
44
|
|
45
|
private Scene createScene() {
|
46
|
return new Scene(createLayout());
|
47
|
}
|
48
|
|
49
|
private Parent createLayout() {
|
50
|
VBox layout = new VBox();
|
51
|
layout.setPadding(new Insets(10.0));
|
52
|
layout.setSpacing(10.0);
|
53
|
|
54
|
Label forInputFile = new Label("Soubor k deserializaci:");
|
55
|
Label inputFile = new Label(" Ještě nebyl vybrán žádný soubor...");
|
56
|
inputFile.setStyle("-fx-font-style: italic;");
|
57
|
VBox forInput = new VBox();
|
58
|
forInput.getChildren().add(forInputFile);
|
59
|
forInput.getChildren().add(inputFile);
|
60
|
|
61
|
Label forOutputFile = new Label("Výstupní soubor:");
|
62
|
Label outputFile = new Label(" Ještě nebyl vybrán žádný soubor...");
|
63
|
outputFile.setStyle("-fx-font-style: italic;");
|
64
|
VBox forOutput = new VBox();
|
65
|
forOutput.getChildren().add(forOutputFile);
|
66
|
forOutput.getChildren().add(outputFile);
|
67
|
|
68
|
convert = new Button("Převést");
|
69
|
convert.setOnAction(event -> {
|
70
|
// a.data a b.data are customers test files (binary files).
|
71
|
convert.setDisable(true);
|
72
|
Converter thread = new Converter(this, testing ? new File("a.data") : this.inputFile, testing ? new File("results.json") : this.outputFile);
|
73
|
thread.start();
|
74
|
});
|
75
|
convert.setDisable(!testing);
|
76
|
Button setInputFile = new Button("Vstupní soubor");
|
77
|
setInputFile.setOnAction(event -> {
|
78
|
FileChooser fCh = new FileChooser();
|
79
|
fCh.setInitialDirectory(new File("."));
|
80
|
// The input can be a zip file or file without a specific extension -> file chooser without extension filters...
|
81
|
// fCh.getExtensionFilters().add(new FileChooser.ExtensionFilter("Binary Files", "*.out"));
|
82
|
File file = fCh.showOpenDialog(stage);
|
83
|
if (file != null) {
|
84
|
this.inputFile = file;
|
85
|
inputFile.setText(this.inputFile == null ? "" : this.inputFile.getAbsolutePath());
|
86
|
inputFile.setStyle("-fx-font-weight: bold;");
|
87
|
convert.setDisable(this.inputFile == null || this.outputFile == null);
|
88
|
}
|
89
|
});
|
90
|
Button setOutputFile = new Button("Výstupní soubor");
|
91
|
setOutputFile.setOnAction(event -> {
|
92
|
FileChooser fCh = new FileChooser();
|
93
|
fCh.setInitialDirectory(new File("."));
|
94
|
fCh.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON Files", "*.json"));
|
95
|
File file = fCh.showSaveDialog(stage);
|
96
|
if (file != null) {
|
97
|
this.outputFile = file;
|
98
|
outputFile.setText(this.outputFile == null ? "" : this.outputFile.getAbsolutePath());
|
99
|
outputFile.setStyle("-fx-font-weight: bold;");
|
100
|
convert.setDisable(this.inputFile == null || this.outputFile == null);
|
101
|
}
|
102
|
});
|
103
|
HBox footer = new HBox();
|
104
|
footer.setSpacing(10.0);
|
105
|
footer.setAlignment(Pos.CENTER_RIGHT);
|
106
|
footer.getChildren().add(setInputFile);
|
107
|
footer.getChildren().add(setOutputFile);
|
108
|
footer.getChildren().add(convert);
|
109
|
|
110
|
layout.getChildren().add(forInput);
|
111
|
layout.getChildren().add(forOutput);
|
112
|
layout.getChildren().add(footer);
|
113
|
|
114
|
return layout;
|
115
|
}
|
116
|
|
117
|
public void convertIsComplete() {
|
118
|
convert.setDisable(false);
|
119
|
}
|
120
|
|
121
|
}
|