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 mybargraph;

import javafx.lang.FX;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.Scene;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import mybargraph.Bar;

/**
 * @author Vaibhav Choudhary
 */


 /* Binding with the main stage, for dragging the window */
var stageX = 200;
var stageY = 200;

/* Percentage usages */
var bars: Integer[] = [15,20,25,15,8,7,10];
var bar_names: String[] = ["C++","C","Java","Perl","PHP","SQL","Others"];

/* opacity of close button */
var opacity = 0.6;

/* instance of Bar */
var bargraph: Bar[];

for(i in [0..6]){
    insert
    Bar {
        X: 100 + i * 50
        Y: 150
        height: bars[i]
        txt: bar_names[i]
    } into bargraph

}

/* for title bar */
var dragRect = Rectangle {
    x: 0,
    y: 0
    width: 550,
    height: 20
    fill: LinearGradient {
        startX: 0.0
        startY: 0.0
        endX: 0.0
        endY: 1.0
        stops: [
            Stop {
                color: Color.GRAY
                offset: 0.0
            },
            Stop {
                color: Color.BLACK
                offset: 1.0
            },

        ]
    }
    stroke: Color.BLACK
    strokeWidth: 2
    opacity: 0.9
    onMouseDragged: function( e: MouseEvent ):Void {
        stageX += e.dragX;
        stageY += e.dragY;

    }
};
var txt_bar = Text {
    fill: Color.WHITE
    font: Font {
        size: 10
        name: "Arial Bold"
        letterSpacing: 0.20
    }
    x: 15,
    y: 14
    content: "Relative Use of Programming Languages by Developers"
}
/* end of title bar */

 /*close button of title bar */
var close = Rectangle {
    x: 530,
    y: 3
    arcHeight: 5
    arcWidth: 5
    width: 15,
    height: 15
    stroke: Color.BLACK
    strokeWidth: 2
    opacity: bind opacity
    fill: LinearGradient {
        startX: 0.0
        startY: 0.0
        endX: 0.0
        endY: 1.0
        stops: [
            Stop {
                color: Color.ORANGE
                offset: 0.0
            },
            Stop {
                color: Color.DARKRED
                offset: 0.5
            },
            Stop {
                color: Color.ORANGE
                offset: 1.0
            },
        ]
    }
    
    onMouseClicked: function( e: MouseEvent ):Void {
        FX.exit();
    }
    onMouseMoved: function( e: MouseEvent ):Void {
        opacity = 1.0
    }
    onMouseExited: function( e: MouseEvent ):Void {
        opacity = 0.6
    }
};

/* Cross in title bar */

var close_sym = Text {
    font: Font {
        size: 15
        name: "Arial Bold"
    }
    x: 534,
    y: 15
    content: "x"
}

/* Reload button */
var op_button = 0.4;
var reloadButton = Rectangle {
    x: 225,
    y: 250
    width: 80,
    height: 20
    fill: LinearGradient {
        startX: 0.0
        startY: 0.0
        endX: 0.0
        endY: 1.0
        stops: [
            Stop {
                color: Color.BLACK
                offset: 0.0
            },
            Stop {
                color: Color.WHITE
                offset: 1.0
            },

        ]
    }
    stroke: Color.WHITE
    opacity: bind op_button
    cursor: Cursor.HAND
    onMouseClicked: function( e: MouseEvent ):Void {
        for(i in [0..6]) {
            bargraph[i].t.playFromStart();
        }
    }
    onMouseEntered: function( e: MouseEvent ):Void {
        op_button = 0.6;
    }
    onMouseExited: function( e: MouseEvent ):Void {
        op_button = 0.4;
    }
}
var textButton = Text {
    fill: Color.WHITE
    font: Font {
        size: 12
        name: "Arial Bold"
    }
    x: 245,
    y: 265
    content: "Reload"
}

/* end of reload button */

 /* Main Stage */
Stage {
    title: "Bar Graph"
    x: bind stageX
    y: bind stageY
    width: 550
    height: 300
    style: StageStyle.UNDECORATED
    scene: Scene {
        fill: Color.BLACK
        content: [
            bargraph, reloadButton, textButton,
            dragRect,  close, close_sym, txt_bar
            /* y-axis line */
            Line {
                startX: 50,
                startY: 50
                endX: 50,
                endY: 200
                strokeWidth: 2
                stroke: Color.WHITE
            },
            /* x-axis line */
            Line {
                startX: 50,
                startY: 200
                endX: 500,
                endY: 200
                strokeWidth: 2
                stroke: Color.WHITE
            },
             /* Making Y axis values */
            Group {
                content: for(i in [1..6]) {
                    [
                        Text {
                            fill: Color.WHITE
                            font: Font {
                                size: 10
                            }
                            x: 20,
                            y: 205 - 25 * i
                            content: "{i*5}% -"
                        },
                    ]
                }
            }
        ]
    }
}