package com.ht.ui.controls;

import javafx.concurrent.Service;
import javafx.scene.Node;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

public class ServiceProgressVeil extends StackPane {
	
	public ServiceProgressVeil(Node child, @SuppressWarnings("rawtypes") Service service) {
		ProgressIndicator progress = new ProgressIndicator();
		progress.setMaxSize(150, 150);
		Region veil = new Region();
		veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");

		VBox.setVgrow(this, Priority.ALWAYS);
		getChildren().addAll(child, veil, progress);

		progress.progressProperty().bind(service.progressProperty());
		veil.visibleProperty().bind(service.runningProperty());
		progress.visibleProperty().bind(service.runningProperty());
	}
	
	public ServiceProgressVeil(@SuppressWarnings("rawtypes") Service service) {
		ProgressIndicator progress = new ProgressIndicator();
		progress.setMaxSize(150, 150);
		Region veil = new Region();
		veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");

		StackPane stackPane = new StackPane();
		VBox.setVgrow(stackPane, Priority.ALWAYS);
		stackPane.getChildren().addAll(veil, progress);

		progress.progressProperty().bind(service.progressProperty());
		veil.visibleProperty().bind(service.runningProperty());
		progress.visibleProperty().bind(service.runningProperty());
	}
}
