/**
 *    SampleJfxWidget3.java
 *    Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.expeditee.items.widgets;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

import org.expeditee.core.bounds.AxisAlignedBoxBounds;
import org.expeditee.gui.MessageBay;
import org.expeditee.items.Text;

public class SampleJfxWidget3 extends JavaFXPaneWidget {

	public SampleJfxWidget3(Text source, String[] args)
	{
		super(source, new VBox(10), 200, 400, 100, 200);
	
		Label label = new Label("Hello World");		
		Button button = new Button("Hello World");

		button.setOnMouseClicked(event -> {
			System.out.println("Button Clicked");
			MessageBay.displayMessage("Mouse button clicked: " + event.getButton());
		});
			
		HBox topBar = new HBox(10, label, button);
        topBar.setPadding(new Insets(12));
        topBar.setAlignment(Pos.CENTER);               // centre children within the bar
        topBar.setMaxWidth(Double.MAX_VALUE);          // allow bar to stretch full width
        topBar.setStyle("-fx-background-color: #EEEEEE;");  // Swing-ish grey

        // Spacer that grows to take all remaining vertical space
        Region spacer = new Region();
        VBox.setVgrow(spacer, Priority.ALWAYS);

        // Root container: puts topBar at top, spacer fills remainder
        final VBox root = (VBox)_node;
        //root.setMinWidth(200);
        //root.setMaxWidth(400);
        //root.setPrefWidth(200);
        //root.setMinHeight(100);
        //root.setMaxHeight(200);
        //root.setPrefHeight(100);
        
        root.getChildren().addAll(topBar,spacer);
        
        root.setAlignment(Pos.TOP_CENTER);             // topBar stays at top
        root.setFillWidth(true);                       // children can fill width
        root.setStyle("-fx-background-color: #EEEEEE;");     // background for remaining space
        
	}

	@Override
	protected String[] getArgs() {
		return new String[0];
	}
	
	/*
	@Override
	protected void layout() {
		System.out.println("*** SampleJfxWidget3::layout()");
		
		super.layout();
		VBox vbox = (VBox) _pane;
		
		AxisAlignedBoxBounds aa_bounds = getContentBounds();
		vbox.setPrefWidth(aa_bounds.getWidth());
		vbox.setPrefHeight(aa_bounds.getHeight());
		
		vbox.applyCss();
		vbox.layout();   // forces VBox to lay out its children now
	}
	*/

}

