KEMBAR78
Svcc Java2D And Groovy | PPT
Java2D and  G r oo v y , a Perfect Match Andres Almiray
Agenda What is  G r oo v y? SwingBuilder GraphicsBuilder Putting it all together What’s next?
W hat is  G r oo v y ?
SwingBuilder
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
GraphicsBuilder
GraphicsBuilder - Basics GraphicsBuilder is to Java2D what SwingBuilder is to Swing It produces a hierarchy of GraphicsOperations (or nodes)‏ A specialized component is required to render graphicsOperations and handle input events: GraphicsPanel
GraphicsBuilder - Features shapes - shape, outline, areas regular Java2D shapes from java.wt.geom additional shapes from jSilhouette paints - solid, gradients, composite strokes - from jhlabs filters - from swingx, jhlabs grouping, transfortmations , images svg - import/export via Batik swf - partial export (still experimental)‏
GraphicsPad
Putting it all together
Mixing Swing & Graphics Use SwingBuilder to build the UI Use GraphicsBuilder to draw anywhere you need in a GraphicsPanel in JLayeredPane in SwingX layered components in Jide’s overlay support
Tips & Hints Use SwingBuilder.build()‏ Use Expando for quick prototyping of beans Use ObservableMap for quick binding tests Reuse shapes as must as you can Group operations that may have the same settings applied (color, borderWidth, fill, transformations)‏
What’s next?
Tips & Hints Custom nodes Custom painting of Swing components Animation support
Resources h tt p : // groovy.codehaus.org h tt p : // groovy.codehaus.org/Swing+Builder h tt p : // groovy.codehaus.org/SwingXBuilder h tt p : // groovy.codehaus.org/JideBuilder h tt p : // groovy.codehaus.org/GraphicsBuilder h tt p : // code.google.com/p/jsilhouette h tt p : // jroller.com/aalmiray h tt p : // twitter.com/aalmiray
Q   &   A
Thank you!

Svcc Java2D And Groovy

  • 1.
    Java2D and G r oo v y , a Perfect Match Andres Almiray
  • 2.
    Agenda What is G r oo v y? SwingBuilder GraphicsBuilder Putting it all together What’s next?
  • 3.
    W hat is G r oo v y ?
  • 4.
  • 5.
    Builder Basics Buildersare 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
  • 6.
    A Quick HelloWorldExample 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)‏ })‏ } }
  • 7.
    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
  • 8.
  • 9.
    GraphicsBuilder - BasicsGraphicsBuilder is to Java2D what SwingBuilder is to Swing It produces a hierarchy of GraphicsOperations (or nodes)‏ A specialized component is required to render graphicsOperations and handle input events: GraphicsPanel
  • 10.
    GraphicsBuilder - Featuresshapes - shape, outline, areas regular Java2D shapes from java.wt.geom additional shapes from jSilhouette paints - solid, gradients, composite strokes - from jhlabs filters - from swingx, jhlabs grouping, transfortmations , images svg - import/export via Batik swf - partial export (still experimental)‏
  • 11.
  • 12.
  • 13.
    Mixing Swing &Graphics Use SwingBuilder to build the UI Use GraphicsBuilder to draw anywhere you need in a GraphicsPanel in JLayeredPane in SwingX layered components in Jide’s overlay support
  • 14.
    Tips & HintsUse SwingBuilder.build()‏ Use Expando for quick prototyping of beans Use ObservableMap for quick binding tests Reuse shapes as must as you can Group operations that may have the same settings applied (color, borderWidth, fill, transformations)‏
  • 15.
  • 16.
    Tips & HintsCustom nodes Custom painting of Swing components Animation support
  • 17.
    Resources h ttp : // groovy.codehaus.org h tt p : // groovy.codehaus.org/Swing+Builder h tt p : // groovy.codehaus.org/SwingXBuilder h tt p : // groovy.codehaus.org/JideBuilder h tt p : // groovy.codehaus.org/GraphicsBuilder h tt p : // code.google.com/p/jsilhouette h tt p : // jroller.com/aalmiray h tt p : // twitter.com/aalmiray
  • 18.
    Q & A
  • 19.