forked from MasterFlomaster1/JFXCrypto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileEncryptionPageController.java
More file actions
135 lines (115 loc) · 3.9 KB
/
Copy pathFileEncryptionPageController.java
File metadata and controls
135 lines (115 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package GUI.Controllers;
import GUI.Main.GUI;
import GUI.Main.AlertDialog;
import Utils.PathCutter;
import Cipher.CurrentCipher;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.DragEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import java.io.File;
import java.util.List;
public class FileEncryptionPageController {
@FXML
public Button browseInFile;
@FXML
public Button browseOutFile;
@FXML
public Text fileInPath;
@FXML
public Text fileOutPath;
@FXML
public Text dragNDropText;
private boolean fileInReady = false;
private boolean fileOutReady = false;
private File in;
private File out;
public ImageView menuImage;
public void encryptButtonAction() {
if ((fileInReady && fileOutReady) && in!=out) {
CurrentCipher.encryptFile(in, out);
} else if (fileInReady && out!=null) {
if (AlertDialog.showConfirmDialog("Do you want to rewrite \"" + out.getName() + "\" ?")) {
CurrentCipher.encryptFile(in, out);
fileInReady = false;
fileOutReady = false;
}
} else if (fileInReady) {
AlertDialog.showWarning("Select result file path");
} else if (fileOutReady) {
AlertDialog.showWarning("Choose file you want to encrypt/decrypt");
}
}
public void decryptButtonAction() {
if ((fileInReady && fileOutReady) && in!=out) {
CurrentCipher.decryptFile(in, out);
} else if (fileInReady && out!=null) {
if (AlertDialog.showConfirmDialog("Do you want to rewrite \"" + out.getName() + "\" ?")) {
CurrentCipher.decryptFile(in, out);
fileInReady = false;
fileOutReady = false;
} else if (fileInReady) {
AlertDialog.showWarning("Select result file path");
} else if (fileOutReady) {
AlertDialog.showWarning("Choose file you want to encrypt/decrypt");
}
}
}
public void browseInButtonAction() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Select file");
in = fileChooser.showOpenDialog(browseInFile.getScene().getWindow());
//Debug here
if (in==null) {
fileInReady = false;
return;
}
hideDragDropText();
fileInPath.setText(PathCutter.cutPath(in.getPath()));
fileInReady = true;
}
public void browseOutButtonAction() {
FileChooser save = new FileChooser();
save.setTitle("Save file");
out = save.showSaveDialog(browseOutFile.getScene().getWindow());
//Debug here
if (out==null) {
fileOutReady = false;
return;
}
fileOutPath.setText(PathCutter.cutPath(out.getPath()));
fileOutReady = true;
}
public void handleDragOver(DragEvent event) {
if (event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.ANY);
}
}
public void handleDragDropped(DragEvent event) {
List<File> files = event.getDragboard().getFiles();
in = files.get(0);
hideDragDropText();
fileInPath.setText(PathCutter.cutPath(in.getPath()));
fileInReady = true;
}
private void hideDragDropText() {
dragNDropText.setVisible(false);
}
private void enableDragDropText() {
dragNDropText.setDisable(true);
}
public void menuButtonPressed() {
menuImage.setImage(new Image("/menu2.png"));
GUI.menuButtonPressed();
}
public void menuButtonRelease() {
menuImage.setImage(new Image("/menu1.png"));
}
public void mouseEntered() {
menuImage.setImage(new Image("/menu2.png"));
}
}