A presentation for the Vancouver Island Java User's Group showcasing how Groovy and the Griffon application framework can ease the pain of coding Swing applications.
Report
Share
Report
Share
1 of 20
More Related Content
Griffon Presentation
1. Griffon “Griffon is a Grails like application framework for developing desktop applications in Groovy.”
2. What is Griffon? framework for developing Swing apps Groovy based, Grails inspired extensible by plugins MVC convention over configuration aims to make build Swing apps easy!
3. State of Swing very verbose to get it right public void actionPerformed(ActionEvent e) { (new Thread(new Runnable() { public void run() { final String result = longRunningOperation(); SwingUtilities.invokeLater(new Runnable() { public void run() { label.setText(result); } }); } }).start(); } final JLabel label = ... ; class MeaningOfLifeFinder extends SwingWorker<String, Object> { @Override public String doInBackground() { return findTheMeaningOfLife(); } @Override protected void done() { try { label.setText(get()); } catch (Exception ignore) { } } } (new MeaningOfLifeFinder()).execute(); SwingWorker helps with the pattern
4. Groovy helps a lot SwingBuilder DSL for fluent syntax shortened forms and simplified configuration Java: JPanel panel = new JPanel(); new BoxLayout(panel, BoxLayout.X_AXIS) Groovy: panel { boxLayout() } map coercion VS constructors huge reduction in boilerplate simple Binding
5. Griffon helps even more CompositeBuilder: combines numerous builders into one common dsl IGriffonApplication: provides a common infrastructure meta-enhancement: additional methods added to Swing components at run-time makes publishing and launching easy
7. App Configuration Your A, B, C’s Application.groovy- title, root MVC group to initialize on startup, all MVC groups registered in the app Builder.groovy - CompositeBuilder configuration Config.groovy - logging, dev/test/prod environments, additional build script or lifecycle event configuration
8. App Lifecycle Initialize - before any Swing code is realized; used for L&F and setup Startup - after startup MVC groups are initialized Ready - all events sent to EDT queue have been processed Shutdown - opportunity to free resources before exit Stop - Applet specific
9. Distribution and Installation stand-alone, webstart and applet support create launchers for Windows(.exe), Linux(shell script), Mac(.app) and as executable jar create installers using IzPack, RPM and DMG ‘big jar’ support for those lucky people in the US who can use the Java Store can create all installers and launchers in one step
10. Testing and Analysis FEST - framework for Swing integration testing; equivalent of Selenium for Web testing EasyB - scenario based testing Cobertura - code coverage metrics JDepend - static analysis
11. Language support Scala - plugin available Clojure - plugin available Java - if you REALLY want :)
12. The EDT in Groovy doOutside{ //long running operations in a new thread edt { //jump back to the EDT if needed } doLater{ //update the UI when we’re done } }
13. EDT With SwingWorker in Griffon in Griffon jxwithWorker {onInit { //setup } work { //do long running work and publish intermediate results publish(...) } onUpdate { //respond to intermediate results } onDone { //update UI with final results }} //update UI with final results }} //update UI with final results }} //update UI with final results }} //update UI with final results }} //update UI with final results }}
14. How to get Griffon? download the izpack installer macports install from source - set $GRIFFON_HOME and put $GRIFFON_HOME/bin in your path, there’s an ant target to install tonite’s demo was 0.2-SNAPSHOT built from source
15. How to use Griffon? On the command line create/run/test Applications create MVC groups or their individual components create tests install/uninstall plugins create your own plugins run a shell/console with your Application on the classpath ...
16. Tool support Netbeans - Geertjan Wielenga crafted an alpha version plugin for Java One this year Intellij - Maia (version 9, in EAP now) parallels existing Grails support Eclipse - Groovy plugin, no specific support for Griffon; yet Griffon in Action has instructions for each of these IDE’s without plugins, based on ant
developers on Griffon are contributors to Groovy and have provided handy AST transformations
What makes it “hard” to program Swing? VERBOSITY, boilerplate
What things does Groovy do to help? Builder pattern is great at building tree structures Helpful abstractions one line initialization, no need to call get/set
What does Griffon add to the mix to make it even easier? no need to remember which builder you are calling; conflicts can be resolved using namespaces standardization/delegation of methods: size(), getAt(), putAt(), iterator()
After this slide, demo CSSBuilder and some of the Swingpad samples Swingpad can be used to prototype UI elements in isolation, Mockfor and Stubfor can be used to mock dependencies
After this slide, show the files in IDE and explain they’re nothing more than properties files consumed by ConfigSlurper
show L&F change? build a new app from scratch, change from label to button, run, change L&F and rerun
Getting your application built and published is important - you do want people to use these things after all Point out that demos are all .app files
No framework would be complete without testing support Show FEST test after this slide
Polyglot programming made easy
Wrappers for SwingUtilities methods Demo Binding example
SwingWorker DSL Demo EDT example and Animation example
Here’s how you work with it at the lowest level. Demo loading up the application in a console
Just out of interest, the demo application created to go along with this talk comes in pretty lean. Lifecycle and Integration Tests are defaults And all of these LOC measures include comments, to be fixed in a release soon