
package Controllers.Dialog;

import Controllers.Traitement.MyWindow;
import java.io.IOException;
import org.apache.log4j.Logger;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;

import javafx.stage.Stage;

/**
 * @author Maher Ben Tili
 */
public class Dialog {
    
    Logger logger = Logger.getLogger(Dialog.class.getName());
    
    public double Height = MyWindow.myStage.getHeight() ;
    public double Width = MyWindow.myStage.getWidth() ;
    
    @FXML public Text Titre;
    @FXML public Text Message;
    @FXML public Button Valider;
    @FXML public Button Annuler;
    @FXML public AnchorPane PaneDialog;
     
    
    public Node  DialogNotification() throws IOException{
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/Views/Dialog/DialogNotification.fxml"));
        fxmlLoader.setController(this);
        Node node = (Node)fxmlLoader.load();
        return node;
    }
    
    public Node  DialogAlert() {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/Views/Dialog/DialogAlert.fxml"));
            fxmlLoader.setController(this);
            Node node;
            node = (Node)fxmlLoader.load();
            return node;
        } catch (IOException ex) {
            logger.error("Dialog  : DialogAlert.fxml :" + ex.getMessage());
        }
        return null;
    }
    
    public void DefaultAnnuler(){
        Annuler.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                PaneDialog.setVisible(false);
            }
        });
    }
    
    
    public void Show(Node node)
    {
        StackPane Sp = new StackPane();
        Sp.setPrefSize((double)MyWindow.PrincipalContentWidth, (double)MyWindow.PrincipalContentHeight);
        
        Sp.getChildren().add(MyWindow.myParent);
        Sp.getChildren().add(node);
        
        Scene scene = new Scene(Sp);
        
        Stage stage = MyWindow.myStage;
        stage.setScene(scene);
        stage.show();
    }
    
    
}
