SlideShare uma empresa Scribd logo
1 de 44
Baixar para ler offline
http://www.flickr.com/photos/iancarroll/5058330466/
Ad::
Ad::

@GrabConfig(systemClassLoader=true) // for GroovyServ
@GrabResolver(name="kobo-repo", root="http://github.com/kobo/maven-repo/raw/master/release")
@Grab("org.jggug.kobo:gexcelapi:0.2")
import org.jggug.kobo.gexcelapi.GExcel


def book = GExcel.open(args[0])
def sheet = book[0]

println sheet.A1.value
sheet.A1.value = "New value of A1"

sheet.A_.each{ cell -> println cell.value }
sheet._1.each{ cell -> println cell.value }
sheet.A1_B6.each{ row -> row.each { cell -> println it.value } }
Sample of   import	
  javafx.stage.*;
            import	
  javafx.scene.*;
            import	
  javafx.scene.shape.*;
            import	
  javafx.scene.paint.*;

            Stage	
  {
            	
  	
  	
  	
  title:	
  "Sample	
  by	
  JavaFX	
  Script"
            	
  	
  	
  	
  width:	
  600
            	
  	
  	
  	
  height:	
  450
            	
  	
  	
  	
  scene:	
  Scene	
  {
            	
  	
  	
  	
  	
  	
  	
  	
  fill:	
  Color.LIGHTSKYBLUE
            	
  	
  	
  	
  	
  	
  	
  	
  content:	
  Rectangle	
  {
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  x:	
  25,	
  y:	
  40
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  width:	
  100,	
  height:	
  50
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  fill:	
  Color.RED
            	
  	
  	
  	
  	
  	
  	
  	
  }
            	
  	
  	
  	
  }
            }
6
import	
  groovy.swing.SwingBuilder

Sample of   import	
  java.awt.BorderLayout	
  as	
  BL

            int	
  count	
  =	
  0
            new	
  SwingBuilder().edt	
  {
            	
  	
  	
  	
  frame(
            	
  	
  	
  	
  	
  	
  	
  	
  title:'Hello',
            	
  	
  	
  	
  	
  	
  	
  	
  size:[600,	
  450],
            	
  	
  	
  	
  	
  	
  	
  	
  show:true
            	
  	
  	
  	
  )	
  {
            	
  	
  	
  	
  	
  	
  	
  	
  borderLayout()
            	
  	
  	
  	
  	
  	
  	
  	
  textLabel	
  =	
  label(
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  text:'Sample	
  of	
  SwingBuilder',
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  constraints:	
  BL.NORTH
            	
  	
  	
  	
  	
  	
  	
  	
  )
            	
  	
  	
  	
  	
  	
  	
  	
  button(
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  text:	
  'Click	
  Me!',
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  actionPerformed:	
  {
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  count++
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  textLabel.text	
  =
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "Clicked	
  ${count}	
  time(s)."
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  println	
  "clicked"
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  },
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  constraints:	
  BL.SOUTH
            	
  	
  	
  	
  	
  	
  	
  	
  )
            	
  	
  	
  	
  }
            }
http://www.flickr.com/photos/33678919@N07/5239012324/
from Roadmap




  http://www.flickr.com/photos/33678919@N07/5239012324/
http://svn.codehaus.org/griffon/builders/fxbuilder/
import	
  griffon.builder.fx.FxBuilder

Sample of   import	
  javafx.stage.*
            import	
  javafx.scene.*
            import	
  javafx.scene.shape.*
            import	
  javafx.scene.paint.*

            new	
  FxBuilder().edt	
  {
            	
  	
  	
  	
  stage(
            	
  	
  	
  	
  	
  	
  	
  	
  title:	
  "Sample	
  by	
  FxBuilder	
  of	
  Groovy",
            	
  	
  	
  	
  	
  	
  	
  	
  width:	
  600,
            	
  	
  	
  	
  	
  	
  	
  	
  height:	
  450,
            	
  	
  	
  	
  	
  	
  	
  	
  scene:	
  scene(fill:	
  Color.$LIGHTSKYBLUE)	
  {
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  rectangle(
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  x:	
  25,	
  y:	
  40,
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  width:	
  100,	
  height:	
  50,
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  fill:	
  Color.$RED
            	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  )
            	
  	
  	
  	
  	
  	
  	
  	
  }
            	
  	
  	
  	
  )
            }




                                                      http://griffon.codehaus.org/FxBuilder+Plugin
