package org.nick.layoutinfo;

import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 *
 * @author Nick Apperley
 */
public class LayoutInfo extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Application.launch(LayoutInfo.class, args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        final Group root = new Group();
        final Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN);
        final Button btn = createButton();
        
        primaryStage.setTitle("Layout Info");
        System.out.println("Detached Button Width: " + 
                btn.getBoundsInLocal().getWidth());
        System.out.println("Detached Button Height: " + 
                btn.getBoundsInLocal().getHeight());
        root.getChildren().add(btn);        
        primaryStage.setScene(scene);
        primaryStage.setVisible(true);
    }
    
    private static Button createButton(){
        final Button btn = new Button("Test");
        
        btn.setLayoutX(100);
        btn.setLayoutY(80);
        btn.setOnMouseClicked(new EventHandler() {
            public void handle(Event event) {
                System.out.println("Attached Button Width: " + 
                        btn.getBoundsInLocal().getWidth());
                System.out.println("Attached Button Height: " + 
                        btn.getBoundsInLocal().getHeight());
            }
        });
        return btn;
    }
}
