/*
* 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 runtimelocalizationsample;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.CustomNode;
import javafx.scene.effect.Reflection;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.Node;
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.Stage;
import runtimelocalizationsample.Main.Clock;
import runtimelocalizationsample.Main.langButton;
import runtimelocalizationsample.Main.WorldMap;
Locale.setDefault(new Locale("en", "US"));
var Flag:String = "{__DIR__}English.gif";
var viewtext:String = ##"Start breaking the barriers!";
var NBTitle:String = ##[NB_Title]"";
var NBDesc:String = ##[NB_Desc]"";
var PSTitle:String = ##[PS_Title]"";
var PSDesc:String = ##[PS_Desc]"";
var SDKTitle:String = ##[SDK_Title]"";
var SDKDesc:String = ##[SDK_Desc]"";
def worldHight = 263.0;
def worldWidth = 398.0;
def CenterX = 200.0;
var worldX:Number;
var USX = 306.0;
var JPX = 190.0;
var KRX = 177.0;
var CNX = 163.0;
var BRX = 377.0;
var MoveX = 0.0;
var StartX = 0.0;
var movedStartX = 0.0;
var LocalizedDate = "";
var LocalizedClock = new Clock();
var t = Timeline {
keyFrames: [
at (0s) {worldX => StartX},
at (2.0s) {worldX => movedStartX tween Interpolator.LINEAR}
]
}
class Clock {
public function nextTime() {
var now = new Date();
LocalizedDate = "{%tEc now}";
}
init {
var time = Timeline {
repeatCount:Timeline.INDEFINITE
keyFrames: [
KeyFrame {
time: 1s
action:function() {
nextTime();
}
}
]
}
time.play();
}
}
class WorldMap extends CustomNode {
var worldY:Number;
var worldMapImage = Group {
translateX: bind worldX
content: [
ImageView {
x: worldWidth * -1, y: worldY
image:Image { url: "{__DIR__}worldmap.png" }
},
ImageView {
x: 0,
y: worldY
image:Image { url: "{__DIR__}worldmap.png" }
},
ImageView {
x: worldWidth,
y: worldY
image:Image { url: "{__DIR__}worldmap.png" }
}
]
}
public override function create():Node {
StartX = movedStartX;
MoveX = CenterX - USX;
movedStartX = StartX + MoveX;
USX = USX + MoveX;
JPX = JPX + MoveX;
CNX = CNX + MoveX;
KRX = KRX + MoveX;
BRX = BRX + MoveX;
t.playFromStart();
Group {
content: [
worldMapImage,
Rectangle {
x: worldWidth
y: worldY
width: worldWidth * 2,
height: worldHight
fill: Color.WHITE
}
]
}
}
}
class langButton extends CustomNode {
var button_x:Number;
var button_y:Number;
var text_x:Number;
var text_y:Number;
var text:String;
var button_width:Number;
var ButtonText:String;
public function CalcLoc():Void {
StartX = movedStartX;
movedStartX = StartX + MoveX;
JPX = JPX + MoveX;
USX = USX + MoveX;
CNX = CNX + MoveX;
KRX = KRX + MoveX;
BRX = BRX + MoveX;
}
override public function create():Node {
Locale.setDefault(new Locale("en", "US"));
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
if (text.equals("English")) {
ButtonText = ##"English";
} else if (text.equals("Japanese")) {
ButtonText = ##"Japanese";
} else if (text.equals("Chinese")) {
ButtonText = ##"Chinese";
}else if (text.equals("Korean")) {
ButtonText = ##"Korean";
}else if (text.equals("Brazilian Portuguese")) {
ButtonText = ##"Brazilian Portuguese";
}
Group {
content: [
Rectangle {
x: button_x,
y: button_y
width: button_width,
height: 40
arcWidth: 20,
arcHeight: 55
stroke: Color.BLACK
fill:LinearGradient {
startX: 0.0,
startY: 0.0
endX: 0.0,
endY: 1.0
proportional: true
stops: [
Stop {
offset: 0.0,
color: Color.WHITE
},
Stop {
offset: 1.0,
color: Color.BLACK
}
]
}
},
Text {
font:Font {
size: 18
}
x: text_x,
y: text_y
fill: Color.WHITE
content: ButtonText
}
]
effect:Reflection {
fraction: 0.9
topOpacity: 0.5
topOffset: 2.5
}
onMouseClicked:function(e:MouseEvent):Void {
Flag = "{__DIR__}{text}.gif";
if (text.equals("Japanese")) {
Locale.setDefault(new Locale("ja", "JP"));
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo"));
MoveX = CenterX - JPX;
CalcLoc();
t.playFromStart();
} else if (text.equals("Chinese")) {
Locale.setDefault(new Locale("zh", "CN"));
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
MoveX = CenterX - CNX;
CalcLoc();
t.playFromStart();
} else if (text.equals("Korean")) {
Locale.setDefault(new Locale("ko", "KR"));
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
MoveX = CenterX - KRX;
CalcLoc();
t.playFromStart();
} else if (text.equals("Brazilian Portuguese")) {
Locale.setDefault(new Locale("pt", "BR"));
TimeZone.setDefault(TimeZone.getTimeZone("America/Sao_Paulo"));
MoveX = CenterX - BRX;
CalcLoc();
t.playFromStart();
} else {
Locale.setDefault(new Locale("en", "US"));
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
MoveX = CenterX - USX;
CalcLoc();
t.playFromStart();
}
viewtext = ##"Start breaking the barriers!";
NBTitle = ##[NB_Title]"";
NBDesc = ##[NB_Desc]"";
PSTitle = ##[PS_Title]"";
PSDesc = ##[PS_Desc]"";
SDKTitle = ##[SDK_Title]"";
SDKDesc = ##[SDK_Desc]"";
}
}
}
}
Stage {
title: "JavaFX Localization Sample"
scene: Scene {
width: 800
height: 600
fill:LinearGradient {
startX: 0.0,
startY: 0.0
endX: 0.0,
endY: 1.0
proportional: true
stops: [
Stop {
offset: 0.0,
color: Color.WHITE
},
Stop {
offset: 1.0,
color: Color.BLUE
}
]
}
content: [
Group {
content: [
langButton {
button_x: 40,
button_y: 55
button_width: 80
text_x: 50,
text_y: 83
text: "English"
},
langButton {
button_x: 140,
button_y: 55
button_width: 75
text_x: 150,
text_y: 83
text: "Japanese"
},
langButton {
button_x: 235,
button_y: 55
button_width: 90
text_x: 245,
text_y: 83
text: "Chinese"
},
langButton {
button_x: 345,
button_y: 55
button_width: 75
text_x: 355,
text_y: 83
text: "Korean"
},
langButton {
button_x: 440,
button_y: 55
button_width: 180
text_x: 450,
text_y: 83
text: "Brazilian Portuguese"
}
]
},
Rectangle {
y: 150
width: 1200,
height: 390
fill: Color.WHITE
},
ImageView{
y: 150
image: bind Image{ url: Flag }
},
Text {
font:Font {
size: 24
}
x: 225,
y: 195
content: bind viewtext
},
WorldMap {
worldY: 250
},
Text {
font:Font {
size: 12
}
x: 450,
y: 260
fill: Color.BLUE
content: bind NBTitle
},
Text {
font:Font {
size: 12
}
x: 450,
y: 275
wrappingWidth: 300
content: bind NBDesc
},
Text {
font:Font {
size: 12
}
x: 450,
y: 370
fill: Color.BLUE;
content: bind PSTitle
},
Text {
font:Font {
size: 12
}
x: 450,
y: 385
wrappingWidth: 300
content: bind PSDesc
},
Text {
font:Font {
size: 12
}
x: 450,
y: 480
fill: Color.BLUE;
content: bind SDKTitle
},
Text {
font:Font {
size: 12
}
x: 450,
y: 495
wrappingWidth: 300
content: bind SDKDesc
},
Text {
font:Font {
size: 18
}
x: 30,
y: 570
content: bind LocalizedDate
fill: Color.WHITE
}
]
}
}