import	
  griffon.builder.fx.FxBuilder

                                                                             import	
  javafx.stage.*
import	
  javafx.stage.*;                                                    import	
  javafx.scene.*
import	
  javafx.scene.*;                                                    import	
  javafx.scene.shape.*
import	
  javafx.scene.shape.*;                                              import	
  javafx.scene.paint.*
import	
  javafx.scene.paint.*;
                                                                                new	
  FxBuilder().edt	
  {
Stage	
  {                                                                      	
  	
  	
  	
  stage(
	
  	
  	
  	
  title:	
  "Sample	
  by	
  JavaFX	
  Script", 	
  	
  	
  	
  	
  	
  	
  	
  title:	
  "Sample	
  by	
  FxBuilder	
  of	
  Groovy",
	
  	
  	
  	
  width:	
  600                                                   	
  	
  	
  	
  	
  	
  	
  	
  width:	
  600,
	
  	
  	
  	
  height:	
  450                                                  	
  	
  	
  	
  	
  	
  	
  	
  height:	
  450,
	
  	
  	
  	
  scene:	
  Scene	
  {
	
  	
  	
  	
  	
  	
  	
  	
  fill:	
  Color.LIGHTSKYBLUE
	
  	
  	
  	
  	
  	
  	
  	
  content:	
  Rectangle	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  x:	
  25,	
  y:	
  40
                                                                       ≒
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  width:	
  100,	
  height:	
  50
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  fill:	
  Color.RED
                                                                                	
  	
  	
  	
  	
  	
  	
  	
  scene:	
  scene(fill:Color.$LIGHTSKYBLUE){
                                                                                	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  rectangle(
                                                                                	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  x:	
  25,	
  y:	
  40,
                                                                                	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  width:	
  100,	
  height:	
  50,
                                                                                	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  fill:	
  Color.$RED
	
  	
  	
  	
  	
  	
  	
  	
  }                                               	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  )
	
  	
  	
  	
  }                                                               	
  	
  	
  	
  	
  	
  	
  	
  }
}                                                                               	
  	
  	
  	
  )
                                                                                }



                                                                                                 FxBuilder
JavaFX Script




                                                 Welcome to




http://www.flickr.com/photos/anirudhkoul/3734360895/
Minimum lecture series #65535



                                only for DSL/Builder

http://www.flickr.com/photos/iancarroll/5058330466/
Minimum Basic



Value:	
  ${value}”
Features for
Features for
Features for
groovy.lang.Closure	
  closure	
  =	
  {	
  String	
  arg	
  -­‐>
	
  	
  	
  	
  return	
  "hoge:${arg}"
}                                       Java8
                                           #



//	
  
closure.call(“foo”)	
  	
  //=>	
  “hoge:foo”

//	
  
closure(“foo”)	
  	
  	
  	
  	
  	
  	
  //=>	
  “hoge:foo”
Args of
//	
              (         )
{	
  -­‐>	
  "hoge"	
  }.call()	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //=>	
  "hoge"

//	
                 (      )
{	
  num	
  -­‐>	
  "hoge:${num}"	
  }.call(123)	
  //=>	
  "hoge:123"

//	
                   (      )
{	
  num,	
  String	
  id,	
  option	
  -­‐>
	
  	
  	
  	
  return	
  "hoge:${num}:${id}:${option}"
}.call(123,	
  “0A”,	
  “X”)	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //=>	
  "hoge:123:0A:X"

//	
           it
{	
  "hoge:${it}"	
  }.call(123)	
  	
  	
  	
  	
  	
  	
  	
  	
  //=>	
  "hoge:123"
