-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoSavingDialog_23072018_MS.java
More file actions
183 lines (130 loc) · 5.45 KB
/
Copy pathAutoSavingDialog_23072018_MS.java
File metadata and controls
183 lines (130 loc) · 5.45 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package de.gsi.cs.co.ap.my_test_project.utils;
import java.io.File;
import javafx.beans.binding.Bindings;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
// for library loggers
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
// for application loggers
// import de.gsi.cs.co.ap.common.gui.elements.logger.AppLogger;
/**
* @author fschirru
*/
public class AutoSavingDialog {
// You can choose a logger (needed imports are given in the import section as comments):
// for libraries:
// private static final Logger LOGGER = LoggerFactory.getLogger(AutoSavingDialog.class);
// for applications:
// private static final AppLogger LOGGER = AppLogger.getLogger();
Stage autoSavingDialogStage;
private boolean destination_directory_isSelected;
String selected_directory;
final private TextField path_tf = new TextField("/home/rifr/scheidenb/lnx/magstat");
private static final AutoSavingDialog INSTANCE = new AutoSavingDialog();
public static AutoSavingDialog getInstance() {
return INSTANCE;
}
/**
*
*/
public AutoSavingDialog() {
autoSavingDialogStage = new Stage();
autoSavingDialogStage.setTitle("Set directory destination");
autoSavingDialogStage.setResizable(false);
autoSavingDialogStage.initModality(Modality.APPLICATION_MODAL);
final Group root = new Group();
final Scene scene = new Scene(root, 570, 90);
autoSavingDialogStage.setScene(scene);
final GridPane gridpane = new GridPane();
// gridpane.setPadding(new Insets(5));
gridpane.setHgap(10);
// gridpane.setVgap(10);
final Label path_lb = new Label("Path: ");
gridpane.add(path_lb, 0, 1);
// final TextField path_tf = new TextField("");
path_tf.setPrefWidth(500);
gridpane.add(path_tf, 1, 1);
final VBox vBox = new VBox();
vBox.setSpacing(15);
vBox.setPadding(new Insets(10, 10, 10, 10));
final ButtonBar button_bar = new ButtonBar();
final Button path_apply_bt = new Button("Apply");
path_apply_bt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent event) {
final File file = new File(path_tf.getText());
final boolean exists = file.exists();
if (exists) {
// It returns true if File or directory does exist
destination_directory_isSelected = true;
setSelectedDirectory(path_tf.getText());
// selected_directory = path_tf.getText();
// startDataRecording();
autoSavingDialogStage.close();
} else {
destination_directory_isSelected = false;
// autoSavingDialogStage.close();
final Alert alert = new Alert(AlertType.ERROR, "The directory selected does not exists!",
ButtonType.CANCEL);
alert.showAndWait();
if (alert.getResult() == ButtonType.CANCEL) {
autoSavingDialogStage.close();
// path_tf.clear();
path_tf.setText("/home/rifr/scheidenb/lnx/magstat");
alert.close();
}
}
}
});
path_apply_bt.disableProperty().bind(Bindings.isEmpty(path_tf.textProperty()));
final Button path_exit_bt = new Button("Close");
path_exit_bt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent event) {
autoSavingDialogStage.close();
destination_directory_isSelected = false;
setSelectedDirectory(null);
}
});
button_bar.getButtons().addAll(path_apply_bt, path_exit_bt);
vBox.getChildren().addAll(gridpane, button_bar);
root.getChildren().add(vBox);
path_exit_bt.requestFocus();
}
public Stage getAutoSavingDialogStage() {
return autoSavingDialogStage;
}
public boolean getDestination_directory_isSelected() {
return destination_directory_isSelected;
}
private void setSelectedDirectory(final String selectedDirectory) {
selected_directory = selectedDirectory;
}
public String getSelectedDirectory() {
return selected_directory;
}
public void setData() {
destination_directory_isSelected = false;
// path_tf.clear();
path_tf.setText("/home/rifr/scheidenb/lnx/magstat");
path_tf.requestFocus();
}
public boolean retrieveDestinationDirectoryisSelected() {
return destination_directory_isSelected;
}
}