/*
* 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 sudoku;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.lang.FX;
import javafx.scene.Cursor;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.geometry.HPos;
import javafx.scene.control.Label;
import javafx.scene.control.Button;
import sudoku.SudokuNode;
import javafx.scene.layout.LayoutInfo;
import javafx.scene.text.Font;
var stageDragInitialX:Number;
var stageDragInitialY:Number;
def _rectPadding = 3;
def _hboxHeight = 30;
def _headingDimX = 15;
def _headingDimY = 15;
def _rectDimXY = 1;
def _btnGridSpace = 7;
def _nodeX = 5;
def _nodePadding = 80;
def _btnGridX = 25;
def _headingPadding = 130;
var stylesheets = "{__DIR__}black.css";
var black = false on replace {
if(black) {
stylesheets = "{__DIR__}black.css";
cssButton.text = "Blue";
} else {
stylesheets = "{__DIR__}blue.css";
cssButton.text = "Black";
}
}
var dropShadow = DropShadow {
offsetX: 2
offsetY: 3
color: Color.color(0.4, 0.4, 0.4)
};
function btn_Hover(btn:Button,opacity:Number){
btn.opacity = opacity;
}
var newButton: Button = Button {
text: "New"
font:Font {name:"Arial" size:12}
layoutInfo:LayoutInfo{
width: 52
height: 25
}
styleClass:"buttonMenu"
onMousePressed:function(e) {
verifyButton.disable = false;
sudokuNode.updateData();
}
onMouseEntered:function(e){
btn_Hover(newButton,0.5);
}
onMouseExited:function(e) {
btn_Hover(newButton,1.0);
}
};
var hintButton: Button = Button {
text: "Hint"
font:Font {name:"Arial" size:12}
layoutInfo:LayoutInfo{
width: 52
height: 25
}
styleClass:"buttonMenu"
onMousePressed:function(e) {
sudokuNode.hint();
}
onMouseEntered:function(e){
btn_Hover(hintButton,0.5);
}
onMouseExited:function(e) {
btn_Hover(hintButton,1.0);
}
}
var verifyButton: Button = Button {
text: "Verify"
font:Font {name:"Arial" size:12}
layoutInfo:LayoutInfo{
width: 52
height: 25
}
styleClass:"buttonMenu"
onMousePressed:function(e) {
verifyButton.disable = true;
sudokuNode.verifyData();
}
onMouseEntered:function(e){
btn_Hover(verifyButton,0.5);
}
onMouseExited:function(e) {
btn_Hover(verifyButton,1.0);
}
}
var cssButton: Button = Button {
text: "Black"
font:Font {name:"Arial" size:12}
layoutInfo:LayoutInfo{
width: 52
height: 25
}
styleClass:"buttonMenu"
onMousePressed: function(e) {
cssButton.opacity = 1.0;
glassRect.visible = true;
timeline.playFromStart();
}
onMouseEntered:function(e){
btn_Hover(cssButton,0.5);
}
onMouseExited:function(e) {
btn_Hover(cssButton,1.0);
}
}
var timeline: Timeline = Timeline {
keyFrames: [
KeyFrame {
time: 250ms
action: function() {
black = not black;
glassRect.visible = false;
}
}
]
}
var buttonGrid:HBox = HBox {
spacing: _btnGridSpace
hpos: HPos.LEFT
content: [ newButton, hintButton, verifyButton, cssButton ]
layoutX: _btnGridX
layoutY: bind _heading.layoutY + _hboxHeight
}
var bgRect:Rectangle = Rectangle {
x: _rectDimXY
y: _rectDimXY
width: getWidth() - _rectPadding
height: getHeight() - _rectPadding
styleClass: "borderRectangle"
onMousePressed:function(e) {
if("{__PROFILE__}" != "browser") {
stageDragInitialX = e.screenX - stage.x;
stageDragInitialY = e.screenY - stage.y;
}
}
onMouseDragged:function(e) {
if("{__PROFILE__}" != "browser") {
stage.x = e.screenX - stageDragInitialX;
stage.y = e.screenY - stageDragInitialY;
}
}
};
var glassRect:Rectangle = Rectangle {
x: _rectDimXY
y: _rectDimXY
width: getWidth() - _rectPadding
height: getHeight() - _rectPadding
opacity: 0.75
styleClass: "borderRectangle"
blocksMouse: true
cursor: Cursor.WAIT
visible: false
};
var titleText:Label = Label {
text: "Sudoku"
effect: dropShadow
styleClass: "titleText"
}
var closeButton:Label = Label {
text: "X"
effect: dropShadow
cursor: Cursor.HAND
styleClass: "titleText"
visible: bind ("{__PROFILE__}" != "browser")
onMousePressed: function(e) {
FX.exit();
}
}
var _heading:HBox = HBox{
layoutX: _headingDimX
layoutY: _headingDimY
layoutInfo:LayoutInfo{
width: bind getWidth()
}
spacing: _headingDimX + _headingPadding
content: [titleText, closeButton]
}
var loadingText:Label = Label {
text: "Loading Theme..."
layoutX: bind getWidth()/4.0
layoutY: bind getHeight()/2.0
effect: dropShadow
styleClass: "titleText"
visible: bind glassRect.visible
}
var sudokuNode: SudokuNode = SudokuNode {
layoutY: buttonGrid.translateY + _nodePadding
layoutX: _nodeX
};
var stage = Stage {
width: getWidth()
height:getHeight()
scene: Scene {
content: [ bgRect, _heading, sudokuNode, buttonGrid, glassRect, loadingText ]
stylesheets: bind stylesheets
}
title: "JavaFX Sudoku"
style: StageStyle.UNDECORATED
}
function getWidth(): Number {
if ({__PROFILE__} != "tv")
return 281
else
return 1280
}
function getHeight(): Number {
if ({__PROFILE__} != "tv")
return 408
else
return 720
}
sudokuNode.updateData();
sudokuNode.requestFocus();