package multiplewindows;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class MainWindow extends Application {
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		Label label = new Label("Welcome to the main window!");
        Button button1 = new Button("Open modal dialog");
        button1.setOnAction(e -> {
        	boolean result = Window.display(true, "Modal window", "This is modal window");
            System.out.println("Window result: " + result);
        });
        Button button2 = new Button("Open nonmodal dialog");
        button2.setOnAction(e -> {
        	boolean result = Window.display(false, "Non modal window", "This is non modal window");
        	System.out.println("Window result: " + result);
        });
        
        VBox layout = new VBox();
        layout.setPadding(new Insets(150,150,150,150));
        layout.setAlignment(Pos.CENTER);
        layout.getChildren().addAll(label, button1, button2);
        
        // Set what happens on close
        primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
			@Override
			public void handle(WindowEvent e) {
				e.consume();
				// do what ever you want, for example show dialog for choosing
				// weather you want to exit the program or no
			}
        });
        
        primaryStage.setScene(new Scene(layout));
        primaryStage.setTitle("Multiple windows demo");
        primaryStage.show();
	}

}
