SlideShare a Scribd company logo
Building Rich Applications with  G r oo v y 's SwingBuilder Andres Almiray
Learn how to create a Swing application with  G r oo v y  using the SwingBuilder Goal
Agenda SwingBuilder Basics Getting up to Speed Advanced Features Custom Components and Extensions Beyond Swing:  G r i ff o n
W hat is  G r oo v y ?
SwingBuilder Basics
Builder Basics Builders are a form of a DSL Focused on Hierarchical Structures SwingBuilder is not the only Builder in  G r oo v y XMLBuilder AntBuilder ObjectGraphBuilder Still Others… Swing applications follow a hierarchical model:  Window Panel Button Builders are a perfect fit for making Swing UIs
A Quick HelloWorld Example groovy.swing.SwingBuilder.build { frame( id: 'root', title:'Hello World',  show:true, pack:true) { flowLayout()‏ label('Enter a message:')‏ textField(id:'name', columns:20)‏ button('Click', actionPerformed: { ActionEvent e -> if (name.text)‏ optionPane().showMessageDialog( root, name.text)‏ })‏ } }
What's going on? Each node is syntactically a method call All of these method calls are dynamically dispatched Most don’t actually exist in bytecode Child closures create hierarchical relations Child widgets are added to parent containers SwingBuilder node names are derived from Swing classes Remove the leading ‘J’ from a Swing class when present SwingBuilder also supports some AWT classes like layouts
Special nodes container embeds a component that accepts nesting widget embeds a component that does not accept nesting bean builds any JavaBean class (not just components)‏
Getting up to Speed
Closures and Event Handlers Closures can handle almost all of the Swing event chores Assignment to an event listener method is equivalent to  adding a listener with that method bean.actionPerformed = { … } in  G r oo v y  is the same in Java architecture as bean.addActionListener(new ActionListener() { void actionPerformed(ActionEvent evt) { … } })‏ Concise syntax, 23+ characters vs. 85+ characters Closures are first class objects Variables can hold Closures Member pointer operator turns methods into closures closureInstance = object.&method
Closures and Event Handlers Example class Controller { def handleFoo() { … } def handleBar(ItemSelectionEvent evt) { … } } def handleBif = {FocusEvent evt -> … } swing.comboBox( actionPerformed: controllerInstance.&handleFoo, itemSelected: controllerInstance.&handleBar, focusGained: handleBif, focusLost: { FocusEvent evt -> … } componentHidden: { … } }
Actions Action values are abstracted as attributes, easy to set Icons Text values Keyboard Accelerators Closure in closure: is called when firing action Preexisting actions can be passed in as node argument No new action created, action values can be adjusted actions() node works like a placeholder for all your actions Child content is not added to parent widgets Actions can and should be defined in one place
Actions Example: Definition actions {  … action( id: 'saveAction', name: 'Save', closure: controller.&fileSave, mnemonic: 'S', accelerator: shortcut('S'), smallIcon: imageIcon( resource:"icons/disk.png", class:Console), shortDescription: 'Save Groovy Script' )‏ … }
Actions Examples: Usage menuBar { menu(text: 'File', mnemonic: 'F') { … menuItem(saveAction) // icon:null for MacOSX … } } toolBar(rollover: true, constraints: NORTH) { … button(saveAction, text: null)‏ … }
Look & Feel SwingBuilder provides convenience node lookAndFeel() to change the global Look & Feel Shorthand names with L&F sensible defaults system nimbus plasticxp substance Themes, skins, fonts, and such can be configured  Hooks exist to add other L&Fs with custom configurations It is recommended to set L&F before building any nodes.
Advanced Features
Threading and the Event Dispatch Thread All painting and UI operations must be done in the EDT Anything else should be outside the EDT Swing has SwingUtilities using Runnable  Java 6 technology adds SwingWorker However, closures are  G r oo v y For code inside EDT edt { … } doLater { … } For code outside EDT doOutside { … } Build UI on the EDT SwingBuilder.build { … }
Threading and the EDT Example action( id: 'countdown', name: 'Start Countdown',  closure: { evt ->  int count = lengthSlider.value status.text = count while ( --count >= 0 ) { sleep( 1000 )‏ status.text = count } status.background = Color.RED })‏
Threading and the EDT Example action( id: 'countdown', name: 'Start Countdown',  closure: { evt ->  int count = lengthSlider.value status.text = count doOutside { while ( --count >= 0 ) { sleep( 1000 )‏ edt {   status.text = count  } } doLater { status.background = Color.RED } } })‏
Binding Binding a set of data to a view and back again is recurring problem found in desktop applications Java Specification Request-295 (JSR) does a good Job for the Java programming Language Deals with static typing issues via generics Accepts JavaServer Pages™ (JSP™) Expression Language to provide dynamic abilities SwingBuilder implements a purely dynamic variant SwingBuilder attributes provide an implicit object and property Add bind() node to an attribute with source or target Attribute hooks exist for validation, conversion, bind on demand
Binding Example import groovy.swing.SwingBuilder new SwingBuilder().edt { frame( title: "Binding Test", size: [200, 120], visible: true ) { gridLayout( cols: 1, rows: 2 )‏ textField( id: "t1" )‏ textField( id: "t2", editable: false )‏ } bind( source: t1, sourceProperty: "text", target: t2, targetProperty: "text" )‏ }
Binding Example import groovy.swing.SwingBuilder new SwingBuilder().edt { frame( title: "Binding Test", size: [200, 120], visible: true ) { gridLayout( cols: 1, rows: 2 )‏ textField( id: "t1" )‏ textField( id: "t2", editable: false, text:  bind(source: t1, sourceProperty: "text")  )‏ } }
Binding Example import groovy.swing.SwingBuilder new SwingBuilder().edt { frame( title: "Binding Test", size: [200, 120], visible: true ) { gridLayout( cols: 1, rows: 2 )‏ textField( id: "t1" )‏ textField( id: "t2", editable: false, text:  bind{ t1.text }  )‏ } }
@Bindable Annotation New in  G r oo v y  1.6 (now in beta)‏ Uses the AST Transformation framework @Bindable Annotates a Property or a Class Annotating a Class is the same as annotating all of the properties AST is transformed to add Property Change support  add/removePropertyChangeListener methods added to Class Unless already present Uses PropertyChangeSupport (unless already present)‏ Setter methods fire PropertyChangeEvents Similar setup for @Vetoable and constrained properties
@Bindable Annotation Example class CountModelController { @Bindable  int count = 1 void incramentCount(def evt = null) { setCount(count + 1)‏ } } def model = new CountModelController()‏ … label(text:bind(source:model, sourceProperty:'count'))‏ …
Custom Components and Extensions
Adding Arbitrary Components Individual components may be added and used in the builder Single use – pass-through widgets Widget – for nodes with no child content widget(new CoolComp(), opaque:false, … )‏ Container – for nodes that can contain other widgets container(new BigComp()) { … } Multiple use – factory registration Simple bean (no-args constructor, no fancy stuff)‏ registerBeanFactory('coolComp', CoolComp)‏ Rich factory (provide your own node factory)‏ registerFactory('bigComp', BigCompFactory)‏
Suite Component Extensions Extending SwingBuilder as a whole is a way to enhance SwingBuilder with suites of components SwingXBuilder SwingX components, painters and effects TimingFramework based animations Many new JX variants of widgets override old values Old widgets available if classicSwing:true set in node attributes withWorker() node -> threading with SwingWorker JIDEBuilder Provides nodes for the Jide CL set of components  Provides svg-enabled icon support
Suite Component Extensions FlamingoBuilder Flamingo Suite of Swing components CommandButton, FlexiSlider, Svg icons (Ribbon support in the near future). Current release is based on Flamingo 4.0dev MacWidgetsBuilder MacWidgets is a set of components that follow Apple's HIG Current build is based on MacWidgets 0.9.3.1 ... and more to come
SwingPad demo
GraphicsBuilder GraphicsBuilder is a builder for Java2D rendering Supports basic Java2D shapes Adds non-basic shapes and filters Provides nodes for paints, filters, transformations, fonts, etc. Almost all properties are observable Allows bind() and animate() to manipulate rendered items Also renders to images and files via GraphicsRenderer
GraphicsBuilder Example def gr = new GraphicsRenderer()   gr.renderToFile("filters.png", 260, 210)  {      antialias on       rect(x:40, y:40, width:180, height:130,  arcWidth:60, arcHeight:60, borderColor:false) {        linearGradient {          stop(offset:0,   color:'red')          stop(offset:0.5, color:'orange')          stop(offset:1,   color:'red')        }       filters(offset: 50) {          weave()          kaleidoscope(sides:10, angle:0,angle2:0)          lights()       }       }   }  
G r i ff o n
G r i ff o n 's Goals Simplify Swing development Provide a common application layout Minimize context gap between web application (Grails) and desktop application development with  G r oo v y Provide easier application deployment standalone webstart applet
G r i ff o n Demo
For More Information G r oo v y h tt p : // groovy.codehaus.org G r i ff o n h tt p : // griffon.codehaus.org Builders mentioned in this presentation h tt p : // groovy.codehaus.org / Swing+Builder h tt p : // groovy.codehaus.org / SwingXBuilder h tt p : // griffon.codehaus.org / JideBuilder h tt p : // griffon.codehaus.org / FlamingoBuilder h tt p : // griffon.codehaus.org / MacWidgetsBuilder h tt p : // groovy. codehaus.org / GraphicsBuilder
For More Information G r oo v y  Swing team blogs h tt p : // jroller.com / aalmiray h tt p : // www.shemnon.com / speling h tt p : // www.jameswilliams.be / blog Twitter @ aalmiray  @ shemnon  @ ecspike
GroovyMag http://groovymag.com
Q   &   A
T h a n k   Y o u !

More Related Content

PPT
Svcc Building Rich Applications with Groovy's SwingBuilder
PPT
Svcc Java2D And Groovy
PPT
Svcc Groovy Testing
PDF
Best Practices in Qt Quick/QML - Part IV
 
PDF
Qt Widget In-Depth
PDF
JavaScript Core
PDF
Best Practices in Qt Quick/QML - Part 4
 
PDF
Practical Model View Programming
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Java2D And Groovy
Svcc Groovy Testing
Best Practices in Qt Quick/QML - Part IV
 
Qt Widget In-Depth
JavaScript Core
Best Practices in Qt Quick/QML - Part 4
 
Practical Model View Programming

What's hot (20)

PDF
Hidden Gems in Swift
PDF
Practical Model View Programming (Roadshow Version)
PDF
Intro to JavaScript
PPTX
Intro to Javascript
PDF
Anonymous functions in JavaScript
PDF
The Future of Qt Widgets
PPTX
Javascript Basics
PDF
Basics of Model/View Qt programming
 
PDF
iOS 101 - Xcode, Objective-C, iOS APIs
PDF
The Next Generation Qt Item Views
PDF
Advanced javascript
PDF
Powerful JavaScript Tips and Best Practices
PPT
Constructor and destructor in C++
PDF
Best Practices in Qt Quick/QML - Part 1 of 4
 
PDF
javascript objects
PDF
JavaScript introduction 1 ( Variables And Values )
PDF
Fun with QML
 
PDF
Java Script Best Practices
PDF
Headless Js Testing
PPTX
Lab #2: Introduction to Javascript
Hidden Gems in Swift
Practical Model View Programming (Roadshow Version)
Intro to JavaScript
Intro to Javascript
Anonymous functions in JavaScript
The Future of Qt Widgets
Javascript Basics
Basics of Model/View Qt programming
 
iOS 101 - Xcode, Objective-C, iOS APIs
The Next Generation Qt Item Views
Advanced javascript
Powerful JavaScript Tips and Best Practices
Constructor and destructor in C++
Best Practices in Qt Quick/QML - Part 1 of 4
 
javascript objects
JavaScript introduction 1 ( Variables And Values )
Fun with QML
 
Java Script Best Practices
Headless Js Testing
Lab #2: Introduction to Javascript
Ad

Viewers also liked (7)

DOC
Inteligencias multiples
PPTX
Historia de la Contaminación
PDF
Cloud computing como herramienta facilitadora para el emprendimiento en colom...
PPTX
Tarjetas de red
PDF
The role of social networks on regulation in the telecommunication industry t...
PPTX
Switch
PPTX
Hub y switch
Inteligencias multiples
Historia de la Contaminación
Cloud computing como herramienta facilitadora para el emprendimiento en colom...
Tarjetas de red
The role of social networks on regulation in the telecommunication industry t...
Switch
Hub y switch
Ad

Similar to CodeMash - Building Rich Apps with Groovy SwingBuilder (20)

PPT
JavaOne TS-5098 Groovy SwingBuilder
PDF
Griffon @ Svwjug
PPT
The Theory Of The Dom
PPT
GWT MVP Case Study
PDF
Front End Development: The Important Parts
ODP
Griffon: Re-imaging Desktop Java Technology
PPT
Smoothing Your Java with DSLs
PPT
Intro to JavaFX & Widget FX
PPT
Java Programming for Designers
PPTX
react-slidlkjfl;kj;dlkjopidfjhopijgpoerjpofjiwoepifjopweifjepoies.pptx
PDF
Introduction to Griffon
PDF
Uncommon Design Patterns
PPT
GWT Extreme!
PDF
MOPCON 2014 - Best software architecture in app development
PPT
Google Web Toolkits
PPT
Widget Tutorial
PPT
Groovy Introduction - JAX Germany - 2008
PPTX
TRAINING pptt efwoiefo weoifjoiewjfoifjow.pptx
PPT
J Query(04 12 2008) Foiaz
PPT
WebGL: GPU acceleration for the open web
JavaOne TS-5098 Groovy SwingBuilder
Griffon @ Svwjug
The Theory Of The Dom
GWT MVP Case Study
Front End Development: The Important Parts
Griffon: Re-imaging Desktop Java Technology
Smoothing Your Java with DSLs
Intro to JavaFX & Widget FX
Java Programming for Designers
react-slidlkjfl;kj;dlkjopidfjhopijgpoerjpofjiwoepifjopweifjepoies.pptx
Introduction to Griffon
Uncommon Design Patterns
GWT Extreme!
MOPCON 2014 - Best software architecture in app development
Google Web Toolkits
Widget Tutorial
Groovy Introduction - JAX Germany - 2008
TRAINING pptt efwoiefo weoifjoiewjfoifjow.pptx
J Query(04 12 2008) Foiaz
WebGL: GPU acceleration for the open web

More from Andres Almiray (20)

PDF
Dealing with JSON in the relational world
PDF
Deploying to production with confidence 🚀
PDF
Going beyond ORMs with JSON Relational Duality Views
PDF
Setting up data driven tests with Java tools
PDF
Creando, creciendo, y manteniendo una comunidad de codigo abierto
PDF
Liberando a produccion con confianza
PDF
Liberando a produccion con confidencia
PDF
OracleDB Ecosystem for Java Developers
PDF
Softcon.ph - Maven Puzzlers
PDF
Maven Puzzlers
PDF
Oracle Database Ecosystem for Java Developers
PDF
JReleaser - Releasing at the speed of light
PDF
Building modular applications with the Java Platform Module System and Layrry
PDF
Going Reactive with g rpc
PDF
Building modular applications with JPMS and Layrry
PDF
Taking Micronaut out for a spin
PDF
Apache Groovy's Metaprogramming Options and You
PDF
What I wish I knew about Maven years ago
PDF
What I wish I knew about maven years ago
PDF
The impact of sci fi in tech
Dealing with JSON in the relational world
Deploying to production with confidence 🚀
Going beyond ORMs with JSON Relational Duality Views
Setting up data driven tests with Java tools
Creando, creciendo, y manteniendo una comunidad de codigo abierto
Liberando a produccion con confianza
Liberando a produccion con confidencia
OracleDB Ecosystem for Java Developers
Softcon.ph - Maven Puzzlers
Maven Puzzlers
Oracle Database Ecosystem for Java Developers
JReleaser - Releasing at the speed of light
Building modular applications with the Java Platform Module System and Layrry
Going Reactive with g rpc
Building modular applications with JPMS and Layrry
Taking Micronaut out for a spin
Apache Groovy's Metaprogramming Options and You
What I wish I knew about Maven years ago
What I wish I knew about maven years ago
The impact of sci fi in tech

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Modernizing your data center with Dell and AMD
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Cloud computing and distributed systems.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation theory and applications.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
cuic standard and advanced reporting.pdf
PPT
Teaching material agriculture food technology
Spectral efficient network and resource selection model in 5G networks
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Modernizing your data center with Dell and AMD
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
“AI and Expert System Decision Support & Business Intelligence Systems”
A Presentation on Artificial Intelligence
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
NewMind AI Monthly Chronicles - July 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Cloud computing and distributed systems.
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation theory and applications.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
cuic standard and advanced reporting.pdf
Teaching material agriculture food technology

CodeMash - Building Rich Apps with Groovy SwingBuilder

  • 1. Building Rich Applications with G r oo v y 's SwingBuilder Andres Almiray
  • 2. Learn how to create a Swing application with G r oo v y using the SwingBuilder Goal
  • 3. Agenda SwingBuilder Basics Getting up to Speed Advanced Features Custom Components and Extensions Beyond Swing: G r i ff o n
  • 4. W hat is G r oo v y ?
  • 6. Builder Basics Builders are a form of a DSL Focused on Hierarchical Structures SwingBuilder is not the only Builder in G r oo v y XMLBuilder AntBuilder ObjectGraphBuilder Still Others… Swing applications follow a hierarchical model: Window Panel Button Builders are a perfect fit for making Swing UIs
  • 7. A Quick HelloWorld Example groovy.swing.SwingBuilder.build { frame( id: 'root', title:'Hello World', show:true, pack:true) { flowLayout()‏ label('Enter a message:')‏ textField(id:'name', columns:20)‏ button('Click', actionPerformed: { ActionEvent e -> if (name.text)‏ optionPane().showMessageDialog( root, name.text)‏ })‏ } }
  • 8. What's going on? Each node is syntactically a method call All of these method calls are dynamically dispatched Most don’t actually exist in bytecode Child closures create hierarchical relations Child widgets are added to parent containers SwingBuilder node names are derived from Swing classes Remove the leading ‘J’ from a Swing class when present SwingBuilder also supports some AWT classes like layouts
  • 9. Special nodes container embeds a component that accepts nesting widget embeds a component that does not accept nesting bean builds any JavaBean class (not just components)‏
  • 10. Getting up to Speed
  • 11. Closures and Event Handlers Closures can handle almost all of the Swing event chores Assignment to an event listener method is equivalent to adding a listener with that method bean.actionPerformed = { … } in G r oo v y is the same in Java architecture as bean.addActionListener(new ActionListener() { void actionPerformed(ActionEvent evt) { … } })‏ Concise syntax, 23+ characters vs. 85+ characters Closures are first class objects Variables can hold Closures Member pointer operator turns methods into closures closureInstance = object.&method
  • 12. Closures and Event Handlers Example class Controller { def handleFoo() { … } def handleBar(ItemSelectionEvent evt) { … } } def handleBif = {FocusEvent evt -> … } swing.comboBox( actionPerformed: controllerInstance.&handleFoo, itemSelected: controllerInstance.&handleBar, focusGained: handleBif, focusLost: { FocusEvent evt -> … } componentHidden: { … } }
  • 13. Actions Action values are abstracted as attributes, easy to set Icons Text values Keyboard Accelerators Closure in closure: is called when firing action Preexisting actions can be passed in as node argument No new action created, action values can be adjusted actions() node works like a placeholder for all your actions Child content is not added to parent widgets Actions can and should be defined in one place
  • 14. Actions Example: Definition actions { … action( id: 'saveAction', name: 'Save', closure: controller.&fileSave, mnemonic: 'S', accelerator: shortcut('S'), smallIcon: imageIcon( resource:"icons/disk.png", class:Console), shortDescription: 'Save Groovy Script' )‏ … }
  • 15. Actions Examples: Usage menuBar { menu(text: 'File', mnemonic: 'F') { … menuItem(saveAction) // icon:null for MacOSX … } } toolBar(rollover: true, constraints: NORTH) { … button(saveAction, text: null)‏ … }
  • 16. Look & Feel SwingBuilder provides convenience node lookAndFeel() to change the global Look & Feel Shorthand names with L&F sensible defaults system nimbus plasticxp substance Themes, skins, fonts, and such can be configured Hooks exist to add other L&Fs with custom configurations It is recommended to set L&F before building any nodes.
  • 18. Threading and the Event Dispatch Thread All painting and UI operations must be done in the EDT Anything else should be outside the EDT Swing has SwingUtilities using Runnable Java 6 technology adds SwingWorker However, closures are G r oo v y For code inside EDT edt { … } doLater { … } For code outside EDT doOutside { … } Build UI on the EDT SwingBuilder.build { … }
  • 19. Threading and the EDT Example action( id: 'countdown', name: 'Start Countdown', closure: { evt -> int count = lengthSlider.value status.text = count while ( --count >= 0 ) { sleep( 1000 )‏ status.text = count } status.background = Color.RED })‏
  • 20. Threading and the EDT Example action( id: 'countdown', name: 'Start Countdown', closure: { evt -> int count = lengthSlider.value status.text = count doOutside { while ( --count >= 0 ) { sleep( 1000 )‏ edt { status.text = count } } doLater { status.background = Color.RED } } })‏
  • 21. Binding Binding a set of data to a view and back again is recurring problem found in desktop applications Java Specification Request-295 (JSR) does a good Job for the Java programming Language Deals with static typing issues via generics Accepts JavaServer Pages™ (JSP™) Expression Language to provide dynamic abilities SwingBuilder implements a purely dynamic variant SwingBuilder attributes provide an implicit object and property Add bind() node to an attribute with source or target Attribute hooks exist for validation, conversion, bind on demand
  • 22. Binding Example import groovy.swing.SwingBuilder new SwingBuilder().edt { frame( title: "Binding Test", size: [200, 120], visible: true ) { gridLayout( cols: 1, rows: 2 )‏ textField( id: "t1" )‏ textField( id: "t2", editable: false )‏ } bind( source: t1, sourceProperty: "text", target: t2, targetProperty: "text" )‏ }
  • 23. Binding Example import groovy.swing.SwingBuilder new SwingBuilder().edt { frame( title: "Binding Test", size: [200, 120], visible: true ) { gridLayout( cols: 1, rows: 2 )‏ textField( id: "t1" )‏ textField( id: "t2", editable: false, text: bind(source: t1, sourceProperty: "text") )‏ } }
  • 24. Binding Example import groovy.swing.SwingBuilder new SwingBuilder().edt { frame( title: "Binding Test", size: [200, 120], visible: true ) { gridLayout( cols: 1, rows: 2 )‏ textField( id: "t1" )‏ textField( id: "t2", editable: false, text: bind{ t1.text } )‏ } }
  • 25. @Bindable Annotation New in G r oo v y 1.6 (now in beta)‏ Uses the AST Transformation framework @Bindable Annotates a Property or a Class Annotating a Class is the same as annotating all of the properties AST is transformed to add Property Change support add/removePropertyChangeListener methods added to Class Unless already present Uses PropertyChangeSupport (unless already present)‏ Setter methods fire PropertyChangeEvents Similar setup for @Vetoable and constrained properties
  • 26. @Bindable Annotation Example class CountModelController { @Bindable int count = 1 void incramentCount(def evt = null) { setCount(count + 1)‏ } } def model = new CountModelController()‏ … label(text:bind(source:model, sourceProperty:'count'))‏ …
  • 27. Custom Components and Extensions
  • 28. Adding Arbitrary Components Individual components may be added and used in the builder Single use – pass-through widgets Widget – for nodes with no child content widget(new CoolComp(), opaque:false, … )‏ Container – for nodes that can contain other widgets container(new BigComp()) { … } Multiple use – factory registration Simple bean (no-args constructor, no fancy stuff)‏ registerBeanFactory('coolComp', CoolComp)‏ Rich factory (provide your own node factory)‏ registerFactory('bigComp', BigCompFactory)‏
  • 29. Suite Component Extensions Extending SwingBuilder as a whole is a way to enhance SwingBuilder with suites of components SwingXBuilder SwingX components, painters and effects TimingFramework based animations Many new JX variants of widgets override old values Old widgets available if classicSwing:true set in node attributes withWorker() node -> threading with SwingWorker JIDEBuilder Provides nodes for the Jide CL set of components Provides svg-enabled icon support
  • 30. Suite Component Extensions FlamingoBuilder Flamingo Suite of Swing components CommandButton, FlexiSlider, Svg icons (Ribbon support in the near future). Current release is based on Flamingo 4.0dev MacWidgetsBuilder MacWidgets is a set of components that follow Apple's HIG Current build is based on MacWidgets 0.9.3.1 ... and more to come
  • 32. GraphicsBuilder GraphicsBuilder is a builder for Java2D rendering Supports basic Java2D shapes Adds non-basic shapes and filters Provides nodes for paints, filters, transformations, fonts, etc. Almost all properties are observable Allows bind() and animate() to manipulate rendered items Also renders to images and files via GraphicsRenderer
  • 33. GraphicsBuilder Example def gr = new GraphicsRenderer()   gr.renderToFile("filters.png", 260, 210) {    antialias on       rect(x:40, y:40, width:180, height:130,  arcWidth:60, arcHeight:60, borderColor:false) {        linearGradient {          stop(offset:0,  color:'red')          stop(offset:0.5, color:'orange')          stop(offset:1,  color:'red')        }       filters(offset: 50) {          weave()          kaleidoscope(sides:10, angle:0,angle2:0)          lights()       }     }   }  
  • 34. G r i ff o n
  • 35. G r i ff o n 's Goals Simplify Swing development Provide a common application layout Minimize context gap between web application (Grails) and desktop application development with G r oo v y Provide easier application deployment standalone webstart applet
  • 36. G r i ff o n Demo
  • 37. For More Information G r oo v y h tt p : // groovy.codehaus.org G r i ff o n h tt p : // griffon.codehaus.org Builders mentioned in this presentation h tt p : // groovy.codehaus.org / Swing+Builder h tt p : // groovy.codehaus.org / SwingXBuilder h tt p : // griffon.codehaus.org / JideBuilder h tt p : // griffon.codehaus.org / FlamingoBuilder h tt p : // griffon.codehaus.org / MacWidgetsBuilder h tt p : // groovy. codehaus.org / GraphicsBuilder
  • 38. For More Information G r oo v y Swing team blogs h tt p : // jroller.com / aalmiray h tt p : // www.shemnon.com / speling h tt p : // www.jameswilliams.be / blog Twitter @ aalmiray @ shemnon @ ecspike
  • 40. Q & A
  • 41. T h a n k Y o u !