summaryrefslogtreecommitdiff
path: root/src/main/java/com/mavlushechka/notaryqueue/NotaryQueueApplication.java
blob: 29605ea5d4736a116707b5f6a505bdbc5af5a54c (plain)
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
package com.mavlushechka.notaryqueue;

import com.mavlushechka.notaryqueue.controller.HelperController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.Objects;

public class NotaryQueueApplication extends Application {


    public static NotaryQueueApplication instance;
    private Stage stage;


    public static void main(String[] args) {
        launch();
    }

    public NotaryQueueApplication() {
        instance = this;
    }

    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(NotaryQueueApplication.class.getResource("main.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 600, 400);

        stage.setScene(scene);
        stage.show();
        this.stage = stage;
    }

    public void setNotaryScene() {
        try {
            setScene(NotaryQueueApplication.class.getResource("notary.fxml"));
        } catch (IOException ioException) {
            throw new RuntimeException(ioException);
        }
    }

    public void setHelperScene() {
        try {
            setScene(NotaryQueueApplication.class.getResource("helper.fxml"));
        } catch (IOException ioException) {
            throw new RuntimeException(ioException);
        }
        HelperController.instance.setContextMenuToClientListViews();
        HelperController.instance.loadClientsToListViews();
        HelperController.instance.receiveUpdates();
    }

    public void setMonitorScene() {
        try {
            setScene(NotaryQueueApplication.class.getResource("monitor.fxml"));
        } catch (IOException ioException) {
            throw new RuntimeException(ioException);
        }
        HelperController.instance.isMonitorScene = true;
        HelperController.instance.loadClientsToListViews();
        HelperController.instance.receiveUpdates();
    }

    private void setScene(URL fxml) throws IOException {
        Parent parent = FXMLLoader.load(Objects.requireNonNull(fxml), null, new JavaFXBuilderFactory());
        Scene scene = stage.getScene();

        if (scene == null) {
            scene = new Scene(parent, 1280, 720);
            stage.setScene(scene);
        } else {
            stage.getScene().setRoot(parent);
        }
        stage.sizeToScene();
    }

}