Helsinki Scala Club 25.4.2013 Punavuoren Ahven
S c a l a F X HelloStage.scala getting the development system up is a h*ll of a work - we’ll skip that! :D c l u d e s . i n e s o f i n c k i n g 1 0 l L a
S c a l a F X Getting started Unfortunately ScalaFX is not yet available as i.e. ‘sbt’ dependency. $ hg clone https://code.google.com/p/scalafx/ ... $ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/ Contents/Home/ $ cd scalafx ... $ sbt clean compile scalafx-demos/run t h , O S X w i u n n i n g o n a d e m o r w t o g e t T h i s i s h o h g s c a l a n s t a l l e d . c l e J R E 7 i a n d O r a o m e b r e w f r o m H a n d s b t 1 3 . 2 5 A p r 2 0 i t o r y o n F X r e p o s e o f S c a l a e d o n s t a t B a s
S c a l a F X DEMO Note: the ‘colorful circles’ demo is pretty intensive of GPU usage. Windows platforms seem to have a way better graphics pipeline than i.e. OS X (or maybe Linux). For other samples, the difference is not as great.
S c a l a F X • New! > Fireworks • Animation > Timelines > Interpolator • Advanced > Adv Area Audio Chart • Advanced > Area Chart • Bar > Advanced Bar Chart (show adding points) • Pie > Advanced Pie Chart • Graphics > Digital Clock • Graphics 3D > Xylophone (try hitting some chords!) • Media > Advanced media (try full screen) • Web > Web view • Web > HTML editor
S c a l a F X Getting started Unfortunately ScalaFX is not yet available as i.e. ‘sbt’ dependency. $ hg clone https://code.google.com/p/scalafx/ ... $ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/ Contents/Home/ $ cd scalafx $ sbt clean compile run $ sbt package $ ls -al scalafx/target/scala-2.9.3/ -rw-r--r-- 1 asko staff 1925012 25 Huh 16:56 ./scalafx/target/scala-2.9.3/ scalafx_2.9.3-1.0.0-M4-SNAPSHOT.jar $ cp scalafx/target/scala-2.9.3/scalafx_*.jar <myproject>/lib N o w h o w t o g e t t h o s e S c a l a v e r s i o n s t o m a t c h ? W h o o o o o . . . . ( w o r t h a f u l l w e e k c a m p )
S c a l a F X Scene graph The ‘live’ UI are those components that are found within a ‘scene graph’. scalafx.stage.Stage scalafx.scene.Scene scalafx.scene.Group scalafx.scene.Node Yes, what a path!? s e s a t : h t h e c l a s o t h r o u g G x c a l a / s c a l a f r c / m a i n / s / s c a l a f x / s s c a l a f x
S c a l a F X Scene graph... • Mouse clicks etc. events travel through the scene graph. => only objects on the scene graph are ‘live’ Other ScalaFX features... • Theming via CSS (just as if the scene graph were HTML) • Binding by ’<==’ syntax sugar (which may be unhealthy!) Good walk through at: Problems? http://code.google.com/p/scalafx/ • ScalaFX API heavily derives from JavaFX objects. Sometimes this shines through! • To study the API one needs to see both the Book / web (Java) and the ScalaFX headers. = a unified, documented Scala ONLY API would imho be welcome.
S c a l a F X GUI paradigms • windowed (stretchable) / full screen; Desktop Web scaled by the user • mouse pointer -> hovering -> tooltips Mobile / Games • full screen only • transparencies (alpha blending) touch consoles • visual transitions Cross pollutation of ideas across paradigms.
S c a l a F X GUI paradigms • windowed (stretchable) / full screen; Desktop Web scaled by the user • mouse pointer -> hovering -> tooltips Mobile / Games • full screen only • transparencies (alpha blending) touch consoles • visual transitions Fastest speed (but code and test x N) native Fastest development (but test and tune x N ² ) HTML Pretty good (but compile x N and test x N) Qt Awesome! (still test x N) ScalaFX
S c a l a F X GUI paradigms • windowed (stretchable) / full screen; Desktop Web scaled by the user • mouse pointer -> hovering -> tooltips Mobile / Games • full screen only • transparencies (alpha blending) touch consoles • visual transitions Fastest speed (but code and test x N) native Fastest development (but test and tune x N ² ) HTML Pretty good (but compile x N and test x N) Qt Awesome! (still test x N) ScalaFX
S c a l a F X GUI paradigms • windowed (stretchable) / full screen; Desktop Web scaled by the user • mouse pointer -> hovering -> tooltips Mobile / Games • full screen only • transparencies (alpha blending) touch consoles • visual transitions Fastest speed (but code and test x N) native Fastest development (but test and tune x N ² ) HTML Pretty good (but compile x N and test x N) Qt Awesome! (still test x N) ScalaFX
S c a l a F X GUI paradigms • windowed (stretchable) / full screen; Desktop Web scaled by the user • mouse pointer -> hovering -> tooltips Mobile / Games • full screen only • transparencies (alpha blending) touch consoles • visual transitions Fastest speed (but code and test x N) native Fastest development (but test and tune x N ² ) HTML Pretty good (but compile x N and test x N) Qt Awesome! (still test x N) ScalaFX
S c a l a F X OpenJDK on ARM platforms ARM Linux preview of JavaFX available since late 2012. • Raspberry Pi • Pandaboard (ES) • FreeScale i.MX6 • etc. https://jdk8.java.net/fxarmpreview/
S c a l a F X OpenJDK on ARM platforms Android and iOS support coming up via OpenJDK in 2013: • JVM will be packaged within the application • Modularity in JVM 8 reduces the footprint (< 10MB?) • JavaFX libraries are included in the JVM runtime (since JVM 7) = hardware accelerated graphics pipeline for Desktop, Android, iOS
S c a l a F X So Why Not Just Do HTML? (+ JavaScript + libraries + CSS) Sure. Please do. Then if it hurts, it’s nice to know there’s another way. 0 50 100 productivity testability maintainability your metrics?
Summary • A more natural way to construct JavaFX apps than the Java API. • JavaFX a built-in part of Java runtime since JRE 7. • Linux ARM support coming up. • Modern, GPU accelerated API • Good media (i.e. H264) and sound support, too. • Touch support • CSS themeable • Worth a try? http://code.google.com/p/scalafx/
Next? • Unit testing I actually started to use • Pretty much the standard of Scala testing (but not the only one) • Can also test Java code of course
Recommend
More recommend