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 pointgraph;
import java.lang.Object;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
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.HLineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.VLineTo;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import pointgraph.PointGraph;
/**
* @author Vaibhav Choudhary
*/
var opacity = 0.6; //opacity for close button
var variable = 0.0; // timeline variable
// 3 instance of PointGraph
var pg: PointGraph = PointGraph{
Y: [3,1,3,5,9,12,10,6],
color: Color.LIGHTBLUE,
CityName: "NewYork,USA"
};
var pg1: PointGraph = PointGraph{
Y: [12,10,14,18,20,23,14,9],
color: Color.YELLOWGREEN,
CityName: "Bangalore,IND"
};
var pg2: PointGraph = PointGraph{
Y: [20, 18, 19, 24, 28, 27, 22,15],
color: Color.ORANGE,
CityName: "Sydney,AUS"
};
/* for binding the main stage */
var stageX = 200;
var stageY = 200;
/* Reload button */
var op_button = 0.4;
var reloadButton = Rectangle {
x: 235,
y: 350
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 {
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: 257,
y: 365
content: "Reload"
}
// timeline for animation
public var t = Timeline {
repeatCount: 1
keyFrames: [
KeyFrame {
time: 5s
canSkip: true
values: [
variable => 530.0 tween Interpolator.LINEAR
]
}
]
};
/* adding everything in group to make changes easy */
var gp = Group {
content: [pg, pg1, pg2]
};
/* stage can be written inside run() method */
public function run(){
t.play();
var s = Stage {
x: bind stageX
y: bind stageY
title: "24-Hour Temperatures in Major World Cities"
width: 550
height: 400
style: StageStyle.DECORATED
scene: Scene {
fill: Color.BLACK
content: [
gp,
/* rectangle moving and showing animation */
Rectangle {
translateX: bind variable
x: 10,
y: 10
width: 500,
height: 500
fill: Color.BLACK
opacity: 1.0
},
reloadButton, textButton
// axis plotter
Path {
translateX: 50
translateY: 0
stroke: Color.WHITE
strokeWidth: 2
opacity: 0.4
elements: [
MoveTo {
x: 10.0,
y: 300.0
},
HLineTo {
x: 450.0
},
MoveTo {
x: 10.0,
y: 300.0
},
VLineTo {
y: 10.0
},
]
},
/* data on Axis */
Group {
translateX: 50
translateY: 0
content: for(num in [0..7]) {[
Text {
fill: Color.WHITE
font: Font {
size: 10
}
x: num * 60 + 5
y: 320
content: "{3*num}"
},
Text {
fill: Color.WHITE
font: Font {
size: 10
}
x: -5
y: 320 - num * 50
content: "{5*num}-"
}
]
}
},
Text {
fill: Color.WHITE
font: Font {
name: "Arial Bold"
size: 12
}
x: 500
y: 330
content: "Time"
},
Text {
rotate: -90
fill: Color.WHITE
font: Font {
name: "Arial Bold"
size: 12
}
x: -10,
y: 80
content: "Temperature"
}
]
}
}
}