Projekt

Obecné

Profil

Stáhnout (2.06 KB) Statistiky
| Větev: | Tag: | Revize:
1
import java.util.List;
2
import java.util.stream.Collectors;
3

    
4
import com.sun.javafx.stage.StageHelper;
5

    
6
import javafx.application.Platform;
7
import javafx.geometry.Rectangle2D;
8
import javafx.scene.control.Alert;
9
import javafx.scene.control.Alert.AlertType;
10
import javafx.stage.Screen;
11
import javafx.stage.Stage;
12
import javafx.stage.Window;
13

    
14
public class Report {
15
	
16
	private static final int HEIGHT = 200;
17
	private static final int WIDTH = 500;
18

    
19
	private static void setPosition(Alert alert) {
20
		List<Stage> stages = Window.getWindows().stream()
21
            .filter(Stage.class::isInstance)
22
            .map(Stage.class::cast)
23
			.collect(Collectors.toList());
24
			//instead of StageHelper.getStages();
25

    
26
		if (stages != null && stages.size() != 0) {
27
			if (Screen.getPrimary() != null && Screen.getPrimary().getVisualBounds() != null) {
28
				Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
29
				alert.setX((primScreenBounds.getWidth() - WIDTH - 20) / 2);
30
		        alert.setY((primScreenBounds.getHeight() - HEIGHT - 20) / 3);
31
			}
32
			alert.initOwner(stages.get(stages.size() - 1));
33
		}
34
	}
35
	
36
	private static Alert createAlert(AlertType type, String title, String header, String content) {
37
		Alert alert = new Alert(type);
38
		alert.setResizable(true);
39
		alert.getDialogPane().setPrefWidth(WIDTH);
40
		alert.setTitle(title);
41
		alert.setHeaderText(header);
42
		alert.setContentText(content);
43
		setPosition(alert);
44
		return alert;
45
	}
46
	
47
	public static void error(String title, String header, String content) {
48
		Platform.runLater(()->{
49
			createAlert(AlertType.WARNING, title, header, content).showAndWait();
50
        });
51
	}
52
	
53
	public static void info(String title, String header, String content) {
54
		Platform.runLater(()->{
55
			createAlert(AlertType.INFORMATION, title, header, content).showAndWait();
56
        });
57
	}
58
	
59
	public static boolean confirm(String title, String header, String content) {
60
		Alert alert = createAlert(AlertType.CONFIRMATION, title, header, content);
61
		alert.showAndWait();
62
		if (alert.getResult().getText().equals("OK")) {
63
			return true;
64
		} else {
65
			return false;
66
		}
67
	}
68
	
69
}
(4-4/4)