1
|
package deserialize;
|
2
|
import com.sun.javafx.stage.StageHelper;
|
3
|
|
4
|
import javafx.application.Platform;
|
5
|
import javafx.geometry.Rectangle2D;
|
6
|
import javafx.scene.control.Alert;
|
7
|
import javafx.scene.control.Alert.AlertType;
|
8
|
import javafx.stage.Screen;
|
9
|
|
10
|
public class Report {
|
11
|
|
12
|
private static final int HEIGHT = 200;
|
13
|
private static final int WIDTH = 500;
|
14
|
|
15
|
private static void setPosition(Alert alert) {
|
16
|
if (StageHelper.getStages() != null && StageHelper.getStages().size() != 0) {
|
17
|
if (Screen.getPrimary() != null && Screen.getPrimary().getVisualBounds() != null) {
|
18
|
Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
|
19
|
alert.setX((primScreenBounds.getWidth() - WIDTH - 20) / 2);
|
20
|
alert.setY((primScreenBounds.getHeight() - HEIGHT - 20) / 3);
|
21
|
}
|
22
|
alert.initOwner(StageHelper.getStages().get(StageHelper.getStages().size() - 1));
|
23
|
}
|
24
|
}
|
25
|
|
26
|
private static Alert createAlert(AlertType type, String title, String header, String content) {
|
27
|
Alert alert = new Alert(type);
|
28
|
alert.setResizable(true);
|
29
|
alert.getDialogPane().setPrefWidth(WIDTH);
|
30
|
alert.setTitle(title);
|
31
|
alert.setHeaderText(header);
|
32
|
alert.setContentText(content);
|
33
|
setPosition(alert);
|
34
|
return alert;
|
35
|
}
|
36
|
|
37
|
public static void error(String title, String header, String content) {
|
38
|
Platform.runLater(()->{
|
39
|
createAlert(AlertType.WARNING, title, header, content).showAndWait();
|
40
|
});
|
41
|
}
|
42
|
|
43
|
public static void info(String title, String header, String content) {
|
44
|
Platform.runLater(()->{
|
45
|
createAlert(AlertType.INFORMATION, title, header, content).showAndWait();
|
46
|
});
|
47
|
}
|
48
|
|
49
|
public static boolean confirm(String title, String header, String content) {
|
50
|
Alert alert = createAlert(AlertType.CONFIRMATION, title, header, content);
|
51
|
alert.showAndWait();
|
52
|
if (alert.getResult().getText().equals("OK")) {
|
53
|
return true;
|
54
|
} else {
|
55
|
return false;
|
56
|
}
|
57
|
}
|
58
|
|
59
|
}
|