as Args
//	
        (              )
someMethod({	
  num	
  -­‐>	
  num	
  *	
  2	
  })

//	
  
someMethod	
  {	
  num	
  -­‐>	
  num	
  *	
  2	
  }

//	
  
someMethod(arg1,	
  arg2,	
  {	
  num	
  -­‐>	
  num	
  *	
  2	
  })
someMethod(arg1,	
  arg2)	
  {	
  num	
  -­‐>	
  num	
  *	
  2	
  }	
  //
Features for
MOP::
class	
  MopSample	
  {
	
  	
  	
  	
  def	
  methodMissing(String	
  name,	
  args)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  println	
  "Method:	
  $name($args)"
	
  	
  	
  	
  }
}
def	
  sample	
  =	
  new	
  MopSample()

sample.hoge()
//	
  =>	
  “Method:	
  hoge([])”

sample.foo(123,	
  456)
//	
  =>	
  “Method:	
  foo([123,	
  456])”
MOP::
class	
  MopSample	
  {
	
  	
  	
  	
  def	
  propertyMissing(String	
  name)	
  {	
  //	
  for	
  getter
	
  	
  	
  	
  	
  	
  	
  	
  println	
  "Property:	
  $name"
	
  	
  	
  	
  }
	
  	
  	
  	
  def	
  propertyMissing(String	
  name,	
  value)	
  {	
  //	
  for	
  setter
	
  	
  	
  	
  	
  	
  	
  	
  println	
  "Property:	
  $name	
  =	
  $value"
	
  	
  	
  	
  }
}
sample	
  =	
  new	
  MopSample2()

sample.hoge	
  	
  	
  	
  	
  	
  	
  //=>	
  "Property:	
  hoge"
sample.bar	
  	
  	
  	
  	
  	
  	
  	
  //=>	
  "Property:	
  bar"
sample.baz	
  =	
  "!!"	
  //=>	
  "Property:	
  baz	
  =	
  !!"
Features for
ex.
def	
  writer	
  =	
  new	
  StringWriter()
def	
  builder	
  =	
  new	
  groovy.xml.MarkupBuilder(writer)
builder.books	
  {
	
  	
  	
  	
  book(published:"2010-­‐12-­‐20")	
  {
	
  	
  	
  	
  	
  	
  	
  	
  author	
  "nobeans"
	
  	
  	
  	
  	
  	
  	
  	
  title	
  	
  "Groovy
                                                              ←Describe here
                                                               "
	
  	
  	
  	
  }
	
  	
  	
  	
  3.times	
  {
	
  	
  	
  	
  	
  	
  	
  	
  book	
  "Groovy      	
   ${it+1} "
	
  	
  	
  	
  }                                                   <books>
}                                                                   	
  	
  <book	
  published='2010-­‐12-­‐20'>
println	
  writer.toString()                                        	
  	
  	
  	
  <author>nobeans</author>
                                                                    	
  	
  	
  	
  <title>Groovy         </title>
                                                          	
  	
  </book>
                                                          	
  	
  <book>Groovy         	
   1 </book>

                    Format as Xml→                        	
  	
  <book>Groovy         	
   2 </book>
                                                          	
  	
  <book>Groovy         	
   3 </book>
                                                          </books>
