Legal Terms and Copyright Notice
/* 
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 * 
 * Copyright © 2010, Oracle and/or its affiliates. All rights reserved.
 * Oracle is a registered trademark of Oracle Corporation and/or its affiliates. 
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
 * Other names may be trademarks of their respective owners.
 * 
 * This file is available and licensed under the following license:
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:

 *   *  Redistributions of source code must retain the above copyright notice, 
        trademark notice, this list of conditions, and the following disclaimer.

 *   *  Redistributions in binary form must reproduce the above copyright notice, 
        trademark notice, this list of conditions, and the following disclaimer in 
        the documentation and/or other materials provided with the distribution.

 *   *  Neither the name of Oracle nor the names of its contributors may be used 
        to endorse or promote products derived from this software without specific 
        prior written permission.
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package flowers;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import java.lang.String;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.Flow;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Panel;
import javafx.scene.layout.Stack;
import javafx.scene.layout.Tile;
import javafx.scene.text.Font;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.control.Label;
import javafx.scene.shape.Rectangle;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.TextBox;


def images = [
Image {url: "{__DIR__}fl1.png"},
Image {url: "{__DIR__}fl2.png"},
Image {url: "{__DIR__}fl3.png"},
Image {url: "{__DIR__}fl4.png"},
Image {url: "{__DIR__}fl5.png"},
Image {url: "{__DIR__}fl6.png"},
Image {url: "{__DIR__}fl7.png"},
Image {url: "{__DIR__}fl8.png"},
Image {url: "{__DIR__}fl9.png"},
Image {url: "{__DIR__}fl10.png"},
Image {url: "{__DIR__}fl11.png"},
Image {url: "{__DIR__}fl12.png"},
Image {url: "{__DIR__}fl13.png"},
Image {url: "{__DIR__}fl14.png"},
Image {url: "{__DIR__}fl15.png"},
Image {url: "{__DIR__}fl16.png"},
];


var group1 = ToggleGroup{};


var vbox = VBox {
           width: 600
           layoutX: 280
           layoutY: 20
           nodeHPos: HPos.CENTER // center nodes horizontally within the column
           spacing: 10
           //padding: Insets{top: 50}
           content: [for (i in [0..4]) ImageView {image: images[i]}]
       }

/*
var textbox = HBox {
           layoutX: 20
           layoutY: 100
           spacing: 10
           nodeVPos: VPos.BASELINE
           content: [
               Label { text: "Name:" }
                TextBox {}
               Label { text: "Button1" }
                Button {text: "OK" }
               Label { text: "Button2" }
                Button {text: "Cancel" }
               Label {text: "Option:" }
                RadioButton { toggleGroup: group1   text: "Opt1"   selected: true }
                RadioButton { toggleGroup: group1   text: "Opt2" }
                RadioButton { toggleGroup: group1   text: "Opt3" }
           ]
       }
*/

var hbox = HBox {
           layoutX: 20
           layoutY: 150
           spacing: 15
           nodeVPos: VPos.CENTER //Centers each node within the HBox's row.
           //padding: Insets{left:50}
           content: [for (i in [0..6]) ImageView {image: images[i]}]
       }

var stack = Stack {
           layoutX: 20
           layoutY: 20
           padding: Insets{top: 50 left:50}
           content: [for (i in [0..8]) ImageView {image: images[i]}]
       }

import javafx.scene.layout.Container.*;
var PanelViews = [ for (i in [0..15]) ImageView {image: images[i]} ];
var panel: Panel = Panel {
    content: PanelViews
    onLayout: function():Void {
        for (node in panel.content) {
            def i = indexof node;
            positionNode(node, i*40, i*20);
        }
    }
}

var flow = Flow {
           //vertical: true
           layoutX: 10
           layoutY: 20
           hgap: 15 // horizontal gap between nodes in a row
           vgap: 10 // vertical gap between rows
           hpos: HPos.LEFT
           nodeVPos: VPos.BOTTOM
           //nodeHPos: HPos.LEFT
           //vpos: VPos.TOP
           //wrapLength: 300
           content: [for (i in [0..15]) ImageView {image: images[i]}]
       }

var tile = Tile {
           columns: 4
           hgap: 5
           vgap: 5
           padding: Insets{top: 20 left: 20}
           nodeVPos: VPos.BOTTOM
           nodeHPos: HPos.LEFT
           //tileWidth: 50
           //autoSizeTiles: false
           content: [for (i in [0..16]) ImageView {image: images[i]}]
       }


var toggleGroup = ToggleGroup {};
def containers = [hbox, vbox, stack, panel, flow, tile];
def captions = ["HBox", "VBox", "Stack", "Panel", "Flow", "Tile"];
var rb: RadioButton[] = for (container in containers) RadioButton {
               text: captions[indexof container]
               toggleGroup: toggleGroup
               value: container
               font: Font {size: 12 name: "Arial Bold"}
           };
rb[0].selected = true;


Application {
   title: "JavaFX Layout"
   //header: ImageView {
   //    image: Image {
   //        url: "{__DIR__}logo.png"
   //    }
   //}
   background: Color.DIMGRAY
   content: bind [
       Rectangle {translateY: 10 width: 590 height: 350 fill: Color.web("#C4DC92")}
       toggleGroup.selectedToggle.value as Node,
       HBox {
           translateY: 390
           translateX: 30
           spacing: 20
           hpos: HPos.CENTER
           content: [
               Label { text: "Select layout\ncontainer:" textFill: Color.web("#C4DC92") font: Font{size: 12 name: "Tahoma Bold"}}
               rb
           ]
       }
   ]
}