package edu.bloomu.ch3b;

import java.util.concurrent.ThreadLocalRandom;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

/**
 * Draws a randomly colored rectangle with rounded corners and a drop shadow.
 * 
 * @author Drue Coles
 */
public class RectangleWithShadow extends Application {

    @Override
    public void start(Stage stage) {
        Pane root = new Pane();
        final int width = 500;
        final int height = 300;
        Scene scene = new Scene(root, width, height);

         // Create a rectangle centered in the scene. 
        final int rectangleWidth = 400;
        final int rectangleHeight = 200;
        int x = (width - rectangleWidth) / 2; // x-coordinate of top-left corner
        int y = (height - rectangleHeight) / 2; // y-coordinate of top-left corner
        Rectangle rectangle = new Rectangle(x, y, rectangleWidth, rectangleHeight);
        root.getChildren().add(rectangle);

        // Create a random opaque color for the rectangle. 
        ThreadLocalRandom rand = ThreadLocalRandom.current();
        double r = rand.nextDouble();
        double g = rand.nextDouble();
        double b = rand.nextDouble();
        Color color = new Color(r, g, b, 1);
        rectangle.setFill(color);
     
        // Round the corners.
        rectangle.setArcWidth(45); 
        rectangle.setArcHeight(45);  
        
        // Add a drop shadow.
        DropShadow dropShadow = new DropShadow();
        dropShadow.setOffsetY(5);
        dropShadow.setOffsetX(5);
        dropShadow.setColor(Color.GRAY);
        rectangle.setEffect(dropShadow);
 
        stage.setTitle("Rectangle with Shadow");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}