Basic Theory of
builder.books	
  {
	
  	
  	
  	
  book(published:"2010-­‐12-­‐20")	
  {
	
  	
  	
  	
  	
  	
  	
  	
  author	
  "nobeans"
	
  	
  	
  	
  	
  	
  	
  	
  title	
  	
  "Groovy           "
	
  	
  	
  	
  }
	
  	
  	
  	
  3.times	
  {
	
  	
  	
  	
  	
  	
  	
  	
  book	
  "Groovy      	
   ${it+1} "
	
  	
  	
  	
  }
}
Basic Theory of
builder.books	
  {
	
  	
  	
  	
  book(published:"2010-­‐12-­‐20")	
  {
	
  	
  	
  	
  	
  	
  	
  	
  author	
  "nobeans"
	
  	
  	
  	
  	
  	
  	
  	
  title	
  	
  "Groovy           "
	
  	
  	
  	
  }
	
  	
  	
  	
  3.times	
  {
	
  	
  	
  	
  	
  	
  	
  	
  book	
  "Groovy      	
   ${it+1} "
	
  	
  	
  	
  }
}
Classification of
               Dynamically          Statically
              Defined Method      Defined Method
                  extends             extends
              BuilderSupport   FactoryBuilderSupport
 Extends      MarkupBuilder       SwingBuilder
 Abstract     NodeBuilder          FxBuilder
  Class         DOMBuilder       ObjectGraphBuilder
                 AntBuilder          JmxBuilder
                SAXBuilder
                ConfigSlurper
Independent      CliBuilder
public	
  abstract	
  class	
  BuilderSupport	
  ...	
  {
	
  	
  	
  //	
  ...snip...
	
  	
  	
  protected	
  abstract	
  void	
  setParent(Object	
  parent,	
  Object	
  child);
	
  	
  	
  protected	
  abstract	
  Object	
  createNode(Object	
  name);
	
  	
  	
  protected	
  abstract	
  Object	
  createNode(Object	
  name,	
  Object	
  value);
	
  	
  	
  protected	
  abstract	
  Object	
  createNode(Object	
  name,	
  Map	
  attributes);
	
  	
  	
  protected	
  abstract	
  Object	
  createNode(Object	
  name,	
  Map	
  attributes,
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Object	
  value);
	
  	
  	
  //	
  ...snip...
}
public	
  class	
  SwingBuilder	
  extends	
  FactoryBuilderSupport	
  {
	
  	
  	
  	
  //	
  ...snip...
	
  	
  	
  	
  def	
  registerSupportNodes()	
  {
	
  	
  	
  	
  	
  	
  	
  	
  registerFactory("action",	
  new	
  ActionFactory())
	
  	
  	
  	
  	
  	
  	
  	
  registerFactory("actions",	
  new	
  CollectionFactory())
	
  	
  	
  	
  	
  	
  	
  	
  registerFactory("map",	
  new	
  MapFactory())
	
  	
  	
  	
  	
  	
  	
  	
  registerFactory("imageIcon",	
  new	
  ImageIconFactory())
	
  	
  	
  	
  	
  	
  	
  	
  registerFactory("buttonGroup",	
  new	
  ButtonGroupFactory())
	
  	
  	
  	
  	
  	
  	
  	
  addAttributeDelegate(ButtonGroupFactory.&buttonGroupAttributeDelegate)
	
  	
  	
  	
  	
  	
  	
  	
  //	
  ...snip...
	
  	
  	
  	
  }
	
  	
  	
  	
  //	
  ...snip...
}
≪sample≫



powered by NodeBuilder




                         http://www.flickr.com/photos/timothymorgan/75294154/
def	
  writer	
  =	
  new	
  StringWriter()
new	
  DdlBuilder(writer).scheme	
  {
	
  	
  book	
  {                                            CREATE	
  TABLE	
  book	
  (
	
  	
  	
  	
  id	
  	
  	
  	
  	
  	
  	
  	
  type:int   	
  	
  	
  	
  id	
  INTEGER,
	
  	
  	
  	
  title	
  	
  	
  	
  	
  type:String         	
  	
  	
  	
  title	
  TEXT,
	
  	
  	
  	
  published	
  type:Date                       	
  	
  	
  	
  published	
  TIMESTAMP,
	
  	
  	
  	
  author	
  	
  	
  	
  type:int               	
  	
  	
  	
  author	
  INTEGER
	
  	
  }                                                    )
	
  	
  author	
  {                                          CREATE	
  TABLE	
  author	
  (
	
  	
  	
  	
  id	
  	
  	
  	
  	
  	
  	
  	
  type:int   	
  	
  	
  	
  id	
  INTEGER,
	
  	
  	
  	
  name	
  	
  	
  	
  	
  	
  type:String      	
  	
  	
  	
  name	
  TEXT
	
  	
  }                                                    )
}
println	
  writer.toString()
