Extending Groovys Swing User Interface in Builder to Build Richer Applications  Danno Ferrin, Intelligent Software Solutio...
<ul><ul><li>Learn how to customized Groovy’s SwingBuilder to add custom widgets and non-visual components. </li></ul></ul>
Not always an enterprise question… <ul><li>BUT WILL IT </li></ul><ul><li>S C A L E </li></ul><ul><li>? </li></ul>
Agenda <ul><li>Ways to Extend SwingBuilder </li></ul><ul><li>FactoryBuilderSupport Overview </li></ul><ul><li>Case Study: ...
First some Terminology <ul><li>nodeName( argument, attr : value, attr2 : value) { … } </li></ul><ul><li>Node </li></ul><ul...
Agenda <ul><li>Ways to Extend SwingBuilder </li></ul><ul><li>FactoryBuilderSupport Overview  </li></ul><ul><li>Case Study:...
Issues of Scale How you extend should be driven by how much the extension is used <ul><li>Magic Nodes </li></ul><ul><ul><l...
Magic Nodes <ul><li>bean(…)  </li></ul><ul><ul><li>Accepts any object  </li></ul></ul><ul><ul><li>Not added to parent  </l...
Magic Nodes <ul><li>An instance of the object must be passed in as the argument </li></ul><ul><li>Attributes are applied a...
Magic Nodes Example <ul><li>bean(model, propertyChanged: { panel.repaint() } ) </li></ul><ul><li>widget(new JXMonthPanel()...
Individual Factory Registration <ul><li>First, what are the characteristics of the Widget? </li></ul><ul><li>Well behaved ...
Individual Factory Registration <ul><li>Well behaved JavaBeans may use  registerBeanFactory(…) </li></ul><ul><ul><li>All l...
Builder Suite <ul><li>Logical progression from creating factories </li></ul><ul><li>Subclass SwingBuilder </li></ul><ul><u...
Builder Suite <ul><li>But what if I want multiple suites? </li></ul><ul><ul><li>JideSplitButton  </li></ul></ul><ul><ul><l...
Composite Builder <ul><li>Coming Soon </li></ul><ul><ul><li>Won’t be in Groovy 1.6 core </li></ul></ul><ul><li>The Idea </...
The Vision <ul><ul><li>def builder = new CompositeBuilder( SwingBuilder,  ogb:ObjectGraphBuilder, jx:SwingXBuilder,  jide:...
The code as of Today <ul><li>Called ‘UberBuilder’ </li></ul><ul><ul><li>Available on SVN (only for the brave…) </li></ul><...
Agenda <ul><li>Ways to Extend SwingBuilder </li></ul><ul><li>FactoryBuilderSupport Overview </li></ul><ul><li>Case Study: ...
Factory Lifecycle
Delegate Closures <ul><li>Some steps can be intercepted without a Factory </li></ul><ul><ul><li>addPreInstantiateDelegate,...
Agenda <ul><li>Ways to Extend SwingBuilder </li></ul><ul><li>FactoryBuilderSupport Overview </li></ul><ul><li>Case Study: ...
SwingXBuilder <ul><li>Google Summer of Code 2007 project </li></ul><ul><ul><li>James Williams – Nova Southeastern Universi...
Summary <ul><li>SwingBuilder extension is easy </li></ul><ul><li>Choose your extension method based on frequency of use </...
For More Information <ul><li>TS-5098 </li></ul><ul><ul><li>Friday at 12:10 in EP 305 </li></ul></ul><ul><ul><li>Covers mor...
Danno Ferrin,  Intelligent Software Solutions, Inc. James Williams,  Spatial Networks, Inc.  BOF-5110 Speaker’s logo here ...
Upcoming SlideShare
Loading in …5
×

Extending Groovys Swing User Interface in Builder to Build Richer Applications

2,141
-1

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,141
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
30
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Extending Groovys Swing User Interface in Builder to Build Richer Applications

  1. 1. Extending Groovys Swing User Interface in Builder to Build Richer Applications Danno Ferrin, Intelligent Software Solutions, Inc. James Williams, Spatial Networks, Inc. BOF-5110 Speaker’s logo here (optional)
  2. 2. <ul><ul><li>Learn how to customized Groovy’s SwingBuilder to add custom widgets and non-visual components. </li></ul></ul>
  3. 3. Not always an enterprise question… <ul><li>BUT WILL IT </li></ul><ul><li>S C A L E </li></ul><ul><li>? </li></ul>
  4. 4. Agenda <ul><li>Ways to Extend SwingBuilder </li></ul><ul><li>FactoryBuilderSupport Overview </li></ul><ul><li>Case Study: SwingXBuilder </li></ul>
  5. 5. First some Terminology <ul><li>nodeName( argument, attr : value, attr2 : value) { … } </li></ul><ul><li>Node </li></ul><ul><ul><li>Syntactically a method call, but it represents a widget or bean </li></ul></ul><ul><li>Argument </li></ul><ul><ul><li>The un-named method argument for the node </li></ul></ul><ul><ul><li>As of Groovy 1.5 there can be only one </li></ul></ul><ul><li>Attribute </li></ul><ul><ul><li>Any named parameter in the node </li></ul></ul><ul><ul><li>Names cannot be duplicated – enforced by the Compiler </li></ul></ul><ul><li>Child Content </li></ul><ul><ul><li>The closure after the method </li></ul></ul><ul><ul><li>Usually executed by the builder </li></ul></ul>
  6. 6. Agenda <ul><li>Ways to Extend SwingBuilder </li></ul><ul><li>FactoryBuilderSupport Overview </li></ul><ul><li>Case Study: SwingXBuilder </li></ul>
  7. 7. Issues of Scale How you extend should be driven by how much the extension is used <ul><li>Magic Nodes </li></ul><ul><ul><li>bean(), widget(), container() </li></ul></ul><ul><li>Individual Factory Registration </li></ul><ul><ul><li>Automatic Bean Factory </li></ul></ul><ul><ul><li>Custom Factory </li></ul></ul><ul><li>Builder Suite </li></ul><ul><ul><li>Example: SwingXBuilder </li></ul></ul><ul><li>CompositeBuilder </li></ul><ul><ul><li><Coming Soon> </li></ul></ul><ul><li>Single use of particular widgets </li></ul><ul><li>Multiple uses of a few types </li></ul><ul><li>Multiple use of a lot of types </li></ul><ul><li>Multiple uses from multiple suites </li></ul>
  8. 8. Magic Nodes <ul><li>bean(…) </li></ul><ul><ul><li>Accepts any object </li></ul></ul><ul><ul><li>Not added to parent </li></ul></ul><ul><ul><li>No child content </li></ul></ul><ul><li>widget(…) </li></ul><ul><ul><li>Accepts any java.awt.Component </li></ul></ul><ul><ul><li>Added to parent java.awt.Container </li></ul></ul><ul><ul><li>No child content </li></ul></ul><ul><li>container(…) </li></ul><ul><ul><li>Accepts any java.awt.Container </li></ul></ul><ul><ul><li>Added to parent java.awt.Container </li></ul></ul><ul><ul><li>Accepts child content </li></ul></ul>
  9. 9. Magic Nodes <ul><li>An instance of the object must be passed in as the argument </li></ul><ul><li>Attributes are applied as JavaBeans properties </li></ul><ul><li>Semi-Magic Nodes </li></ul><ul><ul><li>Most existing nodes can become magic nodes </li></ul></ul><ul><ul><li>Argument must match node type </li></ul></ul>
  10. 10. Magic Nodes Example <ul><li>bean(model, propertyChanged: { panel.repaint() } ) </li></ul><ul><li>widget(new JXMonthPanel(), </li></ul><ul><li>selectedBackground:Color.YELLOW) </li></ul><ul><li>container(new JXTitlePane(), title:&quot;Demo”) { </li></ul><ul><li>// whatever you would add in the JXTitlePane </li></ul><ul><li>} </li></ul>
  11. 11. Individual Factory Registration <ul><li>First, what are the characteristics of the Widget? </li></ul><ul><li>Well behaved JavaBeans </li></ul><ul><ul><li>No-args constructor </li></ul></ul><ul><ul><li>Bean can be fully configured via properties </li></ul></ul><ul><li>Complex Beans/Objects </li></ul><ul><ul><li>Only constructors with arguments </li></ul></ul><ul><ul><li>Some features configured only by constructor </li></ul></ul><ul><ul><ul><li>Example: JFrame, JWindow, JDialog owner </li></ul></ul></ul><ul><ul><li>Non-JavaBeans style properties/configuration </li></ul></ul>
  12. 12. Individual Factory Registration <ul><li>Well behaved JavaBeans may use registerBeanFactory(…) </li></ul><ul><ul><li>All lifecycle methods are automated </li></ul></ul><ul><ul><li>No fancy processing </li></ul></ul><ul><ul><li>Child nodes added via JComponent.add(child [,constraints]) </li></ul></ul><ul><li>Complex Beans/Objects must use registerFactory(…) </li></ul><ul><ul><li>Must implement groovy.util.Factory </li></ul></ul><ul><ul><li>May extend groovy.util.AbstractFactory </li></ul></ul><ul><ul><ul><li>newInstance(builder, name, arg, attrs) is the only unimplemented method </li></ul></ul></ul>
  13. 13. Builder Suite <ul><li>Logical progression from creating factories </li></ul><ul><li>Subclass SwingBuilder </li></ul><ul><ul><li>Do magic in the Constructor </li></ul></ul><ul><ul><li>SwingBuilder factories can be over-ridden </li></ul></ul><ul><ul><li>SwingBuilder factories can be renamed – </li></ul></ul><ul><ul><ul><li>getFactories().each {k, v -> registerFactory(&quot;j&quot; + k, v) } </li></ul></ul></ul>
  14. 14. Builder Suite <ul><li>But what if I want multiple suites? </li></ul><ul><ul><li>JideSplitButton </li></ul></ul><ul><ul><li>JXMap </li></ul></ul><ul><ul><li>JRibbon </li></ul></ul><ul><li>Ways to Add more than one suite </li></ul><ul><ul><li>Manually add via magic nodes </li></ul></ul><ul><ul><li>Manual add factories after construction </li></ul></ul><ul><ul><li>Hand roll a custom suite </li></ul></ul><ul><li>This can be burdensome…. </li></ul>
  15. 15. Composite Builder <ul><li>Coming Soon </li></ul><ul><ul><li>Won’t be in Groovy 1.6 core </li></ul></ul><ul><li>The Idea </li></ul><ul><ul><li>Declare a builder that is a composite of other builders </li></ul></ul><ul><ul><li>Have each builder use a common Binding </li></ul></ul><ul><ul><li>Allow children of one builder to nest inside another </li></ul></ul><ul><ul><ul><li>Widgets from different libraries </li></ul></ul></ul><ul><ul><ul><li>Nesting non-GUI Widgets </li></ul></ul></ul><ul><ul><ul><ul><li>tree() { rootFolder { treeNode(); treeNode(); treeNode(); } } </li></ul></ul></ul></ul>
  16. 16. The Vision <ul><ul><li>def builder = new CompositeBuilder( SwingBuilder, ogb:ObjectGraphBuilder, jx:SwingXBuilder, jide:JIDEBuilder, fl:FlamingoBuilder, nodeName: randomFactory ) builder.jxframe { ribbon { editActionsGroup, saveActionsGroup } </li></ul></ul><ul><ul><li>jidepopup(visible:false) { … popup contents … } } </li></ul></ul>
  17. 17. The code as of Today <ul><li>Called ‘UberBuilder’ </li></ul><ul><ul><li>Available on SVN (only for the brave…) </li></ul></ul><ul><ul><li>https://svn.codehaus.org/groovy/trunk/groovy/modules/griffon/ </li></ul></ul><ul><li>GUIBuilder is an auto composite of a few builders </li></ul><ul><ul><li>SwingBuilder </li></ul></ul><ul><ul><li>SwingXBuilder </li></ul></ul><ul><ul><li>JIDEBuilder </li></ul></ul><ul><ul><li>GraphicsBuilder </li></ul></ul><ul><li>Not quite soup yet… </li></ul>
  18. 18. Agenda <ul><li>Ways to Extend SwingBuilder </li></ul><ul><li>FactoryBuilderSupport Overview </li></ul><ul><li>Case Study: SwingXBuilder </li></ul>
  19. 19. Factory Lifecycle
  20. 20. Delegate Closures <ul><li>Some steps can be intercepted without a Factory </li></ul><ul><ul><li>addPreInstantiateDelegate, addPostInstantiateDelegate, addAttributeDelegate </li></ul></ul><ul><ul><ul><li>{FactoryBulderSupport builder, Object node, Map attributes -> … } </li></ul></ul></ul><ul><ul><li>addPostNodeCompleteDelegate </li></ul></ul><ul><ul><ul><li>{FactoryBulderSupport builder, Object parent, Object node -> … } </li></ul></ul></ul><ul><li>Delegates handle all nodes </li></ul><ul><ul><li>No picking and choosing, each closure must handle every call </li></ul></ul><ul><li>Some built-in tasks done via delegates </li></ul><ul><ul><li>Handling of constraints: attributes </li></ul></ul><ul><ul><li>Handling of id: attributes </li></ul></ul><ul><ul><li>Handling of bind() and attributes </li></ul></ul>
  21. 21. Agenda <ul><li>Ways to Extend SwingBuilder </li></ul><ul><li>FactoryBuilderSupport Overview </li></ul><ul><li>Case Study: SwingXBuilder </li></ul>
  22. 22. SwingXBuilder <ul><li>Google Summer of Code 2007 project </li></ul><ul><ul><li>James Williams – Nova Southeastern University, FL </li></ul></ul><ul><li>Proof of concept for SwingBuilder extension </li></ul><ul><li>First Groovy builder in 100% Groovy </li></ul><ul><ul><li>SwingBuilder later ported to Groovy </li></ul></ul>
  23. 23. Summary <ul><li>SwingBuilder extension is easy </li></ul><ul><li>Choose your extension method based on frequency of use </li></ul><ul><li>FactoryBuilderSupport FTW </li></ul><ul><li>Look to SwingXBuilder to see how it’s been done </li></ul>
  24. 24. For More Information <ul><li>TS-5098 </li></ul><ul><ul><li>Friday at 12:10 in EP 305 </li></ul></ul><ul><ul><li>Covers more of the SwingBuilder basics not covered here </li></ul></ul><ul><li>Groovy </li></ul><ul><ul><li>http://groovy.codehaus.org </li></ul></ul><ul><li>Builders mentioned in this presentation </li></ul><ul><ul><li>http://groovy.codehaus.org/Swing+Builder </li></ul></ul><ul><ul><li>http://groovy.codehaus.org/SwingXBuilder </li></ul></ul><ul><ul><li>http://groovy.codehaus.org/JideBuilder </li></ul></ul><ul><ul><li>http://groovy.codehaus.org/GraphicsBuilder </li></ul></ul><ul><li>Groovy Swing team blogs </li></ul><ul><ul><li>http://jroller.com/aalmiray </li></ul></ul><ul><ul><li>http://www.jameswilliams.be/blog </li></ul></ul><ul><ul><li>http://www.shemnon.com/speling </li></ul></ul>
  25. 25. Danno Ferrin, Intelligent Software Solutions, Inc. James Williams, Spatial Networks, Inc. BOF-5110 Speaker’s logo here (optional)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×