SlideShare a Scribd company logo
JavaFX 2.0 and Alternative LanguagesStephen ChinChief Agile Methodologist, GXSsteveonjava@gmail.comtweet: @steveonjava
About the PresenterStephen ChinJava ChampionFamily ManChief Agile Methodologist, GXSAuthor, Pro JavaFX PlatformMotorcyclist
Disclaimer: This is code-heavyTHE FOLLOWING IS INTENDED TO STIMULATE CREATIVE USE OF JVM LANGUAGES. AFTER WATCHING THIS PRESENTATION YOU MAY FEEL COMPELLED TO START LEARNING A NEW JVM LANGUAGE AND WANT TO APPLY IT AT YOUR WORKPLACE. THE PRESENTERS ARE NOT LIABLE FOR ANY INNOVATION, BREAKTHROUGHS, OR NP-COMPLETE SOLUTIONS THAT MAY RESULT.
AgendaJavaFX 2.0 PlatformJavaFX in JavaExplore Alternative Languages
JavaFX and the Java Platform Java LanguageJava EEHotSpot Java VMLightweight Java VMJava SEJava TV & Java MEJava CardJava FXAPIsCopyright 2010 Oracle
JavaFX Design GoalsDeliver the Best HTML5 & Native Application Experience from JavaProgramming model: the power of Java, the ease of JavaFXNative interoperability between Java, JavaScript & HTML5 High performance 2D and 3D Java graphics engine designed to exploit hardware advances in desktop & mobileComplete & integrated development lifecycle experienceCopyright 2010 Oracle
Programming LanguagesJavaFX 2.0 APIs are now in JavaPure Java APIs for all of JavaFXExpose JavaFX Binding, Sequences as Java APIsEmbrace all JVM languagesJRuby, Clojure, Groovy, ScalaFantom, Mira, Jython, etc.JavaFX Script is no longer supported by OracleExisting JavaFX Script based applications will continue to runVisage is the open-source successor to the JavaFX Script languageCopyright 2010 Oracle
JavaFX 2.0 Product TimelineCYQ1 2011CYQ3 2011CYQ2 2011JavaFX 2.0 EA(Early Access)JavaFX 2.0 BetaJavaFX 2.0 GA(General Availability)Copyright 2010 Oracle
JavaFX With Java
JavaFX in JavaJavaFX API follows JavaBeans approachSimilar in feel to other UI toolkits (Swing, etc)Uses builder pattern to minimize boilerplate
BindingUnquestionably the biggest JavaFX Script innovationSupported via a PropertyBinding classLazy invocation for high performanceStatic construction syntax for simple casese.g.: bindTo(<property>)
Observable Pseudo-PropertiesSupports watching for changes to propertiesImplemented via anonymous inner classesWill take advantage of closures in the future
Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() {});
Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() {});The property we want to watch
Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() {});Only one listener used regardless of data type
Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() {  public void handle(Bean bean, PropertyReference pr) {  }});Rectangle is a Bean
Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() {  public void handle(Bean bean, PropertyReference pr) {  }});Refers to the Rectangle.hover ‘property’
Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() {  public void handle(Bean bean, PropertyReference pr) {rect.setFill(rect.isHover() ? Color.GREEN : Color.RED);  }});
Sequences in JavaReplaced with an Observable ListPublic API is based on JavaFX sequencesInternal code can use lighter collections APIJavaFX 2.0 will also have an Observable Map
Example Applicationpublic class HelloStage extends Application {  @Override public void start() {    Stage stage = new Stage();stage.setTitle("Hello Stage");stage.setWidth(600);    stage.setHeight(450);Group root = new Group();    Scene scene = new Scene(root);scene.setFill(Color.LIGHTGREEN);stage.setScene(scene);stage.setVisible(true);  }  public static void main(String[] args) {Launcher.launch(HelloStage.class, args);  }}
JavaFX With JRuby
Why JRuby?Direct access to Java APIs
Dynamic Typing
Closures
‘Closure conversion’ for interfacesJava in JRuby  - Accessing Propertiestimeline.setAutoReverse(true)timeline.autoReverse = truetimeline.auto_reverse = truetimeline.getKeyFrames().add(kf)timeline.key_frames.add(kf)timeline.key_frames.addkf
JRuby Example 1: Simple Stagerequire 'java'FX = Java::javafx.lang.FXStage = Java::javafx.stage.StageScene = Java::javafx.scene.SceneColor = Java::javafx.scene.paint.Colorclass HelloStage  include java.lang.Runnable  def run    .....  endendFX.start(HelloStage.new);stage = Stage.newstage.title = 'Hello Stage (JRuby)'stage.width = 600stage.height = 450scene = Scene.newscene.fill = Color::LIGHTGREENstage.scene = scenestage.visible = true;
JRuby Example 2rect = Rectangle.newrect.x = 25rect.y = 40rect.width = 100rect.height = 50rect.fill = Color::REDscene.content.add(rect)timeline = Timeline.newtimeline.repeat_count= Timeline::INDEFINITEtimeline.auto_reverse = truekv = KeyValue.new(rect, Rectangle::X, 200);kf = KeyFrame.new(Duration.valueOf(500), kv);timeline.key_frames.addkf;timeline.play();
JRuby Closure Conversionrect.add_change_listener(Rectangle::HOVER) do |bean, pr, bln|rect.fill = rect.hover ? Color::GREEN : Color::RED;end26
JRubySwibyrequire 'swiby'class HelloWorldModelattr_accessor :sayingendmodel = HelloWorldModel.newmodel.saying = "Hello World"Frame {  title "Hello World“  width 200  content {    Label {      text bind(model,:saying)    }  }  visible true}27
28JavaFX With ClojureArtwork by Augusto Sellhornhttp://sellmic.com/
A Little About      ClojureStarted in 2007 by Rich HickeyFunctional Programming LanguageDerived from LISPOptimized for High Concurrency… and looks nothing like Java!29(def hello (fn [] "Hello world"))(hello)
Clojure Syntax in One SlideSymbolsnumbers – 2.178ratios – 355/113strings – “clojure”, “rocks”characters – \a \b \c \dsymbols – a b c dkeywords – :alpha :betaboolean – true, falsenull - nilCollections(commas optional)Lists(1, 2, 3, 4, 5)Vectors[1, 2, 3, 4, 5]Maps{:a 1, :b 2, :c 3, :d 4}Sets#{:a :b :c :d :e}30(plus macros that are syntactic sugar wrapping the above)
Clojure GUI Example(defnjavafxapp []  (let [stage (Stage. "JavaFX Stage")        scene (Scene.)]    (.setFill scene Color/LIGHTGREEN)    (.setWidth stage 600)    (.setHeight stage 450)    (.setScene stage scene)    (.setVisible stage true)))(javafxapp)31
Clojure GUI Example(defnjavafxapp[]  (let [stage (Stage. "JavaFX Stage")        scene (Scene.)]    (.setFill scene Color/LIGHTGREEN)    (.setWidth stage 600)    (.setHeight stage 450)    (.setScene stage scene)    (.setVisible stage true)))(javafxapp)32Create a Function for the Application
Clojure GUI Example(defnjavafxapp [](let [stage (Stage. "JavaFX Stage")        scene (Scene.)]    (.setFill scene Color/LIGHTGREEN)    (.setWidth stage 600)    (.setHeight stage 450)    (.setScene stage scene)    (.setVisible stage true)))(javafxapp)33Initialize the Stage and Scene Variables
Clojure GUI Example(defnjavafxapp []  (let [stage (Stage. "JavaFX Stage")        scene (Scene.)]    (.setFill scene Color/LIGHTGREEN)    (.setWidth stage 600)    (.setHeight stage 450)    (.setScene stage scene)    (.setVisible stage true)))(javafxapp)34Call Setter Methods on Scene and Stage
Clojure GUI Example(defnjavafxapp []  (let [stage (Stage. "JavaFX Stage")        scene (Scene.)]    (.setFillscene Color/LIGHTGREEN)    (.setWidthstage 600)    (.setHeightstage 450)    (.setScenestage scene)    (.setVisiblestage true)))(javafxapp)35Java Constant SyntaxJava Method Syntax
Simpler Code Using doto(defnjavafxapp []  (let [stage (Stage. "JavaFX Stage")        scene (Scene.)]    (doto scene      (.setFillColor/LIGHTGREEN))    (doto stage      (.setWidth600)      (.setHeight450)      (.setScene scene)      (.setVisibletrue))))(javafxapp)36
Simpler Code Using doto(defnjavafxapp []  (let [stage (Stage. "JavaFX Stage")        scene (Scene.)]    (doto scene      (.setFillColor/LIGHTGREEN))    (doto stage      (.setWidth 600)      (.setHeight 450)      (.setScene scene)      (.setVisible true))))(javafxapp)37doto form:(doto symbol   (.method params)) equals:(.method symbol params)
Refined Clojure GUI Example(defnjavafxapp []  (doto (Stage. "JavaFX Stage")    (.setWidth600)    (.setHeight450)    (.setScene (doto (Scene.)      (.setFillColor/LIGHTGREEN)      (.setContent (list (doto (Rectangle.)        (.setX25)        (.setY40)        (.setWidth100)        (.setHeight50)        (.setFillColor/RED))))))    (.setVisibletrue)))(javafxapp)38
Refined Clojure GUI Example(defnjavafxapp []  (doto(Stage. "JavaFX Stage")    (.setWidth 600)    (.setHeight 450)    (.setScene (doto(Scene.)      (.setFillColor/LIGHTGREEN)      (.setContent (list (doto (Rectangle.)        (.setX 25)        (.setY 40)        (.setWidth 100)        (.setHeight 50)        (.setFillColor/RED))))))    (.setVisible true)))(javafxapp)39Let replaced with inline declarations
Refined Clojure GUI Example(defnjavafxapp []  (doto (Stage. "JavaFX Stage")    (.setWidth 600)    (.setHeight 450)    (.setScene (doto (Scene.)      (.setFillColor/LIGHTGREEN)      (.setContent (list (doto (Rectangle.)        (.setX 25)        (.setY 40)        (.setWidth 100)        (.setHeight 50)        (.setFillColor/RED))))))    (.setVisible true)))(javafxapp)40Doto allows nested data structures
Refined Clojure GUI Example(defnjavafxapp []  (doto (Stage. "JavaFX Stage")    (.setWidth 600)    (.setHeight 450)    (.setScene (doto (Scene.)      (.setFillColor/LIGHTGREEN)      (.setContent (list (doto (Rectangle.)        (.setX 25)        (.setY 40)        (.setWidth 100)        (.setHeight 50)        (.setFillColor/RED))))))    (.setVisible true)))(javafxapp)41Now a nested Rectangle fits!
Closures in Clojure42Inner classes can be created using proxy(.addChangeListenerrectRectangle/HOVER  (proxy [Listener] []    (handle [b, p]      (.setFillrect        (if (.isHoverrect) Color/GREEN Color/RED)))))
Closures in ClojureInner classes can be created using proxy43Proxy form:(proxy [class] [args] fs+) f => (name [params*] body)(.addChangeListenerrectRectangle/HOVER  (proxy[Listener][]    (handle [b, p]      (.setFillrect        (if (.isHoverrect) Color/GREEN Color/RED)))))
JavaFX With Groovy
Features of GroovyTight integration with JavaVery easy to port from Java to GroovyDeclarative syntaxFamiliar to JavaFX Script developersBuilders
Example 1: Simple FX Script to Groovy
Step 1: Lazy conversion to Groovyclass HelloStage implements Runnable { void run() {    Stage stage = new Stage();stage.setTitle("Hello Stage (Groovy)“);stage.setWidth(600);stage.setHeight(450);    Scene scene = new Scene();scene.setFill(Color.LIGHTSKYBLUE);stage.setScene(scene);stage.setVisible(true);  }static void main(args) {FX.start(new HelloStage());  }}
Step 2: Slightly More Groovyclass HelloStage implements Runnable {    void run() {        new Stage(            title: "Hello Stage (Groovy)",            width: 600,            height: 450,            visible: true,            scene: new Scene(                fill: Color.LIGHTSKYBLUE,            )        );    }    static void main(args) {FX.start(new HelloStage());    }}
Slight Aside: Groovy BuildersGroovy builders make writing custom DSLs easyFor the next slide, I am using a builder I definedHopefully the community will improve upon this
Step 3: Using a Groovy BuilderFxBuilder.build {    stage = stage(        title: "Hello World",          width: 600,          height: 450,        scene: scene(fill: Color.LIGHTSKYBLUE) {            ...        }    )    stage.visible = true;}
Step 4: With ContentFxBuilder.build {    stage = stage(        title: "Hello Rectangle (Groovy FxBuilder 2)",          width: 600,          height: 450,        scene: scene(fill: Color.LIGHTSKYBLUE) {            rectangle(                x: 25, y: 40,                width: 100, height: 50,                fill: Color.RED            )       }    )    stage.visible = true;}
Example 2: FX Script Animation in Groovy
Step 1: JavaFX Scriptdef timeline = Timeline {repeatCount: Timeline.INDEFINITEautoReverse: truekeyFrames: [KeyFrame {      time: 750ms      values : [        rect1.x => 200.0 tweenInterpolator.LINEAR,        rect2.y => 200.0 tweenInterpolator.LINEAR,        circle1.radius => 200.0 tweenInterpolator.LINEAR      ]    }  ];}timeline.play();
Step 1a: JavaFX Script Simplificationdef timeline = Timeline {repeatCount: Timeline.INDEFINITEautoReverse: true  keyFrames: at (750ms) {    rect1.x => 200.0 tween Interpolator.LINEAR;    rect2.y => 200.0 tween Interpolator.LINEAR;    circle1.radius => 200.0 tween Interpolator.LINEAR;  }}timeline.play();
Step 2: Java-ish Groovy Animationsfinal Timeline timeline = new Timeline(repeatCount: Timeline.INDEFINITE,autoReverse: true)final KeyValue kv1 = new KeyValue (rect1.x(), 200);final KeyValue kv2 = new KeyValue (rect2.y(), 200);final KeyValue kv3 = new KeyValue (circle1.radius(), 200);final KeyFramekf = new KeyFrame(Duration.valueOf(750), kv1, kv2, kv3);timeline.getKeyFrames().add(kf);timeline.play();
Step 3: JavaFX Animation Groovy DSL (courtesy of Jim Clarke – work in progress)timeline = timeline(repeatCount: Timeline.INDEFINITE, autoReverse: true) {  at 750.ms update values {   change rect1.y() to 200   change rect2.x() to 200   change circle.radius() to 200 }}timeline.play();
Groovy Closures  - With interface coerciondef f = {   bean, pr-> rect.setFill(rect.isHover() ? Color.GREEN : Color.RED);} as Listener;rect.addChangedListener(Rectangle.HOVER, f);
58JavaFX With Scala
What is ScalaStarted in 2001 by Martin OderskyCompiles to Java bytecodesPure object-oriented languageAlso a functional programming language59
Why Scala?Shares many language features with JavaFX Script that make GUI programming easier:Static type checking – Catch your errors at compile timeClosures – Wrap behavior and pass it by referenceDeclarative – Express the UI by describing what it should look likeScala also supports DSLs!60
Java vs. Scala DSLpublic class HelloStage implements Runnable {  public void run() {    Stage stage = new Stage();stage.setTitle("Hello Stage");stage.setWidth(600);stage.setHeight(450);    Scene scene = new Scene();scene.setFill(Color.LIGHTGREEN);    Rectangle rect = new Rectangle();rect.setX(25);rect.setY(40);rect.setWidth(100);rect.setHeight(50);rect.setFill(Color.RED);stage.add(rect);stage.setScene(scene);stage.setVisible(true);  }  public static void main(String[] args) {FX.start(new HelloStage());  }}object HelloJavaFX extends JavaFXApplication {  def stage = new Stage {    title = "Hello Stage"    width = 600    height = 450    scene = new Scene {      fill = Color.LIGHTGREEN      content = List(new Rectangle {        x = 25        y = 40        width = 100        height = 50        fill = Color.RED      })    }  }}6122 Lines545 Characters17 Lines324 Characters
object HelloJavaFX extends JavaFXApplication {  def stage = new Stage {    title = "Hello Stage"    width = 600    height = 450    scene = new Scene {      fill = Color.LIGHTGREEN      content = List(new Rectangle {        x = 25        y = 40        width = 100        height = 50        fill = Color.RED      })    }  }}62
63object HelloJavaFX extends JavaFXApplication {  def stage = new Stage {    title = "Hello Stage"    width = 600    height = 450    scene = new Scene {      fill = Color.LIGHTGREEN      content = List(new Rectangle {        x = 25        y = 40        width = 100        height = 50        fill = Color.RED      })    }  }}object HelloJavaFX extends JavaFXApplication {  def stage = new Stage {    title = "Hello Stage"    width = 600    height = 450    scene = new Scene {      fill = Color.LIGHTGREEN      content = List(new Rectangle {        x = 25        y = 40        width = 100        height = 50        fill = Color.RED      })    }  }}Base class for JavaFX applications
64object HelloJavaFX extends JavaFXApplication {def stage = new Stage {    title = "Hello Stage"    width = 600    height = 450    scene = new Scene {      fill = Color.LIGHTGREEN      content = List(new Rectangle {        x = 25        y = 40        width = 100        height = 50        fill = Color.RED      })    }  }}Declarative Stage definition
65object HelloJavaFX extends JavaFXApplication {  def stage = new Stage {title = "Hello Stage"    width = 600    height = 450    scene = new Scene {      fill = Color.LIGHTGREEN      content = List(new Rectangle {        x = 25        y = 40        width = 100        height = 50        fill = Color.RED      })    }  }}Inline property definitions
66object HelloJavaFX extends JavaFXApplication {  def stage = new Stage {    title = "Hello Stage"    width = 600    height = 450    scene = new Scene {      fill = Color.LIGHTGREEN      content = List(new Rectangle {        x = 25        y = 40        width = 100        height = 50        fill = Color.RED      })    }  }}List Construction Syntax
Animation in Scaladef timeline = new Timeline {repeatCount = INDEFINITEautoReverse = truekeyFrames = List(      new KeyFrame(time: 50) {        values = List(          new KeyValue(rect1.x() -> 300),          new KeyValue(rect2.y() -> 500),          new KeyValue(rect2.width() -> 150)        )      }    )  }67
def timeline = new Timeline {repeatCount = INDEFINITEautoReverse = truekeyFrames = List(      new KeyFrame(time: 50) {        values = List(          new KeyValue(rect1.x() -> 300),          new KeyValue(rect2.y() -> 500),          new KeyValue(rect2.width() -> 150)        )      }    )  }Animation in Scala68Duration set by Constructor Parameter
Animation in Scala69def timeline = new Timeline {repeatCount = INDEFINITEautoReverse = truekeyFrames = List(      new KeyFrame(time: 50) {        values = List(          new KeyValue(rect1.x() -> 300),          new KeyValue(rect2.y() -> 500),          new KeyValue(rect2.width() -> 150)        )      }    )  }Operator overloading for animation syntax
Closures in Scala70Closures are also supported in ScalaAnd they are 100% type-saferect.addChangedListener(Node.HOVER, (b, p) => {rect.fill = if (rect.hover) Color.GREEN else Color.RED})
Closures in ScalaClosures are also supported in ScalaAnd they are 100% type-safe71rect.addChangedListener(Node.HOVER, (b, p) => {rect.fill = if (rect.hover) Color.GREEN else Color.RED})Compact syntax(params) => {body}
Other JVM Languages to TryJythonStarted by Jim HuguninHigh Performance PythonMirahInvented by Charles NutterOriginally called DubyLocal Type Inference, Static and Dynamic TypingFantomCreated by Brian and Andy FrankOriginally called FanBuilt-in Declarative SyntaxPortable to Java and .NETLocal Type Inference, Static and Dynamic Typing72
Fantom Code ExampleVoid main() {  Stage {    title= "Hello Stage"    width= 600    height= 450   Scene {      fill= Color.LIGHTGREEN      Rectangle {        x= 25        y= 40        width= 100        height= 50        fill= Color.RED      }    }  }.open}73
timeline := Timeline {  repeatCount = Timeline.INDEFINITE  autoReverse = trueKeyFrame {   time = 50msKeyValue(rect1.x()-> 300),    KeyValue(rect2.y() -> 500),    KeyValue(rect2.width() -> 150)}}Animation in Fantom74Fantom has a built-in Duration typeAnd also supports operator overloading
Announcing Project Visage75“Visage is a domain specific language (DSL) designed for the express purpose of writing user interfaces.”Visage project goals:Compile to JavaFX Java APIsEvolve the Language (Annotations, Maps, etc.)Support Other ToolkitsCome join the team!For more info: http://visage-lang.org/
How about JavaFX on…  VisageStage {  title: "Hello Stage"  width: 600  height: 450 scene: Scene {    fill: Color.LIGHTGREEN    content: Rectangle {      x: 25      y: 40      width: 100      height: 50      fill: Color.RED    }  }}76
How about JavaFX on…  VisageStage {  title: "Hello Stage"  width: 600  height: 450scene: Scene {    fill: Color.LIGHTGREENcontent: Rectangle {      x: 25      y: 40      width: 100      height: 50      fill: Color.RED    }  }}77
How about JavaFX on…  VisageStage {  title: "Hello Stage"  width: 600  height: 450 Scene {    fill: Color.LIGHTGREEN    Rectangle {      x: 25      y: 40      width: 100      height: 50      fill: Color.RED    }  }}78
ConclusionYou can write JavaFX applications in pure JavaJavaFX is also usable in alternate languagesOver time improved support is possibleGroovy Builders, Scala DSL, VisageRemember: This is a proof of concept only – you can not leave this session and do this today.
Challenge the Presenter…

More Related Content

What's hot (20)

PDF
The Magnificent Seven
Mike Fogus
 
PDF
Design Patterns in Luster
Jason Chung
 
PDF
Scala vs Java 8 in a Java 8 World
BTI360
 
PPTX
Using Redux-Saga for Handling Side Effects
GlobalLogic Ukraine
 
PDF
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
PDF
Python decorators (中文)
Yiwei Chen
 
PDF
The Groovy Way
Gabriel Dogaru
 
ODP
JavaScript Web Development
vito jeng
 
PDF
ZIO Queue
John De Goes
 
PPTX
Codestrong 2012 breakout session hacking titanium
Axway Appcelerator
 
PDF
C++ game development with oxygine
corehard_by
 
PPTX
The Challenge of Bringing FEZ to PlayStation Platforms
Miguel Angel Horna
 
PDF
ECMAScript 6
Piotr Lewandowski
 
PDF
Redux Sagas - React Alicante
Ignacio Martín
 
TXT
bullismo e scuola primaria
imartini
 
KEY
Why Learn Python?
Christine Cheung
 
PDF
Kotlin Coroutines Reloaded
Roman Elizarov
 
PDF
Your code is not a string
Ingvar Stepanyan
 
PDF
Programming with GUTs
Kevlin Henney
 
PDF
The Ring programming language version 1.8 book - Part 96 of 202
Mahmoud Samir Fayed
 
The Magnificent Seven
Mike Fogus
 
Design Patterns in Luster
Jason Chung
 
Scala vs Java 8 in a Java 8 World
BTI360
 
Using Redux-Saga for Handling Side Effects
GlobalLogic Ukraine
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
Python decorators (中文)
Yiwei Chen
 
The Groovy Way
Gabriel Dogaru
 
JavaScript Web Development
vito jeng
 
ZIO Queue
John De Goes
 
Codestrong 2012 breakout session hacking titanium
Axway Appcelerator
 
C++ game development with oxygine
corehard_by
 
The Challenge of Bringing FEZ to PlayStation Platforms
Miguel Angel Horna
 
ECMAScript 6
Piotr Lewandowski
 
Redux Sagas - React Alicante
Ignacio Martín
 
bullismo e scuola primaria
imartini
 
Why Learn Python?
Christine Cheung
 
Kotlin Coroutines Reloaded
Roman Elizarov
 
Your code is not a string
Ingvar Stepanyan
 
Programming with GUTs
Kevlin Henney
 
The Ring programming language version 1.8 book - Part 96 of 202
Mahmoud Samir Fayed
 

Viewers also liked (14)

PDF
JavaFX 2.1 - следующее поколение клиентской Java
Alexander_K
 
PPTX
JavaFX technology
Nakraynikov Oleg
 
PDF
JavaFX 2.0 overview
Dmitry Buzdin
 
PDF
01 - JavaFX. Введение в JavaFX
Roman Brovko
 
ODP
JavaFX introduction
José Maria Silveira Neto
 
PDF
JavaFX Advanced
Paul Bakker
 
PDF
Introduction to JavaFX 2
Thierry Wasylczenko
 
PDF
JavaFX in Action (devoxx'16)
Alexander Casall
 
ODP
Presentation - Course about JavaFX
Tom Mix Petreca
 
PDF
JavaFX Overview
José Maria Silveira Neto
 
PDF
8 True Stories about JavaFX
Yuichi Sakuraba
 
PDF
Mini-curso JavaFX Aula1
Raphael Marques
 
PDF
JavaFX for Java Developers
Sten Anderson
 
PDF
Enterprising JavaFX
Richard Bair
 
JavaFX 2.1 - следующее поколение клиентской Java
Alexander_K
 
JavaFX technology
Nakraynikov Oleg
 
JavaFX 2.0 overview
Dmitry Buzdin
 
01 - JavaFX. Введение в JavaFX
Roman Brovko
 
JavaFX introduction
José Maria Silveira Neto
 
JavaFX Advanced
Paul Bakker
 
Introduction to JavaFX 2
Thierry Wasylczenko
 
JavaFX in Action (devoxx'16)
Alexander Casall
 
Presentation - Course about JavaFX
Tom Mix Petreca
 
JavaFX Overview
José Maria Silveira Neto
 
8 True Stories about JavaFX
Yuichi Sakuraba
 
Mini-curso JavaFX Aula1
Raphael Marques
 
JavaFX for Java Developers
Sten Anderson
 
Enterprising JavaFX
Richard Bair
 
Ad

Similar to JavaFX 2.0 and Alternative Languages (20)

PPTX
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
Stephen Chin
 
PPTX
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
Stephen Chin
 
PPTX
JavaFX Your Way - Devoxx Version
Stephen Chin
 
PDF
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
Stephen Chin
 
PPTX
JavaFX 2.0 With Alternative Languages - JavaOne 2011
Stephen Chin
 
PPTX
JavaFX 2.0 With Alternative Languages [Portuguese]
Stephen Chin
 
PDF
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
jaxconf
 
PDF
Groovy's Builder
Yasuharu Nakano
 
PDF
Don't panic in Fortaleza - ScalaFX
Alain Béarez
 
PDF
Greach, GroovyFx Workshop
Dierk König
 
PPTX
Clojure And Swing
Skills Matter
 
PDF
JavaFX
Raphael Marques
 
PPTX
XML-Free Programming
Stephen Chin
 
PPTX
The Java Fx Platform – A Java Developer’S Guide
Stephen Chin
 
PPTX
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
Stephen Chin
 
PDF
L5, Loop and iteration, CSE 202, BN11.pdf
SauravBarua11
 
PPT
Intro to JavaFX & Widget FX
Stephen Chin
 
ODP
Java Fx Overview Tech Tour
Carol McDonald
 
PPTX
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
Stephen Chin
 
PDF
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Naresha K
 
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
Stephen Chin
 
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
Stephen Chin
 
JavaFX Your Way - Devoxx Version
Stephen Chin
 
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
Stephen Chin
 
JavaFX 2.0 With Alternative Languages - JavaOne 2011
Stephen Chin
 
JavaFX 2.0 With Alternative Languages [Portuguese]
Stephen Chin
 
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
jaxconf
 
Groovy's Builder
Yasuharu Nakano
 
Don't panic in Fortaleza - ScalaFX
Alain Béarez
 
Greach, GroovyFx Workshop
Dierk König
 
Clojure And Swing
Skills Matter
 
XML-Free Programming
Stephen Chin
 
The Java Fx Platform – A Java Developer’S Guide
Stephen Chin
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
Stephen Chin
 
L5, Loop and iteration, CSE 202, BN11.pdf
SauravBarua11
 
Intro to JavaFX & Widget FX
Stephen Chin
 
Java Fx Overview Tech Tour
Carol McDonald
 
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
Stephen Chin
 
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Naresha K
 
Ad

More from Stephen Chin (20)

PPTX
DevOps Tools for Java Developers v2
Stephen Chin
 
PPTX
10 Ways Everyone Can Support the Java Community
Stephen Chin
 
PPTX
Java Clients and JavaFX: The Definitive Guide
Stephen Chin
 
PPTX
DevOps Tools for Java Developers
Stephen Chin
 
PPTX
Java Clients and JavaFX - Presented to LJC
Stephen Chin
 
PPTX
RetroPi Handheld Raspberry Pi Gaming Console
Stephen Chin
 
PPTX
JavaFX on Mobile (by Johan Vos)
Stephen Chin
 
PPTX
Confessions of a Former Agile Methodologist (JFrog Edition)
Stephen Chin
 
PPTX
Devoxx4Kids Lego Workshop
Stephen Chin
 
PPTX
Raspberry Pi with Java (JJUG)
Stephen Chin
 
PPTX
Confessions of a Former Agile Methodologist
Stephen Chin
 
PPTX
Internet of Things Magic Show
Stephen Chin
 
PPTX
Zombie Time - JSR 310 for the Undead
Stephen Chin
 
PPTX
JCrete Embedded Java Workshop
Stephen Chin
 
PPTX
Oracle IoT Kids Workshop
Stephen Chin
 
PPTX
OpenJFX on Android and Devices
Stephen Chin
 
PPTX
Java on Raspberry Pi Lab
Stephen Chin
 
PDF
Java 8 for Tablets, Pis, and Legos
Stephen Chin
 
PDF
DukeScript
Stephen Chin
 
PPTX
Devoxx4Kids NAO Workshop
Stephen Chin
 
DevOps Tools for Java Developers v2
Stephen Chin
 
10 Ways Everyone Can Support the Java Community
Stephen Chin
 
Java Clients and JavaFX: The Definitive Guide
Stephen Chin
 
DevOps Tools for Java Developers
Stephen Chin
 
Java Clients and JavaFX - Presented to LJC
Stephen Chin
 
RetroPi Handheld Raspberry Pi Gaming Console
Stephen Chin
 
JavaFX on Mobile (by Johan Vos)
Stephen Chin
 
Confessions of a Former Agile Methodologist (JFrog Edition)
Stephen Chin
 
Devoxx4Kids Lego Workshop
Stephen Chin
 
Raspberry Pi with Java (JJUG)
Stephen Chin
 
Confessions of a Former Agile Methodologist
Stephen Chin
 
Internet of Things Magic Show
Stephen Chin
 
Zombie Time - JSR 310 for the Undead
Stephen Chin
 
JCrete Embedded Java Workshop
Stephen Chin
 
Oracle IoT Kids Workshop
Stephen Chin
 
OpenJFX on Android and Devices
Stephen Chin
 
Java on Raspberry Pi Lab
Stephen Chin
 
Java 8 for Tablets, Pis, and Legos
Stephen Chin
 
DukeScript
Stephen Chin
 
Devoxx4Kids NAO Workshop
Stephen Chin
 

Recently uploaded (20)

PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 

JavaFX 2.0 and Alternative Languages

  • 1. JavaFX 2.0 and Alternative LanguagesStephen ChinChief Agile Methodologist, [email protected]: @steveonjava
  • 2. About the PresenterStephen ChinJava ChampionFamily ManChief Agile Methodologist, GXSAuthor, Pro JavaFX PlatformMotorcyclist
  • 3. Disclaimer: This is code-heavyTHE FOLLOWING IS INTENDED TO STIMULATE CREATIVE USE OF JVM LANGUAGES. AFTER WATCHING THIS PRESENTATION YOU MAY FEEL COMPELLED TO START LEARNING A NEW JVM LANGUAGE AND WANT TO APPLY IT AT YOUR WORKPLACE. THE PRESENTERS ARE NOT LIABLE FOR ANY INNOVATION, BREAKTHROUGHS, OR NP-COMPLETE SOLUTIONS THAT MAY RESULT.
  • 4. AgendaJavaFX 2.0 PlatformJavaFX in JavaExplore Alternative Languages
  • 5. JavaFX and the Java Platform Java LanguageJava EEHotSpot Java VMLightweight Java VMJava SEJava TV & Java MEJava CardJava FXAPIsCopyright 2010 Oracle
  • 6. JavaFX Design GoalsDeliver the Best HTML5 & Native Application Experience from JavaProgramming model: the power of Java, the ease of JavaFXNative interoperability between Java, JavaScript & HTML5 High performance 2D and 3D Java graphics engine designed to exploit hardware advances in desktop & mobileComplete & integrated development lifecycle experienceCopyright 2010 Oracle
  • 7. Programming LanguagesJavaFX 2.0 APIs are now in JavaPure Java APIs for all of JavaFXExpose JavaFX Binding, Sequences as Java APIsEmbrace all JVM languagesJRuby, Clojure, Groovy, ScalaFantom, Mira, Jython, etc.JavaFX Script is no longer supported by OracleExisting JavaFX Script based applications will continue to runVisage is the open-source successor to the JavaFX Script languageCopyright 2010 Oracle
  • 8. JavaFX 2.0 Product TimelineCYQ1 2011CYQ3 2011CYQ2 2011JavaFX 2.0 EA(Early Access)JavaFX 2.0 BetaJavaFX 2.0 GA(General Availability)Copyright 2010 Oracle
  • 10. JavaFX in JavaJavaFX API follows JavaBeans approachSimilar in feel to other UI toolkits (Swing, etc)Uses builder pattern to minimize boilerplate
  • 11. BindingUnquestionably the biggest JavaFX Script innovationSupported via a PropertyBinding classLazy invocation for high performanceStatic construction syntax for simple casese.g.: bindTo(<property>)
  • 12. Observable Pseudo-PropertiesSupports watching for changes to propertiesImplemented via anonymous inner classesWill take advantage of closures in the future
  • 13. Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() {});
  • 14. Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() {});The property we want to watch
  • 15. Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() {});Only one listener used regardless of data type
  • 16. Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() { public void handle(Bean bean, PropertyReference pr) { }});Rectangle is a Bean
  • 17. Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() { public void handle(Bean bean, PropertyReference pr) { }});Refers to the Rectangle.hover ‘property’
  • 18. Observable Pseudo-PropertiesRectangle rect = new Rectangle();rect.setX(40);rect.setY(40);rect.setWidth(100);rect.setHeight(200);rect.addChangeListener(Rectangle.HOVER, new ChangeListener() { public void handle(Bean bean, PropertyReference pr) {rect.setFill(rect.isHover() ? Color.GREEN : Color.RED); }});
  • 19. Sequences in JavaReplaced with an Observable ListPublic API is based on JavaFX sequencesInternal code can use lighter collections APIJavaFX 2.0 will also have an Observable Map
  • 20. Example Applicationpublic class HelloStage extends Application { @Override public void start() { Stage stage = new Stage();stage.setTitle("Hello Stage");stage.setWidth(600); stage.setHeight(450);Group root = new Group(); Scene scene = new Scene(root);scene.setFill(Color.LIGHTGREEN);stage.setScene(scene);stage.setVisible(true); } public static void main(String[] args) {Launcher.launch(HelloStage.class, args); }}
  • 22. Why JRuby?Direct access to Java APIs
  • 25. ‘Closure conversion’ for interfacesJava in JRuby - Accessing Propertiestimeline.setAutoReverse(true)timeline.autoReverse = truetimeline.auto_reverse = truetimeline.getKeyFrames().add(kf)timeline.key_frames.add(kf)timeline.key_frames.addkf
  • 26. JRuby Example 1: Simple Stagerequire 'java'FX = Java::javafx.lang.FXStage = Java::javafx.stage.StageScene = Java::javafx.scene.SceneColor = Java::javafx.scene.paint.Colorclass HelloStage include java.lang.Runnable def run ..... endendFX.start(HelloStage.new);stage = Stage.newstage.title = 'Hello Stage (JRuby)'stage.width = 600stage.height = 450scene = Scene.newscene.fill = Color::LIGHTGREENstage.scene = scenestage.visible = true;
  • 27. JRuby Example 2rect = Rectangle.newrect.x = 25rect.y = 40rect.width = 100rect.height = 50rect.fill = Color::REDscene.content.add(rect)timeline = Timeline.newtimeline.repeat_count= Timeline::INDEFINITEtimeline.auto_reverse = truekv = KeyValue.new(rect, Rectangle::X, 200);kf = KeyFrame.new(Duration.valueOf(500), kv);timeline.key_frames.addkf;timeline.play();
  • 28. JRuby Closure Conversionrect.add_change_listener(Rectangle::HOVER) do |bean, pr, bln|rect.fill = rect.hover ? Color::GREEN : Color::RED;end26
  • 29. JRubySwibyrequire 'swiby'class HelloWorldModelattr_accessor :sayingendmodel = HelloWorldModel.newmodel.saying = "Hello World"Frame { title "Hello World“ width 200 content { Label { text bind(model,:saying) } } visible true}27
  • 30. 28JavaFX With ClojureArtwork by Augusto Sellhornhttp://sellmic.com/
  • 31. A Little About ClojureStarted in 2007 by Rich HickeyFunctional Programming LanguageDerived from LISPOptimized for High Concurrency… and looks nothing like Java!29(def hello (fn [] "Hello world"))(hello)
  • 32. Clojure Syntax in One SlideSymbolsnumbers – 2.178ratios – 355/113strings – “clojure”, “rocks”characters – \a \b \c \dsymbols – a b c dkeywords – :alpha :betaboolean – true, falsenull - nilCollections(commas optional)Lists(1, 2, 3, 4, 5)Vectors[1, 2, 3, 4, 5]Maps{:a 1, :b 2, :c 3, :d 4}Sets#{:a :b :c :d :e}30(plus macros that are syntactic sugar wrapping the above)
  • 33. Clojure GUI Example(defnjavafxapp [] (let [stage (Stage. "JavaFX Stage") scene (Scene.)] (.setFill scene Color/LIGHTGREEN) (.setWidth stage 600) (.setHeight stage 450) (.setScene stage scene) (.setVisible stage true)))(javafxapp)31
  • 34. Clojure GUI Example(defnjavafxapp[] (let [stage (Stage. "JavaFX Stage") scene (Scene.)] (.setFill scene Color/LIGHTGREEN) (.setWidth stage 600) (.setHeight stage 450) (.setScene stage scene) (.setVisible stage true)))(javafxapp)32Create a Function for the Application
  • 35. Clojure GUI Example(defnjavafxapp [](let [stage (Stage. "JavaFX Stage") scene (Scene.)] (.setFill scene Color/LIGHTGREEN) (.setWidth stage 600) (.setHeight stage 450) (.setScene stage scene) (.setVisible stage true)))(javafxapp)33Initialize the Stage and Scene Variables
  • 36. Clojure GUI Example(defnjavafxapp [] (let [stage (Stage. "JavaFX Stage") scene (Scene.)] (.setFill scene Color/LIGHTGREEN) (.setWidth stage 600) (.setHeight stage 450) (.setScene stage scene) (.setVisible stage true)))(javafxapp)34Call Setter Methods on Scene and Stage
  • 37. Clojure GUI Example(defnjavafxapp [] (let [stage (Stage. "JavaFX Stage") scene (Scene.)] (.setFillscene Color/LIGHTGREEN) (.setWidthstage 600) (.setHeightstage 450) (.setScenestage scene) (.setVisiblestage true)))(javafxapp)35Java Constant SyntaxJava Method Syntax
  • 38. Simpler Code Using doto(defnjavafxapp [] (let [stage (Stage. "JavaFX Stage") scene (Scene.)] (doto scene (.setFillColor/LIGHTGREEN)) (doto stage (.setWidth600) (.setHeight450) (.setScene scene) (.setVisibletrue))))(javafxapp)36
  • 39. Simpler Code Using doto(defnjavafxapp [] (let [stage (Stage. "JavaFX Stage") scene (Scene.)] (doto scene (.setFillColor/LIGHTGREEN)) (doto stage (.setWidth 600) (.setHeight 450) (.setScene scene) (.setVisible true))))(javafxapp)37doto form:(doto symbol (.method params)) equals:(.method symbol params)
  • 40. Refined Clojure GUI Example(defnjavafxapp [] (doto (Stage. "JavaFX Stage") (.setWidth600) (.setHeight450) (.setScene (doto (Scene.) (.setFillColor/LIGHTGREEN) (.setContent (list (doto (Rectangle.) (.setX25) (.setY40) (.setWidth100) (.setHeight50) (.setFillColor/RED)))))) (.setVisibletrue)))(javafxapp)38
  • 41. Refined Clojure GUI Example(defnjavafxapp [] (doto(Stage. "JavaFX Stage") (.setWidth 600) (.setHeight 450) (.setScene (doto(Scene.) (.setFillColor/LIGHTGREEN) (.setContent (list (doto (Rectangle.) (.setX 25) (.setY 40) (.setWidth 100) (.setHeight 50) (.setFillColor/RED)))))) (.setVisible true)))(javafxapp)39Let replaced with inline declarations
  • 42. Refined Clojure GUI Example(defnjavafxapp [] (doto (Stage. "JavaFX Stage") (.setWidth 600) (.setHeight 450) (.setScene (doto (Scene.) (.setFillColor/LIGHTGREEN) (.setContent (list (doto (Rectangle.) (.setX 25) (.setY 40) (.setWidth 100) (.setHeight 50) (.setFillColor/RED)))))) (.setVisible true)))(javafxapp)40Doto allows nested data structures
  • 43. Refined Clojure GUI Example(defnjavafxapp [] (doto (Stage. "JavaFX Stage") (.setWidth 600) (.setHeight 450) (.setScene (doto (Scene.) (.setFillColor/LIGHTGREEN) (.setContent (list (doto (Rectangle.) (.setX 25) (.setY 40) (.setWidth 100) (.setHeight 50) (.setFillColor/RED)))))) (.setVisible true)))(javafxapp)41Now a nested Rectangle fits!
  • 44. Closures in Clojure42Inner classes can be created using proxy(.addChangeListenerrectRectangle/HOVER (proxy [Listener] [] (handle [b, p] (.setFillrect (if (.isHoverrect) Color/GREEN Color/RED)))))
  • 45. Closures in ClojureInner classes can be created using proxy43Proxy form:(proxy [class] [args] fs+) f => (name [params*] body)(.addChangeListenerrectRectangle/HOVER (proxy[Listener][] (handle [b, p] (.setFillrect (if (.isHoverrect) Color/GREEN Color/RED)))))
  • 47. Features of GroovyTight integration with JavaVery easy to port from Java to GroovyDeclarative syntaxFamiliar to JavaFX Script developersBuilders
  • 48. Example 1: Simple FX Script to Groovy
  • 49. Step 1: Lazy conversion to Groovyclass HelloStage implements Runnable { void run() { Stage stage = new Stage();stage.setTitle("Hello Stage (Groovy)“);stage.setWidth(600);stage.setHeight(450); Scene scene = new Scene();scene.setFill(Color.LIGHTSKYBLUE);stage.setScene(scene);stage.setVisible(true); }static void main(args) {FX.start(new HelloStage()); }}
  • 50. Step 2: Slightly More Groovyclass HelloStage implements Runnable { void run() { new Stage( title: "Hello Stage (Groovy)", width: 600, height: 450, visible: true, scene: new Scene( fill: Color.LIGHTSKYBLUE, ) ); } static void main(args) {FX.start(new HelloStage()); }}
  • 51. Slight Aside: Groovy BuildersGroovy builders make writing custom DSLs easyFor the next slide, I am using a builder I definedHopefully the community will improve upon this
  • 52. Step 3: Using a Groovy BuilderFxBuilder.build { stage = stage( title: "Hello World", width: 600, height: 450, scene: scene(fill: Color.LIGHTSKYBLUE) { ... } ) stage.visible = true;}
  • 53. Step 4: With ContentFxBuilder.build { stage = stage( title: "Hello Rectangle (Groovy FxBuilder 2)", width: 600, height: 450, scene: scene(fill: Color.LIGHTSKYBLUE) { rectangle( x: 25, y: 40, width: 100, height: 50, fill: Color.RED ) } ) stage.visible = true;}
  • 54. Example 2: FX Script Animation in Groovy
  • 55. Step 1: JavaFX Scriptdef timeline = Timeline {repeatCount: Timeline.INDEFINITEautoReverse: truekeyFrames: [KeyFrame { time: 750ms values : [ rect1.x => 200.0 tweenInterpolator.LINEAR, rect2.y => 200.0 tweenInterpolator.LINEAR, circle1.radius => 200.0 tweenInterpolator.LINEAR ] } ];}timeline.play();
  • 56. Step 1a: JavaFX Script Simplificationdef timeline = Timeline {repeatCount: Timeline.INDEFINITEautoReverse: true keyFrames: at (750ms) { rect1.x => 200.0 tween Interpolator.LINEAR; rect2.y => 200.0 tween Interpolator.LINEAR; circle1.radius => 200.0 tween Interpolator.LINEAR; }}timeline.play();
  • 57. Step 2: Java-ish Groovy Animationsfinal Timeline timeline = new Timeline(repeatCount: Timeline.INDEFINITE,autoReverse: true)final KeyValue kv1 = new KeyValue (rect1.x(), 200);final KeyValue kv2 = new KeyValue (rect2.y(), 200);final KeyValue kv3 = new KeyValue (circle1.radius(), 200);final KeyFramekf = new KeyFrame(Duration.valueOf(750), kv1, kv2, kv3);timeline.getKeyFrames().add(kf);timeline.play();
  • 58. Step 3: JavaFX Animation Groovy DSL (courtesy of Jim Clarke – work in progress)timeline = timeline(repeatCount: Timeline.INDEFINITE, autoReverse: true) { at 750.ms update values { change rect1.y() to 200 change rect2.x() to 200 change circle.radius() to 200 }}timeline.play();
  • 59. Groovy Closures - With interface coerciondef f = { bean, pr-> rect.setFill(rect.isHover() ? Color.GREEN : Color.RED);} as Listener;rect.addChangedListener(Rectangle.HOVER, f);
  • 61. What is ScalaStarted in 2001 by Martin OderskyCompiles to Java bytecodesPure object-oriented languageAlso a functional programming language59
  • 62. Why Scala?Shares many language features with JavaFX Script that make GUI programming easier:Static type checking – Catch your errors at compile timeClosures – Wrap behavior and pass it by referenceDeclarative – Express the UI by describing what it should look likeScala also supports DSLs!60
  • 63. Java vs. Scala DSLpublic class HelloStage implements Runnable { public void run() { Stage stage = new Stage();stage.setTitle("Hello Stage");stage.setWidth(600);stage.setHeight(450); Scene scene = new Scene();scene.setFill(Color.LIGHTGREEN); Rectangle rect = new Rectangle();rect.setX(25);rect.setY(40);rect.setWidth(100);rect.setHeight(50);rect.setFill(Color.RED);stage.add(rect);stage.setScene(scene);stage.setVisible(true); } public static void main(String[] args) {FX.start(new HelloStage()); }}object HelloJavaFX extends JavaFXApplication { def stage = new Stage { title = "Hello Stage" width = 600 height = 450 scene = new Scene { fill = Color.LIGHTGREEN content = List(new Rectangle { x = 25 y = 40 width = 100 height = 50 fill = Color.RED }) } }}6122 Lines545 Characters17 Lines324 Characters
  • 64. object HelloJavaFX extends JavaFXApplication { def stage = new Stage { title = "Hello Stage" width = 600 height = 450 scene = new Scene { fill = Color.LIGHTGREEN content = List(new Rectangle { x = 25 y = 40 width = 100 height = 50 fill = Color.RED }) } }}62
  • 65. 63object HelloJavaFX extends JavaFXApplication { def stage = new Stage { title = "Hello Stage" width = 600 height = 450 scene = new Scene { fill = Color.LIGHTGREEN content = List(new Rectangle { x = 25 y = 40 width = 100 height = 50 fill = Color.RED }) } }}object HelloJavaFX extends JavaFXApplication { def stage = new Stage { title = "Hello Stage" width = 600 height = 450 scene = new Scene { fill = Color.LIGHTGREEN content = List(new Rectangle { x = 25 y = 40 width = 100 height = 50 fill = Color.RED }) } }}Base class for JavaFX applications
  • 66. 64object HelloJavaFX extends JavaFXApplication {def stage = new Stage { title = "Hello Stage" width = 600 height = 450 scene = new Scene { fill = Color.LIGHTGREEN content = List(new Rectangle { x = 25 y = 40 width = 100 height = 50 fill = Color.RED }) } }}Declarative Stage definition
  • 67. 65object HelloJavaFX extends JavaFXApplication { def stage = new Stage {title = "Hello Stage" width = 600 height = 450 scene = new Scene { fill = Color.LIGHTGREEN content = List(new Rectangle { x = 25 y = 40 width = 100 height = 50 fill = Color.RED }) } }}Inline property definitions
  • 68. 66object HelloJavaFX extends JavaFXApplication { def stage = new Stage { title = "Hello Stage" width = 600 height = 450 scene = new Scene { fill = Color.LIGHTGREEN content = List(new Rectangle { x = 25 y = 40 width = 100 height = 50 fill = Color.RED }) } }}List Construction Syntax
  • 69. Animation in Scaladef timeline = new Timeline {repeatCount = INDEFINITEautoReverse = truekeyFrames = List( new KeyFrame(time: 50) { values = List( new KeyValue(rect1.x() -> 300), new KeyValue(rect2.y() -> 500), new KeyValue(rect2.width() -> 150) ) } ) }67
  • 70. def timeline = new Timeline {repeatCount = INDEFINITEautoReverse = truekeyFrames = List( new KeyFrame(time: 50) { values = List( new KeyValue(rect1.x() -> 300), new KeyValue(rect2.y() -> 500), new KeyValue(rect2.width() -> 150) ) } ) }Animation in Scala68Duration set by Constructor Parameter
  • 71. Animation in Scala69def timeline = new Timeline {repeatCount = INDEFINITEautoReverse = truekeyFrames = List( new KeyFrame(time: 50) { values = List( new KeyValue(rect1.x() -> 300), new KeyValue(rect2.y() -> 500), new KeyValue(rect2.width() -> 150) ) } ) }Operator overloading for animation syntax
  • 72. Closures in Scala70Closures are also supported in ScalaAnd they are 100% type-saferect.addChangedListener(Node.HOVER, (b, p) => {rect.fill = if (rect.hover) Color.GREEN else Color.RED})
  • 73. Closures in ScalaClosures are also supported in ScalaAnd they are 100% type-safe71rect.addChangedListener(Node.HOVER, (b, p) => {rect.fill = if (rect.hover) Color.GREEN else Color.RED})Compact syntax(params) => {body}
  • 74. Other JVM Languages to TryJythonStarted by Jim HuguninHigh Performance PythonMirahInvented by Charles NutterOriginally called DubyLocal Type Inference, Static and Dynamic TypingFantomCreated by Brian and Andy FrankOriginally called FanBuilt-in Declarative SyntaxPortable to Java and .NETLocal Type Inference, Static and Dynamic Typing72
  • 75. Fantom Code ExampleVoid main() { Stage { title= "Hello Stage" width= 600 height= 450 Scene { fill= Color.LIGHTGREEN Rectangle { x= 25 y= 40 width= 100 height= 50 fill= Color.RED } } }.open}73
  • 76. timeline := Timeline { repeatCount = Timeline.INDEFINITE autoReverse = trueKeyFrame { time = 50msKeyValue(rect1.x()-> 300), KeyValue(rect2.y() -> 500), KeyValue(rect2.width() -> 150)}}Animation in Fantom74Fantom has a built-in Duration typeAnd also supports operator overloading
  • 77. Announcing Project Visage75“Visage is a domain specific language (DSL) designed for the express purpose of writing user interfaces.”Visage project goals:Compile to JavaFX Java APIsEvolve the Language (Annotations, Maps, etc.)Support Other ToolkitsCome join the team!For more info: http://visage-lang.org/
  • 78. How about JavaFX on… VisageStage { title: "Hello Stage" width: 600 height: 450 scene: Scene { fill: Color.LIGHTGREEN content: Rectangle { x: 25 y: 40 width: 100 height: 50 fill: Color.RED } }}76
  • 79. How about JavaFX on… VisageStage { title: "Hello Stage" width: 600 height: 450scene: Scene { fill: Color.LIGHTGREENcontent: Rectangle { x: 25 y: 40 width: 100 height: 50 fill: Color.RED } }}77
  • 80. How about JavaFX on… VisageStage { title: "Hello Stage" width: 600 height: 450 Scene { fill: Color.LIGHTGREEN Rectangle { x: 25 y: 40 width: 100 height: 50 fill: Color.RED } }}78
  • 81. ConclusionYou can write JavaFX applications in pure JavaJavaFX is also usable in alternate languagesOver time improved support is possibleGroovy Builders, Scala DSL, VisageRemember: This is a proof of concept only – you can not leave this session and do this today.

Editor's Notes

  • #13: There are two kinds of listener: ‘changedListener’ and ‘ChangingListener’. Being informed of the change before it happens allow for it to be vetoed.It is also possible to either watch a single property, or all properties belonging to a bean.Note that the value passed to the callback is the old value. This is to ensure that we aren’t eagerly computing the new value when it might not be required. To get the new value, you can call the function on the bean or via the propertyReference
  • #14: There are two kinds of listener: ‘changedListener’ and ‘ChangingListener’. Being informed of the change before it happens allow for it to be vetoed.It is also possible to either watch a single property, or all properties belonging to a bean.Note that the value passed to the callback is the old value. This is to ensure that we aren’t eagerly computing the new value when it might not be required. To get the new value, you can call the function on the bean or via the propertyReference
  • #15: There are two kinds of listener: ‘changedListener’ and ‘ChangingListener’. Being informed of the change before it happens allow for it to be vetoed.It is also possible to either watch a single property, or all properties belonging to a bean.Note that the value passed to the callback is the old value. This is to ensure that we aren’t eagerly computing the new value when it might not be required. To get the new value, you can call the function on the bean or via the propertyReference
  • #16: There are two kinds of listener: ‘changedListener’ and ‘ChangingListener’. Being informed of the change before it happens allow for it to be vetoed.It is also possible to either watch a single property, or all properties belonging to a bean.Note that the value passed to the callback is the old value. This is to ensure that we aren’t eagerly computing the new value when it might not be required. To get the new value, you can call the function on the bean or via the propertyReference
  • #17: There are two kinds of listener: ‘changedListener’ and ‘ChangingListener’. Being informed of the change before it happens allow for it to be vetoed.It is also possible to either watch a single property, or all properties belonging to a bean.Note that the value passed to the callback is the old value. This is to ensure that we aren’t eagerly computing the new value when it might not be required. To get the new value, you can call the function on the bean or via the propertyReference
  • #18: There are two kinds of listener: ‘changedListener’ and ‘ChangingListener’. Being informed of the change before it happens allow for it to be vetoed.It is also possible to either watch a single property, or all properties belonging to a bean.Note that the value passed to the callback is the old value. This is to ensure that we aren’t eagerly computing the new value when it might not be required. To get the new value, you can call the function on the bean or via the propertyReference
  • #19: There are two kinds of listener: ‘changedListener’ and ‘ChangingListener’. Being informed of the change before it happens allow for it to be vetoed.It is also possible to either watch a single property, or all properties belonging to a bean.Note that the value passed to the callback is the old value. This is to ensure that we aren’t eagerly computing the new value when it might not be required. To get the new value, you can call the function on the bean or via the propertyReference
  • #48: Slight conversion to Groovy. This can be compiled by the Groovy compiler and run, but basically there is only one line difference (the ‘static void main’ line)
  • #49: This is the same code as the previous slide, taking advantage of some of the Groovy syntax tricks. This is getting to look a lot more like JavaFX Script.
  • #51: This DSL handles running on the EDT, and can actually be run as-is – there is no need for a class declaration, or anything else to ensure that we’re on the EDT. This is getting us fairly close to the simple JavaFX Script at the beginning
  • #52: This DSL handles running on the EDT, and can actually be run as-is – there is no need for a class declaration, or anything else to ensure that we’re on the EDT. This is getting us fairly close to the simple JavaFX Script at the beginning