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.langButton; import runtimelocalizationsample.Main.WorldMap; // Set Default Locale to English Locale.setDefault(new Locale("en", "US")); // Localized Strings and Images values 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]""; // Values for World Map 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; // Values for Clock var LocalizedDate = ""; var LocalizedClock = new Clock(); // Animation KeyFrames for World Map 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(); } } // World Map Class. Create 3 Maps and line up them for Animation. class WorldMap extends CustomNode { var worldY: Number; var worldMapImage = Group { translateX: bind worldX content: [ // This left image is displayed when scroll to right ImageView { x: worldWidth * -1, y: worldY image: Image { url: "{__DIR__}worldmap.png" } }, // This center image is diplayed mainly. ImageView { x: 0, y: worldY image: Image { url: "{__DIR__}worldmap.png" } }, // This right image is displayed when scroll to left ImageView { x: worldWidth, y: worldY image: Image { url: "{__DIR__}worldmap.png" } } ] } public override function create(): Node { // Initialize Timezone and values for Map. // All the setting is U.S (default). StartX = movedStartX; MoveX = CenterX - USX; movedStartX = StartX + MoveX; USX = USX + MoveX; JPX = JPX + MoveX; CNX = CNX + MoveX; KRX = KRX + MoveX; BRX = BRX + MoveX; // Inital Animation. Move U.S to center. t.playFromStart(); Group { content: [ // Whole world map. This image is line up 3 world map images. worldMapImage, // This Rectangle is used to hide right world image. Rectangle { x: worldWidth y: worldY width: worldWidth * 2, height: worldHight fill: Color.WHITE } ] } } } // Class for language button with text. class langButton extends CustomNode { // Button coordinates var button_x: Number; var button_y: Number; // Text in button coordinates var text_x: Number; var text_y: Number; // This is used to identify which button is clicked. // Also used to get the localized button lable. var text: String; // Button width var button_width: Number; // Localized button lable var ButtonText: String; // This function is used when a button is clicked // to calcurate coordinates for each city, // and get the time at there. // English: Los_Angeles // Japanese: Tokyo // Simplefied Chinese: Shanghai // Korean: Seoul // Brazilian Portuguese: Sao Paulo 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 { // Initial locale is English (Los Angeles). Locale.setDefault(new Locale("en", "US")); TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); // Get localized button lable from Main_en.properties 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"; } // Button and label group Group { content: [ // Button Rectangle { x: button_x, y: button_y width: button_width, height: 40 arcWidth: 20, arcHeight: 55 stroke: Color.BLACK // Draw Gradient for Buton 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 } ] } }, // Label Text { font: Font { size: 18 } x: text_x, y: text_y fill: Color.WHITE content: ButtonText } ] // Add Reflection effect for Button effect: Reflection { fraction: 0.9 topOpacity: 0.5 topOffset: 2.5 } // Action for Button is clicked onMouseClicked: function( e: MouseEvent ):Void { // Change Flag gif image Flag = "{__DIR__}{text}.gif"; // Actions for each Language Button. // 1. Set locale // 2. Set timezone // 3. Play animation if (text.equals("Japanese")) { Locale.setDefault(new Locale("ja", "JP")); TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo")); MoveX = CenterX - JPX; this.CalcLoc(); t.playFromStart(); } else if (text.equals("Chinese")) { Locale.setDefault(new Locale("zh", "CN")); TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); MoveX = CenterX - CNX; this.CalcLoc(); t.playFromStart(); } else if (text.equals("Korean")) { Locale.setDefault(new Locale("ko", "KR")); TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul")); MoveX = CenterX - KRX; this.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; this.CalcLoc(); t.playFromStart(); } else { Locale.setDefault(new Locale("en", "US")); TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); MoveX = CenterX - USX; this.CalcLoc(); t.playFromStart(); } // Change Display Text. // Those Strings are bind to the Text in Stage. 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 // Add Gradient for whole canvus 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: [ // English Button langButton { button_x: 40, button_y: 55 button_width: 80 text_x: 50, text_y: 83 text: "English" }, // Japanese Button langButton { button_x: 140, button_y: 55 button_width: 75 text_x: 150, text_y: 83 text: "Japanese" }, // Chinese Button langButton { button_x: 235, button_y: 55 button_width: 90 text_x: 245, text_y: 83 text: "Chinese" }, // Korean Button langButton { button_x: 345, button_y: 55 button_width: 75 text_x: 355, text_y: 83 text: "Korean" }, // Brazilian Portuguese Button langButton { button_x: 440, button_y: 55 button_width: 180 text_x: 450, text_y: 83 text: "Brazilian Portuguese" } ] }, // Map and Texts displaye Area Rectangle { y: 150 width: 1200, height: 390 fill: Color.WHITE }, // Flag image ImageView{ y: 150 image: bind Image{ url: Flag } }, // Title for Map and Texts area ("Start breaking the barriers!") Text { font: Font { size: 24 } x: 225, y: 195 content: bind viewtext }, // World Map WorldMap { worldY: 250 }, // Text for NetBeans title Text { font: Font { size: 12 } x: 450, y: 260 fill: Color.BLUE content: bind NBTitle }, // Text for NetBeans description Text { font: Font { size: 12 } x: 450, y: 275 wrappingWidth: 300 content: bind NBDesc }, // Text for Production Suite title Text { font: Font { size: 12 } x: 450, y: 370 fill: Color.BLUE; content: bind PSTitle }, // Text for Production Suite description Text { font: Font { size: 12 } x: 450, y: 385 wrappingWidth: 300 content: bind PSDesc }, // Text for JavaFX SDK title Text { font: Font { size: 12 } x: 450, y: 480 fill: Color.BLUE; content: bind SDKTitle }, // Text for JavaFX SDK description Text { font: Font { size: 12 } x: 450, y: 495 wrappingWidth: 300 content: bind SDKDesc }, // Display Localized Date Text { font: Font { size: 18 } x: 30, y: 570 content: bind LocalizedDate fill: Color.WHITE } ] } }