Projekt

Obecné

Profil

Stáhnout (1.78 KB) Statistiky
| Větev: | Tag: | Revize:
1
import javafx.application.Platform;
2
import javafx.geometry.Rectangle2D;
3
import javafx.scene.control.Alert;
4
import javafx.scene.control.Alert.AlertType;
5
import javafx.stage.Screen;
6
import javafx.stage.Window;
7

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