/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 */
package modalityapplication;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

/**
 *
 * @author alexander_kirov
 */
public class ModalityApp extends Application{
    public static Stage primaryStage = null;

    public static void main(String[] args) {
        launch(ModalityApp.class, args);
    }

    @Override
    public void start(final Stage primaryStage){
        InitScene scene = new InitScene();

        scene.startApp(primaryStage);
    }

    public class InitScene {

        private ModalityWindow mainwin_scene0 = null;


        public void startApp(final Stage primaryStageMain) {
            Button initButton = new Button(INIT_BUTTON_ID);
            initButton.setId(INIT_BUTTON_ID);
            initButton.setOnAction(new EventHandler<ActionEvent>(){
                public void handle(ActionEvent t) {
                    initApp();
                }
            });

            Button setStyleButton = new Button(HIERARHUCAL_BUTTON_ID);
            setStyleButton.setId(HIERARHUCAL_BUTTON_ID);
            setStyleButton.setOnAction(new EventHandler<ActionEvent>(){
                public void handle(ActionEvent t) {
                    ModalityWindow.setWindowsRenderType(ModalityWindow.WindowsRenderType.HIERARHICAL);
                }
            });

            primaryStageMain.setTitle(PRIMATY_STAGE_ID);
            primaryStageMain.setWidth(640);
            primaryStageMain.setHeight(200);
            primaryStageMain.setX(50);
            primaryStageMain.setY(0);

            Rectangle r = new Rectangle(100,100);
            r.setId(ModalityWindow.RECTANGLE_ID);
            r.setFill(Color.GREEN);

            HBox hb = new HBox();
            hb.getChildren().addAll(initButton, setStyleButton, r);

            VBox vb = new VBox();
            vb.getChildren().addAll(new Label("This is the primary window"), hb);
            
            primaryStageMain.setScene(new Scene(vb));
            primaryStageMain.show();
            primaryStage = primaryStageMain;
        }

        public void initApp(){
            if (mainwin_scene0 != null) mainwin_scene0.getStage().hide();
            ModalityWindow.counter = 0;
            mainwin_scene0 = new ModalityWindow(Modality.NONE, primaryStage, false);
        }
    }
    
    public static void tryToFront(){
        primaryStage.toFront();
    }

    public static final String PRIMATY_STAGE_ID = "primaryStage";
    public static final String INIT_BUTTON_ID = "Init";
    public static final String HIERARHUCAL_BUTTON_ID = "Hierarhical order";
}

