License text

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER 
 * Copyright  2008, 2010 Oracle and/or its affiliates.  All rights reserved. 
 * Use is subject to license terms.
 * 
 * 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, 
 *     this list of conditions and the following disclaimer. 
 *
 *   * Redistributions in binary form must reproduce the above copyright 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 Corporation 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 forecasting_mobile;
import javafx.scene.layout.Container;
import javafx.scene.chart.BarChart;
import javafx.scene.paint.Color;
import javafx.scene.chart.part.CategoryAxis;
import javafx.scene.chart.part.NumberAxis;
import javafx.scene.chart.BarChart3D;
import javafx.scene.layout.LayoutInfo;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.layout.VBox;
import javafx.geometry.Insets;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Stack;

/**
 * @author Arun
 */
var city: String = "USNY0996";      // for this sample only, user can change it
var spacing: Number = if(Main.STAGE_WIDTH < 250) 0 else Main.STAGE_WIDTH * 0.2;
var padding: Number = if( {__PROFILE__}=="mobile" or {__PROFILE__}=="browser" )
                          Main.STAGE_WIDTH*0.25
                      else Main.STAGE_WIDTH*0.30;
var bar_names: String[] = bind [
    "Today",
    weather.tempforecast_day[0],
    weather.tempforecast_day[1]
];
public var getMax: String;
public var getMin: String;
public var condition: String;
public var bubbleVisiblity: Boolean = false;
public var weather: Weather = Weather{city: bind city};
var locX: Number = 0;
var locY: Number = 0;

public class Chart extends Container {
     public var barSeries1: BarChart.Series = BarChart.Series {
        data: [
            BarChart.Data {
                action: function():Void {
                    getMax = (weather.tempToday).toString();
                    getMin = "n/a";
                    condition = weather.tempforecast_today_condition;
                    bubbleVisiblity = true;
                    locX = Main.STAGE_WIDTH*0.14;
                    locY = weather.tempToday;
                }
                category: bind bar_names[0]
                value: bind weather.tempToday,
                fill: Color.LIGHTGREEN
            },
            BarChart.Data {
                action: function():Void {
                    getMax = (weather.tempforecast_next_high[0]).toString();
                    getMin = weather.tempforecast_next_low[0].toString();
                    condition = weather.tempforecast_condition[0];
                    bubbleVisiblity = true;
                    locX = Main.STAGE_WIDTH*0.14 + padding;
                    locY = weather.tempforecast_next_high[0];
                }
                category: bind bar_names[1]
                value:  bind weather.tempforecast_next_high[0],
                fill: Color.BROWN
            },
            BarChart.Data {
                action: function():Void {
                    getMax = (weather.tempforecast_next_high[1]).toString();
                    getMin = weather.tempforecast_next_low[1].toString();
                    condition = weather.tempforecast_condition[1];
                    bubbleVisiblity = true;
                    locX = Main.STAGE_WIDTH*0.14 + padding*2;
                    locY = weather.tempforecast_next_high[1];

                }
                category: bind bar_names[2]
                value:  bind weather.tempforecast_next_high[1],
                fill: Color.ORANGE
            },
        ]
    };

    var weatherImages = HBox {
        layoutX: Main.STAGE_WIDTH*0.15
        layoutY: 70
        spacing: bind spacing
	content: bind [
            ImageView {
                image: bind Image { url: "{__DIR__}images/{weather.codeToday}.png" }
            }
            ImageView {
                image: bind Image { url: "{__DIR__}images/{weather.tempforecast_code[0]}.png" }
            }
            ImageView {
                image: bind Image { url: "{__DIR__}images/{weather.tempforecast_code[1]}.png" }
            }
        ]
    }
   
    init {
        weather.getDataFromWS();
        children = [
            HBox {
                padding: Insets { top: 50 left: 10}
                content: [
                    BarChart3D {
                        legendVisible: false
                        layoutInfo: LayoutInfo {
                            width: bind Main.STAGE_WIDTH -20
                            height: bind Main.STAGE_HEIGHT - 100
                        }
                        bottomShelfFill: Color.GREEN
                        data: [ barSeries1 ]
                        categoryAxis: CategoryAxis {
                            tickLabelsVisible: false
                            tickMarkVisible: false
                            categories: bind [
                                bar_names[0],
                                bar_names[1],
                                bar_names[2]
                            ]
                        }
                        valueAxis: NumberAxis {
                            opacity: 0
                            tickLabelsVisible: false
                            tickMarkVisible: false
                            visible: false
                            axisStroke: Color.TRANSPARENT
                            labelFill: Color.TRANSPARENT
                            lowerBound: 0
                            upperBound: 100
                            tickUnit: 10
                        }
                    },
                ]
            },
            weatherImages,
            Stack {
                visible: bind bubbleVisiblity
                translateX: bind locX
                translateY: bind locY +20
                content: [
                   ImageView {
                        image:Image { url: "{__DIR__}images/bubble.png" }
                    },
                    VBox {
                        padding: Insets { top: 4 left: 4 }
                        content: [
                            Text {
                                fill: Color.BLACK
                                font: Font {
                                    size: 10
                                    name: "Arial Bold"
                                }
                                content: bind "High: {getMax}\u00B0F\nLow:  {getMin}\u00B0F";
                            },
                            Text {
                                fill: Color.RED
                                font: Font {
                                    size: 10
                                    name: "Arial"
                                }
                                wrappingWidth: 80
                                content: bind "Condition: \n{condition}";
                            },
                        ]
                    }
                ]
            }
        ]
    }
}