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 bulletgraph;
import bulletgraph.Bullet;
import javafx.lang.Duration;
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.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.AppletStageExtension;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
/**
* @author Vaibhav Choudhary
*/
var vis: Boolean = true;
/* data insertion - will be changed into for loop */
var bullets: Bullet[];
var expected: Number[] = [150,250,50,4.5,17];
var achieved: Number[] =[100,270,60,4,12];
var below: Number[] = [50,150,30,2.5,5];
var avg: Number[] = [120,220,50,4,10];
var good: Number[] = [230,360,70,5,20];
var txt: String[] = [" Profit", " Turnover", " Gross",
" Cust. Sat.", " Iterations"];
var subtxt: String[] = ["1000 USD", "1000 USD", "1000 USD",
" 1-5", " %"];
var startdelay: Duration[] = [1s,7s,13s,19s,26s];
var endtime: Duration[] = [6s,12s,18s,24s,30s];
// inserting the initial value
for(i in [0..4]) {
insert
Bullet {
expected: expected[i]
achieved: achieved[i]
below: below[i]
avg: avg[i]
good: good[i]
txt: txt[i]
subtxt: subtxt[i]
translateX: 5
translateY: i * 100
startdelay: startdelay[i]
endtime: endtime[i]
} into bullets
}
/* BEGIN Reload button ---------- */
var op_button = 0.7;
var reloadButton = Rectangle {
x: 200,
y: 530
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.GRAY
offset: 1.0
},
]
}
stroke: Color.BLACK
opacity: bind op_button
cursor: Cursor.HAND
onMouseClicked: function( e: MouseEvent ):Void {
for(i in [0..4])
bullets[i].t1.playFromStart();
}
onMouseEntered: function( e: MouseEvent ):Void {
op_button = 1.0;
}
onMouseExited: function( e: MouseEvent ):Void {
op_button = 0.7;
}
}
var textButton = Text {
fill: Color.WHITE
font: Font {
size: 12
name: "Arial Bold"
}
x: 220,
y: 545
content: "Reload"
}
/* END Reload Button ------------- */
/* binding the main stage */
var stageX = 100;
var stageY = 100;
/* Start title bar */
var dragRect = Rectangle {
x: 0,
y: 0
width: 530,
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
},
]
}
onMouseDragged: function( e: MouseEvent ):Void {
stageX += e.dragX;
stageY += e.dragY;
}
};
/* End title bar */
/* Close button in title bar */
var opacity = 0.6;
var close = Rectangle {
visible: bind vis
x: 510
y: 3
arcHeight: 2
arcWidth: 2
width: 15,
height: 15
stroke: Color.BLACK
strokeWidth: 2
opacity: 0.9
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
}
};
/* close button 'x' in title bar */
var button = Text {
visible: bind vis
fill: Color.WHITE
font: Font {
name: "Arial Bold"
size: 14
}
x: 514,
y: 15
content: "x"
}
/* Add all data to a Group */
var gp = Group {
content: [bullets]
}
/* Main Stage */
var s = Stage {
x: bind stageX
y: bind stageY
title: "Bullet Graph"
width: 530
height: 600
style: StageStyle.TRANSPARENT
scene: Scene {
content: [
dragRect, close, button,reloadButton, textButton
gp,
/* BEGIN LEGEND ----------------------------------------- */
Rectangle { //Box for legend
x: 400,
y: 36
width: 120,
height: 175
fill: null
stroke: Color.DARKGRAY
strokeWidth: 5
}
Text { //Legend title
font: Font {
size: 16
name: "Arial Bold"
}
fill: Color.DARKGRAY
x: 440,
y: 60
content: "Legend"
}
Rectangle { //Legend color for 'poor' portion
opacity: 1.0
x: 410,
y: 70
width: 10,
height: 10
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
stops: [
Stop {
color: Color.SILVER
offset: 0.0
},
Stop {
color: Color.DARKGREY
offset: 0.5
},
Stop {
color: Color.SILVER
offset: 1.0
},
]
}
}
Text { //Legend label for 'poor' portion
font: Font {
size: 12
name: "Arial Bold"
}
fill: Color.DARKGRAY
x: 425,
y: 80
content: "Poor"
}
Rectangle { //Legend color for 'average' portion
opacity: 0.4
x: 410,
y: 100
width: 10,
height: 10
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
stops: [
Stop {
color: Color.SILVER
offset: 0.0
},
Stop {
color: Color.LIGHTGRAY
offset: 0.5
},
Stop {
color: Color.SILVER
offset: 1.0
},
]
}
}
Rectangle { //Legend color overlay for 'good' portion
cache: true
opacity: 0.4
x: 410,
y: 100
width: 10,
height: 10
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
stops: [
Stop {
color: Color.SILVER
offset: 0.0
},
Stop {
color: Color.LIGHTGRAY
offset: 0.5
},
Stop {
color: Color.SILVER
offset: 1.0
},
]
}
},
Text { //Legend label for 'average' portion
font: Font {
size: 12
name: "Arial Bold"
}
fill: Color.DARKGRAY
x: 425,
y: 110
content: "Average"
}
Rectangle { //Legend color for 'good' portion
cache: true
opacity: 0.4
x: 410,
y: 130
width: 10,
height: 10
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
stops: [
Stop {
color: Color.SILVER
offset: 0.0
},
Stop {
color: Color.LIGHTGRAY
offset: 0.5
},
Stop {
color: Color.SILVER
offset: 1.0
},
]
}
},
Text { //Legend label for 'good' portion
font: Font {
size: 12
name: "Arial Bold"
}
fill: Color.DARKGRAY
x: 425,
y: 140
content: "Good"
}
Rectangle { //Legend color for 'predicted' vertical line
cache: true
x: 410,
y: 155
width: 3,
height: 15
fill: Color.BLACK
},
Text { //Legend label for 'predicted' vertical line
font: Font {
size: 12
name: "Arial Bold"
}
fill: Color.DARKGRAY
x: 425,
y: 170
content: "Predicted value"
}
Rectangle { // Legend color for actual value
cache: true
opacity: 1
x: 410,
y: 190
width: 10
height: 10
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
stops: [
Stop {
color: Color.YELLOWGREEN
offset: 0.0
},
Stop {
color: Color.GREEN
offset: 1.0
},
]
}
}
Text { //Legend label for actual value
font: Font {
size: 12
name: "Arial Bold"
}
fill: Color.DARKGRAY
x: 425,
y: 200
content: "Actual value"
}
/* END LEGEND ---------------------------------------- */
Rectangle { //Background for bottom title
x: 3,
y: 560
width: 525,
height: 44
fill: Color.GRAY
},
Text { //Title at bottom of scene
fill: Color.WHITE
font: Font {
size: 12
name: "Arial Bold"
}
x: 72,
y: 584
content: "Executive Dashboard: Key Metrics - Predicted vs. Actual '08"
},
Rectangle { //Grey border around scene above title
x: 0,
y: 25
width: 530
height: 580
fill: null
stroke: Color.GRAY
strokeWidth: 7
}
]
}
/* Remove custom close button if applet is dragged out of browser */
extensions: [
AppletStageExtension {
onDragStarted: function() {
vis = false;
}
onAppletRestored: function() {
vis = true;
}
useDefaultClose: true
}
]
}