/*
* 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;
import java.lang.Object;
import javafx.fxd.FXDContent;
import javafx.lang.FX;
import javafx.scene.*;
import javafx.scene.chart.*;
import javafx.scene.chart.part.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.*;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
var scene: Scene;
var city: String = "USNY0996" ;
var bar_names: String[] = bind ["Today",
weather.tempforecast_day[0],
weather.tempforecast_day[1]
];
var weather: Weather = Weather{city: city};
var stageDragInitialX:Number;
var stageDragInitialY:Number;
var stageY: Number= 200;
var barvisible: Boolean[] = [false,false,false];
var e: MouseEvent;
var barX = 0.0;
var barY = 0.0;
var getMax: String;
var getMin: String;
var condition: String;
var barSeries1: BarChart.Series = BarChart.Series {
name: "Weather forecasting Data"
data: [
BarChart.Data {
action: function():Void {
barvisible[0] = true;
barX = -80;
barY = -100;
getMax = weather.tempToday.toString();
getMin = "n/a";
condition = weather.tempforecast_today_condition;
}
category: bind bar_names[0]
value: bind weather.tempToday
fill: Color.LIGHTGREEN
},
BarChart.Data {
action: function():Void {
barvisible[0] = true;
barX = 60;
barY = -100;
getMax = weather.tempforecast_next_high[0].toString();
getMin = weather.tempforecast_next_low[0].toString();
condition = weather.tempforecast_condition[0];
}
category: bind bar_names[1]
value: bind weather.tempforecast_next_high[0],
fill: Color.LIGHTBLUE
},
BarChart.Data {
action: function():Void {
barvisible[0] = true;
barX = 200;
barY = -100;
getMax = weather.tempforecast_next_high[1].toString();
getMin = weather.tempforecast_next_low[1].toString();
condition = weather.tempforecast_condition[1];
}
category: bind bar_names[2]
value: bind weather.tempforecast_next_high[1],
fill: Color.BURLYWOOD
},
]
}
var codeToday = bind weather.codeToday;
public var image0 = Group {
translateX: 80
translateY: bind weather.tempToday + 100
content: []
}
public var image1 = Group {
translateX: 220
translateY: bind weather.tempforecast_next_high[0] + 50
content: []
}
public var image2 = Group {
translateX: 360
translateY: bind weather.tempforecast_next_high[1] + 70
content: []
}
public function getTodayWeather(codeToday:String):Node {
var ImageCondition: CustomNode;
if(codeToday == "0") {
ImageCondition = Rain{};
}
if(codeToday == "1") {
ImageCondition = Rain{};
}
if(codeToday == "2") {
ImageCondition = Rain{};
}
if(codeToday == "3") {
ImageCondition = Thunder{};
}
if(codeToday == "4") {
ImageCondition = Thunder{};
}
if(codeToday == "5") {
ImageCondition = SnowAndRain{};
}
if(codeToday == "6") {
ImageCondition = SnowAndRain{};
}
if(codeToday == "7") {
ImageCondition = Snowing{};
}
if(codeToday == "8") {
ImageCondition = Hail{};
}
if(codeToday == "9") {
ImageCondition = Showers{};
}
if(codeToday == "10") {
ImageCondition = Hail{};
}
if(codeToday == "11") {
ImageCondition = RainDay{};
}
if(codeToday == "12") {
ImageCondition = RainNight{};
}
if(codeToday == "13") {
ImageCondition = Snowing{};
}
if(codeToday == "14") {
ImageCondition = Snowing{};
}
if(codeToday == "15") {
ImageCondition = Snowing{};
}
if(codeToday == "16") {
ImageCondition = Snowing{};
}
if(codeToday == "17") {
ImageCondition = Hail{};
}
if(codeToday == "18") {
ImageCondition = Hail{};
}
if(codeToday == "19") {
ImageCondition = Hail{};
}
if(codeToday == "20") {
ImageCondition = Mist{};
}
if(codeToday == "21") {
ImageCondition = Haze{};
}
if(codeToday == "22") {
ImageCondition = Haze{};
}
if(codeToday == "23") {
ImageCondition = Wind{};
}
if(codeToday == "24") {
ImageCondition = Wind{};
}
if(codeToday == "25") {
ImageCondition = IceFreeze{};
}
if(codeToday == "26") {
ImageCondition = CloudyDay{};
}
if(codeToday == "27") {
ImageCondition = CloudNight{};
}
if(codeToday == "28") {
ImageCondition = CloudyDay{};
}
if(codeToday == "29") {
ImageCondition = MostlyClearNight{};
}
if(codeToday == "30") {
ImageCondition = MostlyClear{};
}
if(codeToday == "31") {
ImageCondition = Clear{};
}
if(codeToday == "32") {
ImageCondition = Sunny{};
}
if(codeToday == "33") {
ImageCondition = MostlyClearNight{};
}
if(codeToday == "34") {
ImageCondition = MostlyClear{};
}
if(codeToday == "35") {
ImageCondition = SnowAndRain{};
}
if(codeToday == "36") {
ImageCondition = Sunny{};
}
if(codeToday == "37") {
ImageCondition = Thunder{};
}
if(codeToday == "38") {
ImageCondition = ThundersDay{};
}
if(codeToday == "39") {
ImageCondition = ThundersNight{};
}
if(codeToday == "40") {
ImageCondition = Rain{};
}
if(codeToday == "41") {
ImageCondition = Snow{};
}
if(codeToday == "42") {
ImageCondition = Snow{};
}
if(codeToday == "43") {
ImageCondition = Snow{};
}
if(codeToday == "44") {
ImageCondition = MostlyClear{};
}
if(codeToday == "45") {
ImageCondition = Thunder{};
}
if(codeToday == "46") {
ImageCondition = ThundersDay{};
}
if(codeToday == "47") {
ImageCondition = ThundersDay{};
}
if(codeToday == "3200") {
ImageCondition = NA{};
}
return ImageCondition;
}
package function getFXDNode(fxdc:FXDContent, id:String):Node {
var n = fxdc.getNode(id);
if (n.parent instanceof Group) {
delete n from (n.parent as Group).content;
}
n
}
var im0 = ImageView {
x: 150
y: 230
image: bind Image {
url: "{__DIR__}Mobile/weather/{weather.codeToday}.png"
}
}
var rd = RainDay {
translateX: 50;
translateY: 230
};
var tn = ThundersNight{
translateX: 210;
translateY: 230
};
var im1 = ImageView {
x: 280
y: 230
image: bind Image {
url: "{__DIR__}Mobile/weather/{weather.tempforecast_code[0]}.png"
}
}
var im2 = ImageView {
x: 420
y: 230
image: bind Image {
url: "{__DIR__}Mobile/weather/{weather.tempforecast_code[1]}.png"
}
}
var gp = Group {
visible: bind barvisible[0]
translateX: bind barX
translateY: bind barY
content: [
ImageView {
x: 200
y: 200
opacity: 0.6
image: Image {
url: "{__DIR__}bubble.png"
}
},
Text {
fill: Color.BLACK
font: Font {
size: 14
name: "Arial Bold"
}
x: 210,
y: 220
content: bind "High: {getMax}\u00B0F\nLow: {getMin}\u00B0F";
},
Text {
fill: Color.RED
font: Font {
size: 12
name: "Arial Bold"
}
x: 210,
y: 250
content: bind "Condition: \n{condition}";
},
]
}
public function run() {
weather.getDataFromWS();
var stage:Stage = Stage {
title: "Weather forecasting with 3D Bar Chart"
style: StageStyle.UNDECORATED
scene:
scene = Scene {
width: 630
height: 480
content:[
ImageView {
opacity: 1.0
image: Image {
url: "{__DIR__}background_3.png"
}
},
ImageView {
opacity: 0.8
image: Image {
url: "{__DIR__}elements_top.png"
}
onMousePressed: function(e) {
stageDragInitialX = e.screenX - stage.x;
stageDragInitialY = e.screenY - stage.y;
}
onMouseDragged: function(e) {
stage.x = e.screenX - stageDragInitialX;
stage.y = e.screenY - stageDragInitialY;
}
},
Text {
fill: Color.WHITE
font: Font {
size: 22
name: "Arial Bold"
}
x: 180,
y: 30
content: "3-Day Forecast, NewYork,US"
},
ImageView {
visible: bind ("{__PROFILE__}" != "browser")
x: 590
y: 7
opacity: 1.0
image: Image {
url: "{__DIR__}button_x.png"
}
onMouseClicked: function( e: MouseEvent ):Void {
FX.exit();
}
},
ImageView {
x: 0
y: 440
opacity: 1.0
image: Image {
url: "{__DIR__}elements_bottom.png"
}
},
ImageView {
x: 20
y: 445
opacity: 1.0
image: Image {
url: "{__DIR__}button_blue.png"
}
onMouseClicked: function( e: MouseEvent ):Void {
weather.getDataFromWS();
}
},
Text {
fill: Color.WHITE
font: Font {
size: 18
name: "Arial Bold"
}
x: 35,
y: 465
content: "Refresh"
},
BarChart3D {
chartBackgroundFill: Color.TRANSPARENT
offsetX: 10
offsetY: 10
barGap: 50
zeroShelfFill: Color.TRANSPARENT
bottomShelfFill: Color.TRANSPARENT
sideShelfFill: Color.TRANSPARENT
translateX: 50
translateY: 50
opacity: 1.0
data: [barSeries1]
categoryAxis: CategoryAxis {
opacity: 0.2
categories: bind [bar_names[0],bar_names[1],bar_names[2]]
}
valueAxis: NumberAxis {
opacity: 0.2
visible: false
axisStroke: Color.TRANSPARENT
labelFill: Color.TRANSPARENT
lowerBound: 0
upperBound: 80
tickUnit: 10
}
},
im2,image0, image1, image2,gp
]
}
}
}