/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers.Traitement;

import Controllers.PrincipalController;
import java.io.IOException;
import org.apache.log4j.Logger;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 * @author Maher Ben Tili
 */
public class MyWindow {

    Logger logger = Logger.getLogger(MyWindow.class.getName());
    
    public static Stage myStage;
    
    public static Parent myParent ;
    
    public static AnchorPane anchorpane = new AnchorPane();
    
    public static Node node ;
    
    public static Number PrincipalContentWidth;
    
    public static Number PrincipalContentHeight;
    
    public Object[] ArrayObjectDataSave = new Object[10];

    public static void ShwoWindows(double Height,double Width){
        
        anchorpane.setVisible(true);
        anchorpane.setStyle("-fx-background-color: rgba(0,0,0,0.6);");
        anchorpane.setPrefHeight(Height);
        anchorpane.setPrefWidth(Width);
        
        Group group = new Group();
        group.getChildren().add(node);
        
        
        StackPane Sp = new StackPane();
            
        MyWindow.myStage.setWidth(Width);
        MyWindow.myStage.setHeight(Height);
       
        Stage stage = MyWindow.myStage;
        
        Sp.getChildren().add(MyWindow.myParent);
        Sp.getChildren().add(anchorpane);
        Sp.getChildren().add(group);
        
        Scene scene = new Scene(Sp);
        
        stage.setScene(scene);
        stage.show();
    }

    
    public static void ClearWindows(){
        MyWindow.node.setVisible(false);
        MyWindow.anchorpane.setVisible(false);
        
    }
    
    
    public void Refresh(Parent parent, Integer number_titled_Pane){
        
        try {
            
            FXMLLoader fxmlPrincipal= new FXMLLoader(getClass().getResource("/Views/Principal.fxml"));
            MyWindow.myParent = (Parent) fxmlPrincipal.load();
            PrincipalController dc = fxmlPrincipal.getController();
            dc.window.getChildren().add(parent);
            
            dc.Content.setPrefSize((double) PrincipalContentWidth, (double) PrincipalContentHeight);
            
            dc.DefaultSelectedTitledPane(number_titled_Pane);
            
            Scene scene = new Scene(MyWindow.myParent);
            
            Stage stage = MyWindow.myStage;
            stage.setScene(scene);
            stage.show();
        } catch (IOException ex) {
            logger.error("MyWindow  : Refresh :" + ex.getMessage());
        }
    }
    
    public static void setMyStage(Stage myStage) {
        MyWindow.myStage = myStage;
    }

    public static void setMyParent(Parent myParent) {
        MyWindow.myParent = myParent;
    }

    
    public static void NewMyStage() {
        myStage = new Stage();
    }

    
}