class	
  DdlBuilder	
  {
	
  	
  	
  	
  def	
  writer
	
  	
  	
  	
  DdlBuilder(writer)	
  {	
  this.writer	
  =	
  writer	
  }
	
  	
  	
  	
  def	
  scheme(Closure	
  cls)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  new	
  NodeBuilder().scheme(cls).each	
  {	
  table	
  -­‐>
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  writer.println	
  "CREATE	
  TABLE	
  ${table.name()}	
  ("
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  writer.println	
  table.collect	
  {	
  col	
  -­‐>
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "	
  	
  	
  	
  ${col.name()}	
  ${type(col.attribute('type'))}"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }.join(",n")
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  writer.println	
  ")"
	
  	
  	
  	
  	
  	
  	
  	
  }
	
  	
  	
  	
  }
	
  	
  	
  	
  private	
  type(clazz)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  switch	
  (clazz)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  case	
  String:	
  return	
  "TEXT"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  case	
  int:	
  	
  	
  	
  return	
  "INTEGER"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  case	
  Date:	
  	
  	
  return	
  "TIMESTAMP"
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  default:
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  throw	
  new	
  RuntimeException("unsupported	
  type:	
  $clazz")
	
  	
  	
  	
  	
  	
  	
  	
  }
	
  	
  	
  	
  }
}
Features for
http://www.flickr.com/photos/ztyx/4601942293/

Mais conteúdo relacionado

Mais procurados

Monad Transformers In The Wild
Monad Transformers In The WildMonad Transformers In The Wild
Monad Transformers In The Wild
StackMob Inc
 

Mais procurados (20)

SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generation
 
Hidden Gems in Swift
Hidden Gems in SwiftHidden Gems in Swift
Hidden Gems in Swift
 
ECMA 入门
ECMA 入门ECMA 入门
ECMA 入门
 
Scalaz
ScalazScalaz
Scalaz
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)
 
Monad Transformers In The Wild
Monad Transformers In The WildMonad Transformers In The Wild
Monad Transformers In The Wild
 
Your code is not a string
Your code is not a stringYour code is not a string
Your code is not a string
 
Lecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of TwenteLecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of Twente
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of Atrocity
 
오브젝트C(pdf)
오브젝트C(pdf)오브젝트C(pdf)
오브젝트C(pdf)
 
Practical scalaz
Practical scalazPractical scalaz
Practical scalaz
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance Trivia
 
API design: using type classes and dependent types
API design: using type classes and dependent typesAPI design: using type classes and dependent types
API design: using type classes and dependent types
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 

Semelhante a Groovy's Builder

JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
Kiyotaka Oku
 

Semelhante a Groovy's Builder (20)

JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011
 
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
 
JavaFX 2.0 and Alternative Languages
JavaFX 2.0 and Alternative LanguagesJavaFX 2.0 and Alternative Languages
JavaFX 2.0 and Alternative Languages
 
JavaFX 2.0 With Alternative Languages [Portuguese]
JavaFX 2.0 With Alternative Languages [Portuguese]JavaFX 2.0 With Alternative Languages [Portuguese]
JavaFX 2.0 With Alternative Languages [Portuguese]
 
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative LanguagesJavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
 
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
JavaFX 2.0 With Alternative Languages - Groovy, Clojure, Scala, Fantom, and V...
 
Mini-curso JavaFX Aula1
Mini-curso JavaFX Aula1Mini-curso JavaFX Aula1
Mini-curso JavaFX Aula1
 
JavaFX Your Way - Devoxx Version
JavaFX Your Way - Devoxx VersionJavaFX Your Way - Devoxx Version
JavaFX Your Way - Devoxx Version
 
G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門
 
Java Fx Overview Tech Tour
Java Fx Overview Tech TourJava Fx Overview Tech Tour
Java Fx Overview Tech Tour
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
Javafx Overview 90minutes
Javafx Overview 90minutesJavafx Overview 90minutes
Javafx Overview 90minutes
 
