Projekt

Obecné

Profil

Stáhnout (3.94 KB) Statistiky
| Větev: | Tag: | Revize:
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 = false;
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
		//tests
45
		//Converter thread = new Converter(this, new File("simple_arrays.out"), new File("bcha.json"));
46
		//thread.start();
47
	}
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
		Label inputFile = new Label("    Je�t� nebyl vybr�n ��dn� soubor...");
60
		inputFile.setStyle("-fx-font-style: italic;");
61
		VBox forInput = new VBox();
62
		forInput.getChildren().add(forInputFile);
63
		forInput.getChildren().add(inputFile);
64
		
65
		Label forOutputFile = new Label("V�stupn� soubor:");
66
		Label outputFile = new Label("    Je�t� nebyl vybr�n ��dn� soubor...");
67
		outputFile.setStyle("-fx-font-style: italic;");
68
		VBox forOutput = new VBox();
69
		forOutput.getChildren().add(forOutputFile);
70
		forOutput.getChildren().add(outputFile);
71
		
72
		convert = new Button("P�ev�st");
73
		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
		Button setInputFile = new Button("Vstupn� soubor");
81
		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
		Button setOutputFile = new Button("V�stupn� soubor");
95
		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
}
(2-2/4)