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

import java.lang.Math;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.control.TextBox;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Transform;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.control.Button;
import javafx.scene.layout.Stack;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

/**
 * @author JavaFX Samples Team
 */
var stage: Stage;
var stageDragInitialX: Number;
var stageDragInitialY: Number;
public var t1 = TubePart {
    sAngle: 0
    len: 100
    col: RadialGradient {
        centerX: 200
        centerY: 200
        radius: 100
        proportional: false
        stops: [
            Stop {
                color: Color.DARKRED
                offset: 0.6
            },
            Stop {
                color: Color.ORANGE
                offset: 0.9
            },
            Stop {
                color: Color.DARKRED
                offset: 1.0
            },
        ]
    }
};
public var t2 = TubePart {
    sAngle: 100
    len: 100
    col: RadialGradient {
        centerX: 200
        centerY: 200
        radius: 100
        proportional: false
        stops: [
            Stop {
                color: Color.DARKBLUE
                offset: 0.6
            },
            Stop {
                color: Color.LIGHTBLUE
                offset: 0.9
            },
            Stop {
                color: Color.DARKBLUE
                offset: 1.0
            },
        ]
    }
};
public var t5 = TubePart {
    sAngle: 200
    len: 100
    col: RadialGradient {
        centerX: 200
        centerY: 200
        radius: 100
        proportional: false
        stops: [
            Stop {
                color: Color.DARKGREEN
                offset: 0.6
            },
            Stop {
                color: Color.LIGHTGREEN
                offset: 0.9
            },
            Stop {
                color: Color.DARKGREEN
                offset: 1.0
            },
        ]
    }
};
var titleBar = Rectangle {
    onMousePressed: function (e) {
        stageDragInitialX = e.screenX - stage.x;
        stageDragInitialY = e.screenY - stage.y;
    }
    onMouseDragged: function (e: MouseEvent): Void {
        stage.x = e.screenX - stageDragInitialX;
        stage.y = e.screenY - stageDragInitialY;
    }
    x: 0
    y: 0
    width: 700
    height: 20
    fill: LinearGradient {
        startX: 0.0
        startY: 0.0
        endX: 0.0
        endY: 1.0
        stops: [
            Stop {
                offset: 0.0
                color: Color.DARKGREEN
            },
            Stop {
                offset: 0.5
                color: Color.BLACK
            },
            Stop {
                offset: 1.0
                color: Color.DARKGREEN
            }
        ]
    }
}
var titleText1 = Text {
    fill: Color.LIGHTBLUE
    font: bind Font {
        name:  "Arial Bold Italic"
        size:  10
    }
    x: 10
    y: 15
    content: "SpeedoMeter(JavaFX Samples) "
};
var opacity = 1.0;
var closebutton = Stack {
    visible: bind ("{__PROFILE__}" != "browser");
    layoutX: 220 layoutY: 3
    content: [
        Rectangle {
            width: 15 height: 15
            arcHeight: 10 arcWidth: 10
            stroke: Color.BLACK
            strokeWidth: 2
            opacity: bind opacity
            fill: Color.DARKORANGE
            onMouseClicked: function (e: MouseEvent): Void { FX.exit(); }
            onMouseEntered: function (e: MouseEvent): Void { opacity = 0.6; }
            onMouseExited: function (e: MouseEvent): Void { opacity = 1.0; }
        },
        Text {
            fill: Color.WHITE
            font: bind Font {
                name:  "Arial Bold"
                size:  12
            }
            content: "x"
        }
    ]
}

var rot = 0.0;
var takerot: Integer = 0;
public var t = Timeline {
    repeatCount: 1
    keyFrames: [
        KeyFrame {
            time: 3s
            canSkip: true
            values: bind [
                rot => takerot tween Interpolator.EASEBOTH
            ]
        }
    ]
}
var val_meter: String = "50";
var stf = TextBox {
        translateX: 120
        translateY: 327
        text: "50"
        columns: 5
        selectOnFocus: true
        height: 25
    }
var sb = Button {
    text: "Launch"
    opacity: 0.4
    translateX: 230
    translateY: 327
    width: 50
    height: 25
    onMouseClicked: function (e: MouseEvent): Void {
        takerot = java.lang.Integer.parseInt(stf.rawText);
        if (takerot > 300) {
            takerot = 0;
        } else
            t.evaluateKeyValues();
        t.playFromStart();
    }
}

public function run() {
    stage = Stage {

        title: "SpeedoMeter(JavaFX Samples)"
        width: 240
        height: 320
        style: StageStyle.TRANSPARENT
        scene: Scene {
            fill: Color.BLACK
            content: [
                titleBar, titleText1, closebutton,
                Group {
                    translateX: -85
                    translateY: -50
                    content: [
                        stf, sb,
                        t1, t2, t5,
                        Circle {
                            translateX: 200
                            translateY: 200
                            radius: 9
                            fill: null
                            strokeWidth: 2
                            stroke: Color.WHITE
                        },
                        Circle {
                            translateX: 200
                            translateY: 200
                            radius: 4
                            fill: Color.GRAY
                        },
                        Rectangle {
                            translateX: 200
                            translateY: 200
                            transforms: Rotate {
                                angle: bind rot + 120
                            }
                            x: -3
                            y: -3
                            width: 80
                            height: 6
                            arcHeight: 5
                            arcWidth: 5
                            fill: LinearGradient {
                                startX: 0.0
                                startY: 0.0
                                endX: 0.0
                                endY: 1.0
                                stops: [
                                    Stop {
                                        color: Color.RED
                                        offset: 0.0
                                    },
                                    Stop {
                                        color: Color.DARKRED
                                        offset: 0.5
                                    },
                                    Stop {
                                        color: Color.RED
                                        offset: 1.0
                                    },
                                ]
                            }
                        }
                        for (i in [0, 50, 100, 150, 200, 250, 300])
                            Text {
                                textAlignment: TextAlignment.CENTER
                                translateX: 200
                                translateY: 200
                                fill: Color.WHITE
                                transforms: [
                                    Transform.translate(-5, 5)
                                ]
                                x: 90 * Math.cos(Math.PI * 240 / 360 + 2 * i * Math.PI / 360) - 2
                                y: 90 * Math.sin(Math.PI * 240 / 360 + 2 * i * Math.PI / 360)
                                content: "{i}"
                                 font: bind Font {
                                    size:  11
                                    name:  "Arial Bold"
                                }
                            }
                        for (i in [0, 50, 100, 150, 200, 250, 300])
                            Line {
                                rotate: i - 60
                                startX: 200 + 100 * Math.cos(Math.PI * 240 / 360 + 2 * i * Math.PI / 360),
                                startY: 200 + 100 * Math.sin(Math.PI * 240 / 360 + 2 * i * Math.PI / 360)
                                endX: 195 + 100 * Math.cos(Math.PI * 240 / 360 + 2 * i * Math.PI / 360),
                                endY: 200 + 100 * Math.sin(Math.PI * 240 / 360 + 2 * i * Math.PI / 360)
                                strokeWidth: 3
                                stroke: Color.WHITE
                            },
                        Text {
                            fill: Color.WHITE
                            font: bind Font {
                                size:  10
                                name:  "Arial Bold"
                            }
                            x: 175
                            y: 235
                            content: bind "{takerot} Km/Hr"
                        }
                    ]
                }
            ]
        }
    }
}