Javafx Overview 90minutes
Javafx Overview 90minutesJavafx Overview 90minutes
Javafx Overview 90minutes
 
Javafx Overview 90minutes
Javafx Overview 90minutesJavafx Overview 90minutes
Javafx Overview 90minutes
 
SVGo workshop
SVGo workshopSVGo workshop
SVGo workshop
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
メディアアートにおけるプログラミング言語Rubyの役割
メディアアートにおけるプログラミング言語Rubyの役割メディアアートにおけるプログラミング言語Rubyの役割
メディアアートにおけるプログラミング言語Rubyの役割
 
Greach, GroovyFx Workshop
Greach, GroovyFx WorkshopGreach, GroovyFx Workshop
Greach, GroovyFx Workshop
 
JavaFX
JavaFXJavaFX
JavaFX
 
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen ChinHacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
 

Mais de Yasuharu Nakano (9)

Java開発の強力な相棒として今すぐ使えるGroovy
Java開発の強力な相棒として今すぐ使えるGroovyJava開発の強力な相棒として今すぐ使えるGroovy
Java開発の強力な相棒として今すぐ使えるGroovy
 
OSS Product feat. Gradle
OSS Product feat. GradleOSS Product feat. Gradle
OSS Product feat. Gradle
 
Gr8conf EU 2013 Speed up your development: GroovyServ and Grails Improx Plugin
Gr8conf EU 2013 Speed up your development: GroovyServ and Grails Improx PluginGr8conf EU 2013 Speed up your development: GroovyServ and Grails Improx Plugin
Gr8conf EU 2013 Speed up your development: GroovyServ and Grails Improx Plugin
 
The report of JavaOne2011 about groovy
The report of JavaOne2011 about groovyThe report of JavaOne2011 about groovy
The report of JavaOne2011 about groovy
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
 
レッツゴーデベロッパー2011「プログラミングGroovy〜G*エコシステム編」
レッツゴーデベロッパー2011「プログラミングGroovy〜G*エコシステム編」レッツゴーデベロッパー2011「プログラミングGroovy〜G*エコシステム編」
レッツゴーデベロッパー2011「プログラミングGroovy〜G*エコシステム編」
 
How about Gradle?
How about Gradle?How about Gradle?
How about Gradle?
 
JavaOne2010 Groovy/Spring Roo
JavaOne2010 Groovy/Spring RooJavaOne2010 Groovy/Spring Roo
JavaOne2010 Groovy/Spring Roo
 
GroovyServ - Technical Part
GroovyServ - Technical PartGroovyServ - Technical Part
GroovyServ - Technical Part
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Groovy's Builder

  • 2.
  • 4. Ad:: @GrabConfig(systemClassLoader=true) // for GroovyServ @GrabResolver(name="kobo-repo", root="http://github.com/kobo/maven-repo/raw/master/release") @Grab("org.jggug.kobo:gexcelapi:0.2") import org.jggug.kobo.gexcelapi.GExcel def book = GExcel.open(args[0]) def sheet = book[0] println sheet.A1.value sheet.A1.value = "New value of A1" sheet.A_.each{ cell -> println cell.value } sheet._1.each{ cell -> println cell.value } sheet.A1_B6.each{ row -> row.each { cell -> println it.value } }
  • 5. Sample of import  javafx.stage.*; import  javafx.scene.*; import  javafx.scene.shape.*; import  javafx.scene.paint.*; Stage  {        title:  "Sample  by  JavaFX  Script"        width:  600        height:  450        scene:  Scene  {                fill:  Color.LIGHTSKYBLUE                content:  Rectangle  {                        x:  25,  y:  40                        width:  100,  height:  50                        fill:  Color.RED                }        } }
  • 6. 6
  • 7.
  • 8.
  • 9. import  groovy.swing.SwingBuilder Sample of import  java.awt.BorderLayout  as  BL int  count  =  0 new  SwingBuilder().edt  {        frame(                title:'Hello',                size:[600,  450],                show:true        )  {                borderLayout()                textLabel  =  label(                        text:'Sample  of  SwingBuilder',                        constraints:  BL.NORTH                )                button(                        text:  'Click  Me!',                        actionPerformed:  {                                count++                                textLabel.text  =                                  "Clicked  ${count}  time(s)."                                println  "clicked"                        },                        constraints:  BL.SOUTH                )        } }
  • 10.
  • 11.
  • 13. from Roadmap http://www.flickr.com/photos/33678919@N07/5239012324/
  • 15. import  griffon.builder.fx.FxBuilder Sample of import  javafx.stage.* import  javafx.scene.* import  javafx.scene.shape.* import  javafx.scene.paint.* new  FxBuilder().edt  {        stage(                title:  "Sample  by  FxBuilder  of  Groovy",                width:  600,                height:  450,                scene:  scene(fill:  Color.$LIGHTSKYBLUE)  {                        rectangle(                                x:  25,  y:  40,                                width:  100,  height:  50,                                fill:  Color.$RED                        )                }        ) } http://griffon.codehaus.org/FxBuilder+Plugin
  • 16.
  • 17. import  griffon.builder.fx.FxBuilder import  javafx.stage.* import  javafx.stage.*; import  javafx.scene.* import  javafx.scene.*; import  javafx.scene.shape.* import  javafx.scene.shape.*; import  javafx.scene.paint.* import  javafx.scene.paint.*; new  FxBuilder().edt  { Stage  {        stage(        title:  "Sample  by  JavaFX  Script",                title:  "Sample  by  FxBuilder  of  Groovy",        width:  600                width:  600,        height:  450                height:  450,        scene:  Scene  {                fill:  Color.LIGHTSKYBLUE                content:  Rectangle  {                        x:  25,  y:  40 ≒                        width:  100,  height:  50                        fill:  Color.RED                scene:  scene(fill:Color.$LIGHTSKYBLUE){                        rectangle(                                x:  25,  y:  40,                                width:  100,  height:  50,                                fill:  Color.$RED                }                        )        }                } }        ) } FxBuilder
  • 18. JavaFX Script Welcome to http://www.flickr.com/photos/anirudhkoul/3734360895/
  • 19. Minimum lecture series #65535 only for DSL/Builder http://www.flickr.com/photos/iancarroll/5058330466/
  • 20.
  • 25. groovy.lang.Closure  closure  =  {  String  arg  -­‐>        return  "hoge:${arg}" } Java8 # //   closure.call(“foo”)    //=>  “hoge:foo” //   closure(“foo”)              //=>  “hoge:foo”
  • 26. Args of //   ( ) {  -­‐>  "hoge"  }.call()                              //=>  "hoge" //   ( ) {  num  -­‐>  "hoge:${num}"  }.call(123)  //=>  "hoge:123" //   ( ) {  num,  String  id,  option  -­‐>        return  "hoge:${num}:${id}:${option}" }.call(123,  “0A”,  “X”)                          //=>  "hoge:123:0A:X" //   it {  "hoge:${it}"  }.call(123)                  //=>  "hoge:123"
  • 27. as Args //   ( ) someMethod({  num  -­‐>  num  *  2  }) //   someMethod  {  num  -­‐>  num  *  2  } //   someMethod(arg1,  arg2,  {  num  -­‐>  num  *  2  }) someMethod(arg1,  arg2)  {  num  -­‐>  num  *  2  }  //
  • 29. MOP:: class  MopSample  {        def  methodMissing(String  name,  args)  {                println  "Method:  $name($args)"        } } def  sample  =  new  MopSample() sample.hoge() //  =>  “Method:  hoge([])” sample.foo(123,  456) //  =>  “Method:  foo([123,  456])”
  • 30. MOP:: class  MopSample  {        def  propertyMissing(String  name)  {  //  for  getter                println  "Property:  $name"        }        def  propertyMissing(String  name,  value)  {  //  for  setter                println  "Property:  $name  =  $value"        } } sample  =  new  MopSample2() sample.hoge              //=>  "Property:  hoge" sample.bar                //=>  "Property:  bar" sample.baz  =  "!!"  //=>  "Property:  baz  =  !!"
  • 32. ex. def  writer  =  new  StringWriter() def  builder  =  new  groovy.xml.MarkupBuilder(writer) builder.books  {        book(published:"2010-­‐12-­‐20")  {                author  "nobeans"                title    "Groovy ←Describe here "        }        3.times  {                book  "Groovy   ${it+1} "        } <books> }    <book  published='2010-­‐12-­‐20'> println  writer.toString()        <author>nobeans</author>        <title>Groovy </title>    </book>    <book>Groovy   1 </book> Format as Xml→    <book>Groovy   2 </book>    <book>Groovy   3 </book> </books>
  • 33. Basic Theory of builder.books  {        book(published:"2010-­‐12-­‐20")  {                author  "nobeans"                title    "Groovy "        }        3.times  {                book  "Groovy   ${it+1} "        } }
  • 34. Basic Theory of builder.books  {        book(published:"2010-­‐12-­‐20")  {                author  "nobeans"                title    "Groovy "        }        3.times  {                book  "Groovy   ${it+1} "        } }
  • 35. Classification of Dynamically Statically Defined Method Defined Method extends extends BuilderSupport FactoryBuilderSupport Extends MarkupBuilder SwingBuilder Abstract NodeBuilder FxBuilder Class DOMBuilder ObjectGraphBuilder AntBuilder JmxBuilder SAXBuilder ConfigSlurper Independent CliBuilder
  • 36. public  abstract  class  BuilderSupport  ...  {      //  ...snip...      protected  abstract  void  setParent(Object  parent,  Object  child);      protected  abstract  Object  createNode(Object  name);      protected  abstract  Object  createNode(Object  name,  Object  value);      protected  abstract  Object  createNode(Object  name,  Map  attributes);      protected  abstract  Object  createNode(Object  name,  Map  attributes,                                                                                Object  value);      //  ...snip... }
  • 37. public  class  SwingBuilder  extends  FactoryBuilderSupport  {        //  ...snip...        def  registerSupportNodes()  {                registerFactory("action",  new  ActionFactory())                registerFactory("actions",  new  CollectionFactory())                registerFactory("map",  new  MapFactory())                registerFactory("imageIcon",  new  ImageIconFactory())                registerFactory("buttonGroup",  new  ButtonGroupFactory())                addAttributeDelegate(ButtonGroupFactory.&buttonGroupAttributeDelegate)                //  ...snip...        }        //  ...snip... }
  • 38.
  • 39. ≪sample≫ powered by NodeBuilder http://www.flickr.com/photos/timothymorgan/75294154/
  • 40. def  writer  =  new  StringWriter() new  DdlBuilder(writer).scheme  {    book  { CREATE  TABLE  book  (        id                type:int        id  INTEGER,        title          type:String        title  TEXT,        published  type:Date        published  TIMESTAMP,        author        type:int        author  INTEGER    } )    author  { CREATE  TABLE  author  (        id                type:int        id  INTEGER,        name            type:String        name  TEXT    } ) } println  writer.toString()
  • 41. class  DdlBuilder  {        def  writer        DdlBuilder(writer)  {  this.writer  =  writer  }        def  scheme(Closure  cls)  {                new  NodeBuilder().scheme(cls).each  {  table  -­‐>                        writer.println  "CREATE  TABLE  ${table.name()}  ("                        writer.println  table.collect  {  col  -­‐>                                "        ${col.name()}  ${type(col.attribute('type'))}"                        }.join(",n")                        writer.println  ")"                }        }        private  type(clazz)  {                switch  (clazz)  {                        case  String:  return  "TEXT"                        case  int:        return  "INTEGER"                        case  Date:      return  "TIMESTAMP"                        default:                            throw  new  RuntimeException("unsupported  type:  $clazz")                }        } }
  • 43.