Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Svcc Java2D And Groovy

1,614 views

Published on

Java2D and Groovy, a Perfect Match

Published in: Technology, Art & Photos
  • Be the first to comment

Svcc Java2D And Groovy

  1. 1. Java2D and G r oo v y , a Perfect Match Andres Almiray
  2. 2. Agenda <ul><li>What is G r oo v y? </li></ul><ul><li>SwingBuilder </li></ul><ul><li>GraphicsBuilder </li></ul><ul><li>Putting it all together </li></ul><ul><li>What’s next? </li></ul>
  3. 3. W hat is G r oo v y ?
  4. 4. SwingBuilder
  5. 5. Builder Basics <ul><li>Builders are a form of a DSL </li></ul><ul><li>Focused on Hierarchical Structures </li></ul><ul><li>SwingBuilder is not the only Builder in G r oo v y </li></ul><ul><ul><li>XMLBuilder </li></ul></ul><ul><ul><li>AntBuilder </li></ul></ul><ul><ul><li>ObjectGraphBuilder </li></ul></ul><ul><ul><li>Still Others… </li></ul></ul><ul><li>Swing applications follow a hierarchical model: </li></ul><ul><ul><li>Window </li></ul></ul><ul><ul><li>Panel </li></ul></ul><ul><ul><li>Button </li></ul></ul><ul><li>Builders are a perfect fit for making Swing UIs </li></ul>
  6. 6. A Quick HelloWorld Example <ul><li>groovy.swing.SwingBuilder.build { </li></ul><ul><li>frame( id: 'root', title:'Hello World', </li></ul><ul><li>show:true, pack:true) { </li></ul><ul><li>flowLayout()‏ </li></ul><ul><li>label('Enter a message:')‏ </li></ul><ul><li>textField(id:'name', columns:20)‏ </li></ul><ul><li>button('Click', </li></ul><ul><li>actionPerformed: { ActionEvent e -> </li></ul><ul><li>if (name.text)‏ </li></ul><ul><li>optionPane().showMessageDialog( </li></ul><ul><li>root, name.text)‏ </li></ul><ul><li>})‏ </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  7. 7. What's going on? <ul><li>Each node is syntactically a method call </li></ul><ul><li>All of these method calls are dynamically dispatched </li></ul><ul><ul><li>Most don’t actually exist in bytecode </li></ul></ul><ul><li>Child closures create hierarchical relations </li></ul><ul><ul><li>Child widgets are added to parent containers </li></ul></ul><ul><li>SwingBuilder node names are derived from Swing classes </li></ul><ul><ul><li>Remove the leading ‘J’ from a Swing class when present </li></ul></ul><ul><li>SwingBuilder also supports some AWT classes like layouts </li></ul>
  8. 8. GraphicsBuilder
  9. 9. GraphicsBuilder - Basics <ul><li>GraphicsBuilder is to Java2D what SwingBuilder is to Swing </li></ul><ul><li>It produces a hierarchy of GraphicsOperations (or nodes)‏ </li></ul><ul><li>A specialized component is required to render graphicsOperations and handle input events: GraphicsPanel </li></ul>
  10. 10. GraphicsBuilder - Features <ul><li>shapes - shape, outline, areas </li></ul><ul><ul><li>regular Java2D shapes from java.wt.geom </li></ul></ul><ul><ul><li>additional shapes from jSilhouette </li></ul></ul><ul><li>paints - solid, gradients, composite </li></ul><ul><li>strokes - from jhlabs </li></ul><ul><li>filters - from swingx, jhlabs </li></ul><ul><li>grouping, transfortmations , images </li></ul><ul><li>svg - import/export via Batik </li></ul><ul><li>swf - partial export (still experimental)‏ </li></ul>
  11. 11. GraphicsPad
  12. 12. Putting it all together
  13. 13. Mixing Swing & Graphics <ul><li>Use SwingBuilder to build the UI </li></ul><ul><li>Use GraphicsBuilder to draw anywhere you need </li></ul><ul><ul><li>in a GraphicsPanel </li></ul></ul><ul><ul><li>in JLayeredPane </li></ul></ul><ul><ul><li>in SwingX layered components </li></ul></ul><ul><ul><li>in Jide’s overlay support </li></ul></ul>
  14. 14. Tips & Hints <ul><li>Use SwingBuilder.build()‏ </li></ul><ul><li>Use Expando for quick prototyping of beans </li></ul><ul><li>Use ObservableMap for quick binding tests </li></ul><ul><li>Reuse shapes as must as you can </li></ul><ul><li>Group operations that may have the same settings applied (color, borderWidth, fill, transformations)‏ </li></ul>
  15. 15. What’s next?
  16. 16. Tips & Hints <ul><li>Custom nodes </li></ul><ul><li>Custom painting of Swing components </li></ul><ul><li>Animation support </li></ul>
  17. 17. Resources <ul><li>h tt p : // groovy.codehaus.org </li></ul><ul><li>h tt p : // groovy.codehaus.org/Swing+Builder </li></ul><ul><li>h tt p : // groovy.codehaus.org/SwingXBuilder </li></ul><ul><li>h tt p : // groovy.codehaus.org/JideBuilder </li></ul><ul><li>h tt p : // groovy.codehaus.org/GraphicsBuilder </li></ul><ul><li>h tt p : // code.google.com/p/jsilhouette </li></ul><ul><li>h tt p : // jroller.com/aalmiray </li></ul><ul><li>h tt p : // twitter.com/aalmiray </li></ul>
  18. 18. Q & A
  19. 19. Thank you!

×