GraphicsBuilder: more painting options - No Fluff Just Stuff

GraphicsBuilder: more painting options

Posted by: Andres Almiray on December 19, 2007

As I made my way through the code examples for previous entries on gradientPaint and linearGradient/radialGradient I felt that something was not quite right when specifying stretch and/or fit in a paint that was going to be reused later in several shapes, something had to change.

The good news is that those properties are still in the same place (albeit gradientPaint.cyclic changed to gradientPaint.cycle), the better news is that now exists a generic placeholder for paints, aptly named paint, which serves as a proxy for the wrapped paint, in the same manner shape works for Shapes inside area operations. But this wrapper allows the wrapped element to be changed because it actually clones the original Paint (shape does not allow it, I'm thinking that may change too). Here is a simple example of paint and shape, 3 rectangles are merged into a single Shape thanks to Area.add, then a previously defined paint is applied using paint, then a 4th rectangle is drawn and filled with the same paint but it changes the orientation of the gradient, finally a 5th rectangle is drawn filled with the same paint again, this time changing the cycle mode



This is the code used to create the drawing

Using asPaint=true on Paints has the same effect as asShape=true for Shapes, it means it will not execute the operation, this case setting a Paint on the java.awt.Graphics object, but creates a PaintProvider operation that can be later referenced (thanks to its id property). Note that instead of specifying a fill on Area.add we could also have used paint, with the same result.

The last stop on painting options for GraphicsBuilder will be texturePaint and because it relies on images image will be back as well.

Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »