GraphicsBuilder: multipaints - No Fluff Just Stuff

GraphicsBuilder: multipaints

Posted by: Andres Almiray on December 28, 2007

I've been reading Filthy Rich Clients for quite a while and got some inspiration with chapter 7: Gradients. Somewhere along the chapter Romain shows the power of RadialGradientPaint by creating the illusion of a sphere with 3 gradients applied on a circular shape, something like the following picture



The process for drawing such a sphere as described in the book, requires 3 different paints applied one at a time over the same shape; the way paints currently work on GraphicsBuilder is pretty straight forward: set paint, fill shape, you are done. So how can 3 paints be applied over the same shape? the answer is multiPaint. MultiPaint is a group of paint operations, like gradientPaint, radialGradient and the other paints describe here. The code used to produce the previous image follows

Notice that there is a color operation which serves a java.awt.Color factory depending on the properties you pass to it (default value for each unspecified color property is 0, 1 for alpha). Color has also been groovified with a derive method that creates a copy of the target color and changes the specified color components. Lastly, radialGradient now accepts transformations too, there are still some issues to be solved in terms of relative positions though (absolute=true).

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 »